]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #5250 from bisdhdh/bgp_nexthop_hash
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Wed, 20 Nov 2019 18:52:12 +0000 (20:52 +0200)
committerGitHub <noreply@github.com>
Wed, 20 Nov 2019 18:52:12 +0000 (20:52 +0200)
bgpd: Implementing a hash table for connected address - ipv4/ipv6

27 files changed:
doc/user/nhrpd.rst
lib/command.h
ospfd/ospf_api.c
ospfd/ospf_api.h
ospfd/ospf_asbr.c
ospfd/ospf_dump.c
ospfd/ospf_dump.h
ospfd/ospf_flood.c
ospfd/ospf_interface.c
ospfd/ospf_lsa.c
ospfd/ospf_nsm.c
ospfd/ospf_packet.c
ospfd/ospfd.c
ospfd/ospfd.h
pimd/pim_bsm.c
pimd/pim_join.c
pimd/pim_pim.c
pimd/pim_rp.c
pimd/pim_tlv.c
snapcraft/defaults/vrrpd.conf.default [new file with mode: 0644]
snapcraft/scripts/Makefile
snapcraft/scripts/vrrpd-service [new file with mode: 0644]
snapcraft/snapcraft.yaml.in
tools/frr-reload.py
vtysh/vtysh.c
zebra/rtadv.c
zebra/zebra_router.c

index 33cdbd95913a5df586d2e15d8254e5ce3ae16556..ec6bc56e7685555c22765b8a0862265510bc1486 100644 (file)
@@ -124,9 +124,9 @@ nhrpd connects to strongSwan using VICI protocol based on UNIX socket
 (hardcoded now as /var/run/charon.vici).
 
 strongSwan currently needs few patches applied. Please check out the
-`http://git.alpinelinux.org/cgit/user/tteras/strongswan/log/?h=tteras-release,release <http://git.alpinelinux.org/cgit/user/tteras/strongswan/log/?h=tteras-release,release>`_
+https://git.alpinelinux.org/user/tteras/strongswan/log/?h=tteras-release
 and
-`http://git.alpinelinux.org/cgit/user/tteras/strongswan/log/?h=tteras,working tree <http://git.alpinelinux.org/cgit/user/tteras/strongswan/log/?h=tteras,working tree>`_
+https://git.alpinelinux.org/user/tteras/strongswan/log/?h=tteras
 git repositories for the patches.
 
 .. _nhrp-events:
index 73c15469e7ddec1cdd8fab30c346d1731ec7775e..68ac86f769ad6315a9dfe480bd7cf1f5a1c22e90 100644 (file)
@@ -414,9 +414,9 @@ struct cmd_node {
 
 /* Daemons lists */
 #define DAEMONS_STR                                                            \
-       "For the zebra daemon\nFor the rip daemon\nFor the ripng daemon\nFor the ospf daemon\nFor the ospfv6 daemon\nFor the bgp daemon\nFor the isis daemon\nFor the pbr daemon\nFor the fabricd daemon\nFor the pim daemon\nFor the static daemon\nFor the sharpd daemon\nFor the vrrpd daemon\n"
+       "For the zebra daemon\nFor the rip daemon\nFor the ripng daemon\nFor the ospf daemon\nFor the ospfv6 daemon\nFor the bgp daemon\nFor the isis daemon\nFor the pbr daemon\nFor the fabricd daemon\nFor the pim daemon\nFor the static daemon\nFor the sharpd daemon\nFor the vrrpd daemon\nFor the ldpd daemon\n"
 #define DAEMONS_LIST                                                           \
-       "<zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd|fabricd|pimd|staticd|sharpd|vrrpd>"
+       "<zebra|ripd|ripngd|ospfd|ospf6d|bgpd|isisd|pbrd|fabricd|pimd|staticd|sharpd|vrrpd|ldpd>"
 
 /* Prototypes. */
 extern void install_node(struct cmd_node *, int (*)(struct vty *));
index f06e45392eb09968afe4692c93f29daf7c1fd23e..1ace0977bc349cc7efae6dd246673db0a25ced26 100644 (file)
@@ -246,13 +246,6 @@ void msg_print(struct msg *msg)
                return;
        }
 
-#ifdef ORIGINAL_CODING
-       zlog_debug(
-               "msg=%p msgtype=%d msglen=%d msgseq=%d streamdata=%p streamsize=%lu\n",
-               msg, msg->hdr.msgtype, ntohs(msg->hdr.msglen),
-               ntohl(msg->hdr.msgseq), STREAM_DATA(msg->s),
-               STREAM_SIZE(msg->s));
-#else /* ORIGINAL_CODING */
        /* API message common header part. */
        zlog_debug("API-msg [%s]: type(%d),len(%d),seq(%lu),data(%p),size(%zd)",
                   ospf_api_typename(msg->hdr.msgtype), msg->hdr.msgtype,
@@ -260,16 +253,7 @@ void msg_print(struct msg *msg)
                   (unsigned long)ntohl(msg->hdr.msgseq), STREAM_DATA(msg->s),
                   STREAM_SIZE(msg->s));
 
-/* API message body part. */
-#ifdef ndef
-       /* Generic Hex/Ascii dump */
-       DumpBuf(STREAM_DATA(msg->s), STREAM_SIZE(msg->s)); /* Sorry, deleted! */
-#else  /* ndef */
-/* Message-type dependent dump function. */
-#endif /* ndef */
-
        return;
-#endif /* ORIGINAL_CODING */
 }
 
 void msg_free(struct msg *msg)
