]> git.puffer.fish Git - matthieu/frr.git/commitdiff
nhrp: fix protocol address family parsing on receive
authorTimo Teräs <timo.teras@iki.fi>
Thu, 20 Apr 2017 13:24:14 +0000 (16:24 +0300)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 25 Apr 2017 12:33:11 +0000 (08:33 -0400)
See bugzilla #948

nhrpd/nhrp_peer.c

index 4c1d97a4898e51a9988f5bb91e1fb05ff437b57f..1f624eba0b1ba4899104bc9c4d2654c7c7d4c65d 100644 (file)
@@ -730,6 +730,15 @@ static void nhrp_packet_debug(struct zbuf *zb, const char *dir)
                reply ? buf[0] : buf[1]);
 }
 
+static int proto2afi(uint16_t proto)
+{
+       switch (proto) {
+       case ETH_P_IP: return AFI_IP;
+       case ETH_P_IPV6: return AFI_IP6;
+       }
+       return AF_UNSPEC;
+}
+
 struct nhrp_route_info {
        int local;
        struct interface *ifp;
@@ -749,7 +758,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb)
        const char *info = NULL;
        union sockunion *target_addr;
        unsigned paylen, extoff, extlen, realsize;
-       afi_t afi;
+       afi_t nbma_afi, proto_afi;
 
        debugf(NHRP_DEBUG_KERNEL, "PACKET: Recv %s -> %s",
                sockunion2str(&vc->remote.nbma, buf[0], sizeof buf[0]),
@@ -777,20 +786,21 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb)
        pp.hdr = hdr;
        pp.peer = p;
 
-       afi = htons(hdr->afnum);
+       nbma_afi = htons(hdr->afnum);
+       proto_afi = proto2afi(htons(hdr->protocol_type));
        if (hdr->type > ZEBRA_NUM_OF(packet_types) ||
            hdr->version != NHRP_VERSION_RFC2332 ||
-           afi >= AFI_MAX ||
+           nbma_afi >= AFI_MAX || proto_afi == AF_UNSPEC ||
            packet_types[hdr->type].type == PACKET_UNKNOWN ||
            htons(hdr->packet_size) > realsize) {
-               zlog_info("From %s: error: packet type %d, version %d, AFI %d, size %d (real size %d)",
+               zlog_info("From %s: error: packet type %d, version %d, AFI %d, proto %x, size %d (real size %d)",
                           sockunion2str(&vc->remote.nbma, buf[0], sizeof buf[0]),
-                          (int) hdr->type, (int) hdr->version, (int) afi,
-                          (int) htons(hdr->packet_size),
-                          (int) realsize);
+                          (int) hdr->type, (int) hdr->version,
+                          (int) nbma_afi, (int) htons(hdr->protocol_type),
+                          (int) htons(hdr->packet_size), (int) realsize);
                goto drop;
        }
-       pp.if_ad = &((struct nhrp_interface *)ifp->info)->afi[afi];
+       pp.if_ad = &((struct nhrp_interface *)ifp->info)->afi[proto_afi];
 
        extoff = htons(hdr->extension_offset);
        if (extoff) {
@@ -806,7 +816,7 @@ void nhrp_peer_recv(struct nhrp_peer *p, struct zbuf *zb)
        extlen = zbuf_used(zb);
        zbuf_init(&pp.extensions, zbuf_pulln(zb, extlen), extlen, extlen);
 
-       if (!nifp->afi[afi].network_id) {
+       if (!nifp->afi[proto_afi].network_id) {
                info = "nhrp not enabled";
                goto drop;
        }