]> git.proxmox.com Git - mirror_frr.git/blobdiff - eigrpd/eigrp_packet.c
zebra: Allow ns delete to happen after under/over flow checks
[mirror_frr.git] / eigrpd / eigrp_packet.c
index e2cd44429e2457a14efcd37758a730425e5d4364..f3b583abdde65cfddf1e33793abb4f0223b7c67d 100644 (file)
@@ -42,6 +42,7 @@
 #include "checksum.h"
 #include "md5.h"
 #include "sha256.h"
+#include "lib_errors.h"
 
 #include "eigrpd/eigrp_structs.h"
 #include "eigrpd/eigrpd.h"
 #include "eigrpd/eigrp_zebra.h"
 #include "eigrpd/eigrp_vty.h"
 #include "eigrpd/eigrp_dump.h"
+#include "eigrpd/eigrp_macros.h"
 #include "eigrpd/eigrp_network.h"
 #include "eigrpd/eigrp_topology.h"
 #include "eigrpd/eigrp_fsm.h"
 #include "eigrpd/eigrp_memory.h"
+#include "eigrpd/eigrp_errors.h"
 
 /* Packet Type String. */
 const struct message eigrp_packet_type_str[] = {
@@ -87,14 +90,14 @@ static int eigrp_retrans_count_exceeded(struct eigrp_packet *ep,
 }
 
 int eigrp_make_md5_digest(struct eigrp_interface *ei, struct stream *s,
-                         u_char flags)
+                         uint8_t flags)
 {
        struct key *key = NULL;
        struct keychain *keychain;
 
        unsigned char digest[EIGRP_AUTH_TYPE_MD5_LEN];
        MD5_CTX ctx;
-       u_char *ibuf;
+       uint8_t *ibuf;
        size_t backup_get, backup_end;
        struct TLV_MD5_Authentication_Type *auth_TLV;
 
@@ -157,14 +160,14 @@ int eigrp_make_md5_digest(struct eigrp_interface *ei, struct stream *s,
 
 int eigrp_check_md5_digest(struct stream *s,
                           struct TLV_MD5_Authentication_Type *authTLV,
-                          struct eigrp_neighbor *nbr, u_char flags)
+                          struct eigrp_neighbor *nbr, uint8_t flags)
 {
        MD5_CTX ctx;
        unsigned char digest[EIGRP_AUTH_TYPE_MD5_LEN];
        unsigned char orig[EIGRP_AUTH_TYPE_MD5_LEN];
        struct key *key = NULL;
        struct keychain *keychain;
-       u_char *ibuf;
+       uint8_t *ibuf;
        size_t backup_end;
        struct TLV_MD5_Authentication_Type *auth_TLV;
        struct eigrp_header *eigrph;
@@ -242,7 +245,7 @@ int eigrp_check_md5_digest(struct stream *s,
 }
 
 int eigrp_make_sha256_digest(struct eigrp_interface *ei, struct stream *s,
-                            u_char flags)
+                            uint8_t flags)
 {
        struct key *key = NULL;
        struct keychain *keychain;
@@ -304,7 +307,7 @@ int eigrp_make_sha256_digest(struct eigrp_interface *ei, struct stream *s,
 
 int eigrp_check_sha256_digest(struct stream *s,
                              struct TLV_SHA256_Authentication_Type *authTLV,
-                             struct eigrp_neighbor *nbr, u_char flags)
+                             struct eigrp_neighbor *nbr, uint8_t flags)
 {
        return 1;
 }
@@ -319,13 +322,13 @@ int eigrp_write(struct thread *thread)
        struct ip iph;
        struct msghdr msg;
        struct iovec iov[2];
-       u_int32_t seqno, ack;
+       uint32_t seqno, ack;
 
        int ret;
        int flags = 0;
        struct listnode *node;
 #ifdef WANT_EIGRP_WRITE_FRAGMENT
-       static u_int16_t ipid = 0;
+       static uint16_t ipid = 0;
 #endif /* WANT_EIGRP_WRITE_FRAGMENT */
 #define EIGRP_WRITE_IPHL_SHIFT 2
 
@@ -345,12 +348,14 @@ int eigrp_write(struct thread *thread)
        /* Get one packet from queue. */
        ep = eigrp_fifo_next(ei->obuf);
        if (!ep) {
-               zlog_err("%s: Interface %s no packet on queue?",
+               flog_err(EC_LIB_DEVELOPMENT,
+                        "%s: Interface %s no packet on queue?",
                         __PRETTY_FUNCTION__, ei->ifp->name);
                goto out;
        }
        if (ep->length < EIGRP_HEADER_LEN) {
-               zlog_err("%s: Packet just has a header?", __PRETTY_FUNCTION__);
+               flog_err(EC_EIGRP_PACKET, "%s: Packet just has a header?",
+                        __PRETTY_FUNCTION__);
                eigrp_header_dump((struct eigrp_header *)ep->s->data);
                eigrp_packet_delete(ei);
                goto out;
@@ -479,8 +484,8 @@ int eigrp_read(struct thread *thread)
        struct interface *ifp;
        struct eigrp_neighbor *nbr;
 
-       u_int16_t opcode = 0;
-       u_int16_t length = 0;
+       uint16_t opcode = 0;
+       uint16_t length = 0;
 
        /* first of all get interface pointer. */
        eigrp = THREAD_ARG(thread);
@@ -565,7 +570,7 @@ int eigrp_read(struct thread *thread)
        //    return -1;
 
        /* If incoming interface is passive one, ignore it. */
-       if (ei && eigrp_if_is_passive(ei)) {
+       if (eigrp_if_is_passive(ei)) {
                char buf[3][INET_ADDRSTRLEN];
 
                if (IS_DEBUG_EIGRP_TRANSMIT(0, RECV))
@@ -706,7 +711,7 @@ static struct stream *eigrp_recv_packet(int fd, struct interface **ifp,
 {
        int ret;
        struct ip *iph;
-       u_int16_t ip_len;
+       uint16_t ip_len;
        unsigned int ifindex = 0;
        struct iovec iov;
        /* Header and data both require alignment. */
@@ -724,12 +729,12 @@ static struct stream *eigrp_recv_packet(int fd, struct interface **ifp,
                zlog_warn("stream_recvmsg failed: %s", safe_strerror(errno));
                return NULL;
        }
-       if ((unsigned int)ret < sizeof(iph)) /* ret must be > 0 now */
+       if ((unsigned int)ret < sizeof(*iph)) /* ret must be > 0 now */
        {
                zlog_warn(
                        "eigrp_recv_packet: discarding runt packet of length %d "
                        "(ip header size is %u)",
-                       ret, (u_int)sizeof(iph));
+                       ret, (unsigned int)sizeof(*iph));
                return NULL;
        }
 
@@ -864,7 +869,7 @@ void eigrp_send_packet_reliably(struct eigrp_neighbor *nbr)
 
 /* Calculate EIGRP checksum */
 void eigrp_packet_checksum(struct eigrp_interface *ei, struct stream *s,
-                          u_int16_t length)
+                          uint16_t length)
 {
        struct eigrp_header *eigrph;
 
@@ -876,16 +881,15 @@ void eigrp_packet_checksum(struct eigrp_interface *ei, struct stream *s,
 
 /* Make EIGRP header. */
 void eigrp_packet_header_init(int type, struct eigrp *eigrp, struct stream *s,
-                             u_int32_t flags, u_int32_t sequence,
-                             u_int32_t ack)
+                             uint32_t flags, uint32_t sequence, uint32_t ack)
 {
        struct eigrp_header *eigrph;
 
        stream_reset(s);
        eigrph = (struct eigrp_header *)STREAM_DATA(s);
 
-       eigrph->version = (u_char)EIGRP_HEADER_VERSION;
-       eigrph->opcode = (u_char)type;
+       eigrph->version = (uint8_t)EIGRP_HEADER_VERSION;
+       eigrph->opcode = (uint8_t)type;
        eigrph->checksum = 0;
 
        eigrph->vrid = htons(eigrp->vrid);
@@ -944,8 +948,6 @@ void eigrp_packet_free(struct eigrp_packet *ep)
        THREAD_OFF(ep->t_retrans_timer);
 
        XFREE(MTYPE_EIGRP_PACKET, ep);
-
-       ep = NULL;
 }
 
 /* EIGRP Header verification. */
@@ -1089,7 +1091,7 @@ struct eigrp_packet *eigrp_packet_duplicate(struct eigrp_packet *old,
 {
        struct eigrp_packet *new;
 
-       new = eigrp_packet_new(nbr->ei->ifp->mtu, nbr);
+       new = eigrp_packet_new(EIGRP_PACKET_MTU(nbr->ei->ifp->mtu), nbr);
        new->length = old->length;
        new->retrans_counter = old->retrans_counter;
        new->dst = old->dst;
@@ -1159,10 +1161,10 @@ struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s)
        return tlv;
 }
 
-u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s,
-                                         struct eigrp_prefix_entry *pe)
+uint16_t eigrp_add_internalTLV_to_stream(struct stream *s,
+                                        struct eigrp_prefix_entry *pe)
 {
-       u_int16_t length;
+       uint16_t length;
 
        stream_putw(s, EIGRP_TLV_IPv4_INT);
        switch (pe->destination->prefixlen) {
@@ -1212,7 +1214,7 @@ u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s,
                stream_putw(s, length);
                break;
        default:
-               zlog_err("%s: Unexpected prefix length: %d",
+               flog_err(EC_LIB_DEVELOPMENT, "%s: Unexpected prefix length: %d",
                         __PRETTY_FUNCTION__, pe->destination->prefixlen);
                return 0;
        }
@@ -1245,8 +1247,8 @@ u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s,
        return length;
 }
 
-u_int16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s,
-                                         struct eigrp_interface *ei)
+uint16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s,
+                                        struct eigrp_interface *ei)
 {
        struct key *key;
        struct keychain *keychain;
@@ -1285,8 +1287,8 @@ u_int16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s,
        return 0;
 }
 
-u_int16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s,
-                                            struct eigrp_interface *ei)
+uint16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s,
+                                           struct eigrp_interface *ei)
 {
        struct key *key;
        struct keychain *keychain;