index c99923e7b8261d5ba2959b5ecc02aa4f7d09a518..0fc683a5dbfe73c40972914a37df4b42ceacab2b 100644 (file)
@@ -140,16 +140,10 @@ struct msg_unregister_opaque_type {
  * Power2[0] is not used. */
 
 
-#ifdef ORIGINAL_CODING
-static const uint16_t Power2[] = {0x0,   0x1,    0x2,    0x4,    0x8,   0x10,
-                                 0x20,  0x40,   0x80,   0x100,  0x200, 0x400,
-                                 0x800, 0x1000, 0x2000, 0x4000, 0x8000};
-#else
 static const uint16_t Power2[] = {
        0,       (1 << 0),  (1 << 1),  (1 << 2),  (1 << 3), (1 << 4),
        (1 << 5),  (1 << 6),  (1 << 7),  (1 << 8),  (1 << 9), (1 << 10),
        (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15)};
-#endif /* ORIGINAL_CODING */
 
 struct lsa_filter_type {
        uint16_t typemask; /* bitmask for selecting LSA types (1..16) */
index ea919017d36c91394fee8e9614c12f6c719b9598..a60af36564f6974ff5c9bb756ab398f069f0e439 100644 (file)
@@ -238,20 +238,23 @@ struct ospf_lsa *ospf_external_info_find_lsa(struct ospf *ospf,
 /* Update ASBR status. */
 void ospf_asbr_status_update(struct ospf *ospf, uint8_t status)
 {
-       zlog_info("ASBR[Status:%d]: Update", status);
+       zlog_info("ASBR[%s:Status:%d]: Update",
+                 ospf_get_name(ospf), status);
 
        /* ASBR on. */
        if (status) {
                /* Already ASBR. */
                if (IS_OSPF_ASBR(ospf)) {
-                       zlog_info("ASBR[Status:%d]: Already ASBR", status);
+                       zlog_info("ASBR[%s:Status:%d]: Already ASBR",
+                                 ospf_get_name(ospf), status);
                        return;
                }
                SET_FLAG(ospf->flags, OSPF_FLAG_ASBR);
        } else {
                /* Already non ASBR. */
                if (!IS_OSPF_ASBR(ospf)) {
-                       zlog_info("ASBR[Status:%d]: Already non ASBR", status);
+                       zlog_info("ASBR[%s:Status:%d]: Already non ASBR",
+                                 ospf_get_name(ospf), status);
                        return;
                }
                UNSET_FLAG(ospf->flags, OSPF_FLAG_ASBR);
index f74d9733ee7ee07e22b73f85d3cf313189c62c13..dffcb930e450ea359c02fd46488405030f6eb3aa 100644 (file)
@@ -501,23 +501,6 @@ static void ospf_packet_ls_ack_dump(struct stream *s, uint16_t length)
        stream_set_getp(s, sp);
 }
 
-/* Expects header to be in host order */
-void ospf_ip_header_dump(struct ip *iph)
-{
-       /* IP Header dump. */
-       zlog_debug("ip_v %d", iph->ip_v);
-       zlog_debug("ip_hl %d", iph->ip_hl);
-       zlog_debug("ip_tos %d", iph->ip_tos);
-       zlog_debug("ip_len %d", iph->ip_len);
-       zlog_debug("ip_id %u", (uint32_t)iph->ip_id);
-       zlog_debug("ip_off %u", (uint32_t)iph->ip_off);
-       zlog_debug("ip_ttl %d", iph->ip_ttl);
-       zlog_debug("ip_p %d", iph->ip_p);
-       zlog_debug("ip_sum 0x%x", (uint32_t)iph->ip_sum);
-       zlog_debug("ip_src %s", inet_ntoa(iph->ip_src));
-       zlog_debug("ip_dst %s", inet_ntoa(iph->ip_dst));
-}
-
 static void ospf_header_dump(struct ospf_header *ospfh)
 {
        char buf[9];
index 397f666f6907e845bc7548a22dce88608cb92118..6b2ebb125a76d6807b8a8fa186aa9a94a9de87ae 100644 (file)
        (conf_debug_ospf_packet[a] & OSPF_DEBUG_##b)
 #define IS_CONF_DEBUG_OSPF(a, b) (conf_debug_ospf_##a & OSPF_DEBUG_##b)
 
-#ifdef ORIGINAL_CODING
-#else  /* ORIGINAL_CODING */
-struct stream;
-#endif /* ORIGINAL_CODING */
-
 #define AREA_NAME(A)    ospf_area_name_string ((A))
 #define IF_NAME(I)      ospf_if_name_string ((I))
 
@@ -138,7 +133,6 @@ extern const char *ospf_if_name_string(struct ospf_interface *);
 extern void ospf_nbr_state_message(struct ospf_neighbor *, char *, size_t);
 extern const char *ospf_timer_dump(struct thread *, char *, size_t);
 extern const char *ospf_timeval_dump(struct timeval *, char *, size_t);
-extern void ospf_ip_header_dump(struct ip *);
 extern void ospf_packet_dump(struct stream *);
 extern void ospf_debug_init(void);
 
index 1d85a0498400981dbc06e530f22e4b474621fea1..381fb6820fbe311ef3c465a412b39835ce5d385f 100644 (file)
@@ -157,9 +157,9 @@ static void ospf_process_self_originated_lsa(struct ospf *ospf,
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug(
-                       "LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
-                       new->data->type, inet_ntoa(new->data->id),
-                       ntohl(new->data->ls_seqnum));
+                       "%s:LSA[Type%d:%s]: Process self-originated LSA seq 0x%x",
+                       ospf_get_name(ospf), new->data->type,
+                       inet_ntoa(new->data->id), ntohl(new->data->ls_seqnum));
 
        /* If we're here, we installed a self-originated LSA that we received
           from a neighbor, i.e. it's more recent.  We must see whether we want
@@ -276,8 +276,8 @@ int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr,
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug(
-                       "LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
-                       inet_ntoa(nbr->router_id),
+                       "%s:LSA[Flooding]: start, NBR %s (%s), cur(%p), New-LSA[%s]",
+                       ospf_get_name(ospf), inet_ntoa(nbr->router_id),
                        lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
                        (void *)current, dump_lsa_key(new));
 
@@ -295,15 +295,16 @@ int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr,
                                   == OSPF_INITIAL_SEQUENCE_NUMBER)) {
                        if (IS_DEBUG_OSPF_EVENT)
                                zlog_debug(
-                                       "LSA[Flooding]: Got a self-originated LSA, "
-                                       "while local one is initial instance.");
+                                       "%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.",
+                                       ospf_get_name(ospf));
                        ; /* Accept this LSA for quick LSDB resynchronization.
                             */
                } else if (monotime_since(&current->tv_recv, NULL)
                           < ospf->min_ls_arrival * 1000LL) {
                        if (IS_DEBUG_OSPF_EVENT)
                                zlog_debug(
-                                       "LSA[Flooding]: LSA is received recently.");
+                                       "%s:LSA[Flooding]: LSA is received recently.",
+                                       ospf_get_name(ospf));
                        return -1;
                }
        }
@@ -376,9 +377,8 @@ static int ospf_flood_through_interface(struct ospf_interface *oi,
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug(
-                       "ospf_flood_through_interface(): "
-                       "considering int %s, INBR(%s), LSA[%s] AGE %u",
-                       IF_NAME(oi), inbr ? inet_ntoa(inbr->router_id) : "NULL",
+                       "%s:ospf_flood_through_interface(): considering int %s, INBR(%s), LSA[%s] AGE %u",
+                       ospf_get_name(oi->ospf), IF_NAME(oi), inbr ? inet_ntoa(inbr->router_id) : "NULL",
                        dump_lsa_key(lsa), ntohs(lsa->data->ls_age));
 
        if (!ospf_if_is_enable(oi))
@@ -399,8 +399,9 @@ static int ospf_flood_through_interface(struct ospf_interface *oi,
                onbr = rn->info;
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
-                               "ospf_flood_through_interface(): considering nbr %s (%s)",
+                               "ospf_flood_through_interface(): considering nbr %s(%s) (%s)",
                                inet_ntoa(onbr->router_id),
+                               ospf_get_name(oi->ospf),
                                lookup_msg(ospf_nsm_state_msg, onbr->state,
                                           NULL));
 
@@ -454,13 +455,8 @@ static int ospf_flood_through_interface(struct ospf_interface *oi,
                        }
                }
 
-/* If the new LSA was received from this neighbor,
-   examine the next neighbor. */
-#ifdef ORIGINAL_CODING
-               if (inbr)
-                       if (IPV4_ADDR_SAME(&inbr->router_id, &onbr->router_id))
-                               continue;
-#else  /* ORIGINAL_CODING */
+ /* If the new LSA was received from this neighbor,
+    examine the next neighbor. */
                if (inbr) {
                        /*
                         * Triggered by LSUpd message parser "ospf_ls_upd ()".
@@ -486,7 +482,6 @@ static int ospf_flood_through_interface(struct ospf_interface *oi,
                                continue;
                        }
                }
-#endif /* ORIGINAL_CODING */
 
                /* Add the new LSA to the Link state retransmission list
                   for the adjacency. The LSA will be retransmitted
@@ -691,43 +686,14 @@ int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr,
 {
        int lsa_ack_flag = 0;
 
-/* Type-7 LSA's for NSSA are flooded throughout the AS here, and
-   upon return are updated in the LSDB for Type-7's.  Later,
-   re-fresh will re-send them (and also, if ABR, packet code will
-   translate to Type-5's)
+       /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
+          upon return are updated in the LSDB for Type-7's.  Later,
+          re-fresh will re-send them (and also, if ABR, packet code will
+          translate to Type-5's)
 
-   As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
-   NSSA) are flooded throughout the AS, and are updated in the
-   global table.  */
-#ifdef ORIGINAL_CODING
-       switch (lsa->data->type) {
-       case OSPF_ROUTER_LSA:
-       case OSPF_NETWORK_LSA:
-       case OSPF_SUMMARY_LSA:
-       case OSPF_ASBR_SUMMARY_LSA:
-       case OSPF_OPAQUE_LINK_LSA: /* ospf_flood_through_interface ? */
-       case OSPF_OPAQUE_AREA_LSA:
-               lsa_ack_flag =
-                       ospf_flood_through_area(inbr->oi->area, inbr, lsa);
-               break;
-       case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
-       case OSPF_OPAQUE_AS_LSA:
-               lsa_ack_flag = ospf_flood_through_as(ospf, inbr, lsa);
-               break;
-       /* Type-7 Only received within NSSA, then flooded */
-       case OSPF_AS_NSSA_LSA:
-               /* Any P-bit was installed with the Type-7. */
-               lsa_ack_flag =
-                       ospf_flood_through_area(inbr->oi->area, inbr, lsa);
-
-               if (IS_DEBUG_OSPF_NSSA)
-                       zlog_debug(
-                               "ospf_flood_through: LOCAL NSSA FLOOD of Type-7.");
-               break;
-       default:
-               break;
-       }
-#else  /* ORIGINAL_CODING */
+          As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
+          NSSA) are flooded throughout the AS, and are updated in the
+          global table.  */
        /*
         * At the common sub-sub-function "ospf_flood_through_interface()",
         * a parameter "inbr" will be used to distinguish the called context
@@ -757,7 +723,6 @@ int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr,
                lsa_ack_flag = ospf_flood_through_area(lsa->area, inbr, lsa);
                break;
        }
-#endif /* ORIGINAL_CODING */
 
        return (lsa_ack_flag);
 }
@@ -773,9 +738,10 @@ void ospf_ls_request_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
         * the common function "ospf_lsdb_add()" -- endo.
         */
        if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
-               zlog_debug("RqstL(%lu)++, NBR(%s), LSA[%s]",
+               zlog_debug("RqstL(%lu)++, NBR(%s(%s)), LSA[%s]",
                           ospf_ls_request_count(nbr),
-                          inet_ntoa(nbr->router_id), dump_lsa_key(lsa));
+                          inet_ntoa(nbr->router_id),
+                          ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa));
 
        ospf_lsdb_add(&nbr->ls_req, lsa);
 }
@@ -799,9 +765,10 @@ void ospf_ls_request_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
        }
 
        if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
-               zlog_debug("RqstL(%lu)--, NBR(%s), LSA[%s]",
+               zlog_debug("RqstL(%lu)--, NBR(%s(%s)), LSA[%s]",
                           ospf_ls_request_count(nbr),
-                          inet_ntoa(nbr->router_id), dump_lsa_key(lsa));
+                          inet_ntoa(nbr->router_id),
+                          ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa));
 
        ospf_lsdb_delete(&nbr->ls_req, lsa);
 }
@@ -859,6 +826,12 @@ void ospf_ls_retransmit_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
        if (ospf_lsa_more_recent(old, lsa) < 0) {
                if (old) {
                        old->retransmit_counter--;
+                       if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
+                               zlog_debug("RXmtL(%lu)--, NBR(%s(%s)), LSA[%s]",
+                                          ospf_ls_retransmit_count(nbr),
+                                          inet_ntoa(nbr->router_id),
+                                          ospf_get_name(nbr->oi->ospf),
+                                          dump_lsa_key(old));
                        ospf_lsdb_delete(&nbr->ls_rxmt, old);
                }
                lsa->retransmit_counter++;
@@ -871,9 +844,10 @@ void ospf_ls_retransmit_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
                 * the common function "ospf_lsdb_add()" -- endo.
                 */
                if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
-                       zlog_debug("RXmtL(%lu)++, NBR(%s), LSA[%s]",
+                       zlog_debug("RXmtL(%lu)++, NBR(%s(%s)), LSA[%s]",
                                   ospf_ls_retransmit_count(nbr),
                                   inet_ntoa(nbr->router_id),
+                                  ospf_get_name(nbr->oi->ospf),
                                   dump_lsa_key(lsa));
                ospf_lsdb_add(&nbr->ls_rxmt, lsa);
        }
@@ -885,9 +859,10 @@ void ospf_ls_retransmit_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
        if (ospf_ls_retransmit_lookup(nbr, lsa)) {
                lsa->retransmit_counter--;
                if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
-                       zlog_debug("RXmtL(%lu)--, NBR(%s), LSA[%s]",
+                       zlog_debug("RXmtL(%lu)--, NBR(%s(%s)), LSA[%s]",
                                   ospf_ls_retransmit_count(nbr),
                                   inet_ntoa(nbr->router_id),
+                                  ospf_get_name(nbr->oi->ospf),
                                   dump_lsa_key(lsa));
                ospf_lsdb_delete(&nbr->ls_rxmt, lsa);
        }
index 5459e3b87c5d4ed87b298eed2cd2398b5fae42a6..7ddffbcdbdc36d289b076f7a8ac27cd2d762cae1 100644 (file)
@@ -273,7 +273,7 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug("%s: ospf interface %s vrf %s id %u created",
                           __PRETTY_FUNCTION__, ifp->name,
-                          ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id);
+                          ospf_get_name(ospf), ospf->vrf_id);
 
        return oi;
 }
@@ -832,7 +832,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
        struct prefix_ipv4 *p;
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("ospf_vl_new(): Start");
+               zlog_debug("ospf_vl_new()(%s): Start", ospf_get_name(ospf));
        if (vlink_count == OSPF_VL_MAX_COUNT) {
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
index 5ab0927e71071f06d5d75fbf144564f6cc510824..3e3f288023961ae6318c3a1337d1890c4c0bceeb 100644 (file)
@@ -3202,45 +3202,6 @@ int ospf_lsa_different(struct ospf_lsa *l1, struct ospf_lsa *l2)
        return 0;
 }
 
-#ifdef ORIGINAL_CODING
-void ospf_lsa_flush_self_originated(struct ospf_neighbor *nbr,
-                                   struct ospf_lsa *self, struct ospf_lsa *new)
-{
-       uint32_t seqnum;
-
-       /* Adjust LS Sequence Number. */
-       seqnum = ntohl(new->data->ls_seqnum) + 1;
-       self->data->ls_seqnum = htonl(seqnum);
-
-       /* Recalculate LSA checksum. */
-       ospf_lsa_checksum(self->data);
-
-       /* Reflooding LSA. */
-       /*  RFC2328  Section 13.3
-                 On non-broadcast networks, separate   Link State Update
-                 packets must be sent, as unicasts, to each adjacent   neighbor
-                 (i.e., those in state Exchange or greater).    The destination
-                 IP addresses for these packets are the neighbors' IP
-                 addresses.   */
-       if (nbr->oi->type == OSPF_IFTYPE_NBMA) {
-               struct route_node *rn;
-               struct ospf_neighbor *onbr;
-
-               for (rn = route_top(nbr->oi->nbrs); rn; rn = route_next(rn))
-                       if ((onbr = rn->info) != NULL)
-                               if (onbr != nbr->oi->nbr_self
-                                   && onbr->status >= NSM_Exchange)
-                                       ospf_ls_upd_send_lsa(
-                                               onbr, self,
-                                               OSPF_SEND_PACKET_DIRECT);
-       } else
-               ospf_ls_upd_send_lsa(nbr, self, OSPF_SEND_PACKET_INDIRECT);
-
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-               zlog_debug("LSA[Type%d:%s]: Flush self-originated LSA",
-                          self->data->type, inet_ntoa(self->data->id));
-}
-#else  /* ORIGINAL_CODING */
 int ospf_lsa_flush_schedule(struct ospf *ospf, struct ospf_lsa *lsa)
 {
        if (lsa == NULL || !IS_LSA_SELF(lsa))
@@ -3345,7 +3306,6 @@ void ospf_flush_self_originated_lsas_now(struct ospf *ospf)
 
        return;
 }
-#endif /* ORIGINAL_CODING */
 
 /* If there is self-originated LSA, then return 1, otherwise return 0. */
 /* An interface-independent version of ospf_lsa_is_self_originated */
index 00174b638eaff8c5fe317a6b32b9922f1a1401f4..110738802c5db15fe3f7587feb8922a02b96479f 100644 (file)
@@ -65,8 +65,9 @@ static int ospf_inactivity_timer(struct thread *thread)
        nbr->t_inactivity = NULL;
 
        if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
-               zlog_debug("NSM[%s:%s]: Timer (Inactivity timer expire)",
-                          IF_NAME(nbr->oi), inet_ntoa(nbr->router_id));
+               zlog_debug("NSM[%s:%s:%s]: Timer (Inactivity timer expire)",
+                          IF_NAME(nbr->oi), inet_ntoa(nbr->router_id),
+                          ospf_get_name(nbr->oi->ospf));
 
        OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_InactivityTimer);
 
@@ -81,8 +82,9 @@ static int ospf_db_desc_timer(struct thread *thread)
        nbr->t_db_desc = NULL;
 
        if (IS_DEBUG_OSPF(nsm, NSM_TIMERS))
-               zlog_debug("NSM[%s:%s]: Timer (DD Retransmit timer expire)",
-                          IF_NAME(nbr->oi), inet_ntoa(nbr->src));
+               zlog_debug("NSM[%s:%s:%s]: Timer (DD Retransmit timer expire)",
+                          IF_NAME(nbr->oi), inet_ntoa(nbr->src),
+                          ospf_get_name(nbr->oi->ospf));
 
        /* resent last send DD packet. */
        assert(nbr->last_send);
@@ -387,9 +389,10 @@ static int nsm_kill_nbr(struct ospf_neighbor *nbr)
 
                if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
                        zlog_debug(
-                               "NSM[%s:%s]: Down (PollIntervalTimer scheduled)",
+                               "NSM[%s:%s:%s]: Down (PollIntervalTimer scheduled)",
                                IF_NAME(nbr->oi),
-                               inet_ntoa(nbr->address.u.prefix4));
+                               inet_ntoa(nbr->address.u.prefix4),
+                               ospf_get_name(nbr->oi->ospf));
        }
 
        return 0;
@@ -585,8 +588,9 @@ static void nsm_notice_state_change(struct ospf_neighbor *nbr, int next_state,
 {
        /* Logging change of status. */
        if (IS_DEBUG_OSPF(nsm, NSM_STATUS))
-               zlog_debug("NSM[%s:%s]: State change %s -> %s (%s)",
+               zlog_debug("NSM[%s:%s:%s]: State change %s -> %s (%s)",
                           IF_NAME(nbr->oi), inet_ntoa(nbr->router_id),
+                          ospf_get_name(nbr->oi->ospf),
                           lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
                           lookup_msg(ospf_nsm_state_msg, next_state, NULL),
                           ospf_nsm_event_str[event]);
@@ -595,8 +599,9 @@ static void nsm_notice_state_change(struct ospf_neighbor *nbr, int next_state,
        if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES)
            && (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL)
                || (next_state == NSM_Full) || (next_state < nbr->state)))
-               zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",
-                           inet_ntoa(nbr->router_id), IF_NAME(nbr->oi),
+               zlog_notice("AdjChg: Nbr %s(%s) on %s: %s -> %s (%s)",
+                           inet_ntoa(nbr->router_id),
+                           ospf_get_name(nbr->oi->ospf), IF_NAME(nbr->oi),
                            lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
                            lookup_msg(ospf_nsm_state_msg, next_state, NULL),
                            ospf_nsm_event_str[event]);
@@ -677,9 +682,10 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state)
 
                if (CHECK_FLAG(oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
                        zlog_info(
-                               "%s:(%s, %s -> %s): "
+                               "%s:[%s:%s], %s -> %s): "
                                "scheduling new router-LSA origination",
                                __PRETTY_FUNCTION__, inet_ntoa(nbr->router_id),
+                               ospf_get_name(oi->ospf),
                                lookup_msg(ospf_nsm_state_msg, old_state, NULL),
                                lookup_msg(ospf_nsm_state_msg, state, NULL));
 
@@ -753,8 +759,9 @@ int ospf_nsm_event(struct thread *thread)
        event = THREAD_VAL(thread);
 
        if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
-               zlog_debug("NSM[%s:%s]: %s (%s)", IF_NAME(nbr->oi),
+               zlog_debug("NSM[%s:%s:%s]: %s (%s)", IF_NAME(nbr->oi),
                           inet_ntoa(nbr->router_id),
+                          ospf_get_name(nbr->oi->ospf),
                           lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
                           ospf_nsm_event_str[event]);
 
@@ -777,9 +784,10 @@ int ospf_nsm_event(struct thread *thread)
                         */
                        flog_err(
                                EC_OSPF_FSM_INVALID_STATE,
-                               "NSM[%s:%s]: %s (%s): "
+                               "NSM[%s:%s:%s]: %s (%s): "
                                "Warning: action tried to change next_state to %s",
                                IF_NAME(nbr->oi), inet_ntoa(nbr->router_id),
+                               ospf_get_name(nbr->oi->ospf),
                                lookup_msg(ospf_nsm_state_msg, nbr->state,
                                           NULL),
                                ospf_nsm_event_str[event],
index 453135cb4d89a34c8ab1a32c4023fb1478a5ace8..8634589b11c3c5e0b1320d1b8134c80a6024b312 100644 (file)
@@ -614,13 +614,6 @@ static void ospf_write_frags(int fd, struct ospf_packet *op, struct ip *iph,
                                "ospf_write_frags: sent id %d, off %d, len %d to %s\n",
                                iph->ip_id, iph->ip_off, iph->ip_len,
                                inet_ntoa(iph->ip_dst));
-                       if (IS_DEBUG_OSPF_PACKET(type - 1, DETAIL)) {
-                               zlog_debug(
-                                       "-----------------IP Header Dump----------------------");
-                               ospf_ip_header_dump(iph);
-                               zlog_debug(
-                                       "-----------------------------------------------------");
-                       }
                }
 
                iph->ip_off += offset;
@@ -824,7 +817,6 @@ static int ospf_write(struct thread *thread)
                        if (IS_DEBUG_OSPF_PACKET(type - 1, DETAIL)) {
                                zlog_debug(
                                        "-----------------------------------------------------");
-                               ospf_ip_header_dump(&iph);
                                stream_set_getp(op->s, 0);
                                ospf_packet_dump(op->s);
                        }
@@ -1505,10 +1497,6 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
 
                /* Check DD Options. */
                if (dd->options != nbr->options) {
-#ifdef ORIGINAL_CODING
-                       /* Save the new options for debugging */
-                       nbr->options = dd->options;
-#endif /* ORIGINAL_CODING */
                        flog_warn(EC_OSPF_PACKET,
                                  "Packet[DD]: Neighbor %s options mismatch.",
                                  inet_ntoa(nbr->router_id));
@@ -2322,10 +2310,12 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd,
        msgh.msg_control = (caddr_t)buff;
        msgh.msg_controllen = sizeof(buff);
 
-       ret = stream_recvmsg(ibuf, fd, &msgh, 0, OSPF_MAX_PACKET_SIZE + 1);
+       ret = stream_recvmsg(ibuf, fd, &msgh, MSG_DONTWAIT,
+                            OSPF_MAX_PACKET_SIZE + 1);
        if (ret < 0) {
-               flog_warn(EC_OSPF_PACKET, "stream_recvmsg failed: %s",
-                         safe_strerror(errno));
+               if (errno != EAGAIN && errno != EWOULDBLOCK)
+                       flog_warn(EC_OSPF_PACKET, "stream_recvmsg failed: %s",
+                                 safe_strerror(errno));
                return NULL;
        }
        if ((unsigned int)ret < sizeof(iph)) /* ret must be > 0 now */
@@ -2385,6 +2375,10 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd,
                return NULL;
        }
 
+       if (IS_DEBUG_OSPF_PACKET(0, RECV))
+               zlog_debug("%s: fd %d(%s) on interface %d(%s)",
+                          __PRETTY_FUNCTION__, fd, ospf_get_name(ospf),
+                          ifindex, *ifp ? (*ifp)->name : "Unknown");
        return ibuf;
 }
 
@@ -2943,56 +2937,60 @@ static int ospf_verify_header(struct stream *ibuf, struct ospf_interface *oi,
        return 0;
 }
 
-/* Starting point of packet process function. */
-int ospf_read(struct thread *thread)
+enum ospf_read_return_enum {
+       OSPF_READ_ERROR,
+       OSPF_READ_CONTINUE,
+};
+
+static enum ospf_read_return_enum ospf_read_helper(struct ospf *ospf)
 {
        int ret;
        struct stream *ibuf;
-       struct ospf *ospf;
        struct ospf_interface *oi;
        struct ip *iph;
        struct ospf_header *ospfh;
        uint16_t length;
-       struct interface *ifp = NULL;
        struct connected *c;
-
-       /* first of all get interface pointer. */
-       ospf = THREAD_ARG(thread);
-
-       /* prepare for next packet. */
-       ospf->t_read = NULL;
-       thread_add_read(master, ospf_read, ospf, ospf->fd, &ospf->t_read);
+       struct interface *ifp = NULL;
 
        stream_reset(ospf->ibuf);
        ibuf = ospf_recv_packet(ospf, ospf->fd, &ifp, ospf->ibuf);
        if (ibuf == NULL)
-               return -1;
-       /* This raw packet is known to be at least as big as its IP header. */
+               return OSPF_READ_ERROR;
 
-       /* Note that there should not be alignment problems with this assignment
-          because this is at the beginning of the stream data buffer. */
+       /*
+        * This raw packet is known to be at least as big as its
+        * IP header. Note that there should not be alignment problems with
+        * this assignment because this is at the beginning of the
+        * stream data buffer.
+        */
        iph = (struct ip *)STREAM_DATA(ibuf);
-       /* Note that sockopt_iphdrincl_swab_systoh was called in
-        * ospf_recv_packet. */
-
+       /*
+        * Note that sockopt_iphdrincl_swab_systoh was called in
+        * ospf_recv_packet.
+        */
        if (ifp == NULL) {
-               /* Handle cases where the platform does not support retrieving
-                  the ifindex,
-                  and also platforms (such as Solaris 8) that claim to support
-                  ifindex
-                  retrieval but do not. */
+               /*
+                * Handle cases where the platform does not support
+                * retrieving the ifindex, and also platforms (such as
+                * Solaris 8) that claim to support ifindex retrieval but do
+                * not.
+                */
                c = if_lookup_address((void *)&iph->ip_src, AF_INET,
                                      ospf->vrf_id);
                if (c)
                        ifp = c->ifp;
-               if (ifp == NULL)
-                       return 0;
+               if (ifp == NULL) {
+                       if (IS_DEBUG_OSPF_PACKET(0, RECV))
+                               zlog_debug(
+                                       "%s: Unable to determine incoming interface from: %s(%s)",
+                                       __PRETTY_FUNCTION__,
+                                       inet_ntoa(iph->ip_src),
+                                       ospf_get_name(ospf));
+                       return OSPF_READ_CONTINUE;
+               }
        }
 
-       /* IP Header dump. */
-       if (IS_DEBUG_OSPF_PACKET(0, RECV))
-               ospf_ip_header_dump(iph);
-
        /* Self-originated packet should be discarded silently. */
        if (ospf_if_lookup_by_local_addr(ospf, NULL, iph->ip_src)) {
                if (IS_DEBUG_OSPF_PACKET(0, RECV)) {
@@ -3000,30 +2998,32 @@ int ospf_read(struct thread *thread)
                                "ospf_read[%s]: Dropping self-originated packet",
                                inet_ntoa(iph->ip_src));
                }
-               return 0;
+               return OSPF_READ_CONTINUE;
        }
 
-       /* Advance from IP header to OSPF header (iph->ip_hl has been verified
-          by ospf_recv_packet() to be correct). */
+       /*
+        * Advance from IP header to OSPF header (iph->ip_hl has
+        * been verified by ospf_recv_packet() to be correct).
+        */
        stream_forward_getp(ibuf, iph->ip_hl * 4);
 
        ospfh = (struct ospf_header *)stream_pnt(ibuf);
        if (MSG_OK
-           != ospf_packet_examin(
-                      ospfh, stream_get_endp(ibuf) - stream_get_getp(ibuf)))
-               return -1;
+           != ospf_packet_examin(ospfh, stream_get_endp(ibuf)
+                                                - stream_get_getp(ibuf)))
+               return OSPF_READ_CONTINUE;
        /* Now it is safe to access all fields of OSPF packet header. */
 
        /* associate packet with ospf interface */
        oi = ospf_if_lookup_recv_if(ospf, iph->ip_src, ifp);
 
-       /* ospf_verify_header() relies on a valid "oi" and thus can be called
-          only
-          after the passive/backbone/other checks below are passed. These
-          checks
-          in turn access the fields of unverified "ospfh" structure for their
-          own
-          purposes and must remain very accurate in doing this. */
+       /*
+        * ospf_verify_header() relies on a valid "oi" and thus can be called
+        * only after the passive/backbone/other checks below are passed.
+        * These checks in turn access the fields of unverified "ospfh"
+        * structure for their own purposes and must remain very accurate
+        * in doing this.
+        */
 
        /* If incoming interface is passive one, ignore it. */
        if (oi && OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_PASSIVE) {
@@ -3031,8 +3031,7 @@ int ospf_read(struct thread *thread)
 
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
-                               "ignoring packet from router %s sent to %s, "
-                               "received on a passive interface, %s",
+                               "ignoring packet from router %s sent to %s, received on a passive interface, %s",
                                inet_ntop(AF_INET, &ospfh->router_id, buf[0],
                                          sizeof(buf[0])),
                                inet_ntop(AF_INET, &iph->ip_dst, buf[1],
@@ -3048,7 +3047,7 @@ int ospf_read(struct thread *thread)
                        OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
                        ospf_if_set_multicast(oi);
                }
-               return 0;
+               return OSPF_READ_CONTINUE;
        }
 
 
@@ -3056,34 +3055,35 @@ int ospf_read(struct thread *thread)
         * or header area is backbone but ospf_interface is not
         * check for VLINK interface
         */
-       if ((oi == NULL) || (OSPF_IS_AREA_ID_BACKBONE(ospfh->area_id)
-                            && !OSPF_IS_AREA_ID_BACKBONE(oi->area->area_id))) {
+       if ((oi == NULL)
+           || (OSPF_IS_AREA_ID_BACKBONE(ospfh->area_id)
+               && !OSPF_IS_AREA_ID_BACKBONE(oi->area->area_id))) {
                if ((oi = ospf_associate_packet_vl(ospf, ifp, iph, ospfh))
                    == NULL) {
                        if (!ospf->instance && IS_DEBUG_OSPF_EVENT)
                                zlog_debug(
-                                       "Packet from [%s] received on link %s"
-                                       " but no ospf_interface",
+                                       "Packet from [%s] received on link %s but no ospf_interface",
                                        inet_ntoa(iph->ip_src), ifp->name);
-                       return 0;
+                       return OSPF_READ_CONTINUE;
                }
        }
 
-       /* else it must be a local ospf interface, check it was received on
-        * correct link
+       /*
+        * else it must be a local ospf interface, check it was
+        * received on correct link
         */
        else if (oi->ifp != ifp) {
                if (IS_DEBUG_OSPF_EVENT)
                        flog_warn(EC_OSPF_PACKET,
                                  "Packet from [%s] received on wrong link %s",
                                  inet_ntoa(iph->ip_src), ifp->name);
-               return 0;
+               return OSPF_READ_CONTINUE;
        } else if (oi->state == ISM_Down) {
                char buf[2][INET_ADDRSTRLEN];
+
                flog_warn(
                        EC_OSPF_PACKET,
-                       "Ignoring packet from %s to %s received on interface that is "
-                       "down [%s]; interface flags are %s",
+                       "Ignoring packet from %s to %s received on interface that is down [%s]; interface flags are %s",
                        inet_ntop(AF_INET, &iph->ip_src, buf[0],
                                  sizeof(buf[0])),
                        inet_ntop(AF_INET, &iph->ip_dst, buf[1],
@@ -3096,13 +3096,15 @@ int ospf_read(struct thread *thread)
                        OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
                if (oi->multicast_memberships)
                        ospf_if_set_multicast(oi);
-               return 0;
+               return OSPF_READ_CONTINUE;
        }
 
        /*
-        * If the received packet is destined for AllDRouters, the packet
-        * should be accepted only if the received ospf interface state is
-        * either DR or Backup -- endo.
+        * If the received packet is destined for AllDRouters, the
+        * packet should be accepted only if the received ospf
+        * interface state is either DR or Backup -- endo.
+        *
+        * I wonder who endo is?
         */
        if (iph->ip_dst.s_addr == htonl(OSPF_ALLDROUTERS)
            && (oi->state != ISM_DR && oi->state != ISM_Backup)) {
@@ -3114,7 +3116,7 @@ int ospf_read(struct thread *thread)
                /* Try to fix multicast membership. */
                SET_FLAG(oi->multicast_memberships, MEMBER_DROUTERS);
                ospf_if_set_multicast(oi);
-               return 0;
+               return OSPF_READ_CONTINUE;
        }
 
        /* Verify more OSPF header fields. */
@@ -3125,7 +3127,7 @@ int ospf_read(struct thread *thread)
                                "ospf_read[%s]: Header check failed, "
                                "dropping.",
                                inet_ntoa(iph->ip_src));
-               return ret;
+               return OSPF_READ_CONTINUE;
        }
 
        /* Show debug receiving packet. */
@@ -3152,7 +3154,8 @@ int ospf_read(struct thread *thread)
        /* Adjust size to message length. */
        length = ntohs(ospfh->length) - OSPF_HEADER_SIZE;
 
-       /* Read rest of the packet and call each sort of packet routine. */
+       /* Read rest of the packet and call each sort of packet routine.
+        */
        switch (ospfh->type) {
        case OSPF_MSG_HELLO:
                ospf_hello(iph, ospfh, ibuf, oi, length);
@@ -3170,12 +3173,41 @@ int ospf_read(struct thread *thread)
                ospf_ls_ack(iph, ospfh, ibuf, oi, length);
                break;
        default:
-               flog_warn(EC_OSPF_PACKET,
-                         "interface %s: OSPF packet header type %d is illegal",
-                         IF_NAME(oi), ospfh->type);
+               flog_warn(
+                       EC_OSPF_PACKET,
+                       "interface %s(%s): OSPF packet header type %d is illegal",
+                       IF_NAME(oi), ospf_get_name(ospf), ospfh->type);
                break;
        }
 
+       return OSPF_READ_CONTINUE;
+}
+
+/* Starting point of packet process function. */
+int ospf_read(struct thread *thread)
+{
+       struct ospf *ospf;
+       int32_t count = 0;
+       enum ospf_read_return_enum ret;
+
+       /* first of all get interface pointer. */
+       ospf = THREAD_ARG(thread);
+
+       /* prepare for next packet. */
+       thread_add_read(master, ospf_read, ospf, ospf->fd, &ospf->t_read);
+
+       while (count < ospf->write_oi_count) {
+               count++;
+               ret = ospf_read_helper(ospf);
+               switch (ret) {
+               case OSPF_READ_ERROR:
+                       return -1;
+                       break;
+               case OSPF_READ_CONTINUE:
+                       break;
+               }
+       }
+
        return 0;
 }
 
index b12fa63723639b9bd1fc6f317d31d191f142a67c..5058886f362b32465cef555088932276e72d061b 100644 (file)
@@ -2173,3 +2173,11 @@ const char *ospf_vrf_id_to_name(vrf_id_t vrf_id)
 
        return vrf ? vrf->name : "NIL";
 }
+
+const char *ospf_get_name(const struct ospf *ospf)
+{
+       if (ospf->name)
+               return ospf->name;
+       else
+               return VRF_DEFAULT_NAME;
+}
index b31ad303758d175f4e80abfa0f986da016a1ef69..937d363b4c2030b293f006ec6889c6b5e0009072 100644 (file)
@@ -572,4 +572,5 @@ extern void ospf_vrf_unlink(struct ospf *ospf, struct vrf *vrf);
 const char *ospf_vrf_id_to_name(vrf_id_t vrf_id);
 int ospf_area_nssa_no_summary_set(struct ospf *, struct in_addr);
 
+const char *ospf_get_name(const struct ospf *ospf);
 #endif /* _ZEBRA_OSPFD_H */
index 1383e3db116e41933e46b47f1b65c95917ae7d2f..4a69e4d1abc43f2d050480582be5f5b97fc4b5a3 100644 (file)
@@ -1111,6 +1111,13 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf,
        int ins_count = 0;
 
        while (buflen > offset) {
+               if (offset + (int)sizeof(struct bsmmsg_grpinfo) > buflen) {
+                       if (PIM_DEBUG_BSM)
+                               zlog_debug(
+                                       "%s: buflen received %d is less than the internal data structure of the packet would suggest",
+                                       __PRETTY_FUNCTION__, buflen);
+                       return false;
+               }
                /* Extract Group tlv from BSM */
                memcpy(&grpinfo, buf, sizeof(struct bsmmsg_grpinfo));
 
@@ -1142,6 +1149,12 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf,
                }
 
                group.family = AF_INET;
+               if (grpinfo.group.mask > IPV4_MAX_BITLEN) {
+                       if (PIM_DEBUG_BSM)
+                               zlog_debug("%s, v4 prefix length specified: %d is too long",
+                                          __PRETTY_FUNCTION__, grpinfo.group.mask);
+                       return false;
+               }
                group.prefixlen = grpinfo.group.mask;
                group.u.prefix4.s_addr = grpinfo.group.addr.s_addr;
 
@@ -1174,6 +1187,15 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf,
                ins_count = 0;
 
                while (frag_rp_cnt--) {
+                       if (offset + (int)sizeof(struct bsmmsg_rpinfo)
+                           > buflen) {
+                               if (PIM_DEBUG_BSM)
+                                       zlog_debug(
+                                               "%s, buflen received: %u is less than the internal data structure of the packet would suggest",
+                                               __PRETTY_FUNCTION__, buflen);
+                               return false;
+                       }
+
                        /* Extract RP address tlv from BSM */
                        memcpy(&rpinfo, buf, sizeof(struct bsmmsg_rpinfo));
                        rpinfo.rp_holdtime = ntohs(rpinfo.rp_holdtime);
@@ -1245,6 +1267,13 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf,
                return -1;
        }
 
+       if (buf_size < (PIM_MSG_HEADER_LEN + sizeof(struct bsm_hdr))) {
+               if (PIM_DEBUG_BSM)
+                       zlog_debug("%s: received buffer length of %d which is too small to properly decode",
+                                  __PRETTY_FUNCTION__, buf_size);
+               return -1;
+       }
+
        bshdr = (struct bsm_hdr *)(buf + PIM_MSG_HEADER_LEN);
        pim_inet4_dump("<bsr?>", bshdr->bsr_addr.addr, bsr_str,
                       sizeof(bsr_str));
index 842d6684b53caba438ac34a715da3ce9aed7ea8b..89be42842ee32f1e5c23b046f2a5ea6fd6e1d0c9 100644 (file)
@@ -83,6 +83,11 @@ static void recv_join(struct interface *ifp, struct pim_neighbor *neigh,
            && (source_flags & PIM_WILDCARD_BIT_MASK)) {
                struct pim_rpf *rp = RP(pim_ifp->pim, sg->grp);
 
+               if (!rp) {
+                       zlog_warn("%s: Lookup of RP failed for %pSG4",
+                                 __PRETTY_FUNCTION__, sg);
+                       return;
+               }
                /*
                 * If the RP sent in the message is not
                 * our RP for the group, drop the message
@@ -136,6 +141,12 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh,
            && (source_flags & PIM_WILDCARD_BIT_MASK)) {
                struct pim_rpf *rp = RP(pim_ifp->pim, sg->grp);
 
+               if (!rp) {
+                       if (PIM_DEBUG_PIM_TRACE)
+                               zlog_debug("%s: RP for %pSG4 completely failed lookup",
+                                          __PRETTY_FUNCTION__, sg);
+                       return;
+               }
                // Ignoring Prune *,G's at the moment.
                if (sg->src.s_addr != rp->rpf_addr.u.prefix4.s_addr)
                        return;
index cd2d306f3db2e52b931e953a3ff1dd38e8edd2a8..342c0a74e049fd3554ffbff5eb424d4a8a8dda56 100644 (file)
@@ -190,6 +190,12 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len)
        no_fwd = header->Nbit;
 
        if (header->type == PIM_MSG_TYPE_REGISTER) {
+               if (pim_msg_len < PIM_MSG_REGISTER_LEN) {
+                       if (PIM_DEBUG_PIM_PACKETS)
+                               zlog_debug("PIM Register Message size=%d shorther than min length %d",
+                                          pim_msg_len, PIM_MSG_REGISTER_LEN);
+                       return -1;
+               }
                /* First 8 byte header checksum */
                checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN);
                if (checksum != pim_checksum) {
index 39493b189b20155ab714d3ae61a9f7ef3ca9737b..09529055e059b8bdeda25a69a2fce5559fa0cd28 100644 (file)
@@ -1192,8 +1192,8 @@ int pim_rp_set_upstream_addr(struct pim_instance *pim, struct in_addr *up,
 
        rp_info = pim_rp_find_match_group(pim, &g);
 
-       if ((pim_rpf_addr_is_inaddr_none(&rp_info->rp))
-           && (source.s_addr == INADDR_ANY)) {
+       if (!rp_info || ((pim_rpf_addr_is_inaddr_none(&rp_info->rp))
+                        && (source.s_addr == INADDR_ANY))) {
                if (PIM_DEBUG_PIM_NHT_RP)
                        zlog_debug("%s: Received a (*,G) with no RP configured",
                                   __PRETTY_FUNCTION__);
index 4fe3237395ec47a5db322cc904d1dae20c094f97..93e1cc1f8d5dbbc266f09009da2204d8d62570fa 100644 (file)
@@ -603,9 +603,9 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags,
 
        if (type) {
                zlog_warn(
-                       "%s: unknown source address encoding type=%d: %02x%02x%02x%02x%02x%02x%02x%02x",
+                       "%s: unknown source address encoding type=%d: %02x%02x%02x%02x",
                        __PRETTY_FUNCTION__, type, buf[0], buf[1], buf[2],
-                       buf[3], buf[4], buf[5], buf[6], buf[7]);
+                       buf[3]);
                return -2;
        }
 
@@ -644,9 +644,9 @@ int pim_parse_addr_source(struct prefix_sg *sg, uint8_t *flags,
                break;
        default: {
                zlog_warn(
-                       "%s: unknown source address encoding family=%d: %02x%02x%02x%02x%02x%02x%02x%02x",
+                       "%s: unknown source address encoding family=%d: %02x%02x%02x%02x",
                        __PRETTY_FUNCTION__, family, buf[0], buf[1], buf[2],
-                       buf[3], buf[4], buf[5], buf[6], buf[7]);
+                       buf[3]);
                return -5;
        }
        }
diff --git a/snapcraft/defaults/vrrpd.conf.default b/snapcraft/defaults/vrrpd.conf.default
new file mode 100644 (file)
index 0000000..e69de29
index 7ddb7f0769fe12c70bc70582dfa7d1534d550129..0435b3bc52fafcb6379826bd3f5efce0d7cb3ff0 100644 (file)
@@ -18,6 +18,7 @@ install:
        install -D -m 0755 staticd-service $(DESTDIR)/bin/
        install -D -m 0755 bfdd-service $(DESTDIR)/bin/
        install -D -m 0755 fabricd-service $(DESTDIR)/bin/
+       install -D -m 0755 vrrpd-service $(DESTDIR)/bin/
        install -D -m 0755 set-options $(DESTDIR)/bin/
        install -D -m 0755 show_version $(DESTDIR)/bin/
 
diff --git a/snapcraft/scripts/vrrpd-service b/snapcraft/scripts/vrrpd-service
new file mode 100644 (file)
index 0000000..1f60d11
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e -x
+
+if ! [ -e $SNAP_DATA/vrrpd.conf ]; then
+    cp $SNAP/etc/frr/vrrpd.conf.default $SNAP_DATA/vrrpd.conf
+fi
+exec $SNAP/sbin/vrrpd \
+    -f $SNAP_DATA/vrrpd.conf \
+    --pid_file $SNAP_DATA/vrrpd.pid \
+    --socket $SNAP_DATA/zsock \
+    --vty_socket $SNAP_DATA
+
index d8071e8cfee596c6572759be050331b130fd9e3c..b06e841f74496c30c042cdd0a3d0d4df0e86a170 100644 (file)
@@ -134,6 +134,13 @@ apps:
             - network
             - network-bind
             - network-control
+    vrrpd:
+        command: bin/vrrpd-service
+        daemon: simple
+        plugs:
+            - network
+            - network-bind
+            - network-control
     set:
         command: bin/set-options
     zebra-debug:
@@ -232,7 +239,12 @@ apps:
             - network
             - network-bind
             - network-control
-
+    vrrpd-debug:
+        command: sbin/vrrpd -f $SNAP_DATA/vrrpd.conf --pid_file $SNAP_DATA/vrrpd.pid --socket $SNAP_DATA/zsock --vty_socket $SNAP_DATA
+        plugs:
+            - network
+            - network-bind
+            - network-control
 parts:
     rtrlib:
         build-packages:
@@ -327,6 +339,7 @@ parts:
             - --enable-fpm
             - --enable-protobuf
             - --enable-rpki
+            - --enable-vrrpd
             - --enable-configfile-mask=0640
             - --enable-logfile-mask=0640 
             - --localstatedir=/var/run
@@ -353,6 +366,7 @@ parts:
             pbrd.conf.default: etc/frr/pbrd.conf.default
             bfdd.conf.default: etc/frr/bfdd.conf.default
             fabricd.conf.default: etc/frr/fabricd.conf.default
+            vrrpd.conf.default: etc/frr/vrrpd.conf.default
             vtysh.conf.default: etc/frr/vtysh.conf.default
             staticd.conf.default: etc/frr/staticd.conf.default
     frr-scripts:
index f5784b7ecdcfda728965874f837bfb6a7af1c2f0..412cde091099e543441aecba048c790dd472480f 100755 (executable)
@@ -114,7 +114,7 @@ class Config(object):
         self.lines = []
         self.contexts = OrderedDict()
 
-    def load_from_file(self, filename):
+    def load_from_file(self, filename, bindir, confdir):
         """
         Read configuration from specified file and slurp it into internal memory
         The internal representation has been marked appropriately by passing it
@@ -123,7 +123,7 @@ class Config(object):
         log.info('Loading Config object from file %s', filename)
 
         try:
-            file_output = subprocess.check_output(['/usr/bin/vtysh', '-m', '-f', filename],
+            file_output = subprocess.check_output([str(bindir + '/vtysh'), '-m', '-f', filename, '--config_dir', confdir],
                                                   stderr=subprocess.STDOUT)
         except subprocess.CalledProcessError as e:
             ve = VtyshMarkException(e)
@@ -144,7 +144,7 @@ class Config(object):
 
         self.load_contexts()
 
-    def load_from_show_running(self):
+    def load_from_show_running(self, bindir, confdir, daemon):
         """
         Read running configuration and slurp it into internal memory
         The internal representation has been marked appropriately by passing it
@@ -154,7 +154,7 @@ class Config(object):
 
         try:
             config_text = subprocess.check_output(
-                "/usr/bin/vtysh -c 'show run' | /usr/bin/tail -n +4 | /usr/bin/vtysh -m -f -",
+                bindir + "/vtysh --config_dir " + confdir + " -c 'show run " + daemon + "' | /usr/bin/tail -n +4 | " + bindir + "/vtysh --config_dir " + confdir + " -m -f -",
                 shell=True, stderr=subprocess.STDOUT)
         except subprocess.CalledProcessError as e:
             ve = VtyshMarkException(e)
@@ -404,7 +404,8 @@ end
                                 "ip ",
                                 "ipv6 ",
                                 "log ",
-                                "mpls",
+                                "mpls lsp",
+                                "mpls label",
                                 "no ",
                                 "password ",
                                 "ptm-enable",
@@ -424,7 +425,12 @@ end
                 continue
 
             # one line contexts
-            if new_ctx is True and any(line.startswith(keyword) for keyword in oneline_ctx_keywords):
+            # there is one exception though: ldpd accepts a 'router-id' clause
+            # as part of its 'mpls ldp' config context. If we are processing
+            # ldp configuration and encounter a router-id we should NOT switch
+            # to a new context
+            if new_ctx is True and any(line.startswith(keyword) for keyword in oneline_ctx_keywords) and not (
+                ctx_keys and ctx_keys[0].startswith("mpls ldp") and line.startswith("router-id ")):
                 self.save_contexts(ctx_keys, current_context_lines)
 
                 # Start a new context
@@ -467,7 +473,7 @@ end
                     current_context_lines = []
                     log.debug('LINE %-50s: popping from subcontext to ctx%-50s', line, ctx_keys)
 
-            elif line == "exit-vni":
+            elif line in ["exit-vni", "exit-ldp-if"]:
                 if sub_main_ctx_key:
                     self.save_contexts(ctx_keys, current_context_lines)
 
@@ -489,7 +495,8 @@ end
             elif (line.startswith("address-family ") or
                   line.startswith("vnc defaults") or
                   line.startswith("vnc l2-group") or
-                  line.startswith("vnc nve-group")):
+                  line.startswith("vnc nve-group") or
+                  line.startswith("member pseudowire")):
                 main_ctx_key = []
 
                 # Save old context first
@@ -498,9 +505,9 @@ end
                 main_ctx_key = copy.deepcopy(ctx_keys)
                 log.debug('LINE %-50s: entering sub-context, append to ctx_keys', line)
 
-                if line == "address-family ipv6":
+                if line == "address-family ipv6" and not ctx_keys[0].startswith("mpls ldp"):
                     ctx_keys.append("address-family ipv6 unicast")
-                elif line == "address-family ipv4":
+                elif line == "address-family ipv4" and not ctx_keys[0].startswith("mpls ldp"):
                     ctx_keys.append("address-family ipv4 unicast")
                 elif line == "address-family evpn":
                     ctx_keys.append("address-family l2vpn evpn")
@@ -518,6 +525,18 @@ end
                 sub_main_ctx_key = copy.deepcopy(ctx_keys)
                 log.debug('LINE %-50s: entering sub-sub-context, append to ctx_keys', line)
                 ctx_keys.append(line)
+            
+            elif ((line.startswith("interface ") and
+                   len(ctx_keys) == 2 and
+                   ctx_keys[0].startswith('mpls ldp') and
+                   ctx_keys[1].startswith('address-family'))):
+
+                # Save old context first
+                self.save_contexts(ctx_keys, current_context_lines)
+                current_context_lines = []
+                sub_main_ctx_key = copy.deepcopy(ctx_keys)
+                log.debug('LINE %-50s: entering sub-sub-context, append to ctx_keys', line)
+                ctx_keys.append(line)
 
             else:
                 # Continuing in an existing context, add non-commented lines to it
@@ -528,13 +547,15 @@ end
         self.save_contexts(ctx_keys, current_context_lines)
 
 
-def line_to_vtysh_conft(ctx_keys, line, delete):
+def line_to_vtysh_conft(ctx_keys, line, delete, bindir, confdir):
     """
     Return the vtysh command for the specified context line
     """
 
     cmd = []
-    cmd.append('vtysh')
+    cmd.append(str(bindir + '/vtysh'))
+    cmd.append('--config_dir')
+    cmd.append(confdir)
     cmd.append('-c')
     cmd.append('conf t')
 
@@ -755,9 +776,10 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del):
                 if re_nbr_bfd_timers:
                     nbr = re_nbr_bfd_timers.group(1)
                     bfd_nbr = "neighbor %s" % nbr
+                    bfd_search_string =  bfd_nbr + r' bfd (\S+) (\S+) (\S+)'
 
                     for (ctx_keys, add_line) in lines_to_add:
-                        re_add_nbr_bfd_timers = re.search(r'neighbor bfd_nbr bfd (\S+) (\S+) (\S+)', add_line)
+                        re_add_nbr_bfd_timers = re.search(bfd_search_string, add_line)
 
                         if re_add_nbr_bfd_timers:
                             found_add_bfd_nbr = line_exist(lines_to_add, ctx_keys, bfd_nbr, False)
@@ -1074,7 +1096,7 @@ def compare_context_objects(newconf, running):
 
 
 
-def vtysh_config_available():
+def vtysh_config_available(bindir, confdir):
     """
     Return False if no frr daemon is running or some other vtysh session is
     in 'configuration terminal' mode which will prevent us from making any
@@ -1082,7 +1104,7 @@ def vtysh_config_available():
     """
 
     try:
-        cmd = ['/usr/bin/vtysh', '-c', 'conf t']
+        cmd = [str(bindir + '/vtysh'), '--config_dir', confdir, '-c', 'conf t']
         output = subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
 
         if 'VTY configuration is locked by other VTY' in output.decode('utf-8'):
@@ -1110,6 +1132,11 @@ if __name__ == '__main__':
     parser.add_argument('--stdout', action='store_true', help='Log to STDOUT', default=False)
     parser.add_argument('filename', help='Location of new frr config file')
     parser.add_argument('--overwrite', action='store_true', help='Overwrite frr.conf with running config output', default=False)
+    parser.add_argument('--bindir', help='path to the vtysh executable', default='/usr/bin')
+    parser.add_argument('--confdir', help='path to the daemon config files', default='/etc/frr')
+    parser.add_argument('--rundir', help='path for the temp config file', default='/var/run/frr')
+    parser.add_argument('--daemon', help='daemon for which want to replace the config', default='')
+
     args = parser.parse_args()
 
     # Logging
@@ -1149,8 +1176,29 @@ if __name__ == '__main__':
         log.error(msg)
         sys.exit(1)
 
+    # Verify that confdir is correct
+    if not os.path.isdir(args.confdir):
+        msg = "Confdir %s is not a valid path" % args.confdir
+        print(msg)
+        log.error(msg)
+        sys.exit(1)
+
+    # Verify that bindir is correct
+    if not os.path.isdir(args.bindir) or not os.path.isfile(args.bindir + '/vtysh'):
+        msg = "Bindir %s is not a valid path to vtysh" % args.bindir
+        print(msg)
+        log.error(msg)
+        sys.exit(1)
+
+    # verify that the daemon, if specified, is valid
+    if args.daemon and args.daemon not in ['zebra', 'bgpd', 'fabricd', 'isisd', 'ospf6d', 'ospfd', 'pbrd', 'pimd', 'ripd', 'ripngd', 'sharpd', 'staticd', 'vrrpd', 'ldpd']:
+        msg = "Daemon %s is not a valid option for 'show running-config'" % args.daemon
+        print(msg)
+        log.error(msg)
+        sys.exit(1)
+
     # Verify that 'service integrated-vtysh-config' is configured
-    vtysh_filename = '/etc/frr/vtysh.conf'
+    vtysh_filename = args.confdir + '/vtysh.conf'
     service_integrated_vtysh_config = True
 
     if os.path.isfile(vtysh_filename):
@@ -1162,7 +1210,7 @@ if __name__ == '__main__':
                     service_integrated_vtysh_config = False
                     break
 
-    if not service_integrated_vtysh_config:
+    if not service_integrated_vtysh_config and not args.daemon:
         msg = "'service integrated-vtysh-config' is not configured, this is required for 'service frr reload'"
         print(msg)
         log.error(msg)
@@ -1175,7 +1223,7 @@ if __name__ == '__main__':
 
     # Create a Config object from the config generated by newconf
     newconf = Config()
-    newconf.load_from_file(args.filename)
+    newconf.load_from_file(args.filename, args.bindir, args.confdir)
     reload_ok = True
 
     if args.test:
@@ -1184,9 +1232,9 @@ if __name__ == '__main__':
         running = Config()
 
         if args.input:
-            running.load_from_file(args.input)
+            running.load_from_file(args.input, args.bindir, args.confdir)
         else:
-            running.load_from_show_running()
+            running.load_from_show_running(args.bindir, args.confdir, args.daemon)
 
         (lines_to_add, lines_to_del) = compare_context_objects(newconf, running)
         lines_to_configure = []
@@ -1220,7 +1268,7 @@ if __name__ == '__main__':
     elif args.reload:
 
         # We will not be able to do anything, go ahead and exit(1)
-        if not vtysh_config_available():
+        if not vtysh_config_available(args.bindir, args.confdir):
             sys.exit(1)
 
         log.debug('New Frr Config\n%s', newconf.get_lines())
@@ -1264,7 +1312,7 @@ if __name__ == '__main__':
 
         for x in range(2):
             running = Config()
-            running.load_from_show_running()
+            running.load_from_show_running(args.bindir, args.confdir, args.daemon)
             log.debug('Running Frr Config (Pass #%d)\n%s', x, running.get_lines())
 
             (lines_to_add, lines_to_del) = compare_context_objects(newconf, running)
@@ -1296,7 +1344,7 @@ if __name__ == '__main__':
                     # 'no' commands are tricky, we can't just put them in a file and
                     # vtysh -f that file. See the next comment for an explanation
                     # of their quirks
-                    cmd = line_to_vtysh_conft(ctx_keys, line, True)
+                    cmd = line_to_vtysh_conft(ctx_keys, line, True, args.bindir, args.confdir)
                     original_cmd = cmd
 
                     # Some commands in frr are picky about taking a "no" of the entire line.
@@ -1352,7 +1400,7 @@ if __name__ == '__main__':
                                             string.ascii_uppercase +
                                             string.digits) for _ in range(6))
 
-                    filename = "/var/run/frr/reload-%s.txt" % random_string
+                    filename = args.rundir + "/reload-%s.txt" % random_string
                     log.info("%s content\n%s" % (filename, pformat(lines_to_configure)))
 
                     with open(filename, 'w') as fh:
@@ -1360,15 +1408,16 @@ if __name__ == '__main__':
                             fh.write(line + '\n')
 
                     try:
-                        subprocess.check_output(['/usr/bin/vtysh', '-f', filename], stderr=subprocess.STDOUT)
+                        subprocess.check_output([str(args.bindir + '/vtysh'), '--config_dir', args.confdir, '-f', filename], stderr=subprocess.STDOUT)
                     except subprocess.CalledProcessError as e:
                         log.warning("frr-reload.py failed due to\n%s" % e.output)
                         reload_ok = False
                     os.unlink(filename)
 
         # Make these changes persistent
-        if args.overwrite or args.filename != '/etc/frr/frr.conf':
-            subprocess.call(['/usr/bin/vtysh', '-c', 'write'])
+        target = str(args.confdir + '/frr.conf')
+        if args.overwrite or (not args.daemon and args.filename != target):
+            subprocess.call([str(args.bindir + '/vtysh'), '--config_dir', args.confdir, '-c', 'write'])
 
     if not reload_ok:
         sys.exit(1)
index 643dcb7edc6cce2aa7b601599d47efdc039f6c1e..5c4e8a313b04de5cd840a24d40d60ce586172daf 100644 (file)
@@ -725,19 +725,19 @@ int vtysh_mark_file(const char *filename)
                switch (vty->node) {
                case LDP_IPV4_IFACE_NODE:
                        if (strncmp(vty_buf_copy, "   ", 3)) {
-                               vty_out(vty, "  end\n");
+                               vty_out(vty, " exit-ldp-if\n");
                                vty->node = LDP_IPV4_NODE;
                        }
                        break;
                case LDP_IPV6_IFACE_NODE:
                        if (strncmp(vty_buf_copy, "   ", 3)) {
-                               vty_out(vty, "  end\n");
+                               vty_out(vty, " exit-ldp-if\n");
                                vty->node = LDP_IPV6_NODE;
                        }
                        break;
                case LDP_PSEUDOWIRE_NODE:
                        if (strncmp(vty_buf_copy, "  ", 2)) {
-                               vty_out(vty, " end\n");
+                               vty_out(vty, " exit\n");
                                vty->node = LDP_L2VPN_NODE;
                        }
                        break;
index 2228fcfd3f959a20fd83e9f0bf9dc8b9ce77da3d..4903455a2b9b5a49d35e30cf90fcca2887371b12 100644 (file)
@@ -2120,14 +2120,8 @@ static void rtadv_event(struct zebra_vrf *zvrf, enum rtadv_event event, int val)
                                 &rtadv->ra_timer);
                break;
        case RTADV_STOP:
-               if (rtadv->ra_timer) {
-                       thread_cancel(rtadv->ra_timer);
-                       rtadv->ra_timer = NULL;
-               }
-               if (rtadv->ra_read) {
-                       thread_cancel(rtadv->ra_read);
-                       rtadv->ra_read = NULL;
-               }
+               THREAD_OFF(rtadv->ra_timer);
+               THREAD_OFF(rtadv->ra_read);
                break;
        case RTADV_TIMER:
                thread_add_timer(zrouter.master, rtadv_timer, zvrf, val,
@@ -2152,10 +2146,11 @@ void rtadv_init(struct zebra_vrf *zvrf)
        if (vrf_is_backend_netns()) {
                zvrf->rtadv.sock = rtadv_make_socket(zvrf->zns->ns_id);
                zrouter.rtadv_sock = -1;
-       } else if (!zrouter.rtadv_sock) {
+       } else {
                zvrf->rtadv.sock = -1;
-               if (!zrouter.rtadv_sock)
-                       zrouter.rtadv_sock = rtadv_make_socket(zvrf->zns->ns_id);
+               if (zrouter.rtadv_sock < 0)
+                       zrouter.rtadv_sock =
+                               rtadv_make_socket(zvrf->zns->ns_id);
        }
 }
 
index e5319c64af031452f90c21d782f8143a1037b7b5..e573093b70d4c1b35d98d4a7c56907d105965e97 100644 (file)
@@ -245,6 +245,8 @@ void zebra_router_init(void)
 
        zrouter.packets_to_process = ZEBRA_ZAPI_PACKETS_TO_PROCESS;
 
+       zrouter.rtadv_sock = -1;
+
        zebra_vxlan_init();
        zebra_mlag_init();