diff options
355 files changed, 6290 insertions, 4144 deletions
diff --git a/babeld/babeld.c b/babeld/babeld.c index 0104620cd5..a1e00bfb85 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -49,11 +49,11 @@ THE SOFTWARE. DEFINE_MGROUP(BABELD, "babeld"); DEFINE_MTYPE_STATIC(BABELD, BABEL, "Babel Structure"); -static int babel_init_routing_process(struct thread *thread); +static void babel_init_routing_process(struct thread *thread); static void babel_get_myid(void); static void babel_initial_noise(void); -static int babel_read_protocol (struct thread *thread); -static int babel_main_loop(struct thread *thread); +static void babel_read_protocol(struct thread *thread); +static void babel_main_loop(struct thread *thread); static void babel_set_timer(struct timeval *timeout); static void babel_fill_with_next_timeout(struct timeval *tv); static void @@ -175,8 +175,7 @@ fail: } /* thread reading entries form others babel daemons */ -static int -babel_read_protocol (struct thread *thread) +static void babel_read_protocol(struct thread *thread) { int rc; struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); @@ -207,14 +206,12 @@ babel_read_protocol (struct thread *thread) /* re-add thread */ thread_add_read(master, &babel_read_protocol, NULL, protocol_socket, &babel_routing_process->t_read); - return 0; } /* Zebra will give some information, especially about interfaces. This function must be call with a litte timeout wich may give zebra the time to do his job, making these inits have sense. */ -static int -babel_init_routing_process(struct thread *thread) +static void babel_init_routing_process(struct thread *thread) { myseqno = (frr_weak_random() & 0xFFFF); babel_get_myid(); @@ -222,7 +219,6 @@ babel_init_routing_process(struct thread *thread) debugf(BABEL_DEBUG_COMMON, "My ID is : %s.", format_eui64(myid)); babel_initial_noise(); babel_main_loop(thread);/* this function self-add to the t_update thread */ - return 0; } /* fill "myid" with an unique id (only if myid != {0}). */ @@ -327,8 +323,7 @@ babel_clean_routing_process(void) } /* Function used with timeout. */ -static int -babel_main_loop(struct thread *thread) +static void babel_main_loop(struct thread *thread) { struct timeval tv; struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); @@ -348,8 +343,8 @@ babel_main_loop(struct thread *thread) /* it happens often to have less than 1 ms, it's bad. */ timeval_add_msec(&tv, &tv, 300); babel_set_timer(&tv); - return 0; - } + return; + } gettime(&babel_now); @@ -410,7 +405,6 @@ babel_main_loop(struct thread *thread) } assert(0); /* this line should never be reach */ - return 0; } static void diff --git a/bfdd/bfd.c b/bfdd/bfd.c index fbe0436b50..455dd9fe85 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -609,27 +609,23 @@ struct bfd_session *ptm_bfd_sess_find(struct bfd_pkt *cp, return bfd_key_lookup(key); } -int bfd_xmt_cb(struct thread *t) +void bfd_xmt_cb(struct thread *t) { struct bfd_session *bs = THREAD_ARG(t); ptm_bfd_xmt_TO(bs, 0); - - return 0; } -int bfd_echo_xmt_cb(struct thread *t) +void bfd_echo_xmt_cb(struct thread *t) { struct bfd_session *bs = THREAD_ARG(t); if (bs->echo_xmt_TO > 0) ptm_bfd_echo_xmt_TO(bs); - - return 0; } /* Was ptm_bfd_detect_TO() */ -int bfd_recvtimer_cb(struct thread *t) +void bfd_recvtimer_cb(struct thread *t) { struct bfd_session *bs = THREAD_ARG(t); @@ -639,12 +635,10 @@ int bfd_recvtimer_cb(struct thread *t) ptm_bfd_sess_dn(bs, BD_CONTROL_EXPIRED); break; } - - return 0; } /* Was ptm_bfd_echo_detect_TO() */ -int bfd_echo_recvtimer_cb(struct thread *t) +void bfd_echo_recvtimer_cb(struct thread *t) { struct bfd_session *bs = THREAD_ARG(t); @@ -654,8 +648,6 @@ int bfd_echo_recvtimer_cb(struct thread *t) ptm_bfd_sess_dn(bs, BD_ECHO_FAILED); break; } - - return 0; } struct bfd_session *bfd_session_new(void) @@ -1424,7 +1416,7 @@ int strtosa(const char *addr, struct sockaddr_any *sa) void integer2timestr(uint64_t time, char *buf, size_t buflen) { - unsigned int year, month, day, hour, minute, second; + uint64_t year, month, day, hour, minute, second; int rv; #define MINUTES (60) @@ -1436,7 +1428,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen) year = time / YEARS; time -= year * YEARS; - rv = snprintf(buf, buflen, "%u year(s), ", year); + rv = snprintfrr(buf, buflen, "%" PRIu64 " year(s), ", year); buf += rv; buflen -= rv; } @@ -1444,7 +1436,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen) month = time / MONTHS; time -= month * MONTHS; - rv = snprintf(buf, buflen, "%u month(s), ", month); + rv = snprintfrr(buf, buflen, "%" PRIu64 " month(s), ", month); buf += rv; buflen -= rv; } @@ -1452,7 +1444,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen) day = time / DAYS; time -= day * DAYS; - rv = snprintf(buf, buflen, "%u day(s), ", day); + rv = snprintfrr(buf, buflen, "%" PRIu64 " day(s), ", day); buf += rv; buflen -= rv; } @@ -1460,7 +1452,7 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen) hour = time / HOURS; time -= hour * HOURS; - rv = snprintf(buf, buflen, "%u hour(s), ", hour); + rv = snprintfrr(buf, buflen, "%" PRIu64 " hour(s), ", hour); buf += rv; buflen -= rv; } @@ -1468,12 +1460,12 @@ void integer2timestr(uint64_t time, char *buf, size_t buflen) minute = time / MINUTES; time -= minute * MINUTES; - rv = snprintf(buf, buflen, "%u minute(s), ", minute); + rv = snprintfrr(buf, buflen, "%" PRIu64 " minute(s), ", minute); buf += rv; buflen -= rv; } second = time % MINUTES; - snprintf(buf, buflen, "%u second(s)", second); + snprintfrr(buf, buflen, "%" PRIu64 " second(s)", second); } const char *bs_to_string(const struct bfd_session *bs) diff --git a/bfdd/bfd.h b/bfdd/bfd.h index 473886901c..7ab5ef13b4 100644 --- a/bfdd/bfd.h +++ b/bfdd/bfd.h @@ -426,7 +426,7 @@ int control_init(const char *path); void control_shutdown(void); int control_notify(struct bfd_session *bs, uint8_t notify_state); int control_notify_config(const char *op, struct bfd_session *bs); -int control_accept(struct thread *t); +void control_accept(struct thread *t); /* @@ -556,7 +556,7 @@ int bp_echov6_socket(const struct vrf *vrf); void ptm_bfd_snd(struct bfd_session *bfd, int fbit); void ptm_bfd_echo_snd(struct bfd_session *bfd); -int bfd_recv_cb(struct thread *t); +void bfd_recv_cb(struct thread *t); /* @@ -690,10 +690,10 @@ unsigned long bfd_get_session_count(void); /* Export callback functions for `event.c`. */ extern struct thread_master *master; -int bfd_recvtimer_cb(struct thread *t); -int bfd_echo_recvtimer_cb(struct thread *t); -int bfd_xmt_cb(struct thread *t); -int bfd_echo_xmt_cb(struct thread *t); +void bfd_recvtimer_cb(struct thread *t); +void bfd_echo_recvtimer_cb(struct thread *t); +void bfd_xmt_cb(struct thread *t); +void bfd_echo_xmt_cb(struct thread *t); extern struct in6_addr zero_addr; diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index 8eda78ebdb..34b171f409 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -531,7 +531,7 @@ static void cp_debug(bool mhop, struct sockaddr_any *peer, mhop ? "yes" : "no", peerstr, localstr, portstr, vrfstr); } -int bfd_recv_cb(struct thread *t) +void bfd_recv_cb(struct thread *t) { int sd = THREAD_FD(t); struct bfd_session *bfd; @@ -552,7 +552,7 @@ int bfd_recv_cb(struct thread *t) /* Handle echo packets. */ if (sd == bvrf->bg_echo || sd == bvrf->bg_echov6) { ptm_bfd_process_echo_pkt(bvrf, sd); - return 0; + return; } /* Sanitize input/output. */ @@ -590,14 +590,14 @@ int bfd_recv_cb(struct thread *t) if (mlen < BFD_PKT_LEN) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "too small (%ld bytes)", mlen); - return 0; + return; } /* Validate single hop packet TTL. */ if ((!is_mhop) && (ttl != BFD_TTL_VAL)) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "invalid TTL: %d expected %d", ttl, BFD_TTL_VAL); - return 0; + return; } /* @@ -611,24 +611,24 @@ int bfd_recv_cb(struct thread *t) if (BFD_GETVER(cp->diag) != BFD_VERSION) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "bad version %d", BFD_GETVER(cp->diag)); - return 0; + return; } if (cp->detect_mult == 0) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "detect multiplier set to zero"); - return 0; + return; } if ((cp->len < BFD_PKT_LEN) || (cp->len > mlen)) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "too small"); - return 0; + return; } if (cp->discrs.my_discr == 0) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "'my discriminator' is zero"); - return 0; + return; } /* Find the session that this packet belongs. */ @@ -636,7 +636,7 @@ int bfd_recv_cb(struct thread *t) if (bfd == NULL) { cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "no session found"); - return 0; + return; } /* @@ -648,7 +648,7 @@ int bfd_recv_cb(struct thread *t) cp_debug(is_mhop, &peer, &local, ifindex, vrfid, "exceeded max hop count (expected %d, got %d)", bfd->mh_ttl, ttl); - return 0; + return; } } else if (bfd->local_address.sa_sin.sin_family == AF_UNSPEC) { bfd->local_address = local; @@ -733,8 +733,6 @@ int bfd_recv_cb(struct thread *t) /* Send the control packet with the final bit immediately. */ ptm_bfd_snd(bfd, 1); } - - return 0; } /* diff --git a/bfdd/control.c b/bfdd/control.c index e772aadfc4..473843fe25 100644 --- a/bfdd/control.c +++ b/bfdd/control.c @@ -52,8 +52,8 @@ struct bfd_notify_peer *control_notifypeer_find(struct bfd_control_socket *bcs, struct bfd_control_socket *control_new(int sd); static void control_free(struct bfd_control_socket *bcs); static void control_reset_buf(struct bfd_control_buffer *bcb); -static int control_read(struct thread *t); -static int control_write(struct thread *t); +static void control_read(struct thread *t); +static void control_write(struct thread *t); static void control_handle_request_add(struct bfd_control_socket *bcs, struct bfd_control_msg *bcm); @@ -155,21 +155,19 @@ void control_shutdown(void) } } -int control_accept(struct thread *t) +void control_accept(struct thread *t) { int csock, sd = THREAD_FD(t); csock = accept(sd, NULL, 0); if (csock == -1) { zlog_warn("%s: accept: %s", __func__, strerror(errno)); - return 0; + return; } control_new(csock); thread_add_read(master, control_accept, NULL, sd, &bglobal.bg_csockev); - - return 0; } @@ -394,7 +392,7 @@ static void control_reset_buf(struct bfd_control_buffer *bcb) bcb->bcb_left = 0; } -static int control_read(struct thread *t) +static void control_read(struct thread *t) { struct bfd_control_socket *bcs = THREAD_ARG(t); struct bfd_control_buffer *bcb = &bcs->bcs_bin; @@ -417,7 +415,7 @@ static int control_read(struct thread *t) bread = read(sd, &bcm, sizeof(bcm)); if (bread == 0) { control_free(bcs); - return 0; + return; } if (bread < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) @@ -425,7 +423,7 @@ static int control_read(struct thread *t) zlog_warn("%s: read: %s", __func__, strerror(errno)); control_free(bcs); - return 0; + return; } /* Validate header fields. */ @@ -434,14 +432,14 @@ static int control_read(struct thread *t) zlog_debug("%s: client closed due small message length: %d", __func__, bcm.bcm_length); control_free(bcs); - return 0; + return; } if (bcm.bcm_ver != BMV_VERSION_1) { zlog_debug("%s: client closed due bad version: %d", __func__, bcm.bcm_ver); control_free(bcs); - return 0; + return; } /* Prepare the buffer to load the message. */ @@ -456,7 +454,7 @@ static int control_read(struct thread *t) zlog_warn("%s: not enough memory for message size: %zu", __func__, bcb->bcb_left); control_free(bcs); - return 0; + return; } memcpy(bcb->bcb_buf, &bcm, sizeof(bcm)); @@ -469,7 +467,7 @@ skip_header: bread = read(sd, &bcb->bcb_buf[bcb->bcb_pos], bcb->bcb_left); if (bread == 0) { control_free(bcs); - return 0; + return; } if (bread < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) @@ -477,7 +475,7 @@ skip_header: zlog_warn("%s: read: %s", __func__, strerror(errno)); control_free(bcs); - return 0; + return; } bcb->bcb_pos += bread; @@ -518,11 +516,9 @@ skip_header: schedule_next_read: bcs->bcs_ev = NULL; thread_add_read(master, control_read, bcs, sd, &bcs->bcs_ev); - - return 0; } -static int control_write(struct thread *t) +static void control_write(struct thread *t) { struct bfd_control_socket *bcs = THREAD_ARG(t); struct bfd_control_buffer *bcb = bcs->bcs_bout; @@ -532,19 +528,19 @@ static int control_write(struct thread *t) bwrite = write(sd, &bcb->bcb_buf[bcb->bcb_pos], bcb->bcb_left); if (bwrite == 0) { control_free(bcs); - return 0; + return; } if (bwrite < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { bcs->bcs_outev = NULL; thread_add_write(master, control_write, bcs, bcs->bcs_sd, &bcs->bcs_outev); - return 0; + return; } zlog_warn("%s: write: %s", __func__, strerror(errno)); control_free(bcs); - return 0; + return; } bcb->bcb_pos += bwrite; @@ -553,12 +549,10 @@ static int control_write(struct thread *t) bcs->bcs_outev = NULL; thread_add_write(master, control_write, bcs, bcs->bcs_sd, &bcs->bcs_outev); - return 0; + return; } control_queue_dequeue(bcs); - - return 0; } diff --git a/bfdd/dplane.c b/bfdd/dplane.c index 9dee2a5589..c1081643e3 100644 --- a/bfdd/dplane.c +++ b/bfdd/dplane.c @@ -107,7 +107,7 @@ struct bfd_dplane_ctx { */ typedef void (*bfd_dplane_expect_cb)(struct bfddp_message *msg, void *arg); -static int bfd_dplane_client_connect(struct thread *t); +static void bfd_dplane_client_connect(struct thread *t); static bool bfd_dplane_client_connecting(struct bfd_dplane_ctx *bdc); static void bfd_dplane_ctx_free(struct bfd_dplane_ctx *bdc); static int _bfd_dplane_add_session(struct bfd_dplane_ctx *bdc, @@ -325,17 +325,15 @@ static ssize_t bfd_dplane_flush(struct bfd_dplane_ctx *bdc) return total; } -static int bfd_dplane_write(struct thread *t) +static void bfd_dplane_write(struct thread *t) { struct bfd_dplane_ctx *bdc = THREAD_ARG(t); /* Handle connection stage. */ if (bdc->connecting && bfd_dplane_client_connecting(bdc)) - return 0; + return; bfd_dplane_flush(bdc); - - return 0; } static void @@ -614,18 +612,17 @@ skip_read: return 0; } -static int bfd_dplane_read(struct thread *t) +static void bfd_dplane_read(struct thread *t) { struct bfd_dplane_ctx *bdc = THREAD_ARG(t); int rv; rv = bfd_dplane_expect(bdc, 0, bfd_dplane_handle_message, NULL); if (rv == -1) - return 0; + return; stream_pulldown(bdc->inbuf); thread_add_read(master, bfd_dplane_read, bdc, bdc->sock, &bdc->inbufev); - return 0; } static void _bfd_session_register_dplane(struct hash_bucket *hb, void *arg) @@ -835,7 +832,7 @@ static uint16_t bfd_dplane_request_counters(const struct bfd_session *bs) /* * Data plane listening socket. */ -static int bfd_dplane_accept(struct thread *t) +static void bfd_dplane_accept(struct thread *t) { struct bfd_global *bg = THREAD_ARG(t); struct bfd_dplane_ctx *bdc; @@ -858,7 +855,6 @@ static int bfd_dplane_accept(struct thread *t) reschedule_and_return: thread_add_read(master, bfd_dplane_accept, bg, bg->bg_dplane_sock, &bglobal.bg_dplane_sockev); - return 0; } /* @@ -916,7 +912,7 @@ static bool bfd_dplane_client_connecting(struct bfd_dplane_ctx *bdc) } } -static int bfd_dplane_client_connect(struct thread *t) +static void bfd_dplane_client_connect(struct thread *t) { struct bfd_dplane_ctx *bdc = THREAD_ARG(t); int rv, sock; @@ -965,15 +961,12 @@ static int bfd_dplane_client_connect(struct thread *t) _bfd_dplane_client_bootstrap(bdc); } - return 0; - reschedule_connect: THREAD_OFF(bdc->inbufev); THREAD_OFF(bdc->outbufev); socket_close(&sock); thread_add_timer(master, bfd_dplane_client_connect, bdc, 3, &bdc->connectev); - return 0; } static void bfd_dplane_client_init(const struct sockaddr *sa, socklen_t salen) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 21f92c353e..a96b63cac6 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -669,9 +669,8 @@ unsigned int attrhash_key_make(const void *p) if (attr->aspath) MIX(aspath_key_make(attr->aspath)); - if (attr->community) - MIX(community_hash_make(attr->community)); - + if (bgp_attr_get_community(attr)) + MIX(community_hash_make(bgp_attr_get_community(attr))); if (bgp_attr_get_lcommunity(attr)) MIX(lcommunity_hash_make(bgp_attr_get_lcommunity(attr))); if (bgp_attr_get_ecommunity(attr)) @@ -713,7 +712,9 @@ bool attrhash_cmp(const void *p1, const void *p2) if (attr1->flag == attr2->flag && attr1->origin == attr2->origin && attr1->nexthop.s_addr == attr2->nexthop.s_addr && attr1->aspath == attr2->aspath - && attr1->community == attr2->community && attr1->med == attr2->med + && bgp_attr_get_community(attr1) + == bgp_attr_get_community(attr2) + && attr1->med == attr2->med && attr1->local_pref == attr2->local_pref && attr1->rmap_change_flags == attr2->rmap_change_flags) { if (attr1->aggregator_as == attr2->aggregator_as @@ -844,6 +845,7 @@ struct attr *bgp_attr_intern(struct attr *attr) struct ecommunity *ecomm = NULL; struct ecommunity *ipv6_ecomm = NULL; struct lcommunity *lcomm = NULL; + struct community *comm = NULL; /* Intern referenced strucutre. */ if (attr->aspath) { @@ -852,11 +854,13 @@ struct attr *bgp_attr_intern(struct attr *attr) else attr->aspath->refcnt++; } - if (attr->community) { - if (!attr->community->refcnt) - attr->community = community_intern(attr->community); + + comm = bgp_attr_get_community(attr); + if (comm) { + if (!comm->refcnt) + bgp_attr_set_community(attr, community_intern(comm)); else - attr->community->refcnt++; + comm->refcnt++; } ecomm = bgp_attr_get_ecommunity(attr); @@ -1003,7 +1007,7 @@ struct attr *bgp_attr_aggregate_intern( community_del_val(community, &gshut); } - attr.community = community; + bgp_attr_set_community(&attr, community); attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -1084,14 +1088,16 @@ void bgp_attr_unintern_sub(struct attr *attr) struct ecommunity *ipv6_ecomm = NULL; struct cluster_list *cluster; struct lcommunity *lcomm = NULL; + struct community *comm = NULL; /* aspath refcount shoud be decrement. */ aspath_unintern(&attr->aspath); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)); - if (attr->community) - community_unintern(&attr->community); + comm = bgp_attr_get_community(attr); + community_unintern(&comm); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); + bgp_attr_set_community(attr, NULL); ecomm = bgp_attr_get_ecommunity(attr); ecommunity_unintern(&ecomm); @@ -1171,21 +1177,27 @@ void bgp_attr_flush(struct attr *attr) struct ecommunity *ipv6_ecomm; struct cluster_list *cluster; struct lcommunity *lcomm; + struct community *comm; if (attr->aspath && !attr->aspath->refcnt) { aspath_free(attr->aspath); attr->aspath = NULL; } - if (attr->community && !attr->community->refcnt) - community_free(&attr->community); + comm = bgp_attr_get_community(attr); + if (comm && !comm->refcnt) + community_free(&comm); + bgp_attr_set_community(attr, NULL); + ecomm = bgp_attr_get_ecommunity(attr); if (ecomm && !ecomm->refcnt) ecommunity_free(&ecomm); bgp_attr_set_ecommunity(attr, NULL); + ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr); if (ipv6_ecomm && !ipv6_ecomm->refcnt) ecommunity_free(&ipv6_ecomm); bgp_attr_set_ipv6_ecommunity(attr, NULL); + lcomm = bgp_attr_get_lcommunity(attr); if (lcomm && !lcomm->refcnt) lcommunity_free(&lcomm); @@ -1932,13 +1944,14 @@ bgp_attr_community(struct bgp_attr_parser_args *args) const bgp_size_t length = args->length; if (length == 0) { - attr->community = NULL; + bgp_attr_set_community(attr, NULL); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); } - attr->community = - community_parse((uint32_t *)stream_pnt(peer->curr), length); + bgp_attr_set_community( + attr, + community_parse((uint32_t *)stream_pnt(peer->curr), length)); /* XXX: fix community_parse to use stream API and remove this */ stream_forward_getp(peer->curr, length); @@ -1946,7 +1959,7 @@ bgp_attr_community(struct bgp_attr_parser_args *args) /* The Community attribute SHALL be considered malformed if its * length is not a non-zero multiple of 4. */ - if (!attr->community) + if (!bgp_attr_get_community(attr)) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); @@ -4075,20 +4088,23 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* Community attribute. */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY) && (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) { - if (attr->community->size * 4 > 255) { + struct community *comm = NULL; + + comm = bgp_attr_get_community(attr); + if (comm->size * 4 > 255) { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putw(s, attr->community->size * 4); + stream_putw(s, comm->size * 4); } else { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putc(s, attr->community->size * 4); + stream_putc(s, comm->size * 4); } - stream_put(s, attr->community->val, attr->community->size * 4); + stream_put(s, comm->val, comm->size * 4); } /* @@ -4525,20 +4541,23 @@ void bgp_dump_routes_attr(struct stream *s, struct attr *attr, /* Community attribute. */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) { - if (attr->community->size * 4 > 255) { + struct community *comm = NULL; + + comm = bgp_attr_get_community(attr); + if (comm->size * 4 > 255) { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putw(s, attr->community->size * 4); + stream_putw(s, comm->size * 4); } else { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putc(s, attr->community->size * 4); + stream_putc(s, comm->size * 4); } - stream_put(s, attr->community->val, attr->community->size * 4); + stream_put(s, comm->val, comm->size * 4); } /* Large Community attribute. */ diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 16eb956b3d..1f199da161 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -530,6 +530,17 @@ static inline void bgp_attr_set_lcommunity(struct attr *attr, attr->lcommunity = lcomm; } +static inline struct community *bgp_attr_get_community(const struct attr *attr) +{ + return attr->community; +} + +static inline void bgp_attr_set_community(struct attr *attr, + struct community *comm) +{ + attr->community = comm; +} + static inline struct ecommunity * bgp_attr_get_ipv6_ecommunity(const struct attr *attr) { diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 1c9852f5c2..96c34f9196 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -1315,7 +1315,7 @@ static void bmp_stat_put_u32(struct stream *s, size_t *cnt, uint16_t type, (*cnt)++; } -static int bmp_stats(struct thread *thread) +static void bmp_stats(struct thread *thread) { struct bmp_targets *bt = THREAD_ARG(thread); struct stream *s; @@ -1365,11 +1365,10 @@ static int bmp_stats(struct thread *thread) bmp_send_all(bt->bmpbgp, s); } - return 0; } /* read from the BMP socket to detect session termination */ -static int bmp_read(struct thread *t) +static void bmp_read(struct thread *t) { struct bmp *bmp = THREAD_ARG(t); char buf[1024]; @@ -1383,16 +1382,14 @@ static int bmp_read(struct thread *t) } else if (n == 0) { /* the TCP session was terminated by the far end */ bmp_wrerr(bmp, NULL, true); - return 0; + return; } else if (!(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)) { /* the TCP session experienced a fatal error, likely a timeout */ bmp_wrerr(bmp, NULL, false); - return -1; + return; } thread_add_read(bm->master, bmp_read, bmp, bmp->socket, &bmp->t_read); - - return 0; } static struct bmp *bmp_open(struct bmp_targets *bt, int bmp_sock) @@ -1475,7 +1472,7 @@ static struct bmp *bmp_open(struct bmp_targets *bt, int bmp_sock) } /* Accept BMP connection. */ -static int bmp_accept(struct thread *thread) +static void bmp_accept(struct thread *thread) { union sockunion su; struct bmp_listener *bl = THREAD_ARG(thread); @@ -1490,10 +1487,9 @@ static int bmp_accept(struct thread *thread) bmp_sock = sockunion_accept(bl->sock, &su); if (bmp_sock < 0) { zlog_info("bmp: accept_sock failed: %s", safe_strerror(errno)); - return -1; + return; } bmp_open(bl->targets, bmp_sock); - return 0; } static void bmp_close(struct bmp *bmp) @@ -1837,7 +1833,7 @@ static void bmp_active_resolved(struct resolver_query *resq, const char *errstr, bmp_active_connect(ba); } -static int bmp_active_thread(struct thread *t) +static void bmp_active_thread(struct thread *t) { struct bmp_active *ba = THREAD_ARG(t); socklen_t slen; @@ -1861,7 +1857,7 @@ static int bmp_active_thread(struct thread *t) vrf_id = ba->targets->bgp->vrf_id; resolver_resolve(&ba->resq, AF_UNSPEC, vrf_id, ba->hostname, bmp_active_resolved); - return 0; + return; } slen = sizeof(status); @@ -1886,14 +1882,13 @@ static int bmp_active_thread(struct thread *t) ba->bmp->active = ba; ba->socket = -1; ba->curretry = ba->minretry; - return 0; + return; out_next: close(ba->socket); ba->socket = -1; ba->addrpos++; bmp_active_connect(ba); - return 0; } static void bmp_active_disconnected(struct bmp_active *ba) diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index a5dafd7757..6e6a3cd587 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -497,6 +497,9 @@ void community_unintern(struct community **com) { struct community *ret; + if (!*com) + return; + if ((*com)->refcnt) (*com)->refcnt--; diff --git a/bgpd/bgp_conditional_adv.c b/bgpd/bgp_conditional_adv.c index c0dd3d6f81..f72a373a1c 100644 --- a/bgpd/bgp_conditional_adv.c +++ b/bgpd/bgp_conditional_adv.c @@ -82,7 +82,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, struct peer_af *paf; const struct prefix *dest_p; struct update_subgroup *subgrp; - struct attr dummy_attr = {0}, attr = {0}; + struct attr advmap_attr = {0}, attr = {0}; struct bgp_path_info_extra path_extra = {0}; route_map_result_t ret; @@ -110,55 +110,53 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, assert(dest_p); for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { - dummy_attr = *pi->attr; + advmap_attr = *pi->attr; /* Fill temp path_info */ prep_for_rmap_apply(&path, &path_extra, dest, pi, - pi->peer, &dummy_attr); + pi->peer, &advmap_attr); - RESET_FLAG(dummy_attr.rmap_change_flags); + RESET_FLAG(advmap_attr.rmap_change_flags); ret = route_map_apply(rmap, dest_p, &path); - bgp_attr_flush(&dummy_attr); - - if (ret != RMAP_PERMITMATCH) + if (ret != RMAP_PERMITMATCH || + !bgp_check_selected(pi, peer, addpath_capable, afi, + safi)) { + bgp_attr_flush(&advmap_attr); continue; + } - if (bgp_check_selected(pi, peer, addpath_capable, afi, - safi)) { - /* Skip route-map checks in - * subgroup_announce_check while executing from - * the conditional advertise scanner process. - * otherwise when route-map is also configured - * on same peer, routes in advertise-map may not - * be advertised as expected. + /* Skip route-map checks in + * subgroup_announce_check while executing from + * the conditional advertise scanner process. + * otherwise when route-map is also configured + * on same peer, routes in advertise-map may not + * be advertised as expected. + */ + if (update_type == ADVERTISE && + subgroup_announce_check(dest, pi, subgrp, dest_p, + &attr, &advmap_attr)) { + bgp_adj_out_set_subgroup(dest, subgrp, &attr, + pi); + } else { + /* If default originate is enabled for + * the peer, do not send explicit + * withdraw. This will prevent deletion + * of default route advertised through + * default originate. */ - if ((update_type == ADVERTISE) - && subgroup_announce_check(dest, pi, subgrp, - dest_p, &attr, - true)) - bgp_adj_out_set_subgroup(dest, subgrp, - &attr, pi); - else { - /* If default originate is enabled for - * the peer, do not send explicit - * withdraw. This will prevent deletion - * of default route advertised through - * default originate. - */ - if (CHECK_FLAG( - peer->af_flags[afi][safi], - PEER_FLAG_DEFAULT_ORIGINATE) - && is_default_prefix(dest_p)) - break; - - bgp_adj_out_unset_subgroup( - dest, subgrp, 1, - bgp_addpath_id_for_peer( - peer, afi, safi, - &pi->tx_addpath)); - } + if (CHECK_FLAG(peer->af_flags[afi][safi], + PEER_FLAG_DEFAULT_ORIGINATE) && + is_default_prefix(dest_p)) + break; + + bgp_adj_out_unset_subgroup( + dest, subgrp, 1, + bgp_addpath_id_for_peer( + peer, afi, safi, + &pi->tx_addpath)); } + bgp_attr_flush(&advmap_attr); } } UNSET_FLAG(subgrp->sflags, SUBGRP_STATUS_TABLE_REPARSING); @@ -167,7 +165,7 @@ static void bgp_conditional_adv_routes(struct peer *peer, afi_t afi, /* Handler of conditional advertisement timer event. * Each route in the condition-map is evaluated. */ -static int bgp_conditional_adv_timer(struct thread *t) +static void bgp_conditional_adv_timer(struct thread *t) { afi_t afi; safi_t safi; @@ -288,7 +286,6 @@ static int bgp_conditional_adv_timer(struct thread *t) } peer->advmap_table_change = false; } - return 0; } void bgp_conditional_adv_enable(struct peer *peer, afi_t afi, safi_t safi) diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index 91e983e5d5..62e8e71aa0 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -113,7 +113,7 @@ int bgp_damp_decay(time_t tdiff, int penalty, struct bgp_damp_config *bdc) /* Handler of reuse timer event. Each route in the current reuse-list is evaluated. RFC2439 Section 4.8.7. */ -static int bgp_reuse_timer(struct thread *t) +static void bgp_reuse_timer(struct thread *t) { struct bgp_damp_info *bdi; struct bgp_damp_info *next; @@ -178,8 +178,6 @@ static int bgp_reuse_timer(struct thread *t) * 4.8.6). */ bgp_reuse_list_add(bdi, bdc); } - - return 0; } /* A route becomes unreachable (RFC2439 Section 4.8.2). */ diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 82e05dc53a..5d14ff0fa6 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -411,7 +411,7 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), ", community %s", - community_str(attr->community, false)); + community_str(bgp_attr_get_community(attr), false)); if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 9ddfe7bb5f..c389fec5f4 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -88,7 +88,7 @@ struct bgp_dump { }; static int bgp_dump_unset(struct bgp_dump *bgp_dump); -static int bgp_dump_interval_func(struct thread *); +static void bgp_dump_interval_func(struct thread *); /* BGP packet dump output buffer. */ struct stream *bgp_dump_obuf; @@ -439,7 +439,7 @@ static unsigned int bgp_dump_routes_func(int afi, int first_run, return seq; } -static int bgp_dump_interval_func(struct thread *t) +static void bgp_dump_interval_func(struct thread *t) { struct bgp_dump *bgp_dump; bgp_dump = THREAD_ARG(t); @@ -462,8 +462,6 @@ static int bgp_dump_interval_func(struct thread *t) /* if interval is set reschedule */ if (bgp_dump->interval > 0) bgp_dump_interval_add(bgp_dump, bgp_dump->interval); - - return 0; } /* Dump common information. */ diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index 9b184ac9ca..ea179ec2b4 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -76,7 +76,7 @@ static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es *es, bool is_local); esi_t zero_esi_buf, *zero_esi = &zero_esi_buf; -static int bgp_evpn_run_consistency_checks(struct thread *t); +static void bgp_evpn_run_consistency_checks(struct thread *t); static void bgp_evpn_path_nh_info_free(struct bgp_path_evpn_nh_info *nh_info); static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info *nh_info); @@ -4122,7 +4122,7 @@ static uint32_t bgp_evpn_es_run_consistency_checks(struct bgp_evpn_es *es) return proc_cnt; } -static int bgp_evpn_run_consistency_checks(struct thread *t) +static void bgp_evpn_run_consistency_checks(struct thread *t) { int proc_cnt = 0; int es_cnt = 0; @@ -4147,8 +4147,6 @@ static int bgp_evpn_run_consistency_checks(struct thread *t) thread_add_timer(bm->master, bgp_evpn_run_consistency_checks, NULL, BGP_EVPN_CONS_CHECK_INTERVAL, &bgp_mh_info->t_cons_check); - - return 0; } /***************************************************************************** diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index caf0444850..7ddf159844 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1236,6 +1236,10 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, no_display = 0; for (; pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + total_count++; if (type == bgp_show_type_neighbor) { struct peer *peer = output_arg; @@ -1268,17 +1272,15 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, if (type == bgp_show_type_community) { struct community *com = output_arg; - if (!pi->attr->community || - !community_match( - pi->attr->community, com)) + if (!picomm || + !community_match(picomm, com)) continue; } if (type == bgp_show_type_community_exact) { struct community *com = output_arg; - if (!pi->attr->community || - !community_cmp( - pi->attr->community, com)) + if (!picomm || + !community_cmp(picomm, com)) continue; } if (header) { @@ -3513,8 +3515,8 @@ DEFUN (bgp_evpn_advertise_all_vni, bgp_evpn = bgp_get_evpn(); if (bgp_evpn && bgp_evpn != bgp) { - vty_out(vty, "%% Please unconfigure EVPN in VRF %s\n", - bgp_evpn->name); + vty_out(vty, "%% Please unconfigure EVPN in %s\n", + bgp_evpn->name_pretty); return CMD_WARNING_CONFIG_FAILED; } @@ -3865,19 +3867,19 @@ DEFUN (bgp_evpn_advertise_type5, if (!(afi == AFI_IP || afi == AFI_IP6)) { vty_out(vty, - "%%only ipv4 or ipv6 address families are supported"); + "%%only ipv4 or ipv6 address families are supported\n"); return CMD_WARNING; } if (safi != SAFI_UNICAST) { vty_out(vty, - "%%only ipv4 unicast or ipv6 unicast are supported"); + "%%only ipv4 unicast or ipv6 unicast are supported\n"); return CMD_WARNING; } if ((oly != OVERLAY_INDEX_TYPE_NONE) && (oly != OVERLAY_INDEX_GATEWAY_IP)) { - vty_out(vty, "%%Unknown overlay-index type specified"); + vty_out(vty, "%%Unknown overlay-index type specified\n"); return CMD_WARNING; } @@ -4056,13 +4058,13 @@ DEFUN (no_bgp_evpn_advertise_type5, if (!(afi == AFI_IP || afi == AFI_IP6)) { vty_out(vty, - "%%only ipv4 or ipv6 address families are supported"); + "%%only ipv4 or ipv6 address families are supported\n"); return CMD_WARNING; } if (safi != SAFI_UNICAST) { vty_out(vty, - "%%only ipv4 unicast or ipv6 unicast are supported"); + "%%only ipv4 unicast or ipv6 unicast are supported\n"); return CMD_WARNING; } diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 672fa4512a..f8de3b8dc4 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -90,13 +90,13 @@ static const char *const bgp_event_str[] = { function. */ /* BGP event function. */ -int bgp_event(struct thread *); +void bgp_event(struct thread *); /* BGP thread functions. */ -static int bgp_start_timer(struct thread *); -static int bgp_connect_timer(struct thread *); -static int bgp_holdtime_timer(struct thread *); -static int bgp_delayopen_timer(struct thread *); +static void bgp_start_timer(struct thread *); +static void bgp_connect_timer(struct thread *); +static void bgp_holdtime_timer(struct thread *); +static void bgp_delayopen_timer(struct thread *); /* BGP FSM functions. */ static int bgp_start(struct peer *); @@ -494,7 +494,7 @@ void bgp_timer_set(struct peer *peer) /* BGP start timer. This function set BGP_Start event to thread value and process event. */ -static int bgp_start_timer(struct thread *thread) +static void bgp_start_timer(struct thread *thread) { struct peer *peer; @@ -505,15 +505,12 @@ static int bgp_start_timer(struct thread *thread) THREAD_VAL(thread) = BGP_Start; bgp_event(thread); /* bgp_event unlocks peer */ - - return 0; } /* BGP connect retry timer. */ -static int bgp_connect_timer(struct thread *thread) +static void bgp_connect_timer(struct thread *thread) { struct peer *peer; - int ret; peer = THREAD_ARG(thread); @@ -526,20 +523,16 @@ static int bgp_connect_timer(struct thread *thread) if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [FSM] Timer (connect timer expire)", peer->host); - if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) { + if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)) bgp_stop(peer); - ret = -1; - } else { + else { THREAD_VAL(thread) = ConnectRetry_timer_expired; bgp_event(thread); /* bgp_event unlocks peer */ - ret = 0; } - - return ret; } /* BGP holdtime timer. */ -static int bgp_holdtime_timer(struct thread *thread) +static void bgp_holdtime_timer(struct thread *thread) { atomic_size_t inq_count; struct peer *peer; @@ -562,20 +555,15 @@ static int bgp_holdtime_timer(struct thread *thread) */ inq_count = atomic_load_explicit(&peer->ibuf->count, memory_order_relaxed); - if (inq_count) { + if (inq_count) BGP_TIMER_ON(peer->t_holdtime, bgp_holdtime_timer, peer->v_holdtime); - return 0; - } - THREAD_VAL(thread) = Hold_Timer_expired; bgp_event(thread); /* bgp_event unlocks peer */ - - return 0; } -int bgp_routeadv_timer(struct thread *thread) +void bgp_routeadv_timer(struct thread *thread) { struct peer *peer; @@ -593,11 +581,10 @@ int bgp_routeadv_timer(struct thread *thread) /* MRAI timer will be started again when FIFO is built, no need to * do it here. */ - return 0; } /* RFC 4271 DelayOpenTimer */ -int bgp_delayopen_timer(struct thread *thread) +void bgp_delayopen_timer(struct thread *thread) { struct peer *peer; @@ -609,8 +596,6 @@ int bgp_delayopen_timer(struct thread *thread) THREAD_VAL(thread) = DelayOpen_timer_expired; bgp_event(thread); /* bgp_event unlocks peer */ - - return 0; } /* BGP Peer Down Cause */ @@ -674,7 +659,7 @@ static void bgp_graceful_restart_timer_off(struct peer *peer) bgp_timer_set(peer); } -static int bgp_llgr_stale_timer_expire(struct thread *thread) +static void bgp_llgr_stale_timer_expire(struct thread *thread) { struct peer_af *paf; struct peer *peer; @@ -700,8 +685,6 @@ static int bgp_llgr_stale_timer_expire(struct thread *thread) bgp_clear_stale_route(peer, afi, safi); bgp_graceful_restart_timer_off(peer); - - return 0; } static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) @@ -727,9 +710,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (pi->peer != peer) continue; - if (pi->attr->community && + if (bgp_attr_get_community(pi->attr) && community_include( - pi->attr->community, + bgp_attr_get_community( + pi->attr), COMMUNITY_NO_LLGR)) continue; @@ -755,9 +739,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (pi->peer != peer) continue; - if (pi->attr->community && - community_include(pi->attr->community, - COMMUNITY_NO_LLGR)) + if (bgp_attr_get_community(pi->attr) && + community_include( + bgp_attr_get_community(pi->attr), + COMMUNITY_NO_LLGR)) continue; if (bgp_debug_neighbor_events(peer)) @@ -776,7 +761,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) } } -static int bgp_graceful_restart_timer_expire(struct thread *thread) +static void bgp_graceful_restart_timer_expire(struct thread *thread) { struct peer *peer, *tmp_peer; struct listnode *node, *nnode; @@ -840,11 +825,9 @@ static int bgp_graceful_restart_timer_expire(struct thread *thread) } bgp_graceful_restart_timer_off(peer); - - return 0; } -static int bgp_graceful_stale_timer_expire(struct thread *thread) +static void bgp_graceful_stale_timer_expire(struct thread *thread) { struct peer *peer; afi_t afi; @@ -860,12 +843,10 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread) FOREACH_AFI_SAFI_NSF (afi, safi) if (peer->nsf[afi][safi]) bgp_clear_stale_route(peer, afi, safi); - - return 0; } /* Selection deferral timer processing function */ -static int bgp_graceful_deferral_timer_expire(struct thread *thread) +static void bgp_graceful_deferral_timer_expire(struct thread *thread) { struct afi_safi_info *info; afi_t afi; @@ -887,7 +868,7 @@ static int bgp_graceful_deferral_timer_expire(struct thread *thread) XFREE(MTYPE_TMP, info); /* Best path selection */ - return bgp_best_path_select_defer(bgp, afi, safi); + bgp_best_path_select_defer(bgp, afi, safi); } static bool bgp_update_delay_applicable(struct bgp *bgp) @@ -1135,7 +1116,7 @@ int bgp_fsm_error_subcode(int status) } /* The maxmed onstartup timer expiry callback. */ -static int bgp_maxmed_onstartup_timer(struct thread *thread) +static void bgp_maxmed_onstartup_timer(struct thread *thread) { struct bgp *bgp; @@ -1146,8 +1127,6 @@ static int bgp_maxmed_onstartup_timer(struct thread *thread) bgp->maxmed_onstartup_over = 1; bgp_maxmed_update(bgp); - - return 0; } static void bgp_maxmed_onstartup_begin(struct bgp *bgp) @@ -1179,7 +1158,7 @@ static void bgp_maxmed_onstartup_process_status_change(struct peer *peer) } /* The update delay timer expiry callback. */ -static int bgp_update_delay_timer(struct thread *thread) +static void bgp_update_delay_timer(struct thread *thread) { struct bgp *bgp; @@ -1188,12 +1167,10 @@ static int bgp_update_delay_timer(struct thread *thread) bgp = THREAD_ARG(thread); THREAD_OFF(bgp->t_update_delay); bgp_update_delay_end(bgp); - - return 0; } /* The establish wait timer expiry callback. */ -static int bgp_establish_wait_timer(struct thread *thread) +static void bgp_establish_wait_timer(struct thread *thread) { struct bgp *bgp; @@ -1202,8 +1179,6 @@ static int bgp_establish_wait_timer(struct thread *thread) bgp = THREAD_ARG(thread); THREAD_OFF(bgp->t_establish_wait); bgp_check_update_delay(bgp); - - return 0; } /* Steps to begin the update delay: @@ -1660,7 +1635,7 @@ static int bgp_stop_with_notify(struct peer *peer, uint8_t code, * when the connection is established. A read event is triggered when the * connection is closed. Thus we need to cancel whichever one did not occur. */ -static int bgp_connect_check(struct thread *thread) +static void bgp_connect_check(struct thread *thread) { int status; socklen_t slen; @@ -1686,7 +1661,7 @@ static int bgp_connect_check(struct thread *thread) zlog_err("can't get sockopt for nonblocking connect: %d(%s)", errno, safe_strerror(errno)); BGP_EVENT_ADD(peer, TCP_fatal_error); - return -1; + return; } /* When status is 0 then TCP connection is established. */ @@ -1695,13 +1670,13 @@ static int bgp_connect_check(struct thread *thread) BGP_EVENT_ADD(peer, TCP_connection_open_w_delay); else BGP_EVENT_ADD(peer, TCP_connection_open); - return 1; + return; } else { if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [Event] Connect failed %d(%s)", peer->host, status, safe_strerror(status)); BGP_EVENT_ADD(peer, TCP_connection_open_failed); - return 0; + return; } } @@ -2542,18 +2517,15 @@ static const struct { }; /* Execute event process. */ -int bgp_event(struct thread *thread) +void bgp_event(struct thread *thread) { enum bgp_fsm_events event; struct peer *peer; - int ret; peer = THREAD_ARG(thread); event = THREAD_VAL(thread); - ret = bgp_event_update(peer, event); - - return (ret); + bgp_event_update(peer, event); } int bgp_event_update(struct peer *peer, enum bgp_fsm_events event) diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index 12cbad3eb8..f3d1781ed9 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -125,11 +125,11 @@ * Update FSM for peer based on whether we have valid nexthops or not. */ extern void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops); -extern int bgp_event(struct thread *); +extern void bgp_event(struct thread *); extern int bgp_event_update(struct peer *, enum bgp_fsm_events event); extern int bgp_stop(struct peer *peer); extern void bgp_timer_set(struct peer *); -extern int bgp_routeadv_timer(struct thread *); +extern void bgp_routeadv_timer(struct thread *); extern void bgp_fsm_change_status(struct peer *peer, int status); extern const char *const peer_down_str[]; extern void bgp_update_delay_end(struct bgp *); diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 9b5a31f289..bd0dfb3a6d 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -45,8 +45,8 @@ /* forward declarations */ static uint16_t bgp_write(struct peer *); static uint16_t bgp_read(struct peer *peer, int *code_p); -static int bgp_process_writes(struct thread *); -static int bgp_process_reads(struct thread *); +static void bgp_process_writes(struct thread *); +static void bgp_process_reads(struct thread *); static bool validate_header(struct peer *); /* generic i/o status codes */ @@ -121,7 +121,7 @@ void bgp_reads_off(struct peer *peer) /* * Called from I/O pthread when a file descriptor has become ready for writing. */ -static int bgp_process_writes(struct thread *thread) +static void bgp_process_writes(struct thread *thread) { static struct peer *peer; peer = THREAD_ARG(thread); @@ -130,7 +130,7 @@ static int bgp_process_writes(struct thread *thread) bool fatal = false; if (peer->fd < 0) - return -1; + return; struct frr_pthread *fpt = bgp_pth_io; @@ -161,8 +161,6 @@ static int bgp_process_writes(struct thread *thread) BGP_UPDATE_GROUP_TIMER_ON(&peer->t_generate_updgrp_packets, bgp_generate_updgrp_packets); } - - return 0; } /* @@ -172,7 +170,7 @@ static int bgp_process_writes(struct thread *thread) * We read as much data as possible, process as many packets as we can and * place them on peer->ibuf for secondary processing by the main thread. */ -static int bgp_process_reads(struct thread *thread) +static void bgp_process_reads(struct thread *thread) { /* clang-format off */ static struct peer *peer; // peer to read from @@ -186,7 +184,7 @@ static int bgp_process_reads(struct thread *thread) peer = THREAD_ARG(thread); if (peer->fd < 0 || bm->terminating) - return -1; + return; struct frr_pthread *fpt = bgp_pth_io; @@ -271,8 +269,6 @@ static int bgp_process_reads(struct thread *thread) thread_add_event(bm->master, bgp_process_packet, peer, 0, &peer->t_process_packet); } - - return 0; } /* diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 774953f6f8..6e695d0301 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -842,7 +842,9 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, aspath = aspath_dup(attr.aspath); origin = attr.origin; community = - attr.community ? community_dup(attr.community) : NULL; + bgp_attr_get_community(&attr) + ? community_dup(bgp_attr_get_community(&attr)) + : NULL; ecomm = (bgp_attr_get_ecommunity(&attr)) ? ecommunity_dup(bgp_attr_get_ecommunity(&attr)) : NULL; @@ -860,17 +862,19 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, if (origin < mpinfo->attr->origin) origin = mpinfo->attr->origin; - if (mpinfo->attr->community) { + if (bgp_attr_get_community(mpinfo->attr)) { if (community) { commerge = community_merge( community, - mpinfo->attr->community); + bgp_attr_get_community( + mpinfo->attr)); community = community_uniq_sort(commerge); community_free(&commerge); } else community = community_dup( - mpinfo->attr->community); + bgp_attr_get_community( + mpinfo->attr)); } if (bgp_attr_get_ecommunity(mpinfo->attr)) { @@ -902,7 +906,7 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, attr.aspath = aspath; attr.origin = origin; if (community) { - attr.community = community; + bgp_attr_set_community(&attr, community); attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } if (ecomm) { diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index eafc37f20c..32a1d9a152 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -520,7 +520,7 @@ static bool sid_exist(struct bgp *bgp, const struct in6_addr *sid) * else: try to allocate as auto-mode */ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index, - struct in6_addr *sid) + struct in6_addr *sid_locator) { struct listnode *node; struct prefix_ipv6 *chunk; @@ -528,10 +528,11 @@ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index, bool alloced = false; int label = 0; - if (!bgp || !sid) + if (!bgp || !sid_locator) return false; for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, chunk)) { + *sid_locator = chunk->prefix; sid_buf = chunk->prefix; if (index != 0) { label = index << 12; @@ -556,7 +557,6 @@ static uint32_t alloc_new_sid(struct bgp *bgp, uint32_t index, return 0; sid_register(bgp, &sid_buf, bgp->srv6_locator_name); - *sid = sid_buf; return label; } @@ -564,7 +564,7 @@ void ensure_vrf_tovpn_sid(struct bgp *bgp_vpn, struct bgp *bgp_vrf, afi_t afi) { int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF); char buf[256]; - struct in6_addr *sid; + struct in6_addr *tovpn_sid, *tovpn_sid_locator; uint32_t tovpn_sid_index = 0, tovpn_sid_transpose_label; bool tovpn_sid_auto = false; @@ -598,24 +598,33 @@ void ensure_vrf_tovpn_sid(struct bgp *bgp_vpn, struct bgp *bgp_vrf, afi_t afi) return; } - sid = XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr)); + tovpn_sid_locator = + XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr)); tovpn_sid_transpose_label = - alloc_new_sid(bgp_vpn, tovpn_sid_index, sid); + alloc_new_sid(bgp_vpn, tovpn_sid_index, tovpn_sid_locator); if (tovpn_sid_transpose_label == 0) { zlog_debug("%s: not allocated new sid for vrf %s: afi %s", __func__, bgp_vrf->name_pretty, afi2str(afi)); return; } + tovpn_sid = XCALLOC(MTYPE_BGP_SRV6_SID, sizeof(struct in6_addr)); + *tovpn_sid = *tovpn_sid_locator; + transpose_sid(tovpn_sid, tovpn_sid_transpose_label, + BGP_PREFIX_SID_SRV6_TRANSPOSITION_OFFSET, + BGP_PREFIX_SID_SRV6_TRANSPOSITION_LENGTH); + if (debug) { - inet_ntop(AF_INET6, sid, buf, sizeof(buf)); + inet_ntop(AF_INET6, tovpn_sid, buf, sizeof(buf)); zlog_debug("%s: new sid %s allocated for vrf %s: afi %s", __func__, buf, bgp_vrf->name_pretty, afi2str(afi)); } + + bgp_vrf->vpn_policy[afi].tovpn_sid = tovpn_sid; + bgp_vrf->vpn_policy[afi].tovpn_sid_locator = tovpn_sid_locator; bgp_vrf->vpn_policy[afi].tovpn_sid_transpose_label = tovpn_sid_transpose_label; - bgp_vrf->vpn_policy[afi].tovpn_sid = sid; } void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset, @@ -847,16 +856,11 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ new_attr->srv6_l3vpn->func_len; extra->sid[0].arg_len = new_attr->srv6_l3vpn->arg_len; - - if (new_attr->srv6_l3vpn->transposition_len - != 0) - transpose_sid( - &extra->sid[0].sid, - decode_label(label), - new_attr->srv6_l3vpn - ->transposition_offset, - new_attr->srv6_l3vpn - ->transposition_len); + extra->sid[0].transposition_len = + new_attr->srv6_l3vpn->transposition_len; + extra->sid[0].transposition_offset = + new_attr->srv6_l3vpn + ->transposition_offset; } else if (new_attr->srv6_vpn) setsids(bpi, &new_attr->srv6_vpn->sid, num_sids); @@ -951,14 +955,10 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ new_attr->srv6_l3vpn->loc_node_len; extra->sid[0].func_len = new_attr->srv6_l3vpn->func_len; extra->sid[0].arg_len = new_attr->srv6_l3vpn->arg_len; - - if (new_attr->srv6_l3vpn->transposition_len != 0) - transpose_sid(&extra->sid[0].sid, - decode_label(label), - new_attr->srv6_l3vpn - ->transposition_offset, - new_attr->srv6_l3vpn - ->transposition_len); + extra->sid[0].transposition_len = + new_attr->srv6_l3vpn->transposition_len; + extra->sid[0].transposition_offset = + new_attr->srv6_l3vpn->transposition_offset; } else if (new_attr->srv6_vpn) setsids(new, &new_attr->srv6_vpn->sid, num_sids); } else @@ -1235,7 +1235,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ static_attr.originator_id = bgp_vpn->router_id; /* Set SID for SRv6 VPN */ - if (bgp_vrf->vpn_policy[afi].tovpn_sid) { + if (bgp_vrf->vpn_policy[afi].tovpn_sid_locator) { encode_label(bgp_vrf->vpn_policy[afi].tovpn_sid_transpose_label, &label); static_attr.srv6_l3vpn = XCALLOC(MTYPE_BGP_SRV6_L3VPN, @@ -1255,8 +1255,8 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ static_attr.srv6_l3vpn->transposition_offset = BGP_PREFIX_SID_SRV6_TRANSPOSITION_OFFSET; memcpy(&static_attr.srv6_l3vpn->sid, - bgp_vrf->vpn_policy[afi].tovpn_sid, - sizeof(static_attr.srv6_l3vpn->sid)); + bgp_vrf->vpn_policy[afi].tovpn_sid_locator, + sizeof(struct in6_addr)); } diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index b0d586223f..5bf772fefe 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -21,6 +21,7 @@ #ifndef _QUAGGA_BGP_MPLSVPN_H #define _QUAGGA_BGP_MPLSVPN_H +#include "bgpd/bgp_attr.h" #include "bgpd/bgp_route.h" #include "bgpd/bgp_rd.h" #include "bgpd/bgp_zebra.h" diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 3fb7619ed1..0c325b6781 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -342,7 +342,7 @@ static void bgp_socket_set_buffer_size(const int fd) } /* Accept bgp connection. */ -static int bgp_accept(struct thread *thread) +static void bgp_accept(struct thread *thread) { int bgp_sock; int accept_sock; @@ -363,7 +363,7 @@ static int bgp_accept(struct thread *thread) flog_err_sys(EC_LIB_SOCKET, "[Error] BGP accept socket fd is negative: %d", accept_sock); - return -1; + return; } thread_add_read(bm->master, bgp_accept, listener, accept_sock, @@ -402,7 +402,7 @@ static int bgp_accept(struct thread *thread) "[Error] BGP socket accept failed (%s); retrying", safe_strerror(save_errno)); } - return -1; + return; } set_nonblocking(bgp_sock); @@ -418,7 +418,7 @@ static int bgp_accept(struct thread *thread) "[Event] Could not get instance for incoming conn from %s", inet_sutop(&su, buf)); close(bgp_sock); - return -1; + return; } bgp_socket_set_buffer_size(bgp_sock); @@ -451,7 +451,7 @@ static int bgp_accept(struct thread *thread) TCP_connection_open); } - return 0; + return; } } @@ -463,7 +463,7 @@ static int bgp_accept(struct thread *thread) VRF_LOGNAME(vrf_lookup_by_id(bgp->vrf_id))); } close(bgp_sock); - return -1; + return; } if (CHECK_FLAG(peer1->flags, PEER_FLAG_SHUTDOWN) @@ -474,7 +474,7 @@ static int bgp_accept(struct thread *thread) inet_sutop(&su, buf), bgp->name_pretty, bgp->as, VRF_LOGNAME(vrf_lookup_by_id(bgp->vrf_id))); close(bgp_sock); - return -1; + return; } /* @@ -489,7 +489,7 @@ static int bgp_accept(struct thread *thread) "[Event] Closing incoming conn for %s (%p) state %d", peer1->host, peer1, peer1->status); close(bgp_sock); - return -1; + return; } /* Check that at least one AF is activated for the peer. */ @@ -499,7 +499,7 @@ static int bgp_accept(struct thread *thread) "%s - incoming conn rejected - no AF activated for peer", peer1->host); close(bgp_sock); - return -1; + return; } /* Do not try to reconnect if the peer reached maximum @@ -512,7 +512,7 @@ static int bgp_accept(struct thread *thread) "[Event] Incoming BGP connection rejected from %s due to maximum-prefix or shutdown", peer1->host); close(bgp_sock); - return -1; + return; } if (bgp_debug_neighbor_events(peer1)) @@ -600,8 +600,6 @@ static int bgp_accept(struct thread *thread) * massage the event system to make things happy */ bgp_nht_interface_events(peer); - - return 0; } /* BGP socket bind. */ diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 19ae137208..8313c12e61 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -54,7 +54,7 @@ static void register_zebra_rnh(struct bgp_nexthop_cache *bnc, static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc, int is_bgp_static_route); static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p); -static int bgp_nht_ifp_initial(struct thread *thread); +static void bgp_nht_ifp_initial(struct thread *thread); static int bgp_isvalid_nexthop(struct bgp_nexthop_cache *bnc) { @@ -608,14 +608,14 @@ void bgp_nht_ifp_down(struct interface *ifp) bgp_nht_ifp_handle(ifp, false); } -static int bgp_nht_ifp_initial(struct thread *thread) +static void bgp_nht_ifp_initial(struct thread *thread) { ifindex_t ifindex = THREAD_VAL(thread); struct bgp *bgp = THREAD_ARG(thread); struct interface *ifp = if_lookup_by_index(ifindex, bgp->vrf_id); if (!ifp) - return 0; + return; if (BGP_DEBUG(nht, NHT)) zlog_debug( @@ -626,8 +626,6 @@ static int bgp_nht_ifp_initial(struct thread *thread) bgp_nht_ifp_up(ifp); else bgp_nht_ifp_down(ifp); - - return 0; } /* diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 4bb08404d6..8fac36cf60 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -386,7 +386,7 @@ static void bgp_write_proceed_actions(struct peer *peer) * update group a peer belongs to, encode this information into packets, and * enqueue the packets onto the peer's output buffer. */ -int bgp_generate_updgrp_packets(struct thread *thread) +void bgp_generate_updgrp_packets(struct thread *thread) { struct peer *peer = THREAD_ARG(thread); @@ -407,14 +407,14 @@ int bgp_generate_updgrp_packets(struct thread *thread) * update-delay processing). */ if (!peer_established(peer)) - return 0; + return; if ((peer->bgp->main_peers_update_hold) || bgp_update_delay_active(peer->bgp)) - return 0; + return; if (peer->t_routeadv) - return 0; + return; do { enum bgp_af_index index; @@ -541,8 +541,6 @@ int bgp_generate_updgrp_packets(struct thread *thread) bgp_writes_on(peer); bgp_write_proceed_actions(peer); - - return 0; } /* @@ -1540,7 +1538,7 @@ static int bgp_keepalive_receive(struct peer *peer, bgp_size_t size) return Receive_KEEPALIVE_message; } -static int bgp_refresh_stalepath_timer_expire(struct thread *thread) +static void bgp_refresh_stalepath_timer_expire(struct thread *thread) { struct peer_af *paf; @@ -1560,8 +1558,6 @@ static int bgp_refresh_stalepath_timer_expire(struct thread *thread) peer->host, afi2str(afi), safi2str(safi)); bgp_timer_set(peer); - - return 0; } /** @@ -2573,7 +2569,7 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size) * @param thread * @return 0 */ -int bgp_process_packet(struct thread *thread) +void bgp_process_packet(struct thread *thread) { /* Yes first of all get peer pointer. */ struct peer *peer; // peer @@ -2588,7 +2584,7 @@ int bgp_process_packet(struct thread *thread) /* Guard against scheduled events that occur after peer deletion. */ if (peer->status == Deleted || peer->status == Clearing) - return 0; + return; unsigned int processed = 0; @@ -2602,7 +2598,7 @@ int bgp_process_packet(struct thread *thread) } if (peer->curr == NULL) // no packets to process, hmm... - return 0; + return; /* skip the marker and copy the packet length */ stream_forward_getp(peer->curr, BGP_MARKER_SIZE); @@ -2732,8 +2728,6 @@ int bgp_process_packet(struct thread *thread) &peer->t_process_packet); } } - - return 0; } /* Send EOR when routes are processed by selection deferral timer */ @@ -2752,7 +2746,7 @@ void bgp_send_delayed_eor(struct bgp *bgp) * having the io pthread try to enqueue fsm events or mess with the peer * struct. */ -int bgp_packet_process_error(struct thread *thread) +void bgp_packet_process_error(struct thread *thread) { struct peer *peer; int code; @@ -2777,6 +2771,4 @@ int bgp_packet_process_error(struct thread *thread) } bgp_event_update(peer, code); - - return 0; } diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h index 280d3ec174..8c2de6d622 100644 --- a/bgpd/bgp_packet.h +++ b/bgpd/bgp_packet.h @@ -79,12 +79,12 @@ extern void bgp_check_update_delay(struct bgp *); extern int bgp_packet_set_marker(struct stream *s, uint8_t type); extern void bgp_packet_set_size(struct stream *s); -extern int bgp_generate_updgrp_packets(struct thread *); -extern int bgp_process_packet(struct thread *); +extern void bgp_generate_updgrp_packets(struct thread *); +extern void bgp_process_packet(struct thread *); extern void bgp_send_delayed_eor(struct bgp *bgp); /* Task callback to handle socket error encountered in the io pthread */ -int bgp_packet_process_error(struct thread *thread); +void bgp_packet_process_error(struct thread *thread); #endif /* _QUAGGA_BGP_PACKET_H */ diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8311cb207c..1860686381 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -641,8 +641,9 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, * below). See the Risks of Depreferencing Routes section (Section 5.2) * for a discussion of potential risks inherent in doing this. */ - if (newattr->community && - community_include(newattr->community, COMMUNITY_LLGR_STALE)) { + if (bgp_attr_get_community(newattr) && + community_include(bgp_attr_get_community(newattr), + COMMUNITY_LLGR_STALE)) { if (debug) zlog_debug( "%s: %s wins over %s due to LLGR_STALE community", @@ -650,8 +651,9 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, return 0; } - if (existattr->community && - community_include(existattr->community, COMMUNITY_LLGR_STALE)) { + if (bgp_attr_get_community(existattr) && + community_include(bgp_attr_get_community(existattr), + COMMUNITY_LLGR_STALE)) { if (debug) zlog_debug( "%s: %s loses to %s due to LLGR_STALE community", @@ -1522,20 +1524,22 @@ done: /* If community attribute includes no_export then return 1. */ static bool bgp_community_filter(struct peer *peer, struct attr *attr) { - if (attr->community) { + if (bgp_attr_get_community(attr)) { /* NO_ADVERTISE check. */ - if (community_include(attr->community, COMMUNITY_NO_ADVERTISE)) + if (community_include(bgp_attr_get_community(attr), + COMMUNITY_NO_ADVERTISE)) return true; /* NO_EXPORT check. */ - if (peer->sort == BGP_PEER_EBGP - && community_include(attr->community, COMMUNITY_NO_EXPORT)) + if (peer->sort == BGP_PEER_EBGP && + community_include(bgp_attr_get_community(attr), + COMMUNITY_NO_EXPORT)) return true; /* NO_EXPORT_SUBCONFED check. */ if (peer->sort == BGP_PEER_EBGP || peer->sort == BGP_PEER_CONFED) - if (community_include(attr->community, + if (community_include(bgp_attr_get_community(attr), COMMUNITY_NO_EXPORT_SUBCONFED)) return true; } @@ -1745,7 +1749,7 @@ void bgp_attr_add_llgr_community(struct attr *attr) struct community *merge; struct community *llgr; - old = attr->community; + old = bgp_attr_get_community(attr); llgr = community_str2com("llgr-stale"); assert(llgr); @@ -1764,7 +1768,7 @@ void bgp_attr_add_llgr_community(struct attr *attr) community_free(&llgr); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -1775,7 +1779,7 @@ void bgp_attr_add_gshut_community(struct attr *attr) struct community *merge; struct community *gshut; - old = attr->community; + old = bgp_attr_get_community(attr); gshut = community_str2com("graceful-shutdown"); assert(gshut); @@ -1793,7 +1797,7 @@ void bgp_attr_add_gshut_community(struct attr *attr) } community_free(&gshut); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); /* When we add the graceful-shutdown community we must also @@ -1836,7 +1840,7 @@ void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr) bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, struct update_subgroup *subgrp, const struct prefix *p, struct attr *attr, - bool skip_rmap_check) + struct attr *post_attr) { struct bgp_filter *filter; struct peer *from; @@ -2067,8 +2071,16 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, } } - /* For modify attribute, copy it to temporary structure. */ - *attr = *piattr; + /* For modify attribute, copy it to temporary structure. + * post_attr comes from BGP conditional advertisements, where + * attributes are already processed by advertise-map route-map, + * and this needs to be saved instead of overwriting from the + * path attributes. + */ + if (post_attr) + *attr = *post_attr; + else + *attr = *piattr; /* If local-preference is not set. */ if ((peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED) @@ -2162,8 +2174,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, bgp_peer_as_override(bgp, afi, safi, peer, attr); /* Route map & unsuppress-map apply. */ - if (!skip_rmap_check - && (ROUTE_MAP_OUT_NAME(filter) || bgp_path_suppressed(pi))) { + if (!post_attr && + (ROUTE_MAP_OUT_NAME(filter) || bgp_path_suppressed(pi))) { struct bgp_path_info rmap_path = {0}; struct bgp_path_info_extra dummy_rmap_path_extra = {0}; struct attr dummy_attr = {0}; @@ -2262,8 +2274,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, * The route SHOULD NOT be advertised to any neighbor from which the * Long-lived Graceful Restart Capability has not been received. */ - if (attr->community && - community_include(attr->community, COMMUNITY_LLGR_STALE) && + if (bgp_attr_get_community(attr) && + community_include(bgp_attr_get_community(attr), + COMMUNITY_LLGR_STALE) && !CHECK_FLAG(peer->cap, PEER_CAP_LLGR_RCV) && !CHECK_FLAG(peer->cap, PEER_CAP_LLGR_ADV)) return false; @@ -2394,7 +2407,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, return true; } -static int bgp_route_select_timer_expire(struct thread *thread) +static void bgp_route_select_timer_expire(struct thread *thread) { struct afi_safi_info *info; afi_t afi; @@ -2415,7 +2428,7 @@ static int bgp_route_select_timer_expire(struct thread *thread) XFREE(MTYPE_TMP, info); /* Best path selection */ - return bgp_best_path_select_defer(bgp, afi, safi); + bgp_best_path_select_defer(bgp, afi, safi); } void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest, @@ -2699,7 +2712,7 @@ void subgroup_process_announce_selected(struct update_subgroup *subgrp, if (selected) { if (subgroup_announce_check(dest, selected, subgrp, p, &attr, - false)) { + NULL)) { /* Route is selected, if the route is already installed * in FIB, then it is advertised */ @@ -3346,7 +3359,7 @@ void bgp_add_eoiu_mark(struct bgp *bgp) work_queue_add(bgp->process_queue, pqnode); } -static int bgp_maximum_prefix_restart_timer(struct thread *thread) +static void bgp_maximum_prefix_restart_timer(struct thread *thread) { struct peer *peer; @@ -3360,8 +3373,6 @@ static int bgp_maximum_prefix_restart_timer(struct thread *thread) if ((peer_clear(peer, NULL) < 0) && bgp_debug_neighbor_events(peer)) zlog_debug("%s: %s peer_clear failed", __func__, peer->host); - - return 0; } static uint32_t bgp_filtered_routes_count(struct peer *peer, afi_t afi, @@ -3680,7 +3691,7 @@ static void bgp_attr_add_no_export_community(struct attr *attr) struct community *merge; struct community *no_export; - old = attr->community; + old = bgp_attr_get_community(attr); no_export = community_str2com("no-export"); assert(no_export); @@ -3699,7 +3710,7 @@ static void bgp_attr_add_no_export_community(struct attr *attr) community_free(&no_export); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -3909,15 +3920,16 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, * propagation SHOULD be chosen according to the operator's * routing policy. */ - if (new_attr.community - && community_include(new_attr.community, - COMMUNITY_BLACKHOLE)) + if (bgp_attr_get_community(&new_attr) && + community_include(bgp_attr_get_community(&new_attr), + COMMUNITY_BLACKHOLE)) bgp_attr_add_no_export_community(&new_attr); /* If we receive the graceful-shutdown community from an eBGP * peer we must lower local-preference */ - if (new_attr.community - && community_include(new_attr.community, COMMUNITY_GSHUT)) { + if (bgp_attr_get_community(&new_attr) && + community_include(bgp_attr_get_community(&new_attr), + COMMUNITY_GSHUT)) { new_attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); new_attr.local_pref = BGP_GSHUT_LOCAL_PREF; @@ -4192,6 +4204,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, extra->sid[0].loc_node_len = 0; extra->sid[0].func_len = 0; extra->sid[0].arg_len = 0; + extra->sid[0].transposition_len = 0; + extra->sid[0].transposition_offset = 0; if (attr->srv6_l3vpn->loc_block_len != 0) { extra->sid[0].loc_block_len = @@ -4202,21 +4216,13 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, attr->srv6_l3vpn->func_len; extra->sid[0].arg_len = attr->srv6_l3vpn->arg_len; - } - - /* - * draft-ietf-bess-srv6-services-07 - * The part of SRv6 SID may be encoded as MPLS - * Label for the efficient packing. - */ - if (attr->srv6_l3vpn->transposition_len != 0) - transpose_sid( - &extra->sid[0].sid, - decode_label(label), + extra->sid[0].transposition_len = attr->srv6_l3vpn - ->transposition_offset, + ->transposition_len; + extra->sid[0].transposition_offset = attr->srv6_l3vpn - ->transposition_len); + ->transposition_offset; + } } } else if (attr->srv6_vpn) { extra = bgp_path_info_extra_get(pi); @@ -4413,17 +4419,10 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, attr->srv6_l3vpn->loc_node_len; extra->sid[0].func_len = attr->srv6_l3vpn->func_len; extra->sid[0].arg_len = attr->srv6_l3vpn->arg_len; - - /* - * draft-ietf-bess-srv6-services-07 - * The part of SRv6 SID may be encoded as MPLS Label for - * the efficient packing. - */ - if (attr->srv6_l3vpn->transposition_len != 0) - transpose_sid( - &extra->sid[0].sid, decode_label(label), - attr->srv6_l3vpn->transposition_offset, - attr->srv6_l3vpn->transposition_len); + extra->sid[0].transposition_len = + attr->srv6_l3vpn->transposition_len; + extra->sid[0].transposition_offset = + attr->srv6_l3vpn->transposition_offset; } else if (attr->srv6_vpn) { sid_copy(&extra->sid[0].sid, &attr->srv6_vpn->sid); extra->num_sids = 1; @@ -4702,7 +4701,7 @@ void bgp_stop_announce_route_timer(struct peer_af *paf) * Callback that is invoked when the route announcement timer for a * peer_af expires. */ -static int bgp_announce_route_timer_expired(struct thread *t) +static void bgp_announce_route_timer_expired(struct thread *t) { struct peer_af *paf; struct peer *peer; @@ -4711,17 +4710,15 @@ static int bgp_announce_route_timer_expired(struct thread *t) peer = paf->peer; if (!peer_established(peer)) - return 0; + return; if (!peer->afc_nego[paf->afi][paf->safi]) - return 0; + return; peer_af_announce_route(paf, 1); /* Notify BGP conditional advertisement scanner percess */ peer->advmap_config_change[paf->afi][paf->safi] = true; - - return 0; } /* @@ -4871,7 +4868,7 @@ static void bgp_soft_reconfig_table(struct peer *peer, afi_t afi, safi_t safi, * Without splitting the full job into several part, * vtysh waits for the job to finish before responding to a BGP command */ -static int bgp_soft_reconfig_table_task(struct thread *thread) +static void bgp_soft_reconfig_table_task(struct thread *thread) { uint32_t iter, max_iter; int ret; @@ -4925,7 +4922,7 @@ static int bgp_soft_reconfig_table_task(struct thread *thread) &table->soft_reconfig_peers); bgp_soft_reconfig_table_flag( table, false); - return 0; + return; } } } @@ -4939,7 +4936,7 @@ static int bgp_soft_reconfig_table_task(struct thread *thread) table->soft_reconfig_init = false; thread_add_event(bm->master, bgp_soft_reconfig_table_task, table, 0, &table->soft_reconfig_thread); - return 0; + return; } /* we're done, clean up the background iteration context info and schedule route annoucement @@ -4950,8 +4947,6 @@ static int bgp_soft_reconfig_table_task(struct thread *thread) } list_delete(&table->soft_reconfig_peers); - - return 0; } @@ -5376,9 +5371,10 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) if (CHECK_FLAG( peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT) && - pi->attr->community && + bgp_attr_get_community(pi->attr) && !community_include( - pi->attr->community, + bgp_attr_get_community( + pi->attr), COMMUNITY_NO_LLGR)) break; if (!CHECK_FLAG(pi->flags, @@ -5409,9 +5405,10 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) continue; if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT) && - pi->attr->community && - !community_include(pi->attr->community, - COMMUNITY_NO_LLGR)) + bgp_attr_get_community(pi->attr) && + !community_include( + bgp_attr_get_community(pi->attr), + COMMUNITY_NO_LLGR)) break; if (!CHECK_FLAG(pi->flags, BGP_PATH_STALE)) break; @@ -7055,7 +7052,7 @@ static bool bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin, if (!aspath_cmp(pi->attr->aspath, (aspath) ? aspath : ae)) return false; - if (!community_cmp(pi->attr->community, comm)) + if (!community_cmp(bgp_attr_get_community(pi->attr), comm)) return false; if (!ecommunity_cmp(bgp_attr_get_ecommunity(pi->attr), ecomm)) @@ -7474,10 +7471,10 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi, /* Compute aggregate route's community. */ - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) bgp_compute_aggregate_community_hash( - aggregate, - pi->attr->community); + aggregate, + bgp_attr_get_community(pi->attr)); /* Compute aggregate route's extended community. */ @@ -7596,12 +7593,13 @@ void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi, aggregate, pi->attr->aspath); - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) /* Remove community from aggregate. */ bgp_remove_comm_from_aggregate_hash( - aggregate, - pi->attr->community); + aggregate, + bgp_attr_get_community( + pi->attr)); if (bgp_attr_get_ecommunity(pi->attr)) /* Remove ecommunity from aggregate. @@ -7716,10 +7714,9 @@ static void bgp_add_route_to_aggregate(struct bgp *bgp, /* Compute aggregate route's community. */ - if (pinew->attr->community) + if (bgp_attr_get_community(pinew->attr)) bgp_compute_aggregate_community( - aggregate, - pinew->attr->community); + aggregate, bgp_attr_get_community(pinew->attr)); /* Compute aggregate route's extended community. */ @@ -7819,12 +7816,11 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi, bgp_remove_aspath_from_aggregate(aggregate, pi->attr->aspath); - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) /* Remove community from aggregate. */ bgp_remove_community_from_aggregate( - aggregate, - pi->attr->community); + aggregate, bgp_attr_get_community(pi->attr)); if (bgp_attr_get_ecommunity(pi->attr)) /* Remove ecommunity from aggregate. @@ -10503,14 +10499,16 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, /* Line 4 display Community */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) { if (json_paths) { - if (!attr->community->json) - community_str(attr->community, true); - json_object_lock(attr->community->json); - json_object_object_add(json_path, "community", - attr->community->json); + if (!bgp_attr_get_community(attr)->json) + community_str(bgp_attr_get_community(attr), + true); + json_object_lock(bgp_attr_get_community(attr)->json); + json_object_object_add( + json_path, "community", + bgp_attr_get_community(attr)->json); } else { vty_out(vty, " Community: %s\n", - attr->community->str); + bgp_attr_get_community(attr)->str); } } @@ -10755,8 +10753,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, gr_remaining); } - if (path->peer->t_llgr_stale[afi][safi] && attr->community && - community_include(attr->community, COMMUNITY_LLGR_STALE)) { + if (path->peer->t_llgr_stale[afi][safi] && + bgp_attr_get_community(attr) && + community_include(bgp_attr_get_community(attr), + COMMUNITY_LLGR_STALE)) { unsigned long llgr_remaining = thread_timer_remain_second( path->peer->t_llgr_stale[afi][safi]); @@ -10894,6 +10894,10 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, json_paths = NULL; for (; pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + total_count++; if (type == bgp_show_type_prefix_version) { @@ -10909,9 +10913,9 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, int num; bool found = false; - if (pi->attr->community) { - frrstr_split(pi->attr->community->str, - " ", &communities, &num); + if (picomm) { + frrstr_split(picomm->str, " ", + &communities, &num); for (int i = 0; i < num; i++) { const char *com2alias = bgp_community2alias( @@ -11035,36 +11039,31 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, continue; } if (type == bgp_show_type_community_all) { - if (!pi->attr->community) + if (!picomm) continue; } if (type == bgp_show_type_community) { struct community *com = output_arg; - if (!pi->attr->community - || !community_match(pi->attr->community, - com)) + if (!picomm || !community_match(picomm, com)) continue; } if (type == bgp_show_type_community_exact) { struct community *com = output_arg; - if (!pi->attr->community - || !community_cmp(pi->attr->community, com)) + if (!picomm || !community_cmp(picomm, com)) continue; } if (type == bgp_show_type_community_list) { struct community_list *list = output_arg; - if (!community_list_match(pi->attr->community, - list)) + if (!community_list_match(picomm, list)) continue; } if (type == bgp_show_type_community_list_exact) { struct community_list *list = output_arg; - if (!community_list_exact_match( - pi->attr->community, list)) + if (!community_list_exact_match(picomm, list)) continue; } if (type == bgp_show_type_lcommunity) { @@ -11482,44 +11481,43 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, vty_out(vty, "not allocated\n"); for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + count++; if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { best = count; if (bgp_path_suppressed(pi)) suppress = 1; - if (pi->attr->community == NULL) + if (!picomm) continue; no_advertise += community_include( - pi->attr->community, COMMUNITY_NO_ADVERTISE); - no_export += community_include(pi->attr->community, - COMMUNITY_NO_EXPORT); - local_as += community_include(pi->attr->community, - COMMUNITY_LOCAL_AS); - accept_own += community_include(pi->attr->community, - COMMUNITY_ACCEPT_OWN); + picomm, COMMUNITY_NO_ADVERTISE); + no_export += + community_include(picomm, COMMUNITY_NO_EXPORT); + local_as += + community_include(picomm, COMMUNITY_LOCAL_AS); + accept_own += + community_include(picomm, COMMUNITY_ACCEPT_OWN); route_filter_translated_v4 += community_include( - pi->attr->community, - COMMUNITY_ROUTE_FILTER_TRANSLATED_v4); + picomm, COMMUNITY_ROUTE_FILTER_TRANSLATED_v4); route_filter_translated_v6 += community_include( - pi->attr->community, - COMMUNITY_ROUTE_FILTER_TRANSLATED_v6); + picomm, COMMUNITY_ROUTE_FILTER_TRANSLATED_v6); route_filter_v4 += community_include( - pi->attr->community, COMMUNITY_ROUTE_FILTER_v4); + picomm, COMMUNITY_ROUTE_FILTER_v4); route_filter_v6 += community_include( - pi->attr->community, COMMUNITY_ROUTE_FILTER_v6); - llgr_stale += community_include(pi->attr->community, - COMMUNITY_LLGR_STALE); - no_llgr += community_include(pi->attr->community, - COMMUNITY_NO_LLGR); - accept_own_nexthop += - community_include(pi->attr->community, - COMMUNITY_ACCEPT_OWN_NEXTHOP); - blackhole += community_include(pi->attr->community, - COMMUNITY_BLACKHOLE); - no_peer += community_include(pi->attr->community, - COMMUNITY_NO_PEER); + picomm, COMMUNITY_ROUTE_FILTER_v6); + llgr_stale += + community_include(picomm, COMMUNITY_LLGR_STALE); + no_llgr += community_include(picomm, COMMUNITY_NO_LLGR); + accept_own_nexthop += community_include( + picomm, COMMUNITY_ACCEPT_OWN_NEXTHOP); + blackhole += + community_include(picomm, COMMUNITY_BLACKHOLE); + no_peer += community_include(picomm, COMMUNITY_NO_PEER); } } @@ -12846,7 +12844,7 @@ static void bgp_table_stats_rn(struct bgp_dest *dest, struct bgp_dest *top, } } -static int bgp_table_stats_walker(struct thread *t) +static void bgp_table_stats_walker(struct thread *t) { struct bgp_dest *dest, *ndest; struct bgp_dest *top; @@ -12854,7 +12852,7 @@ static int bgp_table_stats_walker(struct thread *t) unsigned int space = 0; if (!(top = bgp_table_top(ts->table))) - return 0; + return; switch (ts->table->afi) { case AFI_IP: @@ -12867,7 +12865,7 @@ static int bgp_table_stats_walker(struct thread *t) space = EVPN_ROUTE_PREFIXLEN; break; default: - return 0; + return; } ts->counts[BGP_STATS_MAXBITLEN] = space; @@ -12890,8 +12888,6 @@ static int bgp_table_stats_walker(struct thread *t) bgp_table_stats_rn(dest, top, ts, space); } } - - return 0; } static void bgp_table_stats_all(struct vty *vty, afi_t afi, safi_t safi, @@ -13209,7 +13205,7 @@ static void bgp_peer_count_proc(struct bgp_dest *rn, struct peer_pcounts *pc) } } -static int bgp_peer_count_walker(struct thread *t) +static void bgp_peer_count_walker(struct thread *t) { struct bgp_dest *rn, *rm; const struct bgp_table *table; @@ -13229,8 +13225,6 @@ static int bgp_peer_count_walker(struct thread *t) } else for (rn = bgp_table_top(pc->table); rn; rn = bgp_route_next(rn)) bgp_peer_count_proc(rn, pc); - - return 0; } static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi, @@ -14167,7 +14161,7 @@ DEFUN (show_ip_bgp_flowspec_routes_detailed, struct bgp *bgp = NULL; int idx = 0; bool uj = use_json(argc, argv); - uint16_t show_flags = 0; + uint16_t show_flags = BGP_SHOW_OPT_DETAIL; if (uj) { argc--; diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 317995594a..743b369bfa 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -154,6 +154,8 @@ struct bgp_sid_info { uint8_t loc_node_len; uint8_t func_len; uint8_t arg_len; + uint8_t transposition_len; + uint8_t transposition_offset; }; /* Ancillary information to struct bgp_path_info, @@ -785,7 +787,7 @@ extern bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, struct update_subgroup *subgrp, const struct prefix *p, struct attr *attr, - bool skip_rmap_check); + struct attr *post_attr); extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer); extern void bgp_process_queues_drain_immediate(void); diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index efb7f9eb7b..6fcc083e33 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -1246,10 +1246,10 @@ route_match_alias(void *rule, const struct prefix *prefix, void *object) int num; bool found; - if (path->attr->community) { + if (bgp_attr_get_community(path->attr)) { found = false; - frrstr_split(path->attr->community->str, " ", &communities, - &num); + frrstr_split(bgp_attr_get_community(path->attr)->str, " ", + &communities, &num); for (int i = 0; i < num; i++) { const char *com2alias = bgp_community2alias(communities[i]); @@ -1441,10 +1441,12 @@ route_match_community(void *rule, const struct prefix *prefix, void *object) return RMAP_NOMATCH; if (rcom->exact) { - if (community_list_exact_match(path->attr->community, list)) + if (community_list_exact_match( + bgp_attr_get_community(path->attr), list)) return RMAP_MATCH; } else { - if (community_list_match(path->attr->community, list)) + if (community_list_match(bgp_attr_get_community(path->attr), + list)) return RMAP_MATCH; } @@ -2193,12 +2195,12 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) rcs = rule; path = object; attr = path->attr; - old = attr->community; + old = bgp_attr_get_community(attr); /* "none" case. */ if (rcs->none) { attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); - attr->community = NULL; + bgp_attr_set_community(attr, NULL); /* See the longer comment down below. */ if (old && old->refcnt == 0) community_free(&old); @@ -2223,7 +2225,7 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) community_free(&old); /* will be interned by caller if required */ - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); @@ -2507,7 +2509,7 @@ route_set_community_delete(void *rule, const struct prefix *prefix, path = object; list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, COMMUNITY_LIST_MASTER); - old = path->attr->community; + old = bgp_attr_get_community(path->attr); if (list && old) { merge = community_list_match_delete(community_dup(old), list); @@ -2523,12 +2525,12 @@ route_set_community_delete(void *rule, const struct prefix *prefix, community_free(&old); if (new->size == 0) { - path->attr->community = NULL; + bgp_attr_set_community(path->attr, NULL); path->attr->flag &= ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); community_free(&new); } else { - path->attr->community = new; + bgp_attr_set_community(path->attr, new); path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } } @@ -4042,13 +4044,11 @@ static void bgp_route_map_process_update_cb(char *rmap_name) vpn_policy_routemap_event(rmap_name); } -int bgp_route_map_update_timer(struct thread *thread) +void bgp_route_map_update_timer(struct thread *thread) { bm->t_rmap_update = NULL; route_map_walk_update_list(bgp_route_map_process_update_cb); - - return 0; } static void bgp_route_map_mark_update(const char *rmap_name) diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index b320e4e719..c724b938d1 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -357,7 +357,7 @@ static struct prefix *pfx_record_to_prefix(struct pfx_record *record) return prefix; } -static int bgpd_sync_callback(struct thread *thread) +static void bgpd_sync_callback(struct thread *thread) { struct bgp *bgp; struct listnode *node; @@ -369,19 +369,19 @@ static int bgpd_sync_callback(struct thread *thread) thread_add_read(bm->master, bgpd_sync_callback, NULL, socket, &t_rpki); if (atomic_load_explicit(&rtr_update_overflow, memory_order_seq_cst)) { - while (read(socket, &rec, sizeof(struct pfx_record) != -1)) + while (read(socket, &rec, sizeof(struct pfx_record)) != -1) ; atomic_store_explicit(&rtr_update_overflow, 0, memory_order_seq_cst); revalidate_all_routes(); - return 0; + return; } retval = read(socket, &rec, sizeof(struct pfx_record)); if (retval != sizeof(struct pfx_record)) { RPKI_DEBUG("Could not read from socket"); - return retval; + return; } /* RTR-Server crashed/terminated, let's handle and switch @@ -389,7 +389,7 @@ static int bgpd_sync_callback(struct thread *thread) */ if (rec.socket && rec.socket->state == RTR_ERROR_FATAL) { reset(true); - return 0; + return; } prefix = pfx_record_to_prefix(&rec); @@ -421,7 +421,6 @@ static int bgpd_sync_callback(struct thread *thread) } prefix_free(&prefix); - return 0; } static void revalidate_bgp_node(struct bgp_dest *bgp_dest, afi_t afi, @@ -1262,7 +1261,7 @@ DEFPY (show_rpki_prefix, if (pfx_table_validate_r(rtr_config->pfx_table, &matches, &match_count, asn, &addr, prefix->prefixlen, &result) != PFX_SUCCESS) { - vty_out(vty, "Prefix lookup failed"); + vty_out(vty, "Prefix lookup failed\n"); return CMD_WARNING; } diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index bfcb4810d1..aa3e44318a 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -1157,7 +1157,7 @@ bool update_subgroup_check_merge(struct update_subgroup *subgrp, /* * update_subgroup_merge_check_thread_cb */ -static int update_subgroup_merge_check_thread_cb(struct thread *thread) +static void update_subgroup_merge_check_thread_cb(struct thread *thread) { struct update_subgroup *subgrp; @@ -1166,7 +1166,6 @@ static int update_subgroup_merge_check_thread_cb(struct thread *thread) subgrp->t_merge_check = NULL; update_subgroup_check_merge(subgrp, "triggered merge check"); - return 0; } /* @@ -1803,7 +1802,7 @@ update_group_default_originate_route_map_walkcb(struct update_group *updgrp, return UPDWALK_CONTINUE; } -int update_group_refresh_default_originate_route_map(struct thread *thread) +void update_group_refresh_default_originate_route_map(struct thread *thread) { struct bgp *bgp; char reason[] = "refresh default-originate route-map"; @@ -1813,8 +1812,6 @@ int update_group_refresh_default_originate_route_map(struct thread *thread) reason); thread_cancel(&bgp->t_rmap_def_originate_eval); bgp_unlock(bgp); - - return 0; } /* diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 5a9bebf8fe..0e10341bc4 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -375,7 +375,7 @@ extern void update_group_af_walk(struct bgp *bgp, afi_t afi, safi_t safi, updgrp_walkcb cb, void *ctx); extern void update_group_walk(struct bgp *bgp, updgrp_walkcb cb, void *ctx); extern void update_group_periodic_merge(struct bgp *bgp); -extern int +extern void update_group_refresh_default_originate_route_map(struct thread *thread); extern void update_group_start_advtimer(struct bgp *bgp); diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index dd140e48af..0d8ee79ae5 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -316,7 +316,7 @@ static void updgrp_show_adj(struct bgp *bgp, afi_t afi, safi_t safi, update_group_af_walk(bgp, afi, safi, updgrp_show_adj_walkcb, &ctx); } -static int subgroup_coalesce_timer(struct thread *thread) +static void subgroup_coalesce_timer(struct thread *thread) { struct update_subgroup *subgrp; struct bgp *bgp; @@ -351,8 +351,6 @@ static int subgroup_coalesce_timer(struct thread *thread) BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0); } } - - return 0; } static int update_group_announce_walkcb(struct update_group *updgrp, void *arg) @@ -691,7 +689,7 @@ void subgroup_announce_table(struct update_subgroup *subgrp, safi)) { if (subgroup_announce_check(dest, ri, subgrp, dest_p, &attr, - false)) { + NULL)) { /* Check if route can be advertised */ if (advertise) { if (!bgp_check_withdrawal(bgp, @@ -910,7 +908,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) if (subgroup_announce_check( dest, pi, subgrp, bgp_dest_get_prefix(dest), - &attr, false)) + &attr, NULL)) bgp_adj_out_set_subgroup( dest, subgrp, &attr, pi); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index afe4c7ae6f..d21e257cb5 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -8566,7 +8566,7 @@ DEFPY (af_sid_vpn_export, if (!yes) { /* implement me */ - vty_out(vty, "It's not implemented"); + vty_out(vty, "It's not implemented\n"); return CMD_WARNING_CONFIG_FAILED; } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 6691dc56ca..c0a9a38773 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1019,7 +1019,7 @@ static bool bgp_tm_chunk_obtained; static uint32_t bgp_tm_min, bgp_tm_max, bgp_tm_chunk_size; struct bgp *bgp_tm_bgp; -static int bgp_zebra_tm_connect(struct thread *t) +static void bgp_zebra_tm_connect(struct thread *t) { struct zclient *zclient; int delay = 10, ret = 0; @@ -1050,7 +1050,6 @@ static int bgp_zebra_tm_connect(struct thread *t) } thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, &bgp_tm_thread_connect); - return 0; } bool bgp_zebra_tm_chunk_obtained(void) @@ -1261,6 +1260,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, struct bgp_path_info *mpinfo_cp = &local_info; route_tag_t tag; mpls_label_t label; + struct bgp_sid_info *sid_info; int nh_othervrf = 0; bool is_evpn; bool nh_updated = false; @@ -1477,9 +1477,22 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, if (mpinfo->extra && !sid_zero(&mpinfo->extra->sid[0].sid) && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { - memcpy(&api_nh->seg6_segs, &mpinfo->extra->sid[0].sid, + sid_info = &mpinfo->extra->sid[0]; + + memcpy(&api_nh->seg6_segs, &sid_info->sid, sizeof(api_nh->seg6_segs)); + if (sid_info->transposition_len != 0) { + if (!bgp_is_valid_label( + &mpinfo->extra->label[0])) + continue; + + label = label_pton(&mpinfo->extra->label[0]); + transpose_sid(&api_nh->seg6_segs, label, + sid_info->transposition_offset, + sid_info->transposition_len); + } + SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6); } @@ -1497,7 +1510,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, sizeof(bzo.aspath)); if (info->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) - strlcpy(bzo.community, info->attr->community->str, + strlcpy(bzo.community, + bgp_attr_get_community(info->attr)->str, sizeof(bzo.community)); if (info->attr->flag diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 43046f7f18..16488eb4a4 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -3044,14 +3044,12 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer, return 0; } -static int bgp_startup_timer_expire(struct thread *thread) +static void bgp_startup_timer_expire(struct thread *thread) { struct bgp *bgp; bgp = THREAD_ARG(thread); bgp->t_startup = NULL; - - return 0; } /* diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 8b93c450e8..a9475f39a7 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -234,6 +234,7 @@ struct vpn_policy { */ uint32_t tovpn_sid_index; /* unset => set to 0 */ struct in6_addr *tovpn_sid; + struct in6_addr *tovpn_sid_locator; uint32_t tovpn_sid_transpose_label; struct in6_addr *tovpn_zebra_vrf_sid_last_sent; }; @@ -2226,7 +2227,7 @@ extern int peer_ttl_security_hops_unset(struct peer *); extern void peer_tx_shutdown_message_set(struct peer *, const char *msg); extern void peer_tx_shutdown_message_unset(struct peer *); -extern int bgp_route_map_update_timer(struct thread *thread); +extern void bgp_route_map_update_timer(struct thread *thread); extern void bgp_route_map_terminate(void); extern int peer_cmp(struct peer *p1, struct peer *p2); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 1f60c66995..1d58c03313 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -2372,7 +2372,7 @@ static void rfapiMonitorEncapDelete(struct bgp_path_info *vpn_bpi) * quagga lib/thread.h says this must return int even though * it doesn't do anything with the return value */ -static int rfapiWithdrawTimerVPN(struct thread *t) +static void rfapiWithdrawTimerVPN(struct thread *t) { struct rfapi_withdraw *wcb = t->arg; struct bgp_path_info *bpi = wcb->info; @@ -2385,13 +2385,13 @@ static int rfapiWithdrawTimerVPN(struct thread *t) vnc_zlog_debug_verbose( "%s: NULL BGP pointer, assume shutdown race condition!!!", __func__); - return 0; + return; } if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) { vnc_zlog_debug_verbose( "%s: BGP delete in progress, assume shutdown race condition!!!", __func__); - return 0; + return; } assert(wcb->node); assert(bpi); @@ -2503,7 +2503,6 @@ done: RFAPI_CHECK_REFCOUNT(wcb->node, SAFI_MPLS_VPN, 1 + wcb->lockoffset); agg_unlock_node(wcb->node); /* decr ref count */ XFREE(MTYPE_RFAPI_WITHDRAW, wcb); - return 0; } /* @@ -2674,7 +2673,7 @@ rfapiWithdrawEncapUpdateCachedUn(struct rfapi_import_table *import_table, return 0; } -static int rfapiWithdrawTimerEncap(struct thread *t) +static void rfapiWithdrawTimerEncap(struct thread *t) { struct rfapi_withdraw *wcb = t->arg; struct bgp_path_info *bpi = wcb->info; @@ -2748,7 +2747,6 @@ done: agg_unlock_node(wcb->node); /* decr ref count */ XFREE(MTYPE_RFAPI_WITHDRAW, wcb); skiplist_free(vpn_node_sl); - return 0; } @@ -2760,7 +2758,7 @@ static void rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table, struct agg_node *rn, struct bgp_path_info *bpi, afi_t afi, safi_t safi, - int (*timer_service_func)(struct thread *)) + void (*timer_service_func)(struct thread *)) { uint32_t lifetime; struct rfapi_withdraw *wcb; @@ -4062,7 +4060,7 @@ static void rfapiProcessPeerDownRt(struct peer *peer, struct agg_node *rn; struct bgp_path_info *bpi; struct agg_table *rt; - int (*timer_service_func)(struct thread *); + void (*timer_service_func)(struct thread *); assert(afi == AFI_IP || afi == AFI_IP6); diff --git a/bgpd/rfapi/rfapi_import.h b/bgpd/rfapi/rfapi_import.h index 50093111c2..387e6c47c9 100644 --- a/bgpd/rfapi/rfapi_import.h +++ b/bgpd/rfapi/rfapi_import.h @@ -126,8 +126,6 @@ extern void rfapiCheckRefcount(struct agg_node *rn, safi_t safi, extern int rfapiHasNonRemovedRoutes(struct agg_node *rn); -extern int rfapiProcessDeferredClose(struct thread *t); - extern int rfapiGetUnAddrOfVpnBi(struct bgp_path_info *bpi, struct prefix *p); extern void rfapiNexthop2Prefix(struct attr *attr, struct prefix *p); diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c index ce916c104b..58a0f8dea7 100644 --- a/bgpd/rfapi/rfapi_monitor.c +++ b/bgpd/rfapi/rfapi_monitor.c @@ -731,7 +731,7 @@ void rfapiMonitorResponseRemovalOn(struct bgp *bgp) bgp->rfapi_cfg->flags &= ~BGP_VNC_CONFIG_RESPONSE_REMOVAL_DISABLE; } -static int rfapiMonitorTimerExpire(struct thread *t) +static void rfapiMonitorTimerExpire(struct thread *t) { struct rfapi_monitor_vpn *m = t->arg; @@ -740,8 +740,6 @@ static int rfapiMonitorTimerExpire(struct thread *t) /* delete the monitor */ rfapiMonitorDel(bgp_get_default(), m->rfd, &m->p); - - return 0; } static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m) @@ -1041,7 +1039,7 @@ void rfapiMonitorMovedUp(struct rfapi_import_table *import_table, } } -static int rfapiMonitorEthTimerExpire(struct thread *t) +static void rfapiMonitorEthTimerExpire(struct thread *t) { struct rfapi_monitor_eth *m = t->arg; @@ -1052,7 +1050,6 @@ static int rfapiMonitorEthTimerExpire(struct thread *t) rfapiMonitorEthDel(bgp_get_default(), m->rfd, &m->macaddr, m->logical_net_id); - return 0; } static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m) diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 6f555d3685..ba0c576f1e 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -291,7 +291,7 @@ struct rfapi_rib_tcb { /* * remove route from rib */ -static int rfapiRibExpireTimer(struct thread *t) +static void rfapiRibExpireTimer(struct thread *t) { struct rfapi_rib_tcb *tcb = t->arg; @@ -328,8 +328,6 @@ static int rfapiRibExpireTimer(struct thread *t) XFREE(MTYPE_RFAPI_RECENT_DELETE, tcb); RFAPI_RIB_CHECK_COUNTS(1, 0); - - return 0; } static void rfapiRibStartTimer(struct rfapi_descriptor *rfd, diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 174fadc23e..b95bace0d1 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -468,6 +468,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) struct cluster_list *cluster; char buf[BUFSIZ]; struct ecommunity *ecomm; + struct community *comm; if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; @@ -482,8 +483,10 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) fp(out, " aspath=%p, refcnt=%d%s", attr->aspath, (attr->aspath ? attr->aspath->refcnt : 0), HVTYNL); - fp(out, " community=%p, refcnt=%d%s", attr->community, - (attr->community ? attr->community->refcnt : 0), HVTYNL); + + comm = bgp_attr_get_community(attr); + fp(out, " community=%p, refcnt=%d%s", comm, (comm ? comm->refcnt : 0), + HVTYNL); ecomm = bgp_attr_get_ecommunity(attr); fp(out, " ecommunity=%p, refcnt=%d%s", ecomm, diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 67c43a8671..f4f2e11391 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -1728,7 +1728,7 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, bgp_attr_unintern(&iattr); } -static int vncExportWithdrawTimer(struct thread *t) +static void vncExportWithdrawTimer(struct thread *t) { struct vnc_export_info *eti = t->arg; const struct prefix *p = agg_node_get_prefix(eti->node); @@ -1747,8 +1747,6 @@ static int vncExportWithdrawTimer(struct thread *t) * Free the eti */ vnc_eti_delete(eti); - - return 0; } /* diff --git a/configure.ac b/configure.ac index bdddf4b846..170d16ca6a 100644 --- a/configure.ac +++ b/configure.ac @@ -765,7 +765,7 @@ AC_ARG_ENABLE([scripting], AS_HELP_STRING([--enable-scripting], [Build with scripting support])) AC_ARG_ENABLE([netlink-debug], - AS_HELP_STRING([--disable-netlink-debug], [pretty print netlink debug messages])) + AS_HELP_STRING([--disable-netlink-debug], [don't pretty print netlink debug messages])) if test "$enable_netlink_debug" != "no" ; then AC_DEFINE([NETLINK_DEBUG], [1], [Netlink extra debugging code]) @@ -1371,6 +1371,8 @@ case "${enable_vtysh}" in AC_MSG_ERROR([libreadline (needed for vtysh) not found and/or missing dependencies]) ], [$LIBREADLINE]) ], []) + LIBS="$LIBS -lreadline" + AC_CHECK_FUNCS([rl_clear_visible_line]) LIBS="$prev_libs" AC_CHECK_HEADER([readline/history.h]) @@ -1526,6 +1528,13 @@ AC_CHECK_HEADERS([linux/mroute.h], [], [],[ #include <linux/types.h> ]) +AC_CHECK_HEADERS([linux/mroute6.h], [], [],[ + #include <sys/socket.h> + #include <netinet/in.h> + #define _LINUX_IN_H /* For Linux <= 2.6.25 */ + #include <linux/types.h> +]) + m4_define([FRR_INCLUDES], FRR_INCLUDES [#ifdef HAVE_LINUX_MROUTE_H diff --git a/doc/developer/cli.rst b/doc/developer/cli.rst index 9254eb4739..ff6c4f6e16 100644 --- a/doc/developer/cli.rst +++ b/doc/developer/cli.rst @@ -48,6 +48,16 @@ a node and returns the parent of the node. This interface causes all manner of insidious problems, even for experienced developers, and needs to be fixed at some point in the future. +Deprecation of old style of commands +------------------------------------ + +There are currently 2 styles of defining commands within a FRR source file. +``DEFUN`` and ``DEFPY``. ``DEFPY`` should be used for all new commands that +a developer is writing. This is because it allows for much better handling +of command line arguments as well as ensuring that input is correct. ``DEFUN`` +is listed here for historical reasons as well as for ensuring that existing +code can be understood by new developers. + Defining Commands ----------------- All definitions for the CLI system are exposed in ``lib/command.h``. In this diff --git a/doc/developer/topotests.rst b/doc/developer/topotests.rst index fa1fd20067..b41181f4e9 100644 --- a/doc/developer/topotests.rst +++ b/doc/developer/topotests.rst @@ -1088,6 +1088,9 @@ Requirements: a pull request. This ensures we have a unified code style. - Mark test modules with pytest markers depending on the daemons used during the tests (see :ref:`topotests-markers`) +- Always use IPv4 :rfc:`5737` (``192.0.2.0/24``, ``198.51.100.0/24``, + ``203.0.113.0/24``) and IPv6 :rfc:`3849` (``2001:db8::/32``) ranges reserved + for documentation. Tips: diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index 45bee17b71..af8756a909 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -346,6 +346,13 @@ Pre-submission Checklist the new feature within our existing CI infrastructure. Also the addition of automated testing to cover any pull request is encouraged. +- All new code must use the current latest version of acceptable code. + + - If a daemon is converted to YANG, then new code must use YANG. + - DEFPY's must be used for new cli + - Typesafe lists must be used + - printf formatting changes must be used + .. _signing-off: Signing Off @@ -1250,8 +1257,8 @@ CLI changes ----------- CLI's are a complicated ugly beast. Additions or changes to the CLI should use -a DEFUN to encapsulate one setting as much as is possible. Additionally as new -DEFUN's are added to the system, documentation should be provided for the new +a DEFPY to encapsulate one setting as much as is possible. Additionally as new +DEFPY's are added to the system, documentation should be provided for the new commands. Backwards Compatibility diff --git a/doc/user/basic.rst b/doc/user/basic.rst index 21432039c1..4c196cfcfe 100644 --- a/doc/user/basic.rst +++ b/doc/user/basic.rst @@ -673,6 +673,11 @@ Terminal Mode Commands we are setting each individual fd for the poll command at that point in time. +.. clicmd:: show thread timers + + This command displays FRR's timer data for timers that will pop in + the future. + .. _common-invocation-options: Common Invocation Options diff --git a/doc/user/isisd.rst b/doc/user/isisd.rst index 5d53f60f93..f7d42d8200 100644 --- a/doc/user/isisd.rst +++ b/doc/user/isisd.rst @@ -396,13 +396,6 @@ Known limitations: may not exceed 65535. Optionally sets also the Segment Routing Local Block. The negative command always unsets both. -.. clicmd:: segment-routing local-block (16-1048575) (16-1048575) - - Set the Segment Routing Local Block i.e. the label range used by MPLS - to store label in the MPLS FIB for Adjacency SID. Note that the block size - may not exceed 65535. This command is deprecated in favor of the combined - 'segment-routing global-block A B local-block C D' command. - .. clicmd:: segment-routing node-msd (1-16) Set the Maximum Stack Depth supported by the router. The value depend of the diff --git a/doc/user/vtysh.rst b/doc/user/vtysh.rst index ec674e377c..97b3863ef5 100644 --- a/doc/user/vtysh.rst +++ b/doc/user/vtysh.rst @@ -29,6 +29,30 @@ administrator with an external editor. vtysh. +Live logs +========= + +.. clicmd:: terminal monitor [DAEMON] + + Receive and display log messages. + + It is not currently possible to change the minimum message priority (fixed + to debug) or output formatting. These will likely be made configurable in + the future. + + Log messages are received asynchronously and may be printed both during + command execution as well as while on the prompt. They are printed to + stderr, unlike regular CLI output which is printed to stdout. The intent is + that stdin/stdout might be driven by some script while log messages are + visible on stderr. If stdout and stderr are the same file, the prompt and + pending input will be cleared and reprinted appropriately. + + .. note:: + + If ``vtysh`` cannot keep up, some log messages may be lost. The daemons + do **not** wait for, get blocked by, or buffer messages for ``vtysh``. + + Pager usage =========== diff --git a/doc/user/zebra.rst b/doc/user/zebra.rst index 7ca473ceb6..221e9c6fe2 100644 --- a/doc/user/zebra.rst +++ b/doc/user/zebra.rst @@ -29,6 +29,9 @@ Besides the common invocation options (:ref:`common-invocation-options`), the Zebra, when started, will read in routes. Those routes that Zebra identifies that it was the originator of will be swept in TIME seconds. If no time is specified then we will sweep those routes immediately. + Under the \*BSD's, there is no way to properly store the originating + route and the route types in this case will show up as a static route + with an admin distance of 255. .. option:: -r, --retain @@ -78,6 +81,11 @@ Besides the common invocation options (:ref:`common-invocation-options`), the protocols about route installation/update on ack received from the linux kernel or from offload notification. +.. option:: -s <SIZE>, --nl-bufsize <SIZE> + + Allow zebra to modify the default receive buffer size to SIZE + in bytes. Under \*BSD only the -s option is available. + .. _interface-commands: Configuration Addresses behaviour diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index 69c0d22aea..8d50ed689e 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -251,13 +251,13 @@ void eigrp_distribute_update_all_wrapper(struct access_list *notused) * * @param[in] thread current execution thread timer is associated with * - * @return int always returns 0 + * @return void * * @par * Called when 10sec waiting time expire and * executes Graceful restart for whole process */ -int eigrp_distribute_timer_process(struct thread *thread) +void eigrp_distribute_timer_process(struct thread *thread) { struct eigrp *eigrp; @@ -265,8 +265,6 @@ int eigrp_distribute_timer_process(struct thread *thread) /* execute GR for whole process */ eigrp_update_send_process_GR(eigrp, EIGRP_GR_FILTER, NULL); - - return 0; } /* @@ -274,13 +272,13 @@ int eigrp_distribute_timer_process(struct thread *thread) * * @param[in] thread current execution thread timer is associated with * - * @return int always returns 0 + * @return void * * @par * Called when 10sec waiting time expire and * executes Graceful restart for interface */ -int eigrp_distribute_timer_interface(struct thread *thread) +void eigrp_distribute_timer_interface(struct thread *thread) { struct eigrp_interface *ei; @@ -289,6 +287,4 @@ int eigrp_distribute_timer_interface(struct thread *thread) /* execute GR for interface */ eigrp_update_send_interface_GR(ei, EIGRP_GR_FILTER, NULL); - - return 0; } diff --git a/eigrpd/eigrp_filter.h b/eigrpd/eigrp_filter.h index 03f45cedbf..4dbfe276d2 100644 --- a/eigrpd/eigrp_filter.h +++ b/eigrpd/eigrp_filter.h @@ -38,7 +38,7 @@ extern void eigrp_distribute_update(struct distribute_ctx *ctx, extern void eigrp_distribute_update_interface(struct interface *ifp); extern void eigrp_distribute_update_all(struct prefix_list *plist); extern void eigrp_distribute_update_all_wrapper(struct access_list *alist); -extern int eigrp_distribute_timer_process(struct thread *thread); -extern int eigrp_distribute_timer_interface(struct thread *thread); +extern void eigrp_distribute_timer_process(struct thread *thread); +extern void eigrp_distribute_timer_interface(struct thread *thread); #endif /* EIGRPD_EIGRP_FILTER_H_ */ diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c index 2ff8fc5f39..717d8c0954 100644 --- a/eigrpd/eigrp_hello.c +++ b/eigrpd/eigrp_hello.c @@ -74,14 +74,14 @@ static const struct message eigrp_general_tlv_type_str[] = { * * @param[in] thread current execution thread timer is associated with * - * @return int always returns 0 + * @return void * * @par * Called once per "hello" time interval, default 5 seconds * Sends hello packet via multicast for all interfaces eigrp * is configured for */ -int eigrp_hello_timer(struct thread *thread) +void eigrp_hello_timer(struct thread *thread) { struct eigrp_interface *ei; @@ -97,8 +97,6 @@ int eigrp_hello_timer(struct thread *thread) /* Hello timer set. */ thread_add_timer(master, eigrp_hello_timer, ei, ei->params.v_hello, &ei->t_hello); - - return 0; } /** diff --git a/eigrpd/eigrp_metric.c b/eigrpd/eigrp_metric.c index ea62f9d1be..7ccafd4fa8 100644 --- a/eigrpd/eigrp_metric.c +++ b/eigrpd/eigrp_metric.c @@ -86,19 +86,24 @@ eigrp_metric_t eigrp_calculate_metrics(struct eigrp *eigrp, */ if (eigrp->k_values[0]) - composite += (eigrp->k_values[0] * metric.bandwidth); + composite += ((eigrp_metric_t)eigrp->k_values[0] * + (eigrp_metric_t)metric.bandwidth); if (eigrp->k_values[1]) - composite += ((eigrp->k_values[1] * metric.bandwidth) - / (256 - metric.load)); + composite += (((eigrp_metric_t)eigrp->k_values[1] * + (eigrp_metric_t)metric.bandwidth) / + (256 - metric.load)); if (eigrp->k_values[2]) - composite += (eigrp->k_values[2] * metric.delay); + composite += ((eigrp_metric_t)eigrp->k_values[2] * + (eigrp_metric_t)metric.delay); if (eigrp->k_values[3] && !eigrp->k_values[4]) - composite *= eigrp->k_values[3]; + composite *= (eigrp_metric_t)eigrp->k_values[3]; if (!eigrp->k_values[3] && eigrp->k_values[4]) - composite *= (eigrp->k_values[4] / metric.reliability); + composite *= ((eigrp_metric_t)eigrp->k_values[4] / + (eigrp_metric_t)metric.reliability); if (eigrp->k_values[3] && eigrp->k_values[4]) - composite *= ((eigrp->k_values[4] / metric.reliability) - + eigrp->k_values[3]); + composite *= (((eigrp_metric_t)eigrp->k_values[4] / + (eigrp_metric_t)metric.reliability) + + (eigrp_metric_t)eigrp->k_values[3]); composite = (composite <= EIGRP_METRIC_MAX) ? composite : EIGRP_METRIC_MAX; diff --git a/eigrpd/eigrp_neighbor.c b/eigrpd/eigrp_neighbor.c index f2d5217eb0..0ed8927d47 100644 --- a/eigrpd/eigrp_neighbor.c +++ b/eigrpd/eigrp_neighbor.c @@ -189,7 +189,7 @@ void eigrp_nbr_delete(struct eigrp_neighbor *nbr) XFREE(MTYPE_EIGRP_NEIGHBOR, nbr); } -int holddown_timer_expired(struct thread *thread) +void holddown_timer_expired(struct thread *thread) { struct eigrp_neighbor *nbr = THREAD_ARG(thread); struct eigrp *eigrp = nbr->ei->eigrp; @@ -198,8 +198,6 @@ int holddown_timer_expired(struct thread *thread) ifindex2ifname(nbr->ei->ifp->ifindex, eigrp->vrf_id)); nbr->state = EIGRP_NEIGHBOR_DOWN; eigrp_nbr_delete(nbr); - - return 0; } uint8_t eigrp_nbr_state_get(struct eigrp_neighbor *nbr) diff --git a/eigrpd/eigrp_neighbor.h b/eigrpd/eigrp_neighbor.h index 80ab1eded5..693d780f0f 100644 --- a/eigrpd/eigrp_neighbor.h +++ b/eigrpd/eigrp_neighbor.h @@ -39,7 +39,7 @@ extern struct eigrp_neighbor *eigrp_nbr_get(struct eigrp_interface *ei, extern struct eigrp_neighbor *eigrp_nbr_new(struct eigrp_interface *ei); extern void eigrp_nbr_delete(struct eigrp_neighbor *neigh); -extern int holddown_timer_expired(struct thread *thread); +extern void holddown_timer_expired(struct thread *thread); extern int eigrp_neighborship_check(struct eigrp_neighbor *neigh, struct TLV_Parameter_Type *tlv); diff --git a/eigrpd/eigrp_network.h b/eigrpd/eigrp_network.h index eeb32ba356..912a9248cf 100644 --- a/eigrpd/eigrp_network.h +++ b/eigrpd/eigrp_network.h @@ -35,7 +35,7 @@ extern int eigrp_if_ipmulticast(struct eigrp *, struct prefix *, unsigned int); extern int eigrp_network_set(struct eigrp *eigrp, struct prefix *p); extern int eigrp_network_unset(struct eigrp *eigrp, struct prefix *p); -extern int eigrp_hello_timer(struct thread *); +extern void eigrp_hello_timer(struct thread *thread); extern void eigrp_if_update(struct interface *); extern int eigrp_if_add_allspfrouters(struct eigrp *, struct prefix *, unsigned int); diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c index 529d94567d..491b2994b0 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -320,7 +320,7 @@ int eigrp_check_sha256_digest(struct stream *s, return 1; } -int eigrp_write(struct thread *thread) +void eigrp_write(struct thread *thread) { struct eigrp *eigrp = THREAD_ARG(thread); struct eigrp_header *eigrph; @@ -471,12 +471,10 @@ out: thread_add_write(master, eigrp_write, eigrp, eigrp->fd, &eigrp->t_write); } - - return 0; } /* Starting point of packet process function. */ -int eigrp_read(struct thread *thread) +void eigrp_read(struct thread *thread) { int ret; struct stream *ibuf; @@ -500,7 +498,7 @@ int eigrp_read(struct thread *thread) if (!(ibuf = eigrp_recv_packet(eigrp, eigrp->fd, &ifp, eigrp->ibuf))) { /* This raw packet is known to be at least as big as its IP * header. */ - return -1; + return; } /* Note that there should not be alignment problems with this assignment @@ -531,7 +529,7 @@ int eigrp_read(struct thread *thread) eigrp->vrf_id); if (c == NULL) - return 0; + return; ifp = c->ifp; } @@ -546,7 +544,7 @@ int eigrp_read(struct thread *thread) must remain very accurate in doing this. */ if (!ei) - return 0; + return; /* Self-originated packet should be discarded silently. */ if (eigrp_if_lookup_by_local_addr(eigrp, NULL, iph->ip_src) @@ -555,7 +553,7 @@ int eigrp_read(struct thread *thread) zlog_debug( "eigrp_read[%pI4]: Dropping self-originated packet", &srcaddr); - return 0; + return; } /* Advance from IP header to EIGRP header (iph->ip_hl has been verified @@ -574,7 +572,7 @@ int eigrp_read(struct thread *thread) "ignoring packet from router %u sent to %pI4, wrong AS Number received: %u", ntohs(eigrph->vrid), &iph->ip_dst, ntohs(eigrph->ASNumber)); - return 0; + return; } /* If incoming interface is passive one, ignore it. */ @@ -588,7 +586,7 @@ int eigrp_read(struct thread *thread) if (iph->ip_dst.s_addr == htonl(EIGRP_MULTICAST_ADDRESS)) { eigrp_if_set_multicast(ei); } - return 0; + return; } /* else it must be a local eigrp interface, check it was received on @@ -599,7 +597,7 @@ int eigrp_read(struct thread *thread) zlog_warn( "Packet from [%pI4] received on wrong link %s", &iph->ip_src, ifp->name); - return 0; + return; } /* Verify more EIGRP header fields. */ @@ -609,7 +607,7 @@ int eigrp_read(struct thread *thread) zlog_debug( "eigrp_read[%pI4]: Header check failed, dropping.", &iph->ip_src); - return ret; + return; } /* calcualte the eigrp packet length, and move the pounter to the @@ -700,8 +698,6 @@ int eigrp_read(struct thread *thread) IF_NAME(ei), opcode); break; } - - return 0; } static struct stream *eigrp_recv_packet(struct eigrp *eigrp, @@ -989,7 +985,7 @@ static int eigrp_check_network_mask(struct eigrp_interface *ei, return 0; } -int eigrp_unack_packet_retrans(struct thread *thread) +void eigrp_unack_packet_retrans(struct thread *thread) { struct eigrp_neighbor *nbr; nbr = (struct eigrp_neighbor *)THREAD_ARG(thread); @@ -1005,8 +1001,10 @@ int eigrp_unack_packet_retrans(struct thread *thread) eigrp_fifo_push(nbr->ei->obuf, duplicate); ep->retrans_counter++; - if (ep->retrans_counter == EIGRP_PACKET_RETRANS_MAX) - return eigrp_retrans_count_exceeded(ep, nbr); + if (ep->retrans_counter == EIGRP_PACKET_RETRANS_MAX) { + eigrp_retrans_count_exceeded(ep, nbr); + return; + } /*Start retransmission timer*/ thread_add_timer(master, eigrp_unack_packet_retrans, nbr, @@ -1021,11 +1019,9 @@ int eigrp_unack_packet_retrans(struct thread *thread) thread_add_write(master, eigrp_write, nbr->ei->eigrp, nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write); } - - return 0; } -int eigrp_unack_multicast_packet_retrans(struct thread *thread) +void eigrp_unack_multicast_packet_retrans(struct thread *thread) { struct eigrp_neighbor *nbr; nbr = (struct eigrp_neighbor *)THREAD_ARG(thread); @@ -1040,8 +1036,10 @@ int eigrp_unack_multicast_packet_retrans(struct thread *thread) eigrp_fifo_push(nbr->ei->obuf, duplicate); ep->retrans_counter++; - if (ep->retrans_counter == EIGRP_PACKET_RETRANS_MAX) - return eigrp_retrans_count_exceeded(ep, nbr); + if (ep->retrans_counter == EIGRP_PACKET_RETRANS_MAX) { + eigrp_retrans_count_exceeded(ep, nbr); + return; + } /*Start retransmission timer*/ thread_add_timer(master, eigrp_unack_multicast_packet_retrans, @@ -1056,8 +1054,6 @@ int eigrp_unack_multicast_packet_retrans(struct thread *thread) thread_add_write(master, eigrp_write, nbr->ei->eigrp, nbr->ei->eigrp->fd, &nbr->ei->eigrp->t_write); } - - return 0; } /* Get packet from tail of fifo. */ diff --git a/eigrpd/eigrp_packet.h b/eigrpd/eigrp_packet.h index cb69bc26b2..f659176667 100644 --- a/eigrpd/eigrp_packet.h +++ b/eigrpd/eigrp_packet.h @@ -33,8 +33,8 @@ #define _ZEBRA_EIGRP_PACKET_H /*Prototypes*/ -extern int eigrp_read(struct thread *); -extern int eigrp_write(struct thread *); +extern void eigrp_read(struct thread *thread); +extern void eigrp_write(struct thread *thread); extern struct eigrp_packet *eigrp_packet_new(size_t size, struct eigrp_neighbor *nbr); @@ -66,8 +66,8 @@ extern uint16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s, extern uint16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s, struct eigrp_interface *ei); -extern int eigrp_unack_packet_retrans(struct thread *thread); -extern int eigrp_unack_multicast_packet_retrans(struct thread *thread); +extern void eigrp_unack_packet_retrans(struct thread *thread); +extern void eigrp_unack_multicast_packet_retrans(struct thread *thread); /* * untill there is reason to have their own header, these externs are found in @@ -80,7 +80,7 @@ extern void eigrp_hello_send_ack(struct eigrp_neighbor *nbr); extern void eigrp_hello_receive(struct eigrp *eigrp, struct ip *iph, struct eigrp_header *eigrph, struct stream *s, struct eigrp_interface *ei, int size); -extern int eigrp_hello_timer(struct thread *thread); +extern void eigrp_hello_timer(struct thread *thread); /* * These externs are found in eigrp_update.c @@ -96,7 +96,7 @@ extern void eigrp_update_send_all(struct eigrp *eigrp, struct eigrp_interface *exception); extern void eigrp_update_send_init(struct eigrp_neighbor *nbr); extern void eigrp_update_send_EOT(struct eigrp_neighbor *nbr); -extern int eigrp_update_send_GR_thread(struct thread *thread); +extern void eigrp_update_send_GR_thread(struct thread *thread); extern void eigrp_update_send_GR(struct eigrp_neighbor *nbr, enum GR_type gr_type, struct vty *vty); extern void eigrp_update_send_interface_GR(struct eigrp_interface *ei, diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c index 8a9eea8a79..5848632d8b 100644 --- a/eigrpd/eigrp_update.c +++ b/eigrpd/eigrp_update.c @@ -910,7 +910,7 @@ static void eigrp_update_send_GR_part(struct eigrp_neighbor *nbr) * * Uses nbr_gr_packet_type and t_nbr_send_gr from neighbor. */ -int eigrp_update_send_GR_thread(struct thread *thread) +void eigrp_update_send_GR_thread(struct thread *thread) { struct eigrp_neighbor *nbr; @@ -923,7 +923,7 @@ int eigrp_update_send_GR_thread(struct thread *thread) if (nbr->retrans_queue->count > 0) { thread_add_timer_msec(master, eigrp_update_send_GR_thread, nbr, 10, &nbr->t_nbr_send_gr); - return 0; + return; } /* send GR EIGRP packet chunk */ @@ -933,8 +933,6 @@ int eigrp_update_send_GR_thread(struct thread *thread) if (nbr->nbr_gr_packet_type != EIGRP_PACKET_PART_LAST) { thread_execute(master, eigrp_update_send_GR_thread, nbr, 0); } - - return 0; } /** diff --git a/include/linux/netconf.h b/include/linux/netconf.h new file mode 100644 index 0000000000..fac4edd553 --- /dev/null +++ b/include/linux/netconf.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_NETCONF_H_ +#define _UAPI_LINUX_NETCONF_H_ + +#include <linux/types.h> +#include <linux/netlink.h> + +struct netconfmsg { + __u8 ncm_family; +}; + +enum { + NETCONFA_UNSPEC, + NETCONFA_IFINDEX, + NETCONFA_FORWARDING, + NETCONFA_RP_FILTER, + NETCONFA_MC_FORWARDING, + NETCONFA_PROXY_NEIGH, + NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN, + NETCONFA_INPUT, + NETCONFA_BC_FORWARDING, + __NETCONFA_MAX +}; +#define NETCONFA_MAX (__NETCONFA_MAX - 1) +#define NETCONFA_ALL -1 + +#define NETCONFA_IFINDEX_ALL -1 +#define NETCONFA_IFINDEX_DEFAULT -2 + +#endif /* _UAPI_LINUX_NETCONF_H_ */ diff --git a/include/subdir.am b/include/subdir.am index 86129c4d68..a06a8e5649 100644 --- a/include/subdir.am +++ b/include/subdir.am @@ -5,6 +5,7 @@ noinst_HEADERS += \ include/linux/lwtunnel.h \ include/linux/mpls_iptunnel.h \ include/linux/neighbour.h \ + include/linux/netconf.h \ include/linux/netlink.h \ include/linux/nexthop.h \ include/linux/rtnetlink.h \ diff --git a/isisd/fabricd.c b/isisd/fabricd.c index 2937df992c..3e0d4ba549 100644 --- a/isisd/fabricd.c +++ b/isisd/fabricd.c @@ -250,7 +250,7 @@ void fabricd_finish(struct fabricd *f) hash_free(f->neighbors_neighbors); } -static int fabricd_initial_sync_timeout(struct thread *thread) +static void fabricd_initial_sync_timeout(struct thread *thread) { struct fabricd *f = THREAD_ARG(thread); @@ -258,7 +258,6 @@ static int fabricd_initial_sync_timeout(struct thread *thread) f->initial_sync_circuit->interface->name); f->initial_sync_state = FABRICD_SYNC_PENDING; f->initial_sync_circuit = NULL; - return 0; } void fabricd_initial_sync_hello(struct isis_circuit *circuit) @@ -399,22 +398,21 @@ static uint8_t fabricd_calculate_fabric_tier(struct isis_area *area) return tier; } -static int fabricd_tier_set_timer(struct thread *thread) +static void fabricd_tier_set_timer(struct thread *thread) { struct fabricd *f = THREAD_ARG(thread); fabricd_set_tier(f, f->tier_pending); - return 0; } -static int fabricd_tier_calculation_cb(struct thread *thread) +static void fabricd_tier_calculation_cb(struct thread *thread) { struct fabricd *f = THREAD_ARG(thread); uint8_t tier = ISIS_TIER_UNDEFINED; tier = fabricd_calculate_fabric_tier(f->area); if (tier == ISIS_TIER_UNDEFINED) - return 0; + return; zlog_info("OpenFabric: Got tier %hhu from algorithm. Arming timer.", tier); @@ -423,7 +421,6 @@ static int fabricd_tier_calculation_cb(struct thread *thread) f->area->lsp_gen_interval[ISIS_LEVEL2 - 1], &f->tier_set_timer); - return 0; } static void fabricd_bump_tier_calculation_timer(struct fabricd *f) diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c index d75613f300..06909c4306 100644 --- a/isisd/isis_adjacency.c +++ b/isisd/isis_adjacency.c @@ -448,7 +448,7 @@ const char *isis_adj_yang_state(enum isis_adj_state state) } } -int isis_adj_expire(struct thread *thread) +void isis_adj_expire(struct thread *thread) { struct isis_adjacency *adj; @@ -461,8 +461,6 @@ int isis_adj_expire(struct thread *thread) /* trigger the adj expire event */ isis_adj_state_change(&adj, ISIS_ADJ_DOWN, "holding time expired"); - - return 0; } /* diff --git a/isisd/isis_adjacency.h b/isisd/isis_adjacency.h index af70775a87..4d84c5ca4d 100644 --- a/isisd/isis_adjacency.h +++ b/isisd/isis_adjacency.h @@ -141,13 +141,13 @@ void isis_adj_state_change(struct isis_adjacency **adj, enum isis_adj_state state, const char *reason); void isis_adj_print(struct isis_adjacency *adj); const char *isis_adj_yang_state(enum isis_adj_state state); -int isis_adj_expire(struct thread *thread); +void isis_adj_expire(struct thread *thread); void isis_adj_print_vty(struct isis_adjacency *adj, struct vty *vty, char detail); void isis_adj_build_neigh_list(struct list *adjdb, struct list *list); void isis_adj_build_up_list(struct list *adjdb, struct list *list); int isis_adj_usage2levels(enum isis_adj_usage usage); -int isis_bfd_startup_timer(struct thread *thread); +void isis_bfd_startup_timer(struct thread *thread); const char *isis_adj_name(const struct isis_adjacency *adj); #endif /* ISIS_ADJACENCY_H */ diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c index 089ad5747c..c23b0f0dc1 100644 --- a/isisd/isis_cli.c +++ b/isisd/isis_cli.c @@ -1560,48 +1560,6 @@ void cli_show_isis_label_blocks(struct vty *vty, const struct lyd_node *dnode, } /* - * XPath: /frr-isisd:isis/instance/segment-routing/srlb - */ -DEFPY_HIDDEN( - isis_sr_local_block_label_range, isis_sr_local_block_label_range_cmd, - "segment-routing local-block (16-1048575)$lower_bound (16-1048575)$upper_bound", - SR_STR - "Segment Routing Local Block label range\n" - "The lower bound of the block\n" - "The upper bound of the block (block size may not exceed 65535)\n") -{ -#if CONFDATE > 20220217 -CPP_NOTICE("Use of the local-block command is deprecated") -#endif - nb_cli_enqueue_change(vty, - "./segment-routing/label-blocks/srlb/lower-bound", - NB_OP_MODIFY, lower_bound_str); - nb_cli_enqueue_change(vty, - "./segment-routing/label-blocks/srlb/upper-bound", - NB_OP_MODIFY, upper_bound_str); - - return nb_cli_apply_changes(vty, NULL); -} - -DEFPY_HIDDEN(no_isis_sr_local_block_label_range, - no_isis_sr_local_block_label_range_cmd, - "no segment-routing local-block [(16-1048575) (16-1048575)]", - NO_STR SR_STR - "Segment Routing Local Block label range\n" - "The lower bound of the block\n" - "The upper bound of the block (block size may not exceed 65535)\n") -{ - nb_cli_enqueue_change(vty, - "./segment-routing/label-blocks/srlb/lower-bound", - NB_OP_MODIFY, NULL); - nb_cli_enqueue_change(vty, - "./segment-routing/label-blocks/srlb/upper-bound", - NB_OP_MODIFY, NULL); - - return nb_cli_apply_changes(vty, NULL); -} - -/* * XPath: /frr-isisd:isis/instance/segment-routing/msd/node-msd */ DEFPY_YANG (isis_sr_node_msd, @@ -3189,8 +3147,6 @@ void isis_cli_init(void) install_element(ISIS_NODE, &no_isis_sr_enable_cmd); install_element(ISIS_NODE, &isis_sr_global_block_label_range_cmd); install_element(ISIS_NODE, &no_isis_sr_global_block_label_range_cmd); - install_element(ISIS_NODE, &isis_sr_local_block_label_range_cmd); - install_element(ISIS_NODE, &no_isis_sr_local_block_label_range_cmd); install_element(ISIS_NODE, &isis_sr_node_msd_cmd); install_element(ISIS_NODE, &no_isis_sr_node_msd_cmd); install_element(ISIS_NODE, &isis_sr_prefix_sid_cmd); diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c index e09e23aaeb..78197974d7 100644 --- a/isisd/isis_dr.c +++ b/isisd/isis_dr.c @@ -61,7 +61,7 @@ const char *isis_disflag2string(int disflag) return NULL; /* not reached */ } -int isis_run_dr(struct thread *thread) +void isis_run_dr(struct thread *thread) { struct isis_circuit_arg *arg = THREAD_ARG(thread); @@ -76,7 +76,7 @@ int isis_run_dr(struct thread *thread) zlog_warn("%s: scheduled for non broadcast circuit from %s:%d", __func__, thread->xref->xref.file, thread->xref->xref.line); - return ISIS_WARNING; + return; } if (circuit->u.bc.run_dr_elect[level - 1]) @@ -84,8 +84,6 @@ int isis_run_dr(struct thread *thread) circuit->u.bc.t_run_dr[level - 1] = NULL; circuit->u.bc.run_dr_elect[level - 1] = 1; - - return ISIS_OK; } static int isis_check_dr_change(struct isis_adjacency *adj, int level) diff --git a/isisd/isis_dr.h b/isisd/isis_dr.h index 5cab985d4b..f01a03f374 100644 --- a/isisd/isis_dr.h +++ b/isisd/isis_dr.h @@ -24,7 +24,7 @@ #ifndef _ZEBRA_ISIS_DR_H #define _ZEBRA_ISIS_DR_H -int isis_run_dr(struct thread *thread); +void isis_run_dr(struct thread *thread); int isis_dr_elect(struct isis_circuit *circuit, int level); int isis_dr_resign(struct isis_circuit *circuit, int level); int isis_dr_commence(struct isis_circuit *circuit, int level); diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c index ade6e82220..8d76e81934 100644 --- a/isisd/isis_dynhn.c +++ b/isisd/isis_dynhn.c @@ -42,7 +42,7 @@ DEFINE_MTYPE_STATIC(ISISD, ISIS_DYNHN, "ISIS dyn hostname"); -static int dyn_cache_cleanup(struct thread *); +static void dyn_cache_cleanup(struct thread *); void dyn_cache_init(struct isis *isis) { @@ -67,7 +67,7 @@ void dyn_cache_finish(struct isis *isis) list_delete(&isis->dyn_cache); } -static int dyn_cache_cleanup(struct thread *thread) +static void dyn_cache_cleanup(struct thread *thread) { struct listnode *node, *nnode; struct isis_dynhn *dyn; @@ -87,8 +87,6 @@ static int dyn_cache_cleanup(struct thread *thread) thread_add_timer(master, dyn_cache_cleanup, isis, 120, &isis->t_dync_clean); - - return ISIS_OK; } struct isis_dynhn *dynhn_find_by_id(struct isis *isis, const uint8_t *id) diff --git a/isisd/isis_events.c b/isisd/isis_events.c index 26c68db762..fce48fec97 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -209,7 +209,7 @@ void isis_circuit_is_type_set(struct isis_circuit *circuit, int newtype) /* events supporting code */ -int isis_event_dis_status_change(struct thread *thread) +void isis_event_dis_status_change(struct thread *thread) { struct isis_circuit *circuit; @@ -217,15 +217,13 @@ int isis_event_dis_status_change(struct thread *thread) /* invalid arguments */ if (!circuit || !circuit->area) - return 0; + return; if (IS_DEBUG_EVENTS) zlog_debug("ISIS-Evt (%s) DIS status change", circuit->area->area_tag); /* LSP generation again */ lsp_regenerate_schedule(circuit->area, IS_LEVEL_1 | IS_LEVEL_2, 0); - - return 0; } void isis_event_auth_failure(char *area_tag, const char *error_string, diff --git a/isisd/isis_events.h b/isisd/isis_events.h index 25643f4ede..e6d9af58be 100644 --- a/isisd/isis_events.h +++ b/isisd/isis_events.h @@ -31,7 +31,7 @@ void isis_event_circuit_type_change(struct isis_circuit *circuit, int newtype); /* * Events related to adjacencies */ -int isis_event_dis_status_change(struct thread *thread); +void isis_event_dis_status_change(struct thread *thread); /* * Error events diff --git a/isisd/isis_ldp_sync.c b/isisd/isis_ldp_sync.c index 0c541348df..3c68b8d15f 100644 --- a/isisd/isis_ldp_sync.c +++ b/isisd/isis_ldp_sync.c @@ -344,7 +344,7 @@ void isis_ldp_sync_set_if_metric(struct isis_circuit *circuit, bool run_regen) /* * LDP-SYNC holddown timer routines */ -static int isis_ldp_sync_holddown_timer(struct thread *thread) +static void isis_ldp_sync_holddown_timer(struct thread *thread) { struct isis_circuit *circuit; struct ldp_sync_info *ldp_sync_info; @@ -355,7 +355,7 @@ static int isis_ldp_sync_holddown_timer(struct thread *thread) */ circuit = THREAD_ARG(thread); if (circuit->ldp_sync_info == NULL) - return 0; + return; ldp_sync_info = circuit->ldp_sync_info; @@ -366,7 +366,6 @@ static int isis_ldp_sync_holddown_timer(struct thread *thread) circuit->interface->name); isis_ldp_sync_set_if_metric(circuit, true); - return 0; } void isis_ldp_sync_holddown_timer_add(struct isis_circuit *circuit) diff --git a/isisd/isis_lfa.c b/isisd/isis_lfa.c index 84aac24d52..d515873ec1 100644 --- a/isisd/isis_lfa.c +++ b/isisd/isis_lfa.c @@ -1401,7 +1401,7 @@ static struct rlfa *rlfa_lookup(struct isis_spftree *spftree, return rlfa_tree_find(&spftree->lfa.remote.rlfas, &s); } -static int isis_area_verify_routes_cb(struct thread *thread) +static void isis_area_verify_routes_cb(struct thread *thread) { struct isis_area *area = THREAD_ARG(thread); @@ -1409,8 +1409,6 @@ static int isis_area_verify_routes_cb(struct thread *thread) zlog_debug("ISIS-LFA: updating RLFAs in the RIB"); isis_area_verify_routes(area); - - return 0; } static mpls_label_t rlfa_nexthop_label(struct isis_spftree *spftree, diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 92d329f035..463d26f6c7 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -62,9 +62,9 @@ DEFINE_MTYPE_STATIC(ISISD, ISIS_LSP, "ISIS LSP"); -static int lsp_refresh(struct thread *thread); -static int lsp_l1_refresh_pseudo(struct thread *thread); -static int lsp_l2_refresh_pseudo(struct thread *thread); +static void lsp_refresh(struct thread *thread); +static void lsp_l1_refresh_pseudo(struct thread *thread); +static void lsp_l2_refresh_pseudo(struct thread *thread); static void lsp_destroy(struct isis_lsp *lsp); @@ -1447,7 +1447,7 @@ static int lsp_regenerate(struct isis_area *area, int level) /* * Something has changed or periodic refresh -> regenerate LSP */ -static int lsp_refresh(struct thread *thread) +static void lsp_refresh(struct thread *thread) { struct lsp_refresh_arg *arg = THREAD_ARG(thread); @@ -1463,7 +1463,7 @@ static int lsp_refresh(struct thread *thread) area->lsp_regenerate_pending[level - 1] = 0; if ((area->is_type & level) == 0) - return ISIS_ERROR; + return; /* * Throttle regeneration of LSPs (but not when BFD signalled a 'down' @@ -1476,13 +1476,13 @@ static int lsp_refresh(struct thread *thread) area->area_tag, level); _lsp_regenerate_schedule(area, level, 0, false, __func__, __FILE__, __LINE__); - return 0; + return; } sched_debug( "ISIS (%s): LSP L%d refresh timer expired. Refreshing LSP...", area->area_tag, level); - return lsp_regenerate(area, level); + lsp_regenerate(area, level); } int _lsp_regenerate_schedule(struct isis_area *area, int level, @@ -1827,7 +1827,7 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level) /* * Something has changed or periodic refresh -> regenerate pseudo LSP */ -static int lsp_l1_refresh_pseudo(struct thread *thread) +static void lsp_l1_refresh_pseudo(struct thread *thread) { struct isis_circuit *circuit; uint8_t id[ISIS_SYS_ID_LEN + 2]; @@ -1843,13 +1843,13 @@ static int lsp_l1_refresh_pseudo(struct thread *thread) LSP_PSEUDO_ID(id) = circuit->circuit_id; LSP_FRAGMENT(id) = 0; lsp_purge_pseudo(id, circuit, IS_LEVEL_1); - return ISIS_ERROR; + return; } - return lsp_regenerate_pseudo(circuit, IS_LEVEL_1); + lsp_regenerate_pseudo(circuit, IS_LEVEL_1); } -static int lsp_l2_refresh_pseudo(struct thread *thread) +static void lsp_l2_refresh_pseudo(struct thread *thread) { struct isis_circuit *circuit; uint8_t id[ISIS_SYS_ID_LEN + 2]; @@ -1865,10 +1865,10 @@ static int lsp_l2_refresh_pseudo(struct thread *thread) LSP_PSEUDO_ID(id) = circuit->circuit_id; LSP_FRAGMENT(id) = 0; lsp_purge_pseudo(id, circuit, IS_LEVEL_2); - return ISIS_ERROR; + return; } - return lsp_regenerate_pseudo(circuit, IS_LEVEL_2); + lsp_regenerate_pseudo(circuit, IS_LEVEL_2); } int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level) @@ -1973,7 +1973,7 @@ int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level) * Walk through LSPs for an area * - set remaining lifetime */ -int lsp_tick(struct thread *thread) +void lsp_tick(struct thread *thread) { struct isis_area *area; struct isis_lsp *lsp; @@ -2064,8 +2064,6 @@ int lsp_tick(struct thread *thread) && !isis_tx_queue_len(fabricd_init_c->tx_queue)) { fabricd_initial_sync_finish(area); } - - return ISIS_OK; } void lsp_purge_pseudo(uint8_t *id, struct isis_circuit *circuit, int level) diff --git a/isisd/isis_lsp.h b/isisd/isis_lsp.h index cac5f0d733..f42d702b37 100644 --- a/isisd/isis_lsp.h +++ b/isisd/isis_lsp.h @@ -65,7 +65,7 @@ DECLARE_RBTREE_UNIQ(lspdb, struct isis_lsp, dbe, lspdb_compare); void lsp_db_init(struct lspdb_head *head); void lsp_db_fini(struct lspdb_head *head); -int lsp_tick(struct thread *thread); +void lsp_tick(struct thread *thread); int lsp_generate(struct isis_area *area, int level); #define lsp_regenerate_schedule(area, level, all_pseudo) \ diff --git a/isisd/isis_nb_notifications.c b/isisd/isis_nb_notifications.c index f219632acf..fd7b1b3159 100644 --- a/isisd/isis_nb_notifications.c +++ b/isisd/isis_nb_notifications.c @@ -245,7 +245,7 @@ void isis_notif_max_area_addr_mismatch(const struct isis_circuit *circuit, data = yang_data_new_uint8(xpath_arg, max_area_addrs); listnode_add(arguments, data); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_max_area_addr_mismatch, circuit, max_area_addrs, @@ -270,7 +270,7 @@ void isis_notif_authentication_type_failure(const struct isis_circuit *circuit, notif_prep_instance_hdr(xpath, area, "default", arguments); notif_prepr_iface_hdr(xpath, circuit, arguments); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_authentication_type_failure, circuit, raw_pdu, @@ -294,7 +294,7 @@ void isis_notif_authentication_failure(const struct isis_circuit *circuit, notif_prep_instance_hdr(xpath, area, "default", arguments); notif_prepr_iface_hdr(xpath, circuit, arguments); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_authentication_failure, circuit, raw_pdu, @@ -361,7 +361,7 @@ void isis_notif_reject_adjacency(const struct isis_circuit *circuit, data = yang_data_new_string(xpath_arg, reason); listnode_add(arguments, data); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_reject_adjacency, circuit, raw_pdu, raw_pdu_len); @@ -384,7 +384,7 @@ void isis_notif_area_mismatch(const struct isis_circuit *circuit, notif_prep_instance_hdr(xpath, area, "default", arguments); notif_prepr_iface_hdr(xpath, circuit, arguments); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_area_mismatch, circuit, raw_pdu, raw_pdu_len); @@ -467,7 +467,7 @@ void isis_notif_id_len_mismatch(const struct isis_circuit *circuit, data = yang_data_new_uint8(xpath_arg, rcv_id_len); listnode_add(arguments, data); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_id_len_mismatch, circuit, rcv_id_len, raw_pdu, @@ -495,7 +495,7 @@ void isis_notif_version_skew(const struct isis_circuit *circuit, data = yang_data_new_uint8(xpath_arg, version); listnode_add(arguments, data); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); hook_call(isis_hook_version_skew, circuit, version, raw_pdu, @@ -525,7 +525,7 @@ void isis_notif_lsp_error(const struct isis_circuit *circuit, data = yang_data_new_string(xpath_arg, rawlspid_print(lsp_id)); listnode_add(arguments, data); snprintf(xpath_arg, sizeof(xpath_arg), "%s/raw-pdu", xpath); - data = yang_data_new(xpath_arg, raw_pdu); + data = yang_data_new_binary(xpath_arg, raw_pdu, raw_pdu_len); listnode_add(arguments, data); /* ignore offset and tlv_type which cannot be set properly */ diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 0814f3eea0..517c9ec5aa 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -1793,11 +1793,10 @@ int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa) return retval; } -int isis_receive(struct thread *thread) +void isis_receive(struct thread *thread) { struct isis_circuit *circuit; uint8_t ssnpa[ETH_ALEN]; - int retval; /* * Get the circuit @@ -1809,20 +1808,22 @@ int isis_receive(struct thread *thread) isis_circuit_stream(circuit, &circuit->rcv_stream); +#if ISIS_METHOD != ISIS_METHOD_BPF + int retval; + retval = circuit->rx(circuit, ssnpa); -#if ISIS_METHOD != ISIS_METHOD_BPF if (retval == ISIS_OK) - retval = isis_handle_pdu(circuit, ssnpa); -#endif //ISIS_METHOD != ISIS_METHOD_BPF + isis_handle_pdu(circuit, ssnpa); +#else // ISIS_METHOD != ISIS_METHOD_BPF + circuit->rx(circuit, ssnpa); +#endif /* * prepare for next packet. */ if (!circuit->is_passive) isis_circuit_prepare(circuit); - - return retval; } /* @@ -2015,7 +2016,7 @@ int send_hello(struct isis_circuit *circuit, int level) return retval; } -static int send_hello_cb(struct thread *thread) +static void send_hello_cb(struct thread *thread) { struct isis_circuit_arg *arg = THREAD_ARG(thread); assert(arg); @@ -2030,30 +2031,29 @@ static int send_hello_cb(struct thread *thread) send_hello(circuit, 1); send_hello_sched(circuit, ISIS_LEVEL1, 1000 * circuit->hello_interval[1]); - return ISIS_OK; + return; } if (circuit->circ_type != CIRCUIT_T_BROADCAST) { zlog_warn("ISIS-Hello (%s): Trying to send hello on unknown circuit type %d", circuit->area->area_tag, circuit->circ_type); - return ISIS_WARNING; + return; } circuit->u.bc.t_send_lan_hello[level - 1] = NULL; if (!(circuit->is_type & level)) { zlog_warn("ISIS-Hello (%s): Trying to send L%d IIH in L%d-only circuit", circuit->area->area_tag, level, 3 - level); - return ISIS_WARNING; + return; } if (circuit->u.bc.run_dr_elect[level - 1]) isis_dr_elect(circuit, level); - int rv = send_hello(circuit, level); + send_hello(circuit, level); /* set next timer thread */ send_hello_sched(circuit, level, 1000 * circuit->hello_interval[level - 1]); - return rv; } static void _send_hello_sched(struct isis_circuit *circuit, @@ -2247,7 +2247,7 @@ int send_csnp(struct isis_circuit *circuit, int level) return ISIS_OK; } -int send_l1_csnp(struct thread *thread) +void send_l1_csnp(struct thread *thread) { struct isis_circuit *circuit; @@ -2265,11 +2265,9 @@ int send_l1_csnp(struct thread *thread) thread_add_timer(master, send_l1_csnp, circuit, isis_jitter(circuit->csnp_interval[0], CSNP_JITTER), &circuit->t_send_csnp[0]); - - return ISIS_OK; } -int send_l2_csnp(struct thread *thread) +void send_l2_csnp(struct thread *thread) { struct isis_circuit *circuit; @@ -2287,8 +2285,6 @@ int send_l2_csnp(struct thread *thread) thread_add_timer(master, send_l2_csnp, circuit, isis_jitter(circuit->csnp_interval[1], CSNP_JITTER), &circuit->t_send_csnp[1]); - - return ISIS_OK; } /* @@ -2405,7 +2401,7 @@ static int send_psnp(int level, struct isis_circuit *circuit) return ISIS_OK; } -int send_l1_psnp(struct thread *thread) +void send_l1_psnp(struct thread *thread) { struct isis_circuit *circuit; @@ -2420,15 +2416,13 @@ int send_l1_psnp(struct thread *thread) thread_add_timer(master, send_l1_psnp, circuit, isis_jitter(circuit->psnp_interval[0], PSNP_JITTER), &circuit->t_send_psnp[0]); - - return ISIS_OK; } /* * 7.3.15.4 action on expiration of partial SNP interval * level 2 */ -int send_l2_psnp(struct thread *thread) +void send_l2_psnp(struct thread *thread) { struct isis_circuit *circuit; @@ -2443,8 +2437,6 @@ int send_l2_psnp(struct thread *thread) thread_add_timer(master, send_l2_psnp, circuit, isis_jitter(circuit->psnp_interval[1], PSNP_JITTER), &circuit->t_send_psnp[1]); - - return ISIS_OK; } /* diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h index 1e70a42f13..b2e43781f6 100644 --- a/isisd/isis_pdu.h +++ b/isisd/isis_pdu.h @@ -195,7 +195,7 @@ struct isis_partial_seqnum_hdr { /* * Function for receiving IS-IS PDUs */ -int isis_receive(struct thread *thread); +void isis_receive(struct thread *thread); /* * calling arguments for snp_process () @@ -210,10 +210,10 @@ int isis_receive(struct thread *thread); */ void send_hello_sched(struct isis_circuit *circuit, int level, long delay); int send_csnp(struct isis_circuit *circuit, int level); -int send_l1_csnp(struct thread *thread); -int send_l2_csnp(struct thread *thread); -int send_l1_psnp(struct thread *thread); -int send_l2_psnp(struct thread *thread); +void send_l1_csnp(struct thread *thread); +void send_l2_csnp(struct thread *thread); +void send_l1_psnp(struct thread *thread); +void send_l2_psnp(struct thread *thread); void send_lsp(struct isis_circuit *circuit, struct isis_lsp *lsp, enum isis_tx_type tx_type); void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream); diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 5718b48b9d..04b5cf1a67 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -1832,7 +1832,7 @@ void isis_spf_invalidate_routes(struct isis_spftree *tree) tree->route_table_backup->cleanup = isis_route_node_cleanup; } -static int isis_run_spf_cb(struct thread *thread) +static void isis_run_spf_cb(struct thread *thread) { struct isis_spf_run *run = THREAD_ARG(thread); struct isis_area *area = run->area; @@ -1845,7 +1845,7 @@ static int isis_run_spf_cb(struct thread *thread) if (IS_DEBUG_SPF_EVENTS) zlog_warn("ISIS-SPF (%s) area does not share level", area->area_tag); - return ISIS_WARNING; + return; } isis_area_delete_backup_adj_sids(area, level); @@ -1883,8 +1883,6 @@ static int isis_run_spf_cb(struct thread *thread) UNSET_FLAG(circuit->flags, ISIS_CIRCUIT_FLAPPED_AFTER_SPF); fabricd_run_spf(area); - - return 0; } static struct isis_spf_run *isis_run_spf_arg(struct isis_area *area, int level) diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c index 18a727adde..91886cbc37 100644 --- a/isisd/isis_sr.c +++ b/isisd/isis_sr.c @@ -1090,7 +1090,7 @@ DEFUN(show_sr_node, show_sr_node_cmd, * * @return 1 on success */ -static int sr_start_label_manager(struct thread *start) +static void sr_start_label_manager(struct thread *start) { struct isis_area *area; @@ -1098,8 +1098,6 @@ static int sr_start_label_manager(struct thread *start) /* re-attempt to start SR & Label Manager connection */ isis_sr_start(area); - - return 1; } /** diff --git a/isisd/isis_tx_queue.c b/isisd/isis_tx_queue.c index d3da5b9d39..078329221a 100644 --- a/isisd/isis_tx_queue.c +++ b/isisd/isis_tx_queue.c @@ -114,7 +114,7 @@ static struct isis_tx_queue_entry *tx_queue_find(struct isis_tx_queue *queue, return hash_lookup(queue->hash, &e); } -static int tx_queue_send_event(struct thread *thread) +static void tx_queue_send_event(struct thread *thread) { struct isis_tx_queue_entry *e = THREAD_ARG(thread); struct isis_tx_queue *queue = e->queue; @@ -128,8 +128,6 @@ static int tx_queue_send_event(struct thread *thread) queue->send_event(queue->circuit, e->lsp, e->type); /* Don't access e here anymore, send_event might have destroyed it */ - - return 0; } void _isis_tx_queue_add(struct isis_tx_queue *queue, diff --git a/ldpd/accept.c b/ldpd/accept.c index e8d3976ee9..2999a35c06 100644 --- a/ldpd/accept.c +++ b/ldpd/accept.c @@ -25,7 +25,7 @@ struct accept_ev { LIST_ENTRY(accept_ev) entry; struct thread *ev; - int (*accept_cb)(struct thread *); + void (*accept_cb)(struct thread *); void *arg; int fd; }; @@ -37,8 +37,8 @@ struct { static void accept_arm(void); static void accept_unarm(void); -static int accept_cb(struct thread *); -static int accept_timeout(struct thread *); +static void accept_cb(struct thread *); +static void accept_timeout(struct thread *); void accept_init(void) @@ -46,8 +46,7 @@ accept_init(void) LIST_INIT(&accept_queue.queue); } -int -accept_add(int fd, int (*cb)(struct thread *), void *arg) +int accept_add(int fd, void (*cb)(struct thread *), void *arg) { struct accept_ev *av; @@ -115,23 +114,17 @@ accept_unarm(void) thread_cancel(&av->ev); } -static int -accept_cb(struct thread *thread) +static void accept_cb(struct thread *thread) { struct accept_ev *av = THREAD_ARG(thread); thread_add_read(master, accept_cb, av, av->fd, &av->ev); av->accept_cb(thread); - - return (0); } -static int -accept_timeout(struct thread *thread) +static void accept_timeout(struct thread *thread) { accept_queue.evt = NULL; log_debug(__func__); accept_arm(); - - return (0); } diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index d390e70ad0..bbc8a277a6 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -26,12 +26,12 @@ #include "log.h" static __inline int adj_compare(const struct adj *, const struct adj *); -static int adj_itimer(struct thread *); +static void adj_itimer(struct thread *); static __inline int tnbr_compare(const struct tnbr *, const struct tnbr *); static void tnbr_del(struct ldpd_conf *, struct tnbr *); static void tnbr_start(struct tnbr *); static void tnbr_stop(struct tnbr *); -static int tnbr_hello_timer(struct thread *); +static void tnbr_hello_timer(struct thread *); static void tnbr_start_hello_timer(struct tnbr *); static void tnbr_stop_hello_timer(struct tnbr *); @@ -172,8 +172,7 @@ adj_get_af(const struct adj *adj) /* adjacency timers */ /* ARGSUSED */ -static int -adj_itimer(struct thread *thread) +static void adj_itimer(struct thread *thread) { struct adj *adj = THREAD_ARG(thread); @@ -187,13 +186,11 @@ adj_itimer(struct thread *thread) adj->source.target->rlfa_count == 0) { /* remove dynamic targeted neighbor */ tnbr_del(leconf, adj->source.target); - return (0); + return; } } adj_del(adj, S_HOLDTIME_EXP); - - return (0); } void @@ -345,16 +342,13 @@ tnbr_get_hello_interval(struct tnbr *tnbr) /* target neighbors timers */ /* ARGSUSED */ -static int -tnbr_hello_timer(struct thread *thread) +static void tnbr_hello_timer(struct thread *thread) { struct tnbr *tnbr = THREAD_ARG(thread); tnbr->hello_timer = NULL; send_hello(HELLO_TARGETED, NULL, tnbr); tnbr_start_hello_timer(tnbr); - - return (0); } static void diff --git a/ldpd/control.c b/ldpd/control.c index 3b77765952..376f488bd1 100644 --- a/ldpd/control.c +++ b/ldpd/control.c @@ -26,11 +26,11 @@ #define CONTROL_BACKLOG 5 -static int control_accept(struct thread *); +static void control_accept(struct thread *); static struct ctl_conn *control_connbyfd(int); static struct ctl_conn *control_connbypid(pid_t); static void control_close(int); -static int control_dispatch_imsg(struct thread *); +static void control_dispatch_imsg(struct thread *); struct ctl_conns ctl_conns; @@ -101,8 +101,7 @@ control_cleanup(char *path) } /* ARGSUSED */ -static int -control_accept(struct thread *thread) +static void control_accept(struct thread *thread) { int connfd; socklen_t len; @@ -121,14 +120,14 @@ control_accept(struct thread *thread) else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED) log_warn("%s: accept", __func__); - return (0); + return; } sock_set_nonblock(connfd); if ((c = calloc(1, sizeof(struct ctl_conn))) == NULL) { log_warn(__func__); close(connfd); - return (0); + return; } imsg_init(&c->iev.ibuf, connfd); @@ -140,8 +139,6 @@ control_accept(struct thread *thread) c->iev.ev_write = NULL; TAILQ_INSERT_TAIL(&ctl_conns, c, entry); - - return (0); } static struct ctl_conn * @@ -191,8 +188,7 @@ control_close(int fd) } /* ARGSUSED */ -static int -control_dispatch_imsg(struct thread *thread) +static void control_dispatch_imsg(struct thread *thread) { int fd = THREAD_FD(thread); struct ctl_conn *c; @@ -202,7 +198,7 @@ control_dispatch_imsg(struct thread *thread) if ((c = control_connbyfd(fd)) == NULL) { log_warnx("%s: fd %d: not found", __func__, fd); - return (0); + return; } c->iev.ev_read = NULL; @@ -210,13 +206,13 @@ control_dispatch_imsg(struct thread *thread) if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || n == 0) { control_close(fd); - return (0); + return; } for (;;) { if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) { control_close(fd); - return (0); + return; } if (n == 0) @@ -278,8 +274,6 @@ control_dispatch_imsg(struct thread *thread) } imsg_event_add(&c->iev); - - return (0); } int diff --git a/ldpd/interface.c b/ldpd/interface.c index 5e04eab1b3..af6e8fd7ec 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -33,7 +33,7 @@ static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); static int if_start(struct iface *, int); static int if_reset(struct iface *, int); static void if_update_af(struct iface_af *); -static int if_hello_timer(struct thread *); +static void if_hello_timer(struct thread *thread); static void if_start_hello_timer(struct iface_af *); static void if_stop_hello_timer(struct iface_af *); static int if_join_ipv4_group(struct iface *, struct in_addr *); @@ -43,7 +43,7 @@ static int if_leave_ipv6_group(struct iface *, struct in6_addr *); static int ldp_sync_fsm_init(struct iface *iface, int state); static int ldp_sync_act_iface_start_sync(struct iface *iface); -static int iface_wait_for_ldp_sync_timer(struct thread *thread); +static void iface_wait_for_ldp_sync_timer(struct thread *thread); static void start_wait_for_ldp_sync_timer(struct iface *iface); static void stop_wait_for_ldp_sync_timer(struct iface *iface); static int ldp_sync_act_ldp_start_sync(struct iface *iface); @@ -455,16 +455,13 @@ if_get_wait_for_sync_interval(void) /* timers */ /* ARGSUSED */ -static int -if_hello_timer(struct thread *thread) +static void if_hello_timer(struct thread *thread) { struct iface_af *ia = THREAD_ARG(thread); ia->hello_timer = NULL; send_hello(HELLO_LINK, ia, NULL); if_start_hello_timer(ia); - - return (0); } static void @@ -737,14 +734,11 @@ ldp_sync_act_iface_start_sync(struct iface *iface) return (0); } -static int -iface_wait_for_ldp_sync_timer(struct thread *thread) +static void iface_wait_for_ldp_sync_timer(struct thread *thread) { struct iface *iface = THREAD_ARG(thread); ldp_sync_fsm(iface, LDP_SYNC_EVT_LDP_SYNC_COMPLETE); - - return (0); } static void start_wait_for_ldp_sync_timer(struct iface *iface) diff --git a/ldpd/lde.c b/ldpd/lde.c index 55fa806d4d..9d1daabbe9 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -41,8 +41,8 @@ #include "libfrr.h" static void lde_shutdown(void); -static int lde_dispatch_imsg(struct thread *); -static int lde_dispatch_parent(struct thread *); +static void lde_dispatch_imsg(struct thread *thread); +static void lde_dispatch_parent(struct thread *thread); static __inline int lde_nbr_compare(const struct lde_nbr *, const struct lde_nbr *); static struct lde_nbr *lde_nbr_new(uint32_t, struct lde_nbr *); @@ -243,8 +243,7 @@ lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data, } /* ARGSUSED */ -static int -lde_dispatch_imsg(struct thread *thread) +static void lde_dispatch_imsg(struct thread *thread) { struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; @@ -422,13 +421,10 @@ lde_dispatch_imsg(struct thread *thread) thread_cancel(&iev->ev_write); lde_shutdown(); } - - return (0); } /* ARGSUSED */ -static int -lde_dispatch_parent(struct thread *thread) +static void lde_dispatch_parent(struct thread *thread) { static struct ldpd_conf *nconf; struct iface *iface, *niface; @@ -710,8 +706,6 @@ lde_dispatch_parent(struct thread *thread) thread_cancel(&iev->ev_write); lde_shutdown(); } - - return (0); } int @@ -2173,11 +2167,9 @@ lde_address_list_free(struct lde_nbr *ln) /* * Event callback used to retry the label-manager sync zapi session. */ -static int zclient_sync_retry(struct thread *thread) +static void zclient_sync_retry(struct thread *thread) { zclient_sync_init(); - - return 0; } /* diff --git a/ldpd/lde.h b/ldpd/lde.h index dee6f3fcb9..bcb1e1ccaa 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -227,7 +227,7 @@ void lde_check_withdraw(struct map *, struct lde_nbr *); void lde_check_withdraw_wcard(struct map *, struct lde_nbr *); int lde_wildcard_apply(struct map *, struct fec *, struct lde_map *); -int lde_gc_timer(struct thread *); +void lde_gc_timer(struct thread *thread); void lde_gc_start_timer(void); void lde_gc_stop_timer(void); diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index 33bb6c0fc7..1ade3c5378 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -1037,8 +1037,7 @@ lde_wildcard_apply(struct map *wcard, struct fec *fec, struct lde_map *me) /* gabage collector timer: timer to remove dead entries from the LIB */ /* ARGSUSED */ -int -lde_gc_timer(struct thread *thread) +void lde_gc_timer(struct thread *thread) { struct fec *fec, *safe; struct fec_node *fn; @@ -1064,8 +1063,6 @@ lde_gc_timer(struct thread *thread) log_debug("%s: %u entries removed", __func__, count); lde_gc_start_timer(); - - return (0); } void diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 92cf24bd5d..a78d2b25d6 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -46,8 +46,8 @@ static void ldpd_shutdown(void); static pid_t start_child(enum ldpd_process, char *, int, int); -static int main_dispatch_ldpe(struct thread *); -static int main_dispatch_lde(struct thread *); +static void main_dispatch_ldpe(struct thread *thread); +static void main_dispatch_lde(struct thread *thread); static int main_imsg_send_ipc_sockets(struct imsgbuf *, struct imsgbuf *); static void main_imsg_send_net_sockets(int); @@ -219,7 +219,7 @@ FRR_DAEMON_INFO(ldpd, LDP, .n_yang_modules = array_size(ldpd_yang_modules), ); -static int ldp_config_fork_apply(struct thread *t) +static void ldp_config_fork_apply(struct thread *t) { /* * So the frr_config_fork() function schedules @@ -231,8 +231,6 @@ static int ldp_config_fork_apply(struct thread *t) * after the read in of the config. */ ldp_config_apply(NULL, vty_conf); - - return 0; } int @@ -563,8 +561,7 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) /* imsg handling */ /* ARGSUSED */ -static int -main_dispatch_ldpe(struct thread *thread) +static void main_dispatch_ldpe(struct thread *thread) { struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; @@ -627,13 +624,10 @@ main_dispatch_ldpe(struct thread *thread) else kill(lde_pid, SIGTERM); } - - return (0); } /* ARGSUSED */ -static int -main_dispatch_lde(struct thread *thread) +static void main_dispatch_lde(struct thread *thread) { struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; @@ -735,13 +729,10 @@ main_dispatch_lde(struct thread *thread) else kill(ldpe_pid, SIGTERM); } - - return (0); } /* ARGSUSED */ -int -ldp_write_handler(struct thread *thread) +void ldp_write_handler(struct thread *thread) { struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; @@ -755,12 +746,10 @@ ldp_write_handler(struct thread *thread) /* this pipe is dead, so remove the event handlers */ thread_cancel(&iev->ev_read); thread_cancel(&iev->ev_write); - return (0); + return; } imsg_event_add(iev); - - return (0); } void @@ -828,9 +817,8 @@ evbuf_event_add(struct evbuf *eb) &eb->ev); } -void -evbuf_init(struct evbuf *eb, int fd, int (*handler)(struct thread *), - void *arg) +void evbuf_init(struct evbuf *eb, int fd, void (*handler)(struct thread *), + void *arg) { msgbuf_init(&eb->wbuf); eb->wbuf.fd = fd; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 616c390e50..fd0097ca5e 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -63,15 +63,15 @@ struct evbuf { struct msgbuf wbuf; struct thread *ev; - int (*handler)(struct thread *); + void (*handler)(struct thread *); void *arg; }; struct imsgev { struct imsgbuf ibuf; - int (*handler_write)(struct thread *); + void (*handler_write)(struct thread *); struct thread *ev_write; - int (*handler_read)(struct thread *); + void (*handler_read)(struct thread *); struct thread *ev_read; }; @@ -792,7 +792,7 @@ void sa2addr(struct sockaddr *, int *, union ldpd_addr *, socklen_t sockaddr_len(struct sockaddr *); /* ldpd.c */ -int ldp_write_handler(struct thread *); +void ldp_write_handler(struct thread *thread); void main_imsg_compose_ldpe(int, pid_t, void *, uint16_t); void main_imsg_compose_lde(int, pid_t, void *, uint16_t); int main_imsg_compose_both(enum imsg_type, void *, @@ -802,8 +802,7 @@ int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, int, void *, uint16_t); void evbuf_enqueue(struct evbuf *, struct ibuf *); void evbuf_event_add(struct evbuf *); -void evbuf_init(struct evbuf *, int, - int (*)(struct thread *), void *); +void evbuf_init(struct evbuf *, int, void (*)(struct thread *), void *); void evbuf_clear(struct evbuf *); int ldp_acl_request(struct imsgev *, char *, int, union ldpd_addr *, uint8_t); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 31f8026e3f..29abd420e5 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -36,10 +36,10 @@ #include "libfrr.h" static void ldpe_shutdown(void); -static int ldpe_dispatch_main(struct thread *); -static int ldpe_dispatch_lde(struct thread *); +static void ldpe_dispatch_main(struct thread *thread); +static void ldpe_dispatch_lde(struct thread *thread); #ifdef __OpenBSD__ -static int ldpe_dispatch_pfkey(struct thread *); +static void ldpe_dispatch_pfkey(struct thread *thread); #endif static void ldpe_setup_sockets(int, int, int, int); static void ldpe_close_sockets(int); @@ -273,8 +273,7 @@ ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data, } /* ARGSUSED */ -static int -ldpe_dispatch_main(struct thread *thread) +static void ldpe_dispatch_main(struct thread *thread) { static struct ldpd_conf *nconf; struct iface *niface; @@ -631,13 +630,10 @@ ldpe_dispatch_main(struct thread *thread) thread_cancel(&iev->ev_write); ldpe_shutdown(); } - - return (0); } /* ARGSUSED */ -static int -ldpe_dispatch_lde(struct thread *thread) +static void ldpe_dispatch_lde(struct thread *thread) { struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; @@ -770,14 +766,11 @@ ldpe_dispatch_lde(struct thread *thread) thread_cancel(&iev->ev_write); ldpe_shutdown(); } - - return (0); } #ifdef __OpenBSD__ /* ARGSUSED */ -static int -ldpe_dispatch_pfkey(struct thread *thread) +static void ldpe_dispatch_pfkey(struct thread *thread) { int fd = THREAD_FD(thread); @@ -786,8 +779,6 @@ ldpe_dispatch_pfkey(struct thread *thread) if (pfkey_read(fd, NULL) == -1) fatal("pfkey_read failed, exiting..."); - - return (0); } #endif /* __OpenBSD__ */ diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index 0f650a86d3..ddb0e0d970 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -148,7 +148,7 @@ extern struct nbr_pid_head nbrs_by_pid; /* accept.c */ void accept_init(void); -int accept_add(int, int (*)(struct thread *), void *); +int accept_add(int, void (*)(struct thread *), void *); void accept_del(int); void accept_pause(void); void accept_unpause(void); @@ -292,8 +292,8 @@ int gen_ldp_hdr(struct ibuf *, uint16_t); int gen_msg_hdr(struct ibuf *, uint16_t, uint16_t); int send_packet(int, int, union ldpd_addr *, struct iface_af *, void *, size_t); -int disc_recv_packet(struct thread *); -int session_accept(struct thread *); +void disc_recv_packet(struct thread *thread); +void session_accept(struct thread *thread); void session_accept_nbr(struct nbr *, int); void session_shutdown(struct nbr *, uint32_t, uint32_t, uint32_t); diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index e884b3ebfc..867ad92e47 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -35,13 +35,13 @@ static __inline int nbr_addr_compare(const struct nbr *, static __inline int nbr_pid_compare(const struct nbr *, const struct nbr *); static void nbr_update_peerid(struct nbr *); -static int nbr_ktimer(struct thread *); +static void nbr_ktimer(struct thread *thread); static void nbr_start_ktimer(struct nbr *); -static int nbr_ktimeout(struct thread *); +static void nbr_ktimeout(struct thread *thread); static void nbr_start_ktimeout(struct nbr *); -static int nbr_itimeout(struct thread *); +static void nbr_itimeout(struct thread *thread); static void nbr_start_itimeout(struct nbr *); -static int nbr_idtimer(struct thread *); +static void nbr_idtimer(struct thread *thread); static int nbr_act_session_operational(struct nbr *); static void nbr_send_labelmappings(struct nbr *); static __inline int nbr_params_compare(const struct nbr_params *, @@ -419,16 +419,13 @@ nbr_session_active_role(struct nbr *nbr) /* Keepalive timer: timer to send keepalive message to neighbors */ -static int -nbr_ktimer(struct thread *thread) +static void nbr_ktimer(struct thread *thread) { struct nbr *nbr = THREAD_ARG(thread); nbr->keepalive_timer = NULL; send_keepalive(nbr); nbr_start_ktimer(nbr); - - return (0); } static void @@ -451,8 +448,7 @@ nbr_stop_ktimer(struct nbr *nbr) /* Keepalive timeout: if the nbr hasn't sent keepalive */ -static int -nbr_ktimeout(struct thread *thread) +static void nbr_ktimeout(struct thread *thread) { struct nbr *nbr = THREAD_ARG(thread); @@ -461,8 +457,6 @@ nbr_ktimeout(struct thread *thread) log_debug("%s: lsr-id %pI4", __func__, &nbr->id); session_shutdown(nbr, S_KEEPALIVE_TMR, 0, 0); - - return (0); } static void @@ -482,16 +476,13 @@ nbr_stop_ktimeout(struct nbr *nbr) /* Session initialization timeout: if nbr got stuck in the initialization FSM */ -static int -nbr_itimeout(struct thread *thread) +static void nbr_itimeout(struct thread *thread) { struct nbr *nbr = THREAD_ARG(thread); log_debug("%s: lsr-id %pI4", __func__, &nbr->id); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); - - return (0); } static void @@ -513,8 +504,7 @@ nbr_stop_itimeout(struct nbr *nbr) /* Init delay timer: timer to retry to iniziatize session */ -static int -nbr_idtimer(struct thread *thread) +static void nbr_idtimer(struct thread *thread) { struct nbr *nbr = THREAD_ARG(thread); @@ -523,8 +513,6 @@ nbr_idtimer(struct thread *thread) log_debug("%s: lsr-id %pI4", __func__, &nbr->id); nbr_establish_connection(nbr); - - return (0); } void @@ -573,8 +561,7 @@ nbr_pending_connect(struct nbr *nbr) return (nbr->ev_connect != NULL); } -static int -nbr_connect_cb(struct thread *thread) +static void nbr_connect_cb(struct thread *thread) { struct nbr *nbr = THREAD_ARG(thread); int error; @@ -585,7 +572,7 @@ nbr_connect_cb(struct thread *thread) len = sizeof(error); if (getsockopt(nbr->fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) { log_warn("%s: getsockopt SOL_SOCKET SO_ERROR", __func__); - return (0); + return; } if (error) { @@ -593,12 +580,10 @@ nbr_connect_cb(struct thread *thread) errno = error; log_debug("%s: error while connecting to %s: %s", __func__, log_addr(nbr->af, &nbr->raddr), strerror(errno)); - return (0); + return; } nbr_fsm(nbr, NBR_EVT_CONNECT_UP); - - return (0); } int diff --git a/ldpd/packet.c b/ldpd/packet.c index 56af16d280..707878ca9f 100644 --- a/ldpd/packet.c +++ b/ldpd/packet.c @@ -28,12 +28,12 @@ static struct iface *disc_find_iface(unsigned int, int, union ldpd_addr *); -static int session_read(struct thread *); -static int session_write(struct thread *); +static void session_read(struct thread *thread); +static void session_write(struct thread *thread); static ssize_t session_get_pdu(struct ibuf_read *, char **); static void tcp_close(struct tcp_conn *); static struct pending_conn *pending_conn_new(int, int, union ldpd_addr *); -static int pending_conn_timeout(struct thread *); +static void pending_conn_timeout(struct thread *thread); int gen_ldp_hdr(struct ibuf *buf, uint16_t size) @@ -106,8 +106,7 @@ send_packet(int fd, int af, union ldpd_addr *dst, struct iface_af *ia, } /* Discovery functions */ -int -disc_recv_packet(struct thread *thread) +void disc_recv_packet(struct thread *thread) { int fd = THREAD_FD(thread); struct thread **threadp = THREAD_ARG(thread); @@ -158,7 +157,7 @@ disc_recv_packet(struct thread *thread) if (errno != EAGAIN && errno != EINTR) log_debug("%s: read error: %s", __func__, strerror(errno)); - return (0); + return; } sa2addr((struct sockaddr *)&from, &af, &src, NULL); @@ -205,7 +204,7 @@ disc_recv_packet(struct thread *thread) if (bad_addr(af, &src)) { log_debug("%s: invalid source address: %s", __func__, log_addr(af, &src)); - return (0); + return; } ifindex = getsockopt_ifindex(af, &m); @@ -213,7 +212,7 @@ disc_recv_packet(struct thread *thread) if (multicast) { iface = disc_find_iface(ifindex, af, &src); if (iface == NULL) - return (0); + return; } /* check packet size */ @@ -221,7 +220,7 @@ disc_recv_packet(struct thread *thread) if (len < (LDP_HDR_SIZE + LDP_MSG_SIZE) || len > LDP_MAX_LEN) { log_debug("%s: bad packet size, source %s", __func__, log_addr(af, &src)); - return (0); + return; } /* LDP header sanity checks */ @@ -229,12 +228,12 @@ disc_recv_packet(struct thread *thread) if (ntohs(ldp_hdr.version) != LDP_VERSION) { log_debug("%s: invalid LDP version %d, source %s", __func__, ntohs(ldp_hdr.version), log_addr(af, &src)); - return (0); + return; } if (ntohs(ldp_hdr.lspace_id) != 0) { log_debug("%s: invalid label space %u, source %s", __func__, ntohs(ldp_hdr.lspace_id), log_addr(af, &src)); - return (0); + return; } /* check "PDU Length" field */ pdu_len = ntohs(ldp_hdr.length); @@ -242,7 +241,7 @@ disc_recv_packet(struct thread *thread) (pdu_len > (len - LDP_HDR_DEAD_LEN))) { log_debug("%s: invalid LDP packet length %u, source %s", __func__, ntohs(ldp_hdr.length), log_addr(af, &src)); - return (0); + return; } buf += LDP_HDR_SIZE; len -= LDP_HDR_SIZE; @@ -261,7 +260,7 @@ disc_recv_packet(struct thread *thread) if (msg_len < LDP_MSG_LEN || ((msg_len + LDP_MSG_DEAD_LEN) > pdu_len)) { log_debug("%s: invalid LDP message length %u, source %s", __func__, ntohs(msg.length), log_addr(af, &src)); - return (0); + return; } buf += LDP_MSG_SIZE; len -= LDP_MSG_SIZE; @@ -275,8 +274,6 @@ disc_recv_packet(struct thread *thread) log_debug("%s: unknown LDP packet type, source %s", __func__, log_addr(af, &src)); } - - return (0); } static struct iface * @@ -304,8 +301,7 @@ disc_find_iface(unsigned int ifindex, int af, union ldpd_addr *src) return (iface); } -int -session_accept(struct thread *thread) +void session_accept(struct thread *thread) { int fd = THREAD_FD(thread); struct sockaddr_storage src; @@ -328,7 +324,7 @@ session_accept(struct thread *thread) errno != ECONNABORTED) log_debug("%s: accept error: %s", __func__, strerror(errno)); - return (0); + return; } sock_set_nonblock(newfd); @@ -357,22 +353,20 @@ session_accept(struct thread *thread) close(newfd); else pending_conn_new(newfd, af, &addr); - return (0); + return; } /* protection against buggy implementations */ if (nbr_session_active_role(nbr)) { close(newfd); - return (0); + return; } if (nbr->state != NBR_STA_PRESENT) { log_debug("%s: lsr-id %pI4: rejecting additional transport connection", __func__, &nbr->id); close(newfd); - return (0); + return; } session_accept_nbr(nbr, newfd); - - return (0); } void @@ -411,8 +405,7 @@ session_accept_nbr(struct nbr *nbr, int fd) nbr_fsm(nbr, NBR_EVT_MATCH_ADJ); } -static int -session_read(struct thread *thread) +static void session_read(struct thread *thread) { int fd = THREAD_FD(thread); struct nbr *nbr = THREAD_ARG(thread); @@ -431,16 +424,16 @@ session_read(struct thread *thread) if (errno != EINTR && errno != EAGAIN) { log_warn("%s: read error", __func__); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); - return (0); + return; } /* retry read */ - return (0); + return; } if (n == 0) { /* connection closed */ log_debug("%s: connection closed by remote end", __func__); nbr_fsm(nbr, NBR_EVT_CLOSE_SESSION); - return (0); + return; } tcp->rbuf->wpos += n; @@ -450,7 +443,7 @@ session_read(struct thread *thread) if (ntohs(ldp_hdr->version) != LDP_VERSION) { session_shutdown(nbr, S_BAD_PROTO_VER, 0, 0); free(buf); - return (0); + return; } pdu_len = ntohs(ldp_hdr->length); @@ -467,14 +460,14 @@ session_read(struct thread *thread) pdu_len > max_pdu_len) { session_shutdown(nbr, S_BAD_PDU_LEN, 0, 0); free(buf); - return (0); + return; } pdu_len -= LDP_HDR_PDU_LEN; if (ldp_hdr->lsr_id != nbr->id.s_addr || ldp_hdr->lspace_id != 0) { session_shutdown(nbr, S_BAD_LDP_ID, 0, 0); free(buf); - return (0); + return; } pdu += LDP_HDR_SIZE; len -= LDP_HDR_SIZE; @@ -492,7 +485,7 @@ session_read(struct thread *thread) session_shutdown(nbr, S_BAD_MSG_LEN, msg->id, msg->type); free(buf); - return (0); + return; } msg_size = msg_len + LDP_MSG_DEAD_LEN; pdu_len -= msg_size; @@ -505,7 +498,7 @@ session_read(struct thread *thread) session_shutdown(nbr, S_SHUTDOWN, msg->id, msg->type); free(buf); - return (0); + return; } break; case MSG_TYPE_KEEPALIVE: @@ -514,7 +507,7 @@ session_read(struct thread *thread) session_shutdown(nbr, S_SHUTDOWN, msg->id, msg->type); free(buf); - return (0); + return; } break; case MSG_TYPE_NOTIFICATION: @@ -524,7 +517,7 @@ session_read(struct thread *thread) session_shutdown(nbr, S_SHUTDOWN, msg->id, msg->type); free(buf); - return (0); + return; } break; } @@ -571,7 +564,7 @@ session_read(struct thread *thread) if (ret == -1) { /* parser failed, giving up */ free(buf); - return (0); + return; } /* no errors - update per neighbor message counters */ @@ -618,7 +611,7 @@ session_read(struct thread *thread) buf = NULL; if (len != 0) { session_shutdown(nbr, S_BAD_PDU_LEN, 0, 0); - return (0); + return; } } @@ -626,11 +619,9 @@ session_read(struct thread *thread) * allocated - but let's get rid of the SA warning. */ free(buf); - return (0); } -static int -session_write(struct thread *thread) +static void session_write(struct thread *thread) { struct tcp_conn *tcp = THREAD_ARG(thread); struct nbr *nbr = tcp->nbr; @@ -647,12 +638,10 @@ session_write(struct thread *thread) * close the socket. */ tcp_close(tcp); - return (0); + return; } evbuf_event_add(&tcp->wbuf); - - return (0); } void @@ -817,8 +806,7 @@ pending_conn_find(int af, union ldpd_addr *addr) return (NULL); } -static int -pending_conn_timeout(struct thread *thread) +static void pending_conn_timeout(struct thread *thread) { struct pending_conn *pconn = THREAD_ARG(thread); struct tcp_conn *tcp; @@ -837,6 +825,4 @@ pending_conn_timeout(struct thread *thread) msgbuf_write(&tcp->wbuf.wbuf); pending_conn_del(pconn); - - return (0); } diff --git a/lib/agentx.c b/lib/agentx.c index 5f865ca2b8..821c573fb2 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -46,7 +46,7 @@ static struct list *events = NULL; static void agentx_events_update(void); -static int agentx_timeout(struct thread *t) +static void agentx_timeout(struct thread *t) { timeout_thr = NULL; @@ -54,10 +54,9 @@ static int agentx_timeout(struct thread *t) run_alarms(); netsnmp_check_outstanding_agent_requests(); agentx_events_update(); - return 0; } -static int agentx_read(struct thread *t) +static void agentx_read(struct thread *t) { fd_set fds; int flags, new_flags = 0; @@ -72,7 +71,7 @@ static int agentx_read(struct thread *t) if (-1 == flags) { flog_err(EC_LIB_SYSTEM_CALL, "Failed to get FD settings fcntl: %s(%d)", strerror(errno), errno); - return -1; + return; } if (flags & O_NONBLOCK) @@ -101,7 +100,6 @@ static int agentx_read(struct thread *t) netsnmp_check_outstanding_agent_requests(); agentx_events_update(); - return 0; } static void agentx_events_update(void) diff --git a/lib/base64.c b/lib/base64.c new file mode 100644 index 0000000000..e3f238969b --- /dev/null +++ b/lib/base64.c @@ -0,0 +1,193 @@ +/* + * This is part of the libb64 project, and has been placed in the public domain. + * For details, see http://sourceforge.net/projects/libb64 + */ + +#include "base64.h" + +static const int CHARS_PER_LINE = 72; +static const char *ENCODING = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +void base64_init_encodestate(struct base64_encodestate *state_in) +{ + state_in->step = step_A; + state_in->result = 0; + state_in->stepcount = 0; +} + +char base64_encode_value(char value_in) +{ + if (value_in > 63) + return '='; + return ENCODING[(int)value_in]; +} + +int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, + struct base64_encodestate *state_in) +{ + const char *plainchar = plaintext_in; + const char *const plaintextend = plaintext_in + length_in; + char *codechar = code_out; + char result; + char fragment; + + result = state_in->result; + + switch (state_in->step) { + while (1) { + case step_A: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_A; + return codechar - code_out; + } + fragment = *plainchar++; + result = (fragment & 0x0fc) >> 2; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x003) << 4; + /* fall through */ + case step_B: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_B; + return codechar - code_out; + } + fragment = *plainchar++; + result |= (fragment & 0x0f0) >> 4; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x00f) << 2; + /* fall through */ + case step_C: + if (plainchar == plaintextend) { + state_in->result = result; + state_in->step = step_C; + return codechar - code_out; + } + fragment = *plainchar++; + result |= (fragment & 0x0c0) >> 6; + *codechar++ = base64_encode_value(result); + result = (fragment & 0x03f) >> 0; + *codechar++ = base64_encode_value(result); + + ++(state_in->stepcount); + if (state_in->stepcount == CHARS_PER_LINE/4) { + *codechar++ = '\n'; + state_in->stepcount = 0; + } + } + } + /* control should not reach here */ + return codechar - code_out; +} + +int base64_encode_blockend(char *code_out, struct base64_encodestate *state_in) +{ + char *codechar = code_out; + + switch (state_in->step) { + case step_B: + *codechar++ = base64_encode_value(state_in->result); + *codechar++ = '='; + *codechar++ = '='; + break; + case step_C: + *codechar++ = base64_encode_value(state_in->result); + *codechar++ = '='; + break; + case step_A: + break; + } + *codechar++ = '\n'; + + return codechar - code_out; +} + + +signed char base64_decode_value(signed char value_in) +{ + static const signed char decoding[] = { + 62, -1, -1, -1, 63, 52, 53, 54, + 55, 56, 57, 58, 59, 60, 61, -1, + -1, -1, -2, -1, -1, -1, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, + -1, -1, -1, -1, -1, -1, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, + 36, 37, 38, 39, 40, 41, 42, 43, + 44, 45, 46, 47, 48, 49, 50, 51 + }; + value_in -= 43; + if (value_in < 0 || value_in >= 80) + return -1; + return decoding[(int)value_in]; +} + +void base64_init_decodestate(struct base64_decodestate *state_in) +{ + state_in->step = step_a; + state_in->plainchar = 0; +} + +int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, + struct base64_decodestate *state_in) +{ + const char *codec = code_in; + char *plainc = plaintext_out; + signed char fragmt; + + *plainc = state_in->plainchar; + + switch (state_in->step) { + while (1) { + case step_a: + do { + if (codec == code_in+length_in) { + state_in->step = step_a; + state_in->plainchar = *plainc; + return plainc - plaintext_out; + } + fragmt = base64_decode_value(*codec++); + } while (fragmt < 0); + *plainc = (fragmt & 0x03f) << 2; + /* fall through */ + case step_b: + do { + if (codec == code_in+length_in) { + state_in->step = step_b; + state_in->plainchar = *plainc; + return plainc - plaintext_out; + } + fragmt = base64_decode_value(*codec++); + } while (fragmt < 0); + *plainc++ |= (fragmt & 0x030) >> 4; + *plainc = (fragmt & 0x00f) << 4; + /* fall through */ + case step_c: + do { + if (codec == code_in+length_in) { + state_in->step = step_c; + state_in->plainchar = *plainc; + return plainc - plaintext_out; + } + fragmt = base64_decode_value(*codec++); + } while (fragmt < 0); + *plainc++ |= (fragmt & 0x03c) >> 2; + *plainc = (fragmt & 0x003) << 6; + /* fall through */ + case step_d: + do { + if (codec == code_in+length_in) { + state_in->step = step_d; + state_in->plainchar = *plainc; + return plainc - plaintext_out; + } + fragmt = base64_decode_value(*codec++); + } while (fragmt < 0); + *plainc++ |= (fragmt & 0x03f); + } + } + /* control should not reach here */ + return plainc - plaintext_out; +} diff --git a/lib/base64.h b/lib/base64.h new file mode 100644 index 0000000000..3dc1559aa4 --- /dev/null +++ b/lib/base64.h @@ -0,0 +1,45 @@ +/* + * This is part of the libb64 project, and has been placed in the public domain. + * For details, see http://sourceforge.net/projects/libb64 + */ + +#ifndef _BASE64_H_ +#define _BASE64_H_ + +enum base64_encodestep { + step_A, step_B, step_C +}; + +struct base64_encodestate { + enum base64_encodestep step; + char result; + int stepcount; +}; + +void base64_init_encodestate(struct base64_encodestate *state_in); + +char base64_encode_value(char value_in); + +int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, + struct base64_encodestate *state_in); + +int base64_encode_blockend(char *code_out, struct base64_encodestate *state_in); + + +enum base64_decodestep { + step_a, step_b, step_c, step_d +}; + +struct base64_decodestate { + enum base64_decodestep step; + char plainchar; +}; + +void base64_init_decodestate(struct base64_decodestate *state_in); + +signed char base64_decode_value(signed char value_in); + +int base64_decode_block(const char *code_in, int length_in, char *plaintext_out, + struct base64_decodestate *state_in); + +#endif /* _BASE64_H_ */ @@ -461,14 +461,14 @@ static bool _bfd_sess_valid(const struct bfd_session_params *bsp) return true; } -static int _bfd_sess_send(struct thread *t) +static void _bfd_sess_send(struct thread *t) { struct bfd_session_params *bsp = THREAD_ARG(t); int rv; /* Validate configuration before trying to send bogus data. */ if (!_bfd_sess_valid(bsp)) - return 0; + return; if (bsp->lastev == BSE_INSTALL) { bsp->args.command = bsp->installed ? ZEBRA_BFD_DEST_UPDATE @@ -478,7 +478,7 @@ static int _bfd_sess_send(struct thread *t) /* If not installed and asked for uninstall, do nothing. */ if (!bsp->installed && bsp->args.command == ZEBRA_BFD_DEST_DEREGISTER) - return 0; + return; rv = zclient_bfd_command(bsglobal.zc, &bsp->args); /* Command was sent successfully. */ @@ -504,8 +504,6 @@ static int _bfd_sess_send(struct thread *t) bsp->lastev == BSE_INSTALL ? "installed" : "uninstalled"); } - - return 0; } static void _bfd_sess_remove(struct bfd_session_params *bsp) diff --git a/lib/checksum.c b/lib/checksum.c index 3473370041..6c5f06de45 100644 --- a/lib/checksum.c +++ b/lib/checksum.c @@ -9,13 +9,24 @@ #include <zebra.h> #include "checksum.h" -int /* return checksum in low-order 16 bits */ - in_cksum(void *parg, int nbytes) +#define add_carry(dst, add) \ + do { \ + typeof(dst) _add = (add); \ + dst += _add; \ + if (dst < _add) \ + dst++; \ + } while (0) + +uint16_t in_cksumv(const struct iovec *iov, size_t iov_len) { - unsigned short *ptr = parg; - register long sum; /* assumes long == 32 bits */ - unsigned short oddbyte; - register unsigned short answer; /* assumes unsigned short == 16 bits */ + const struct iovec *iov_end; + uint32_t sum = 0; + + union { + uint8_t bytes[2]; + uint16_t word; + } wordbuf; + bool have_oddbyte = false; /* * Our algorithm is simple, using a 32-bit accumulator (sum), @@ -23,17 +34,42 @@ int /* return checksum in low-order 16 bits */ * all the carry bits from the top 16 bits into the lower 16 bits. */ - sum = 0; - while (nbytes > 1) { - sum += *ptr++; - nbytes -= 2; + for (iov_end = iov + iov_len; iov < iov_end; iov++) { + const uint8_t *ptr, *end; + + ptr = (const uint8_t *)iov->iov_base; + end = ptr + iov->iov_len; + if (ptr == end) + continue; + + if (have_oddbyte) { + have_oddbyte = false; + wordbuf.bytes[1] = *ptr++; + + add_carry(sum, wordbuf.word); + } + + while (ptr + 8 <= end) { + add_carry(sum, *(const uint32_t *)(ptr + 0)); + add_carry(sum, *(const uint32_t *)(ptr + 4)); + ptr += 8; + } + + while (ptr + 2 <= end) { + add_carry(sum, *(const uint16_t *)ptr); + ptr += 2; + } + + if (ptr + 1 <= end) { + wordbuf.bytes[0] = *ptr++; + have_oddbyte = true; + } } /* mop up an odd byte, if necessary */ - if (nbytes == 1) { - oddbyte = 0; /* make sure top half is zero */ - *((uint8_t *)&oddbyte) = *(uint8_t *)ptr; /* one byte only */ - sum += oddbyte; + if (have_oddbyte) { + wordbuf.bytes[1] = 0; + add_carry(sum, wordbuf.word); } /* @@ -42,26 +78,7 @@ int /* return checksum in low-order 16 bits */ sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */ sum += (sum >> 16); /* add carry */ - answer = ~sum; /* ones-complement, then truncate to 16 bits */ - return (answer); -} - -int in_cksum_with_ph4(struct ipv4_ph *ph, void *data, int nbytes) -{ - uint8_t dat[sizeof(struct ipv4_ph) + nbytes]; - - memcpy(dat, ph, sizeof(struct ipv4_ph)); - memcpy(dat + sizeof(struct ipv4_ph), data, nbytes); - return in_cksum(dat, sizeof(dat)); -} - -int in_cksum_with_ph6(struct ipv6_ph *ph, void *data, int nbytes) -{ - uint8_t dat[sizeof(struct ipv6_ph) + nbytes]; - - memcpy(dat, ph, sizeof(struct ipv6_ph)); - memcpy(dat + sizeof(struct ipv6_ph), data, nbytes); - return in_cksum(dat, sizeof(dat)); + return ~sum; } /* Fletcher Checksum -- Refer to RFC1008. */ diff --git a/lib/checksum.h b/lib/checksum.h index 56771d4f24..508c3f38a6 100644 --- a/lib/checksum.h +++ b/lib/checksum.h @@ -1,3 +1,6 @@ +#ifndef _FRR_CHECKSUM_H +#define _FRR_CHECKSUM_H + #include <stdint.h> #include <netinet/in.h> @@ -24,9 +27,41 @@ struct ipv6_ph { uint8_t next_hdr; } __attribute__((packed)); -extern int in_cksum(void *data, int nbytes); -extern int in_cksum_with_ph4(struct ipv4_ph *ph, void *data, int nbytes); -extern int in_cksum_with_ph6(struct ipv6_ph *ph, void *data, int nbytes); + +extern uint16_t in_cksumv(const struct iovec *iov, size_t iov_len); + +static inline uint16_t in_cksum(const void *data, size_t nbytes) +{ + struct iovec iov[1]; + + iov[0].iov_base = (void *)data; + iov[0].iov_len = nbytes; + return in_cksumv(iov, array_size(iov)); +} + +static inline uint16_t in_cksum_with_ph4(const struct ipv4_ph *ph, + const void *data, size_t nbytes) +{ + struct iovec iov[2]; + + iov[0].iov_base = (void *)ph; + iov[0].iov_len = sizeof(*ph); + iov[1].iov_base = (void *)data; + iov[1].iov_len = nbytes; + return in_cksumv(iov, array_size(iov)); +} + +static inline uint16_t in_cksum_with_ph6(const struct ipv6_ph *ph, + const void *data, size_t nbytes) +{ + struct iovec iov[2]; + + iov[0].iov_base = (void *)ph; + iov[0].iov_len = sizeof(*ph); + iov[1].iov_base = (void *)data; + iov[1].iov_len = nbytes; + return in_cksumv(iov, array_size(iov)); +} #define FLETCHER_CHECKSUM_VALIDATE 0xffff extern uint16_t fletcher_checksum(uint8_t *, const size_t len, @@ -35,3 +70,5 @@ extern uint16_t fletcher_checksum(uint8_t *, const size_t len, #ifdef __cplusplus } #endif + +#endif /* _FRR_CHECKSUM_H */ diff --git a/lib/command.c b/lib/command.c index ebdbf162d1..1989668bf0 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2239,9 +2239,9 @@ DEFUN (banner_motd_file, int cmd = cmd_banner_motd_file(filename); if (cmd == CMD_ERR_NO_FILE) - vty_out(vty, "%s does not exist", filename); + vty_out(vty, "%s does not exist\n", filename); else if (cmd == CMD_WARNING_CONFIG_FAILED) - vty_out(vty, "%s must be in %s", filename, SYSCONFDIR); + vty_out(vty, "%s must be in %s\n", filename, SYSCONFDIR); return cmd; } diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 898fe98aad..0f56fbac83 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -237,18 +237,16 @@ void frr_pthread_stop_all(void) */ /* dummy task for sleeper pipe */ -static int fpt_dummy(struct thread *thread) +static void fpt_dummy(struct thread *thread) { - return 0; } /* poison pill task to end event loop */ -static int fpt_finish(struct thread *thread) +static void fpt_finish(struct thread *thread) { struct frr_pthread *fpt = THREAD_ARG(thread); atomic_store_explicit(&fpt->running, false, memory_order_relaxed); - return 0; } /* stop function, called from other threads to halt this one */ diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index e572558de1..db5c4c91a2 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -56,7 +56,7 @@ void frrzmq_finish(void) } } -static int frrzmq_read_msg(struct thread *t) +static void frrzmq_read_msg(struct thread *t) { struct frrzmq_cb **cbp = THREAD_ARG(t); struct frrzmq_cb *cb; @@ -67,10 +67,10 @@ static int frrzmq_read_msg(struct thread *t) size_t moresz; if (!cbp) - return 1; + return; cb = (*cbp); if (!cb || !cb->zmqsock) - return 1; + return; while (1) { zmq_pollitem_t polli = {.socket = cb->zmqsock, @@ -97,7 +97,7 @@ static int frrzmq_read_msg(struct thread *t) if (cb->write.cancelled && !cb->write.thread) XFREE(MTYPE_ZEROMQ_CB, *cbp); - return 0; + return; } continue; } @@ -129,7 +129,7 @@ static int frrzmq_read_msg(struct thread *t) if (cb->write.cancelled && !cb->write.thread) XFREE(MTYPE_ZEROMQ_CB, *cbp); - return 0; + return; } /* cb_part may have read additional parts of the @@ -153,14 +153,13 @@ static int frrzmq_read_msg(struct thread *t) thread_add_read(t->master, frrzmq_read_msg, cbp, cb->fd, &cb->read.thread); - return 0; + return; out_err: flog_err(EC_LIB_ZMQ, "ZeroMQ read error: %s(%d)", strerror(errno), errno); if (cb->read.cb_error) cb->read.cb_error(cb->read.arg, cb->zmqsock); - return 1; } int _frrzmq_thread_add_read(const struct xref_threadsched *xref, @@ -215,7 +214,7 @@ int _frrzmq_thread_add_read(const struct xref_threadsched *xref, return 0; } -static int frrzmq_write_msg(struct thread *t) +static void frrzmq_write_msg(struct thread *t) { struct frrzmq_cb **cbp = THREAD_ARG(t); struct frrzmq_cb *cb; @@ -223,10 +222,10 @@ static int frrzmq_write_msg(struct thread *t) int ret; if (!cbp) - return 1; + return; cb = (*cbp); if (!cb || !cb->zmqsock) - return 1; + return; while (1) { zmq_pollitem_t polli = {.socket = cb->zmqsock, @@ -252,7 +251,7 @@ static int frrzmq_write_msg(struct thread *t) if (cb->read.cancelled && !cb->read.thread) XFREE(MTYPE_ZEROMQ_CB, *cbp); - return 0; + return; } continue; } @@ -263,14 +262,13 @@ static int frrzmq_write_msg(struct thread *t) thread_add_write(t->master, frrzmq_write_msg, cbp, cb->fd, &cb->write.thread); - return 0; + return; out_err: flog_err(EC_LIB_ZMQ, "ZeroMQ write error: %s(%d)", strerror(errno), errno); if (cb->write.cb_error) cb->write.cb_error(cb->write.arg, cb->zmqsock); - return 1; } int _frrzmq_thread_add_write(const struct xref_threadsched *xref, @@ -490,7 +490,8 @@ struct connected *if_lookup_address(const void *matchaddr, int family, addr.family = AF_INET6; addr.u.prefix6 = *((struct in6_addr *)matchaddr); addr.prefixlen = IPV6_MAX_BITLEN; - } + } else + assert(!"Attempted lookup of family not supported"); match = NULL; diff --git a/lib/lib_errors.c b/lib/lib_errors.c index acc9a05c33..a658e4c295 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -69,6 +69,12 @@ static struct log_ref ferr_lib_warn[] = { .suggestion = "Gather log data and open an Issue", }, { + .code = EC_LIB_TIMER_TOO_LONG, + .title = "The Event subsystem has detected an internal timer that is scheduled to pop in greater than one year", + .description = "The Event subsystem has detected a timer being started that will pop in a timer that is greater than one year. This is a bug, please collect log data and open an issue.", + .suggestion = "Gather log data and open an Issue", + }, + { .code = EC_LIB_RMAP_RECURSION_LIMIT, .title = "Reached the Route-Map Recursion Limit", .description = "The Route-Map subsystem has detected a route-map depth of RMAP_RECURSION_LIMIT and has stopped processing", diff --git a/lib/lib_errors.h b/lib/lib_errors.h index 64ac6c1ceb..91f206f74a 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -48,6 +48,7 @@ enum lib_log_refs { EC_LIB_SLOW_THREAD_WALL, EC_LIB_STARVE_THREAD, EC_LIB_NO_THREAD, + EC_LIB_TIMER_TOO_LONG, EC_LIB_RMAP_RECURSION_LIMIT, EC_LIB_BACKUP_CONFIG, EC_LIB_VRF_LENGTH, diff --git a/lib/libfrr.c b/lib/libfrr.c index d5e326be41..10b3aad89e 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -962,7 +962,7 @@ static void frr_daemonize(void) * to read the config in after thread execution starts, so that * we can match this behavior. */ -static int frr_config_read_in(struct thread *t) +static void frr_config_read_in(struct thread *t) { hook_call(frr_config_pre, master); @@ -1000,8 +1000,6 @@ static int frr_config_read_in(struct thread *t) } hook_call(frr_config_post, master); - - return 0; } void frr_config_fork(void) @@ -1097,7 +1095,7 @@ static void frr_terminal_close(int isexit) static struct thread *daemon_ctl_thread = NULL; -static int frr_daemon_ctl(struct thread *t) +static void frr_daemon_ctl(struct thread *t) { char buf[1]; ssize_t nr; @@ -1106,7 +1104,7 @@ static int frr_daemon_ctl(struct thread *t) if (nr < 0 && (errno == EINTR || errno == EAGAIN)) goto out; if (nr <= 0) - return 0; + return; switch (buf[0]) { case 'S': /* SIGTSTP */ @@ -1131,7 +1129,6 @@ static int frr_daemon_ctl(struct thread *t) out: thread_add_read(master, frr_daemon_ctl, NULL, daemon_ctl_sock, &daemon_ctl_thread); - return 0; } void frr_detach(void) diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 70c71b18c4..1e25f6a1e2 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -347,7 +347,7 @@ int nb_cli_confirmed_commit_rollback(struct vty *vty) return ret; } -static int nb_cli_confirmed_commit_timeout(struct thread *thread) +static void nb_cli_confirmed_commit_timeout(struct thread *thread) { struct vty *vty = THREAD_ARG(thread); @@ -357,8 +357,6 @@ static int nb_cli_confirmed_commit_timeout(struct thread *thread) nb_cli_confirmed_commit_rollback(vty); nb_cli_confirmed_commit_clean(vty); - - return 0; } static int nb_cli_commit(struct vty *vty, bool force, diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index e1c8983fca..27eaefd071 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -283,7 +283,7 @@ frr_confd_cdb_diff_iter(confd_hkeypath_t *kp, enum cdb_iter_op cdb_op, return ITER_RECURSE; } -static int frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen) +static void frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen) { struct nb_context context = {}; struct nb_config *candidate; @@ -313,9 +313,9 @@ static int frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen) 0, "Couldn't apply configuration changes") != CONFD_OK) { flog_err_confd("cdb_sub_abort_trans"); - return -1; + return; } - return 0; + return; } /* @@ -346,25 +346,23 @@ static int frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen) errmsg) != CONFD_OK) { flog_err_confd("cdb_sub_abort_trans"); - return -1; + return; } } else { /* Acknowledge the notification. */ if (cdb_sync_subscription_socket(fd, CDB_DONE_PRIORITY) != CONFD_OK) { flog_err_confd("cdb_sync_subscription_socket"); - return -1; + return; } /* No configuration changes. */ if (!transaction) nb_config_free(candidate); } - - return 0; } -static int frr_confd_cdb_read_cb_commit(int fd, int *subp, int reslen) +static void frr_confd_cdb_read_cb_commit(int fd, int *subp, int reslen) { /* * No need to process the configuration changes again as we're already @@ -385,10 +383,8 @@ static int frr_confd_cdb_read_cb_commit(int fd, int *subp, int reslen) /* Acknowledge the notification. */ if (cdb_sync_subscription_socket(fd, CDB_DONE_PRIORITY) != CONFD_OK) { flog_err_confd("cdb_sync_subscription_socket"); - return -1; + return; } - - return 0; } static int frr_confd_cdb_read_cb_abort(int fd, int *subp, int reslen) @@ -417,7 +413,7 @@ static int frr_confd_cdb_read_cb_abort(int fd, int *subp, int reslen) return 0; } -static int frr_confd_cdb_read_cb(struct thread *thread) +static void frr_confd_cdb_read_cb(struct thread *thread) { int fd = THREAD_FD(thread); enum cdb_sub_notification cdb_ev; @@ -430,19 +426,22 @@ static int frr_confd_cdb_read_cb(struct thread *thread) if (cdb_read_subscription_socket2(fd, &cdb_ev, &flags, &subp, &reslen) != CONFD_OK) { flog_err_confd("cdb_read_subscription_socket2"); - return -1; + return; } switch (cdb_ev) { case CDB_SUB_PREPARE: - return frr_confd_cdb_read_cb_prepare(fd, subp, reslen); + frr_confd_cdb_read_cb_prepare(fd, subp, reslen); + break; case CDB_SUB_COMMIT: - return frr_confd_cdb_read_cb_commit(fd, subp, reslen); + frr_confd_cdb_read_cb_commit(fd, subp, reslen); + break; case CDB_SUB_ABORT: - return frr_confd_cdb_read_cb_abort(fd, subp, reslen); + frr_confd_cdb_read_cb_abort(fd, subp, reslen); + break; default: flog_err_confd("unknown CDB event"); - return -1; + break; } } @@ -1186,7 +1185,7 @@ static int frr_confd_dp_read(struct confd_daemon_ctx *dctx, int fd) return 0; } -static int frr_confd_dp_ctl_read(struct thread *thread) +static void frr_confd_dp_ctl_read(struct thread *thread) { struct confd_daemon_ctx *dctx = THREAD_ARG(thread); int fd = THREAD_FD(thread); @@ -1194,11 +1193,9 @@ static int frr_confd_dp_ctl_read(struct thread *thread) thread_add_read(master, frr_confd_dp_ctl_read, dctx, fd, &t_dp_ctl); frr_confd_dp_read(dctx, fd); - - return 0; } -static int frr_confd_dp_worker_read(struct thread *thread) +static void frr_confd_dp_worker_read(struct thread *thread) { struct confd_daemon_ctx *dctx = THREAD_ARG(thread); int fd = THREAD_FD(thread); @@ -1206,8 +1203,6 @@ static int frr_confd_dp_worker_read(struct thread *thread) thread_add_read(master, frr_confd_dp_worker_read, dctx, fd, &t_dp_worker); frr_confd_dp_read(dctx, fd); - - return 0; } static int frr_confd_subscribe_state(const struct lysc_node *snode, void *arg) diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp index f5c2a91a50..e2a6290035 100644 --- a/lib/northbound_grpc.cpp +++ b/lib/northbound_grpc.cpp @@ -215,7 +215,7 @@ template <typename Q, typename S> class NewRpcState : RpcStateBase } - static int c_callback(struct thread *thread) + static void c_callback(struct thread *thread) { auto _tag = static_cast<NewRpcState<Q, S> *>(thread->arg); /* @@ -234,7 +234,7 @@ template <typename Q, typename S> class NewRpcState : RpcStateBase pthread_cond_signal(&_tag->cond); pthread_mutex_unlock(&_tag->cmux); - return 0; + return; } const char *name; @@ -1410,7 +1410,7 @@ static int frr_grpc_finish(void) * fork. This is done by scheduling this init function as an event task, since * the event loop doesn't run until after fork. */ -static int frr_grpc_module_very_late_init(struct thread *thread) +static void frr_grpc_module_very_late_init(struct thread *thread) { const char *args = THIS_MODULE->load_args; uint port = GRPC_DEFAULT_PORT; @@ -1428,11 +1428,10 @@ static int frr_grpc_module_very_late_init(struct thread *thread) if (frr_grpc_init(port) < 0) goto error; - return 0; + return; error: flog_err(EC_LIB_GRPC_INIT, "failed to initialize the gRPC module"); - return -1; } static int frr_grpc_module_late_init(struct thread_master *tm) diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c index 86a159e507..0158d8ea0a 100644 --- a/lib/northbound_sysrepo.c +++ b/lib/northbound_sysrepo.c @@ -41,7 +41,7 @@ static sr_session_ctx_t *session; static sr_conn_ctx_t *connection; static struct nb_transaction *transaction; -static int frr_sr_read_cb(struct thread *thread); +static void frr_sr_read_cb(struct thread *thread); static int frr_sr_finish(void); /* Convert FRR YANG data value to sysrepo YANG data value. */ @@ -526,7 +526,7 @@ static int frr_sr_notification_send(const char *xpath, struct list *arguments) return NB_OK; } -static int frr_sr_read_cb(struct thread *thread) +static void frr_sr_read_cb(struct thread *thread) { struct yang_module *module = THREAD_ARG(thread); int fd = THREAD_FD(thread); @@ -536,12 +536,10 @@ static int frr_sr_read_cb(struct thread *thread) if (ret != SR_ERR_OK) { flog_err(EC_LIB_LIBSYSREPO, "%s: sr_fd_event_process(): %s", __func__, sr_strerror(ret)); - return -1; + return; } thread_add_read(master, frr_sr_read_cb, module, fd, &module->sr_thread); - - return 0; } static void frr_sr_subscribe_config(struct yang_module *module) diff --git a/lib/pullwr.c b/lib/pullwr.c index 15563d2471..5e836984b2 100644 --- a/lib/pullwr.c +++ b/lib/pullwr.c @@ -51,7 +51,7 @@ struct pullwr { DEFINE_MTYPE_STATIC(LIB, PULLWR_HEAD, "pull-driven write controller"); DEFINE_MTYPE_STATIC(LIB, PULLWR_BUF, "pull-driven write buffer"); -static int pullwr_run(struct thread *t); +static void pullwr_run(struct thread *t); struct pullwr *_pullwr_new(struct thread_master *tm, int fd, void *arg, @@ -189,7 +189,7 @@ void pullwr_write(struct pullwr *pullwr, const void *data, size_t len) pullwr_bump(pullwr); } -static int pullwr_run(struct thread *t) +static void pullwr_run(struct thread *t) { struct pullwr *pullwr = THREAD_ARG(t); struct iovec iov[2]; @@ -222,7 +222,7 @@ static int pullwr_run(struct thread *t) * into idle, i.e. no calling thread_add_write() */ pullwr_resize(pullwr, 0); - return 0; + return; } niov = pullwr_iov(pullwr, iov); @@ -233,12 +233,12 @@ static int pullwr_run(struct thread *t) if (errno == EAGAIN || errno == EWOULDBLOCK) break; pullwr->err(pullwr->arg, pullwr, false); - return 0; + return; } if (nwr == 0) { pullwr->err(pullwr->arg, pullwr, true); - return 0; + return; } pullwr->total_written += nwr; @@ -258,7 +258,6 @@ static int pullwr_run(struct thread *t) */ if (!maxspun) pullwr_resize(pullwr, 0); - return 0; } void pullwr_stats(struct pullwr *pullwr, uint64_t *total_written, diff --git a/lib/resolver.c b/lib/resolver.c index 29138bbc8d..93fa84bbe9 100644 --- a/lib/resolver.c +++ b/lib/resolver.c @@ -104,17 +104,15 @@ static void resolver_fd_drop_maybe(struct resolver_fd *resfd) static void resolver_update_timeouts(struct resolver_state *r); -static int resolver_cb_timeout(struct thread *t) +static void resolver_cb_timeout(struct thread *t) { struct resolver_state *r = THREAD_ARG(t); ares_process(r->channel, NULL, NULL); resolver_update_timeouts(r); - - return 0; } -static int resolver_cb_socket_readable(struct thread *t) +static void resolver_cb_socket_readable(struct thread *t) { struct resolver_fd *resfd = THREAD_ARG(t); struct resolver_state *r = resfd->state; @@ -127,11 +125,9 @@ static int resolver_cb_socket_readable(struct thread *t) */ ares_process_fd(r->channel, resfd->fd, ARES_SOCKET_BAD); resolver_update_timeouts(r); - - return 0; } -static int resolver_cb_socket_writable(struct thread *t) +static void resolver_cb_socket_writable(struct thread *t) { struct resolver_fd *resfd = THREAD_ARG(t); struct resolver_state *r = resfd->state; @@ -144,8 +140,6 @@ static int resolver_cb_socket_writable(struct thread *t) */ ares_process_fd(r->channel, ARES_SOCKET_BAD, resfd->fd); resolver_update_timeouts(r); - - return 0; } static void resolver_update_timeouts(struct resolver_state *r) @@ -232,7 +226,7 @@ static void ares_address_cb(void *arg, int status, int timeouts, callback(query, NULL, i, &addr[0]); } -static int resolver_cb_literal(struct thread *t) +static void resolver_cb_literal(struct thread *t) { struct resolver_query *query = THREAD_ARG(t); void (*callback)(struct resolver_query *, const char *, int, @@ -242,7 +236,6 @@ static int resolver_cb_literal(struct thread *t) query->callback = NULL; callback(query, ARES_SUCCESS, 1, &query->literal_addr); - return 0; } void resolver_resolve(struct resolver_query *query, int af, vrf_id_t vrf_id, diff --git a/lib/routemap.c b/lib/routemap.c index 7f733c8114..9afe18d10b 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -1799,12 +1799,11 @@ static struct list *route_map_get_index_list(struct route_node **rn, /* * This function returns the route-map index that best matches the prefix. */ -static struct route_map_index *route_map_get_index(struct route_map *map, - const struct prefix *prefix, - void *object, - uint8_t *match_ret) +static struct route_map_index * +route_map_get_index(struct route_map *map, const struct prefix *prefix, + void *object, enum route_map_cmd_result_t *match_ret) { - int ret = 0; + enum route_map_cmd_result_t ret = RMAP_NOMATCH; struct list *candidate_rmap_list = NULL; struct route_node *rn = NULL; struct listnode *ln = NULL, *nn = NULL; @@ -2559,7 +2558,7 @@ route_map_result_t route_map_apply_ext(struct route_map *map, if ((!map->optimization_disabled) && (map->ipv4_prefix_table || map->ipv6_prefix_table)) { index = route_map_get_index(map, prefix, match_object, - (uint8_t *)&match_ret); + &match_ret); if (index) { index->applied++; if (rmap_debug) diff --git a/lib/sigevent.c b/lib/sigevent.c index 00bc31f517..0f20bc0270 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -143,7 +143,7 @@ int frr_sigevent_process(void) #ifdef SIGEVENT_SCHEDULE_THREAD /* timer thread to check signals. shouldn't be needed */ -int frr_signal_timer(struct thread *t) +void frr_signal_timer(struct thread *t) { struct frr_sigevent_master_t *sigm; @@ -151,7 +151,7 @@ int frr_signal_timer(struct thread *t) sigm->t = NULL; thread_add_timer(sigm->t->master, frr_signal_timer, &sigmaster, FRR_SIGNAL_TIMER_INTERVAL, &sigm->t); - return frr_sigevent_process(); + frr_sigevent_process(); } #endif /* SIGEVENT_SCHEDULE_THREAD */ diff --git a/lib/spf_backoff.c b/lib/spf_backoff.c index a273e93463..117b7d3e88 100644 --- a/lib/spf_backoff.c +++ b/lib/spf_backoff.c @@ -117,17 +117,16 @@ void spf_backoff_free(struct spf_backoff *backoff) XFREE(MTYPE_SPF_BACKOFF, backoff); } -static int spf_backoff_timetolearn_elapsed(struct thread *thread) +static void spf_backoff_timetolearn_elapsed(struct thread *thread) { struct spf_backoff *backoff = THREAD_ARG(thread); backoff->state = SPF_BACKOFF_LONG_WAIT; backoff_debug("SPF Back-off(%s) TIMETOLEARN elapsed, move to state %s", backoff->name, spf_backoff_state2str(backoff->state)); - return 0; } -static int spf_backoff_holddown_elapsed(struct thread *thread) +static void spf_backoff_holddown_elapsed(struct thread *thread) { struct spf_backoff *backoff = THREAD_ARG(thread); @@ -136,7 +135,6 @@ static int spf_backoff_holddown_elapsed(struct thread *thread) backoff->state = SPF_BACKOFF_QUIET; backoff_debug("SPF Back-off(%s) HOLDDOWN elapsed, move to state %s", backoff->name, spf_backoff_state2str(backoff->state)); - return 0; } long spf_backoff_schedule(struct spf_backoff *backoff) diff --git a/lib/subdir.am b/lib/subdir.am index 648ab7f14a..b505e235ca 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -8,6 +8,7 @@ lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST lib_libfrr_la_SOURCES = \ lib/agg_table.c \ lib/atomlist.c \ + lib/base64.c \ lib/bfd.c \ lib/buffer.c \ lib/checksum.c \ @@ -113,6 +114,7 @@ lib_libfrr_la_SOURCES = \ lib/zlog.c \ lib/zlog_5424.c \ lib/zlog_5424_cli.c \ + lib/zlog_live.c \ lib/zlog_targets.c \ lib/printf/printf-pos.c \ lib/printf/vfprintf.c \ @@ -177,6 +179,7 @@ clippy_scan += \ pkginclude_HEADERS += \ lib/agg_table.h \ lib/atomlist.h \ + lib/base64.h \ lib/bfd.h \ lib/bitfield.h \ lib/buffer.h \ @@ -287,6 +290,7 @@ pkginclude_HEADERS += \ lib/zebra.h \ lib/zlog.h \ lib/zlog_5424.h \ + lib/zlog_live.h \ lib/zlog_targets.h \ lib/pbr.h \ lib/routing_nb.h \ diff --git a/lib/systemd.c b/lib/systemd.c index 2238dc9f3d..1c9a6f122e 100644 --- a/lib/systemd.c +++ b/lib/systemd.c @@ -80,14 +80,13 @@ void systemd_send_stopping(void) static struct thread_master *systemd_master = NULL; -static int systemd_send_watchdog(struct thread *t) +static void systemd_send_watchdog(struct thread *t) { systemd_send_information("WATCHDOG=1"); assert(watchdog_msec > 0); thread_add_timer_msec(systemd_master, systemd_send_watchdog, NULL, watchdog_msec, NULL); - return 1; } void systemd_send_started(struct thread_master *m) diff --git a/lib/thread.c b/lib/thread.c index ada7a9cc80..90074b3d89 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -498,6 +498,41 @@ DEFUN (clear_thread_cpu, return CMD_SUCCESS; } +static void show_thread_timers_helper(struct vty *vty, struct thread_master *m) +{ + const char *name = m->name ? m->name : "main"; + char underline[strlen(name) + 1]; + struct thread *thread; + + memset(underline, '-', sizeof(underline)); + underline[sizeof(underline) - 1] = '\0'; + + vty_out(vty, "\nShowing timers for %s\n", name); + vty_out(vty, "-------------------%s\n", underline); + + frr_each (thread_timer_list, &m->timer, thread) { + vty_out(vty, " %-50s%pTH\n", thread->hist->funcname, thread); + } +} + +DEFPY_NOSH (show_thread_timers, + show_thread_timers_cmd, + "show thread timers", + SHOW_STR + "Thread information\n" + "Show all timers and how long they have in the system\n") +{ + struct listnode *node; + struct thread_master *m; + + frr_with_mutex (&masters_mtx) { + for (ALL_LIST_ELEMENTS_RO(masters, node, m)) + show_thread_timers_helper(vty, m); + } + + return CMD_SUCCESS; +} + void thread_cmd_init(void) { install_element(VIEW_NODE, &show_thread_cpu_cmd); @@ -509,6 +544,8 @@ void thread_cmd_init(void) install_element(CONFIG_NODE, &no_service_cputime_warning_cmd); install_element(CONFIG_NODE, &service_walltime_warning_cmd); install_element(CONFIG_NODE, &no_service_walltime_warning_cmd); + + install_element(VIEW_NODE, &show_thread_timers_cmd); } /* CLI end ------------------------------------------------------------------ */ @@ -773,7 +810,7 @@ char *thread_timer_to_hhmmss(char *buf, int buf_size, /* Get new thread. */ static struct thread *thread_get(struct thread_master *m, uint8_t type, - int (*func)(struct thread *), void *arg, + void (*func)(struct thread *), void *arg, const struct xref_threadsched *xref) { struct thread *thread = thread_list_pop(&m->unuse); @@ -930,7 +967,7 @@ done: /* Add new read thread. */ void _thread_add_read_write(const struct xref_threadsched *xref, struct thread_master *m, - int (*func)(struct thread *), void *arg, int fd, + void (*func)(struct thread *), void *arg, int fd, struct thread **t_ptr) { int dir = xref->thread_type; @@ -1010,7 +1047,7 @@ void _thread_add_read_write(const struct xref_threadsched *xref, static void _thread_add_timer_timeval(const struct xref_threadsched *xref, struct thread_master *m, - int (*func)(struct thread *), void *arg, + void (*func)(struct thread *), void *arg, struct timeval *time_relative, struct thread **t_ptr) { @@ -1052,12 +1089,18 @@ static void _thread_add_timer_timeval(const struct xref_threadsched *xref, if (thread_timer_list_first(&m->timer) == thread) AWAKEN(m); } +#define ONEYEAR2SEC (60 * 60 * 24 * 365) + if (time_relative->tv_sec > ONEYEAR2SEC) + flog_err( + EC_LIB_TIMER_TOO_LONG, + "Timer: %pTHD is created with an expiration that is greater than 1 year", + thread); } /* Add timer event thread. */ void _thread_add_timer(const struct xref_threadsched *xref, - struct thread_master *m, int (*func)(struct thread *), + struct thread_master *m, void (*func)(struct thread *), void *arg, long timer, struct thread **t_ptr) { struct timeval trel; @@ -1073,8 +1116,8 @@ void _thread_add_timer(const struct xref_threadsched *xref, /* Add timer event thread with "millisecond" resolution */ void _thread_add_timer_msec(const struct xref_threadsched *xref, struct thread_master *m, - int (*func)(struct thread *), void *arg, long timer, - struct thread **t_ptr) + void (*func)(struct thread *), void *arg, + long timer, struct thread **t_ptr) { struct timeval trel; @@ -1088,15 +1131,16 @@ void _thread_add_timer_msec(const struct xref_threadsched *xref, /* Add timer event thread with "timeval" resolution */ void _thread_add_timer_tv(const struct xref_threadsched *xref, - struct thread_master *m, int (*func)(struct thread *), - void *arg, struct timeval *tv, struct thread **t_ptr) + struct thread_master *m, + void (*func)(struct thread *), void *arg, + struct timeval *tv, struct thread **t_ptr) { _thread_add_timer_timeval(xref, m, func, arg, tv, t_ptr); } /* Add simple event thread. */ void _thread_add_event(const struct xref_threadsched *xref, - struct thread_master *m, int (*func)(struct thread *), + struct thread_master *m, void (*func)(struct thread *), void *arg, int val, struct thread **t_ptr) { struct thread *thread = NULL; @@ -1840,6 +1884,27 @@ unsigned long thread_consumed_time(RUSAGE_T *now, RUSAGE_T *start, unsigned long *cputime) { #ifdef HAVE_CLOCK_THREAD_CPUTIME_ID + +#ifdef __FreeBSD__ + /* + * FreeBSD appears to have an issue when calling clock_gettime + * with CLOCK_THREAD_CPUTIME_ID really close to each other + * occassionally the now time will be before the start time. + * This is not good and FRR is ending up with CPU HOG's + * when the subtraction wraps to very large numbers + * + * What we are going to do here is cheat a little bit + * and notice that this is a problem and just correct + * it so that it is impossible to happen + */ + if (start->cpu.tv_sec == now->cpu.tv_sec && + start->cpu.tv_nsec > now->cpu.tv_nsec) + now->cpu.tv_nsec = start->cpu.tv_nsec + 1; + else if (start->cpu.tv_sec > now->cpu.tv_sec) { + now->cpu.tv_sec = start->cpu.tv_sec; + now->cpu.tv_nsec = start->cpu.tv_nsec + 1; + } +#endif *cputime = (now->cpu.tv_sec - start->cpu.tv_sec) * TIMER_SECOND_MICRO + (now->cpu.tv_nsec - start->cpu.tv_nsec) / 1000; #else @@ -2008,7 +2073,7 @@ void thread_call(struct thread *thread) /* Execute thread */ void _thread_execute(const struct xref_threadsched *xref, - struct thread_master *m, int (*func)(struct thread *), + struct thread_master *m, void (*func)(struct thread *), void *arg, int val) { struct thread *thread; diff --git a/lib/thread.h b/lib/thread.h index 0c2a4ba869..a2049ae52a 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -114,7 +114,7 @@ struct thread { struct thread_timer_list_item timeritem; struct thread **ref; /* external reference (if given) */ struct thread_master *master; /* pointer to the struct thread_master */ - int (*func)(struct thread *); /* event function */ + void (*func)(struct thread *); /* event function */ void *arg; /* event argument */ union { int val; /* second argument of the event. */ @@ -134,7 +134,7 @@ struct thread { #endif struct cpu_thread_history { - int (*func)(struct thread *); + void (*func)(struct thread *); atomic_size_t total_cpu_warn; atomic_size_t total_wall_warn; atomic_size_t total_starv_warn; @@ -227,32 +227,32 @@ extern void thread_master_free_unused(struct thread_master *); extern void _thread_add_read_write(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, + void (*fn)(struct thread *), void *arg, int fd, struct thread **tref); extern void _thread_add_timer(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, long t, + void (*fn)(struct thread *), void *arg, long t, struct thread **tref); extern void _thread_add_timer_msec(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, + void (*fn)(struct thread *), void *arg, long t, struct thread **tref); extern void _thread_add_timer_tv(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, + void (*fn)(struct thread *), void *arg, struct timeval *tv, struct thread **tref); extern void _thread_add_event(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, int val, + void (*fn)(struct thread *), void *arg, int val, struct thread **tref); extern void _thread_execute(const struct xref_threadsched *xref, struct thread_master *master, - int (*fn)(struct thread *), void *arg, int val); + void (*fn)(struct thread *), void *arg, int val); extern void thread_cancel(struct thread **event); extern void thread_cancel_async(struct thread_master *, struct thread **, @@ -65,7 +65,7 @@ DEFINE_MTYPE_STATIC(LIB, VTY_HIST, "VTY history"); DECLARE_DLIST(vtys, struct vty, itm); /* Vty events */ -enum event { +enum vty_event { VTY_SERV, VTY_READ, VTY_WRITE, @@ -90,8 +90,8 @@ struct vty_serv { DECLARE_DLIST(vtyservs, struct vty_serv, itm); -static void vty_event_serv(enum event event, struct vty_serv *); -static void vty_event(enum event, struct vty *); +static void vty_event_serv(enum vty_event event, struct vty_serv *); +static void vty_event(enum vty_event, struct vty *); /* Extern host structure from command.c */ extern struct host host; @@ -1299,7 +1299,7 @@ static void vty_buffer_reset(struct vty *vty) } /* Read data via vty socket. */ -static int vty_read(struct thread *thread) +static void vty_read(struct thread *thread) { int i; int nbytes; @@ -1312,10 +1312,8 @@ static int vty_read(struct thread *thread) if (nbytes < 0) { if (ERRNO_IO_RETRY(errno)) { vty_event(VTY_READ, vty); - return 0; + return; } - vty->monitor = 0; /* disable monitoring to avoid - infinite recursion */ flog_err( EC_LIB_SOCKET, "%s: read error on vty client fd %d, closing: %s", @@ -1464,6 +1462,11 @@ static int vty_read(struct thread *thread) vty_out(vty, "\n"); buffer_flush_available(vty->obuf, vty->wfd); vty_execute(vty); + + if (vty->pass_fd != -1) { + close(vty->pass_fd); + vty->pass_fd = -1; + } break; case '\t': vty_complete_command(vty); @@ -1496,11 +1499,10 @@ static int vty_read(struct thread *thread) vty_event(VTY_WRITE, vty); vty_event(VTY_READ, vty); } - return 0; } /* Flush buffer to the vty. */ -static int vty_flush(struct thread *thread) +static void vty_flush(struct thread *thread) { int erase; buffer_status_t flushrc; @@ -1525,14 +1527,12 @@ static int vty_flush(struct thread *thread) vty->lines >= 0 ? vty->lines : vty->height, erase, 0); switch (flushrc) { case BUFFER_ERROR: - vty->monitor = - 0; /* disable monitoring to avoid infinite recursion */ zlog_info("buffer_flush failed on vty client fd %d/%d, closing", vty->fd, vty->wfd); buffer_reset(vty->lbuf); buffer_reset(vty->obuf); vty_close(vty); - return 0; + return; case BUFFER_EMPTY: if (vty->status == VTY_CLOSE) vty_close(vty); @@ -1549,8 +1549,6 @@ static int vty_flush(struct thread *thread) vty_event(VTY_WRITE, vty); break; } - - return 0; } /* Allocate new vty struct. */ @@ -1564,6 +1562,7 @@ struct vty *vty_new(void) new->obuf = buffer_new(0); /* Use default buffer size. */ new->buf = XCALLOC(MTYPE_VTY, VTY_BUFSIZ); new->max = VTY_BUFSIZ; + new->pass_fd = -1; return new; } @@ -1753,7 +1752,7 @@ struct vty *vty_stdio(void (*atclose)(int isexit)) } /* Accept connection from the network. */ -static int vty_accept(struct thread *thread) +static void vty_accept(struct thread *thread) { struct vty_serv *vtyserv = THREAD_ARG(thread); int vty_sock; @@ -1774,7 +1773,7 @@ static int vty_accept(struct thread *thread) if (vty_sock < 0) { flog_err(EC_LIB_SOCKET, "can't accept vty socket : %s", safe_strerror(errno)); - return -1; + return; } set_nonblocking(vty_sock); set_cloexec(vty_sock); @@ -1783,7 +1782,7 @@ static int vty_accept(struct thread *thread) close(vty_sock); zlog_info("Vty unable to convert prefix from sockunion %pSU", &su); - return -1; + return; } /* VTY's accesslist apply. */ @@ -1792,7 +1791,7 @@ static int vty_accept(struct thread *thread) && (access_list_apply(acl, &p) == FILTER_DENY)) { zlog_info("Vty connection refused from %pSU", &su); close(vty_sock); - return 0; + return; } } @@ -1803,7 +1802,7 @@ static int vty_accept(struct thread *thread) && (access_list_apply(acl, &p) == FILTER_DENY)) { zlog_info("Vty connection refused from %pSU", &su); close(vty_sock); - return 0; + return; } } @@ -1817,8 +1816,6 @@ static int vty_accept(struct thread *thread) zlog_info("Vty connection from %pSU", &su); vty_create(vty_sock, &su); - - return 0; } static void vty_serv_sock_addrinfo(const char *hostname, unsigned short port) @@ -1968,7 +1965,7 @@ static void vty_serv_un(const char *path) /* #define VTYSH_DEBUG 1 */ -static int vtysh_accept(struct thread *thread) +static void vtysh_accept(struct thread *thread) { struct vty_serv *vtyserv = THREAD_ARG(thread); int accept_sock = vtyserv->sock; @@ -1988,7 +1985,7 @@ static int vtysh_accept(struct thread *thread) if (sock < 0) { flog_err(EC_LIB_SOCKET, "can't accept vty socket : %s", safe_strerror(errno)); - return -1; + return; } if (set_nonblocking(sock) < 0) { @@ -1997,7 +1994,7 @@ static int vtysh_accept(struct thread *thread) "vtysh_accept: could not set vty socket %d to non-blocking, %s, closing", sock, safe_strerror(errno)); close(sock); - return -1; + return; } set_cloexec(sock); @@ -2013,19 +2010,70 @@ static int vtysh_accept(struct thread *thread) vtys_add_tail(vtysh_sessions, vty); vty_event(VTYSH_READ, vty); +} - return 0; +static int vtysh_do_pass_fd(struct vty *vty) +{ + struct iovec iov[1] = { + { + .iov_base = vty->pass_fd_status, + .iov_len = sizeof(vty->pass_fd_status), + }, + }; + union { + uint8_t buf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr mh = { + .msg_iov = iov, + .msg_iovlen = array_size(iov), + .msg_control = u.buf, + .msg_controllen = sizeof(u.buf), + }; + struct cmsghdr *cmh = CMSG_FIRSTHDR(&mh); + ssize_t ret; + + cmh->cmsg_level = SOL_SOCKET; + cmh->cmsg_type = SCM_RIGHTS; + cmh->cmsg_len = CMSG_LEN(sizeof(int)); + memcpy(CMSG_DATA(cmh), &vty->pass_fd, sizeof(int)); + + ret = sendmsg(vty->wfd, &mh, 0); + if (ret < 0 && ERRNO_IO_RETRY(errno)) + return BUFFER_PENDING; + + close(vty->pass_fd); + vty->pass_fd = -1; + vty->status = VTY_NORMAL; + + if (ret <= 0) + return BUFFER_ERROR; + + /* resume accepting commands (suspended in vtysh_read) */ + vty_event(VTYSH_READ, vty); + + if ((size_t)ret < sizeof(vty->pass_fd_status)) { + size_t remains = sizeof(vty->pass_fd_status) - ret; + + buffer_put(vty->obuf, vty->pass_fd_status + ret, remains); + return BUFFER_PENDING; + } + return BUFFER_EMPTY; } static int vtysh_flush(struct vty *vty) { - switch (buffer_flush_available(vty->obuf, vty->wfd)) { + int ret; + + ret = buffer_flush_available(vty->obuf, vty->wfd); + if (ret == BUFFER_EMPTY && vty->status == VTY_PASSFD) + ret = vtysh_do_pass_fd(vty); + + switch (ret) { case BUFFER_PENDING: vty_event(VTYSH_WRITE, vty); break; case BUFFER_ERROR: - vty->monitor = - 0; /* disable monitoring to avoid infinite recursion */ flog_err(EC_LIB_SOCKET, "%s: write error to fd %d, closing", __func__, vty->fd); buffer_reset(vty->lbuf); @@ -2038,7 +2086,15 @@ static int vtysh_flush(struct vty *vty) return 0; } -static int vtysh_read(struct thread *thread) +void vty_pass_fd(struct vty *vty, int fd) +{ + if (vty->pass_fd != -1) + close(vty->pass_fd); + + vty->pass_fd = fd; +} + +static void vtysh_read(struct thread *thread) { int ret; int sock; @@ -2055,10 +2111,8 @@ static int vtysh_read(struct thread *thread) if (nbytes < 0) { if (ERRNO_IO_RETRY(errno)) { vty_event(VTYSH_READ, vty); - return 0; + return; } - vty->monitor = 0; /* disable monitoring to avoid - infinite recursion */ flog_err( EC_LIB_SOCKET, "%s: read failed on vtysh client fd %d, closing: %s", @@ -2070,7 +2124,7 @@ static int vtysh_read(struct thread *thread) #ifdef VTYSH_DEBUG printf("close vtysh\n"); #endif /* VTYSH_DEBUG */ - return 0; + return; } #ifdef VTYSH_DEBUG @@ -2097,6 +2151,26 @@ static int vtysh_read(struct thread *thread) printf("vtysh node: %d\n", vty->node); #endif /* VTYSH_DEBUG */ + if (vty->pass_fd != -1) { + memset(vty->pass_fd_status, 0, 4); + vty->pass_fd_status[3] = ret; + vty->status = VTY_PASSFD; + + if (!vty->t_write) + vty_event(VTYSH_WRITE, vty); + + /* this introduces a "sequence point" + * command output is written normally, + * read processing is suspended until + * buffer is empty + * then retcode + FD is written + * then normal processing resumes + * + * => skip vty_event(VTYSH_READ, vty)! + */ + return; + } + /* hack for asynchronous "write integrated" * - other commands in "buf" will be ditched * - input during pending config-write is @@ -2112,7 +2186,7 @@ static int vtysh_read(struct thread *thread) if (!vty->t_write && (vtysh_flush(vty) < 0)) /* Try to flush results; exit if a write * error occurs. */ - return 0; + return; } } } @@ -2121,16 +2195,13 @@ static int vtysh_read(struct thread *thread) vty_close(vty); else vty_event(VTYSH_READ, vty); - - return 0; } -static int vtysh_write(struct thread *thread) +static void vtysh_write(struct thread *thread) { struct vty *vty = THREAD_ARG(thread); vtysh_flush(vty); - return 0; } #endif /* VTYSH */ @@ -2171,6 +2242,12 @@ void vty_close(struct vty *vty) THREAD_OFF(vty->t_write); THREAD_OFF(vty->t_timeout); + if (vty->pass_fd != -1) { + close(vty->pass_fd); + vty->pass_fd = -1; + } + zlog_live_close(&vty->live_log); + /* Flush buffer. */ buffer_flush_all(vty->obuf, vty->wfd); @@ -2221,7 +2298,7 @@ void vty_close(struct vty *vty) } /* When time out occur output message then close connection. */ -static int vty_timeout(struct thread *thread) +static void vty_timeout(struct thread *thread) { struct vty *vty; @@ -2236,8 +2313,6 @@ static int vty_timeout(struct thread *thread) /* Close connection. */ vty->status = VTY_CLOSE; vty_close(vty); - - return 0; } /* Read up configuration file from file_name. */ @@ -2608,7 +2683,7 @@ int vty_config_node_exit(struct vty *vty) /* Master of the threads. */ static struct thread_master *vty_master; -static void vty_event_serv(enum event event, struct vty_serv *vty_serv) +static void vty_event_serv(enum vty_event event, struct vty_serv *vty_serv) { switch (event) { case VTY_SERV: @@ -2626,7 +2701,7 @@ static void vty_event_serv(enum event event, struct vty_serv *vty_serv) } } -static void vty_event(enum event event, struct vty *vty) +static void vty_event(enum vty_event event, struct vty *vty) { switch (event) { #ifdef VTYSH @@ -2673,8 +2748,9 @@ DEFUN_NOSH (config_who, struct vty *v; frr_each (vtys, vty_sessions, v) - vty_out(vty, "%svty[%d] connected from %s.\n", - v->config ? "*" : " ", v->fd, v->address); + vty_out(vty, "%svty[%d] connected from %s%s.\n", + v->config ? "*" : " ", v->fd, v->address, + zlog_live_is_null(&v->live_log) ? "" : ", live log"); return CMD_SUCCESS; } @@ -2867,35 +2943,56 @@ DEFUN (no_service_advanced_vty, return CMD_SUCCESS; } -DEFUN_NOSH (terminal_monitor, - terminal_monitor_cmd, - "terminal monitor", - "Set terminal line parameters\n" - "Copy debug output to the current terminal line\n") +DEFUN_NOSH(terminal_monitor, + terminal_monitor_cmd, + "terminal monitor [detach]", + "Set terminal line parameters\n" + "Copy debug output to the current terminal line\n" + "Keep logging feed open independent of VTY session\n") { - vty->monitor = 1; + int fd_ret = -1; + + if (vty->type != VTY_SHELL_SERV) { + vty_out(vty, "%% not supported\n"); + return CMD_WARNING; + } + + if (argc == 3) { + struct zlog_live_cfg detach_log = {}; + + zlog_live_open(&detach_log, LOG_DEBUG, &fd_ret); + zlog_live_disown(&detach_log); + } else + zlog_live_open(&vty->live_log, LOG_DEBUG, &fd_ret); + + if (fd_ret == -1) { + vty_out(vty, "%% error opening live log: %m\n"); + return CMD_WARNING; + } + + vty_pass_fd(vty, fd_ret); return CMD_SUCCESS; } -DEFUN_NOSH (terminal_no_monitor, - terminal_no_monitor_cmd, - "terminal no monitor", - "Set terminal line parameters\n" - NO_STR - "Copy debug output to the current terminal line\n") +DEFUN_NOSH(no_terminal_monitor, + no_terminal_monitor_cmd, + "no terminal monitor", + NO_STR + "Set terminal line parameters\n" + "Copy debug output to the current terminal line\n") { - vty->monitor = 0; + zlog_live_close(&vty->live_log); return CMD_SUCCESS; } -DEFUN_NOSH (no_terminal_monitor, - no_terminal_monitor_cmd, - "no terminal monitor", - NO_STR - "Set terminal line parameters\n" - "Copy debug output to the current terminal line\n") +DEFUN_NOSH(terminal_no_monitor, + terminal_no_monitor_cmd, + "terminal no monitor", + "Set terminal line parameters\n" + NO_STR + "Copy debug output to the current terminal line\n") { - return terminal_no_monitor(self, vty, argc, argv); + return no_terminal_monitor(self, vty, argc, argv); } @@ -34,6 +34,7 @@ #include "qobj.h" #include "compiler.h" #include "northbound.h" +#include "zlog_live.h" #ifdef __cplusplus extern "C" { @@ -161,7 +162,22 @@ struct vty { unsigned char escape; /* Current vty status. */ - enum { VTY_NORMAL, VTY_CLOSE, VTY_MORE, VTY_MORELINE } status; + enum { + VTY_NORMAL, + VTY_CLOSE, + VTY_MORE, + VTY_MORELINE, + VTY_PASSFD, + } status; + + /* vtysh socket/fd passing (for terminal monitor) */ + int pass_fd; + + /* CLI command return value (likely CMD_SUCCESS) when pass_fd != -1 */ + uint8_t pass_fd_status[4]; + + /* live logging target / terminal monitor */ + struct zlog_live_cfg live_log; /* IAC handling: was the last character received the IAC (interpret-as-command) escape character (and therefore the next @@ -186,9 +202,6 @@ struct vty { /* Configure lines. */ int lines; - /* Terminal monitor. */ - int monitor; - /* Read and write thread. */ struct thread *t_read; struct thread *t_write; @@ -329,6 +342,11 @@ extern bool vty_set_include(struct vty *vty, const char *regexp); */ extern int vty_json(struct vty *vty, struct json_object *json); +/* post fd to be passed to the vtysh client + * fd is owned by the VTY code after this and will be closed when done + */ +extern void vty_pass_fd(struct vty *vty, int fd); + extern bool vty_read_config(struct nb_config *config, const char *config_file, char *config_default_dir); extern void vty_time_print(struct vty *, int); diff --git a/lib/wheel.c b/lib/wheel.c index 1a0469b256..463410bea4 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -29,9 +29,9 @@ DEFINE_MTYPE_STATIC(LIB, TIMER_WHEEL_LIST, "Timer Wheel Slot List"); static int debug_timer_wheel = 0; -static int wheel_timer_thread(struct thread *t); +static void wheel_timer_thread(struct thread *t); -static int wheel_timer_thread_helper(struct thread *t) +static void wheel_timer_thread_helper(struct thread *t) { struct listnode *node, *nextnode; unsigned long long curr_slot; @@ -63,19 +63,15 @@ static int wheel_timer_thread_helper(struct thread *t) wheel->slots_to_skip = slots_to_skip; thread_add_timer_msec(wheel->master, wheel_timer_thread, wheel, wheel->nexttime * slots_to_skip, &wheel->timer); - - return 0; } -static int wheel_timer_thread(struct thread *t) +static void wheel_timer_thread(struct thread *t) { struct timer_wheel *wheel; wheel = THREAD_ARG(t); thread_execute(wheel->master, wheel_timer_thread_helper, wheel, 0); - - return 0; } struct timer_wheel *wheel_init(struct thread_master *master, int period, diff --git a/lib/workqueue.c b/lib/workqueue.c index 86afe4082e..92869594dd 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -238,7 +238,7 @@ void work_queue_unplug(struct work_queue *wq) * will reschedule itself if required, * otherwise work_queue_item_add */ -int work_queue_run(struct thread *thread) +void work_queue_run(struct thread *thread) { struct work_queue *wq; struct work_queue_item *item, *titem; @@ -388,6 +388,4 @@ stats: } else if (wq->spec.completion_func) wq->spec.completion_func(wq); - - return 0; } diff --git a/lib/workqueue.h b/lib/workqueue.h index b076ed0d28..39202dcda7 100644 --- a/lib/workqueue.h +++ b/lib/workqueue.h @@ -177,7 +177,7 @@ extern void work_queue_unplug(struct work_queue *wq); bool work_queue_is_scheduled(struct work_queue *); /* Helpers, exported for thread.c and command.c */ -extern int work_queue_run(struct thread *); +extern void work_queue_run(struct thread *); extern void workqueue_cmd_init(void); diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index 85aa003db7..bee76c6e0f 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -19,6 +19,7 @@ #include <zebra.h> +#include "base64.h" #include "log.h" #include "lib_errors.h" #include "northbound.h" @@ -677,6 +678,64 @@ void yang_get_default_string_buf(char *buf, size_t size, const char *xpath_fmt, } /* + * Primitive type: binary. + */ +struct yang_data *yang_data_new_binary(const char *xpath, const char *value, + size_t len) +{ + char *value_str; + struct base64_encodestate s; + int cnt; + char *c; + struct yang_data *data; + + value_str = (char *)malloc(len * 2); + base64_init_encodestate(&s); + cnt = base64_encode_block(value, len, value_str, &s); + c = value_str + cnt; + cnt = base64_encode_blockend(c, &s); + c += cnt; + *c = 0; + data = yang_data_new(xpath, value_str); + free(value_str); + return data; +} + +size_t yang_dnode_get_binary_buf(char *buf, size_t size, + const struct lyd_node *dnode, + const char *xpath_fmt, ...) +{ + const char *canon; + size_t cannon_len; + size_t decode_len; + size_t ret_len; + size_t cnt; + char *value_str; + struct base64_decodestate s; + + canon = YANG_DNODE_XPATH_GET_CANON(dnode, xpath_fmt); + cannon_len = strlen(canon); + decode_len = cannon_len; + value_str = (char *)malloc(decode_len); + base64_init_decodestate(&s); + cnt = base64_decode_block(canon, cannon_len, value_str, &s); + + ret_len = size > cnt ? cnt : size; + memcpy(buf, value_str, ret_len); + if (size < cnt) { + char xpath[XPATH_MAXLEN]; + + yang_dnode_get_path(dnode, xpath, sizeof(xpath)); + flog_warn(EC_LIB_YANG_DATA_TRUNCATED, + "%s: value was truncated [xpath %s]", __func__, + xpath); + } + free(value_str); + return ret_len; +} + + +/* * Primitive type: empty. */ struct yang_data *yang_data_new_empty(const char *xpath) diff --git a/lib/yang_wrappers.h b/lib/yang_wrappers.h index d781dfb1e4..56b314876f 100644 --- a/lib/yang_wrappers.h +++ b/lib/yang_wrappers.h @@ -118,6 +118,13 @@ extern const char *yang_get_default_string(const char *xpath_fmt, ...); extern void yang_get_default_string_buf(char *buf, size_t size, const char *xpath_fmt, ...); +/* binary */ +extern struct yang_data *yang_data_new_binary(const char *xpath, + const char *value, size_t len); +extern size_t yang_dnode_get_binary_buf(char *buf, size_t size, + const struct lyd_node *dnode, + const char *xpath_fmt, ...); + /* empty */ extern struct yang_data *yang_data_new_empty(const char *xpath); extern bool yang_dnode_get_empty(const struct lyd_node *dnode, diff --git a/lib/zclient.c b/lib/zclient.c index ab2dd09896..930adf6a7a 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -47,10 +47,10 @@ DEFINE_MTYPE_STATIC(LIB, ZCLIENT, "Zclient"); DEFINE_MTYPE_STATIC(LIB, REDIST_INST, "Redistribution instance IDs"); /* Zebra client events. */ -enum event { ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT }; +enum zclient_event { ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT }; /* Prototype for event manager. */ -static void zclient_event(enum event, struct zclient *); +static void zclient_event(enum zclient_event, struct zclient *); static void zebra_interface_if_set_value(struct stream *s, struct interface *ifp); @@ -263,20 +263,21 @@ static enum zclient_send_status zclient_failed(struct zclient *zclient) return ZCLIENT_SEND_FAILURE; } -static int zclient_flush_data(struct thread *thread) +static void zclient_flush_data(struct thread *thread) { struct zclient *zclient = THREAD_ARG(thread); zclient->t_write = NULL; if (zclient->sock < 0) - return -1; + return; switch (buffer_flush_available(zclient->wb, zclient->sock)) { case BUFFER_ERROR: flog_err( EC_LIB_ZAPI_SOCKET, "%s: buffer_flush_available failed on zclient fd %d, closing", __func__, zclient->sock); - return zclient_failed(zclient); + zclient_failed(zclient); + return; case BUFFER_PENDING: zclient->t_write = NULL; thread_add_write(zclient->master, zclient_flush_data, zclient, @@ -287,7 +288,6 @@ static int zclient_flush_data(struct thread *thread) (*zclient->zebra_buffer_write_ready)(); break; } - return 0; } /* @@ -754,7 +754,7 @@ void zclient_init(struct zclient *zclient, int redist_default, /* This function is a wrapper function for calling zclient_start from timer or event thread. */ -static int zclient_connect(struct thread *t) +static void zclient_connect(struct thread *t) { struct zclient *zclient; @@ -764,7 +764,7 @@ static int zclient_connect(struct thread *t) if (zclient_debug) zlog_debug("zclient_connect is called"); - return zclient_start(zclient); + zclient_start(zclient); } enum zclient_send_status zclient_send_rnh(struct zclient *zclient, int command, @@ -3864,7 +3864,7 @@ static zclient_handler *const lib_handlers[] = { }; /* Zebra client message read function. */ -static int zclient_read(struct thread *thread) +static void zclient_read(struct thread *thread) { size_t already; uint16_t length, command; @@ -3888,11 +3888,12 @@ static int zclient_read(struct thread *thread) zlog_debug( "zclient connection closed socket [%d].", zclient->sock); - return zclient_failed(zclient); + zclient_failed(zclient); + return; } if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE - already)) { zclient_event(ZCLIENT_READ, zclient); - return 0; + return; } already = ZEBRA_HEADER_SIZE; } @@ -3912,14 +3913,16 @@ static int zclient_read(struct thread *thread) EC_LIB_ZAPI_MISSMATCH, "%s: socket %d version mismatch, marker %d, version %d", __func__, zclient->sock, marker, version); - return zclient_failed(zclient); + zclient_failed(zclient); + return; } if (length < ZEBRA_HEADER_SIZE) { flog_err(EC_LIB_ZAPI_MISSMATCH, "%s: socket %d message length %u is less than %d ", __func__, zclient->sock, length, ZEBRA_HEADER_SIZE); - return zclient_failed(zclient); + zclient_failed(zclient); + return; } /* Length check. */ @@ -3947,12 +3950,13 @@ static int zclient_read(struct thread *thread) zlog_debug( "zclient connection closed socket [%d].", zclient->sock); - return zclient_failed(zclient); + zclient_failed(zclient); + return; } if (nbyte != (ssize_t)(length - already)) { /* Try again later. */ zclient_event(ZCLIENT_READ, zclient); - return 0; + return; } } @@ -3969,13 +3973,11 @@ static int zclient_read(struct thread *thread) if (zclient->sock < 0) /* Connection was closed during packet processing. */ - return -1; + return; /* Register read thread. */ stream_reset(zclient->ibuf); zclient_event(ZCLIENT_READ, zclient); - - return 0; } void zclient_redistribute(int command, struct zclient *zclient, afi_t afi, @@ -4036,7 +4038,7 @@ void zclient_redistribute_default(int command, struct zclient *zclient, zebra_redistribute_default_send(command, zclient, afi, vrf_id); } -static void zclient_event(enum event event, struct zclient *zclient) +static void zclient_event(enum zclient_event event, struct zclient *zclient) { switch (event) { case ZCLIENT_SCHEDULE: diff --git a/lib/zlog.c b/lib/zlog.c index 1b0751559d..85606d2624 100644 --- a/lib/zlog.c +++ b/lib/zlog.c @@ -908,6 +908,11 @@ size_t zlog_msg_ts_3164(struct zlog_msg *msg, struct fbuf *out, uint32_t flags) return bputs(out, msg->ts_3164_str); } +void zlog_msg_tsraw(struct zlog_msg *msg, struct timespec *ts) +{ + memcpy(ts, &msg->ts, sizeof(*ts)); +} + void zlog_set_prefix_ec(bool enable) { atomic_store_explicit(&zlog_ec, enable, memory_order_relaxed); diff --git a/lib/zlog.h b/lib/zlog.h index 6e84fe8923..a530c589a8 100644 --- a/lib/zlog.h +++ b/lib/zlog.h @@ -183,8 +183,11 @@ extern void zlog_msg_args(struct zlog_msg *msg, size_t *hdrlen, /* default is local time zone */ #define ZLOG_TS_UTC (1 << 10) +struct timespec; + extern size_t zlog_msg_ts(struct zlog_msg *msg, struct fbuf *out, uint32_t flags); +extern void zlog_msg_tsraw(struct zlog_msg *msg, struct timespec *ts); /* "mmm dd hh:mm:ss" for RFC3164 syslog. Only ZLOG_TS_UTC for flags. */ extern size_t zlog_msg_ts_3164(struct zlog_msg *msg, struct fbuf *out, diff --git a/lib/zlog_5424.c b/lib/zlog_5424.c index 740d6bfba8..9da7c55fc5 100644 --- a/lib/zlog_5424.c +++ b/lib/zlog_5424.c @@ -799,7 +799,7 @@ static void zlog_5424_cycle(struct zlog_cfg_5424 *zcf, int fd) rcu_free(MTYPE_LOG_5424, oldt, zt.rcu_head); } -static int zlog_5424_reconnect(struct thread *t) +static void zlog_5424_reconnect(struct thread *t) { struct zlog_cfg_5424 *zcf = THREAD_ARG(t); int fd = THREAD_FD(t); @@ -812,7 +812,7 @@ static int zlog_5424_reconnect(struct thread *t) /* logger is sending us something?!?! */ thread_add_read(t->master, zlog_5424_reconnect, zcf, fd, &zcf->t_reconnect); - return 0; + return; } if (ret == 0) @@ -832,7 +832,6 @@ static int zlog_5424_reconnect(struct thread *t) frr_with_mutex (&zcf->cfg_mtx) { zlog_5424_cycle(zcf, fd); } - return 0; } static int zlog_5424_unix(struct sockaddr_un *suna, int sock_type) diff --git a/lib/zlog_live.c b/lib/zlog_live.c new file mode 100644 index 0000000000..fbe0e5ee49 --- /dev/null +++ b/lib/zlog_live.c @@ -0,0 +1,245 @@ +/* + * Copyright (c) 2019-22 David Lamparter, for NetDEF, Inc. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "zebra.h" + +#include "zlog_live.h" + +#include "memory.h" +#include "frrcu.h" +#include "zlog.h" +#include "printfrr.h" + +DEFINE_MTYPE_STATIC(LOG, LOG_LIVE, "log vtysh live target"); + +enum { + STATE_NORMAL = 0, + STATE_FD_DEAD, + STATE_DISOWNED, +}; + +struct zlt_live { + struct zlog_target zt; + + atomic_uint_fast32_t fd; + struct rcu_head_close head_close; + struct rcu_head head_self; + + atomic_uint_fast32_t state; +}; + +static void zlog_live(struct zlog_target *zt, struct zlog_msg *msgs[], + size_t nmsgs) +{ + struct zlt_live *zte = container_of(zt, struct zlt_live, zt); + struct zlog_live_hdr hdrs[nmsgs], *hdr = hdrs; + struct mmsghdr mmhs[nmsgs], *mmh = mmhs; + struct iovec iovs[nmsgs * 3], *iov = iovs; + struct timespec ts; + size_t i, textlen; + int fd; + uint_fast32_t state; + + fd = atomic_load_explicit(&zte->fd, memory_order_relaxed); + + if (fd < 0) + return; + + memset(mmhs, 0, sizeof(mmhs)); + memset(hdrs, 0, sizeof(hdrs)); + + for (i = 0; i < nmsgs; i++) { + const struct fmt_outpos *argpos; + size_t n_argpos, arghdrlen; + struct zlog_msg *msg = msgs[i]; + int prio = zlog_msg_prio(msg); + + if (prio > zt->prio_min) + continue; + + zlog_msg_args(msg, &arghdrlen, &n_argpos, &argpos); + + mmh->msg_hdr.msg_iov = iov; + + iov->iov_base = hdr; + iov->iov_len = sizeof(*hdr); + iov++; + + if (n_argpos) { + iov->iov_base = (char *)argpos; + iov->iov_len = sizeof(*argpos) * n_argpos; + iov++; + } + + iov->iov_base = (char *)zlog_msg_text(msg, &textlen); + iov->iov_len = textlen; + iov++; + + zlog_msg_tsraw(msg, &ts); + + hdr->ts_sec = ts.tv_sec; + hdr->ts_nsec = ts.tv_nsec; + hdr->prio = zlog_msg_prio(msg); + hdr->flags = 0; + hdr->textlen = textlen; + hdr->arghdrlen = arghdrlen; + hdr->n_argpos = n_argpos; + + mmh->msg_hdr.msg_iovlen = iov - mmh->msg_hdr.msg_iov; + mmh++; + hdr++; + } + + size_t msgtotal = mmh - mmhs; + ssize_t sent; + + for (size_t msgpos = 0; msgpos < msgtotal; msgpos += sent) { + sent = sendmmsg(fd, mmhs + msgpos, msgtotal - msgpos, 0); + + if (sent <= 0) + goto out_err; + } + return; + +out_err: + fd = atomic_exchange_explicit(&zte->fd, -1, memory_order_relaxed); + if (fd < 0) + return; + + rcu_close(&zte->head_close, fd); + zlog_target_replace(zt, NULL); + + state = STATE_NORMAL; + atomic_compare_exchange_strong_explicit( + &zte->state, &state, STATE_FD_DEAD, memory_order_relaxed, + memory_order_relaxed); + if (state == STATE_DISOWNED) + rcu_free(MTYPE_LOG_LIVE, zte, head_self); +} + +static void zlog_live_sigsafe(struct zlog_target *zt, const char *text, + size_t len) +{ + struct zlt_live *zte = container_of(zt, struct zlt_live, zt); + struct zlog_live_hdr hdr[1]; + struct iovec iovs[2], *iov = iovs; + struct timespec ts; + int fd; + + fd = atomic_load_explicit(&zte->fd, memory_order_relaxed); + if (fd < 0) + return; + + clock_gettime(CLOCK_MONOTONIC, &ts); + + hdr->ts_sec = ts.tv_sec; + hdr->ts_nsec = ts.tv_nsec; + hdr->prio = LOG_CRIT; + hdr->flags = 0; + hdr->textlen = len; + hdr->n_argpos = 0; + + iov->iov_base = (char *)hdr; + iov->iov_len = sizeof(hdr); + iov++; + + iov->iov_base = (char *)text; + iov->iov_len = len; + iov++; + + writev(fd, iovs, iov - iovs); +} + +void zlog_live_open(struct zlog_live_cfg *cfg, int prio_min, int *other_fd) +{ + int sockets[2]; + struct zlt_live *zte; + struct zlog_target *zt; + + if (cfg->target) + zlog_live_close(cfg); + + *other_fd = -1; + if (prio_min == ZLOG_DISABLED) + return; + + /* the only reason for SEQPACKET here is getting close notifications. + * otherwise if you open a bunch of vtysh connections with live logs + * and close them all, the fds will stick around until we get an error + * when trying to log something to them at some later point -- which + * eats up fds and might be *much* later for some daemons. + */ + if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, sockets) < 0) { + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sockets) < 0) { + zlog_warn("%% could not open socket pair: %m"); + return; + } + } else + /* SEQPACKET only: try to zap read direction */ + shutdown(sockets[0], SHUT_RD); + + *other_fd = sockets[1]; + + zt = zlog_target_clone(MTYPE_LOG_LIVE, NULL, sizeof(*zte)); + zte = container_of(zt, struct zlt_live, zt); + cfg->target = zte; + + zte->fd = sockets[0]; + zte->zt.prio_min = prio_min; + zte->zt.logfn = zlog_live; + zte->zt.logfn_sigsafe = zlog_live_sigsafe; + + zlog_target_replace(NULL, zt); +} + +void zlog_live_close(struct zlog_live_cfg *cfg) +{ + struct zlt_live *zte; + int fd; + + if (!cfg->target) + return; + + zte = cfg->target; + cfg->target = NULL; + + fd = atomic_exchange_explicit(&zte->fd, -1, memory_order_relaxed); + + if (fd >= 0) { + rcu_close(&zte->head_close, fd); + zlog_target_replace(&zte->zt, NULL); + } + rcu_free(MTYPE_LOG_LIVE, zte, head_self); +} + +void zlog_live_disown(struct zlog_live_cfg *cfg) +{ + struct zlt_live *zte; + uint_fast32_t state; + + if (!cfg->target) + return; + + zte = cfg->target; + cfg->target = NULL; + + state = STATE_NORMAL; + atomic_compare_exchange_strong_explicit( + &zte->state, &state, STATE_DISOWNED, memory_order_relaxed, + memory_order_relaxed); + if (state == STATE_FD_DEAD) + rcu_free(MTYPE_LOG_LIVE, zte, head_self); +} diff --git a/lib/zlog_live.h b/lib/zlog_live.h new file mode 100644 index 0000000000..c948baeab1 --- /dev/null +++ b/lib/zlog_live.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019-22 David Lamparter, for NetDEF, Inc. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _FRR_ZLOG_LIVE_H +#define _FRR_ZLOG_LIVE_H + +#include "printfrr.h" + +struct zlog_live_hdr { + uint64_t ts_sec; + uint32_t ts_nsec; + uint32_t prio; + uint32_t flags; + uint32_t textlen; + + uint32_t arghdrlen; + uint32_t n_argpos; + struct fmt_outpos argpos[0]; +}; + +struct zlt_live; + +struct zlog_live_cfg { + struct zlt_live *target; + + /* nothing else here */ +}; + +extern void zlog_live_open(struct zlog_live_cfg *cfg, int prio_min, + int *other_fd); + +static inline bool zlog_live_is_null(struct zlog_live_cfg *cfg) +{ + return cfg->target == NULL; +} + +extern void zlog_live_close(struct zlog_live_cfg *cfg); +extern void zlog_live_disown(struct zlog_live_cfg *cfg); + +#endif /* _FRR_ZLOG_5424_H */ diff --git a/nhrpd/netlink_arp.c b/nhrpd/netlink_arp.c index 3658cb16bb..cd7fb7aed4 100644 --- a/nhrpd/netlink_arp.c +++ b/nhrpd/netlink_arp.c @@ -100,7 +100,7 @@ static void netlink_log_indication(struct nlmsghdr *msg, struct zbuf *zb) nhrp_peer_send_indication(ifp, htons(pkthdr->hw_protocol), &pktpl); } -static int netlink_log_recv(struct thread *t) +static void netlink_log_recv(struct thread *t) { uint8_t buf[ZNL_BUFFER_SIZE]; int fd = THREAD_FD(t); @@ -124,8 +124,6 @@ static int netlink_log_recv(struct thread *t) thread_add_read(master, netlink_log_recv, 0, netlink_log_fd, &netlink_log_thread); - - return 0; } void netlink_set_nflog_group(int nlgroup) diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index 3823464a73..81d9bb255f 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -197,16 +197,15 @@ struct nhrp_cache *nhrp_cache_get(struct interface *ifp, create ? nhrp_cache_alloc : NULL); } -static int nhrp_cache_do_free(struct thread *t) +static void nhrp_cache_do_free(struct thread *t) { struct nhrp_cache *c = THREAD_ARG(t); c->t_timeout = NULL; nhrp_cache_free(c); - return 0; } -static int nhrp_cache_do_timeout(struct thread *t) +static void nhrp_cache_do_timeout(struct thread *t) { struct nhrp_cache *c = THREAD_ARG(t); @@ -214,7 +213,6 @@ static int nhrp_cache_do_timeout(struct thread *t) if (c->cur.type != NHRP_CACHE_INVALID) nhrp_cache_update_binding(c, c->cur.type, -1, NULL, 0, NULL, NULL); - return 0; } static void nhrp_cache_update_route(struct nhrp_cache *c) @@ -392,12 +390,11 @@ static void nhrp_cache_authorize_binding(struct nhrp_reqid *r, void *arg) nhrp_cache_update_timers(c); } -static int nhrp_cache_do_auth_timeout(struct thread *t) +static void nhrp_cache_do_auth_timeout(struct thread *t) { struct nhrp_cache *c = THREAD_ARG(t); c->t_auth = NULL; nhrp_cache_authorize_binding(&c->eventid, (void *)"timeout"); - return 0; } static void nhrp_cache_newpeer_notifier(struct notifier_block *n, diff --git a/nhrpd/nhrp_event.c b/nhrpd/nhrp_event.c index 206b2caccf..e46a6d17cb 100644 --- a/nhrpd/nhrp_event.c +++ b/nhrpd/nhrp_event.c @@ -31,7 +31,7 @@ struct event_manager { uint8_t ibuf_data[4 * 1024]; }; -static int evmgr_reconnect(struct thread *t); +static void evmgr_reconnect(struct thread *t); static void evmgr_connection_error(struct event_manager *evmgr) { @@ -78,7 +78,7 @@ static void evmgr_recv_message(struct event_manager *evmgr, struct zbuf *zb) } } -static int evmgr_read(struct thread *t) +static void evmgr_read(struct thread *t) { struct event_manager *evmgr = THREAD_ARG(t); struct zbuf *ibuf = &evmgr->ibuf; @@ -86,7 +86,7 @@ static int evmgr_read(struct thread *t) if (zbuf_read(ibuf, evmgr->fd, (size_t)-1) < 0) { evmgr_connection_error(evmgr); - return 0; + return; } /* Process all messages in buffer */ @@ -94,10 +94,9 @@ static int evmgr_read(struct thread *t) evmgr_recv_message(evmgr, &msg); thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read); - return 0; } -static int evmgr_write(struct thread *t) +static void evmgr_write(struct thread *t) { struct event_manager *evmgr = THREAD_ARG(t); int r; @@ -109,8 +108,6 @@ static int evmgr_write(struct thread *t) } else if (r < 0) { evmgr_connection_error(evmgr); } - - return 0; } static void evmgr_hexdump(struct zbuf *zb, const uint8_t *val, size_t vallen) @@ -186,13 +183,13 @@ static void evmgr_submit(struct event_manager *evmgr, struct zbuf *obuf) &evmgr->t_write); } -static int evmgr_reconnect(struct thread *t) +static void evmgr_reconnect(struct thread *t) { struct event_manager *evmgr = THREAD_ARG(t); int fd; if (evmgr->fd >= 0 || !nhrp_event_socket_path) - return 0; + return; fd = sock_open_unix(nhrp_event_socket_path); if (fd < 0) { @@ -201,14 +198,12 @@ static int evmgr_reconnect(struct thread *t) zbufq_reset(&evmgr->obuf); thread_add_timer(master, evmgr_reconnect, evmgr, 10, &evmgr->t_reconnect); - return 0; + return; } zlog_info("Connected to Event Manager"); evmgr->fd = fd; thread_add_read(master, evmgr_read, evmgr, evmgr->fd, &evmgr->t_read); - - return 0; } static struct event_manager evmgr_connection; diff --git a/nhrpd/nhrp_multicast.c b/nhrpd/nhrp_multicast.c index d8372ae8a8..89be13b60d 100644 --- a/nhrpd/nhrp_multicast.c +++ b/nhrpd/nhrp_multicast.c @@ -142,7 +142,7 @@ static void netlink_mcast_log_handler(struct nlmsghdr *msg, struct zbuf *zb) } } -static int netlink_mcast_log_recv(struct thread *t) +static void netlink_mcast_log_recv(struct thread *t) { uint8_t buf[65535]; /* Max OSPF Packet size */ int fd = THREAD_FD(t); @@ -166,8 +166,6 @@ static int netlink_mcast_log_recv(struct thread *t) thread_add_read(master, netlink_mcast_log_recv, 0, netlink_mcast_log_fd, &netlink_mcast_log_thread); - - return 0; } static void netlink_mcast_log_register(int fd, int group) diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 3733910a63..63eaf1e394 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -17,8 +17,8 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_NHS, "NHRP next hop server"); DEFINE_MTYPE_STATIC(NHRPD, NHRP_REGISTRATION, "NHRP registration entries"); -static int nhrp_nhs_resolve(struct thread *t); -static int nhrp_reg_send_req(struct thread *t); +static void nhrp_nhs_resolve(struct thread *t); +static void nhrp_reg_send_req(struct thread *t); static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg) { @@ -107,7 +107,7 @@ static void nhrp_reg_reply(struct nhrp_reqid *reqid, void *arg) &cie_nbma_nhs); } -static int nhrp_reg_timeout(struct thread *t) +static void nhrp_reg_timeout(struct thread *t) { struct nhrp_registration *r = THREAD_ARG(t); struct nhrp_cache *c; @@ -138,8 +138,6 @@ static int nhrp_reg_timeout(struct thread *t) r->timeout = 2; } thread_add_timer_msec(master, nhrp_reg_send_req, r, 10, &r->t_register); - - return 0; } static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd) @@ -161,7 +159,7 @@ static void nhrp_reg_peer_notify(struct notifier_block *n, unsigned long cmd) } } -static int nhrp_reg_send_req(struct thread *t) +static void nhrp_reg_send_req(struct thread *t) { struct nhrp_registration *r = THREAD_ARG(t); struct nhrp_nhs *nhs = r->nhs; @@ -180,7 +178,7 @@ static int nhrp_reg_send_req(struct thread *t) &r->peer->vc->remote.nbma); thread_add_timer(master, nhrp_reg_send_req, r, 120, &r->t_register); - return 0; + return; } thread_add_timer(master, nhrp_reg_timeout, r, r->timeout, @@ -198,7 +196,7 @@ static int nhrp_reg_send_req(struct thread *t) /* No protocol address configured for tunnel interface */ if (sockunion_family(&if_ad->addr) == AF_UNSPEC) - return 0; + return; zb = zbuf_alloc(1400); hdr = nhrp_packet_push(zb, NHRP_PACKET_REGISTRATION_REQUEST, @@ -246,8 +244,6 @@ static int nhrp_reg_send_req(struct thread *t) nhrp_packet_complete(zb, hdr); nhrp_peer_send(r->peer, zb); zbuf_free(zb); - - return 0; } static void nhrp_reg_delete(struct nhrp_registration *r) @@ -320,14 +316,12 @@ static void nhrp_nhs_resolve_cb(struct resolver_query *q, const char *errstr, nhrp_reg_delete(reg); } -static int nhrp_nhs_resolve(struct thread *t) +static void nhrp_nhs_resolve(struct thread *t) { struct nhrp_nhs *nhs = THREAD_ARG(t); resolver_resolve(&nhs->dns_resolve, AF_INET, VRF_DEFAULT, nhs->nbma_fqdn, nhrp_nhs_resolve_cb); - - return 0; } int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, diff --git a/nhrpd/nhrp_packet.c b/nhrpd/nhrp_packet.c index fd77533c89..2407a8d366 100644 --- a/nhrpd/nhrp_packet.c +++ b/nhrpd/nhrp_packet.c @@ -290,7 +290,7 @@ err: return -1; } -static int nhrp_packet_recvraw(struct thread *t) +static void nhrp_packet_recvraw(struct thread *t) { int fd = THREAD_FD(t), ifindex; struct zbuf *zb; @@ -304,7 +304,7 @@ static int nhrp_packet_recvraw(struct thread *t) zb = zbuf_alloc(1500); if (!zb) - return 0; + return; len = zbuf_size(zb); addrlen = sizeof(addr); @@ -332,11 +332,10 @@ static int nhrp_packet_recvraw(struct thread *t) nhrp_peer_recv(p, zb); nhrp_peer_unref(p); - return 0; + return; err: zbuf_free(zb); - return 0; } int nhrp_packet_init(void) diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index 51cae44bd1..67d12cbcf3 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -54,7 +54,7 @@ static void nhrp_peer_check_delete(struct nhrp_peer *p) XFREE(MTYPE_NHRP_PEER, p); } -static int nhrp_peer_notify_up(struct thread *t) +static void nhrp_peer_notify_up(struct thread *t) { struct nhrp_peer *p = THREAD_ARG(t); struct nhrp_vc *vc = p->vc; @@ -68,8 +68,6 @@ static int nhrp_peer_notify_up(struct thread *t) notifier_call(&p->notifier_list, NOTIFY_PEER_UP); nhrp_peer_unref(p); } - - return 0; } static void __nhrp_peer_check(struct nhrp_peer *p) @@ -258,7 +256,7 @@ void nhrp_peer_unref(struct nhrp_peer *p) } } -static int nhrp_peer_request_timeout(struct thread *t) +static void nhrp_peer_request_timeout(struct thread *t) { struct nhrp_peer *p = THREAD_ARG(t); struct nhrp_vc *vc = p->vc; @@ -267,7 +265,7 @@ static int nhrp_peer_request_timeout(struct thread *t) if (p->online) - return 0; + return; if (nifp->ipsec_fallback_profile && !p->prio && !p->fallback_requested) { @@ -279,11 +277,9 @@ static int nhrp_peer_request_timeout(struct thread *t) } else { p->requested = p->fallback_requested = 0; } - - return 0; } -static int nhrp_peer_defer_vici_request(struct thread *t) +static void nhrp_peer_defer_vici_request(struct thread *t) { struct nhrp_peer *p = THREAD_ARG(t); struct nhrp_vc *vc = p->vc; @@ -304,7 +300,6 @@ static int nhrp_peer_defer_vici_request(struct thread *t) (nifp->ipsec_fallback_profile && !p->prio) ? 15 : 30, &p->t_fallback); } - return 0; } int nhrp_peer_check(struct nhrp_peer *p, int establish) diff --git a/nhrpd/nhrp_shortcut.c b/nhrpd/nhrp_shortcut.c index 244273cd58..71b6dd8702 100644 --- a/nhrpd/nhrp_shortcut.c +++ b/nhrpd/nhrp_shortcut.c @@ -22,7 +22,7 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_SHORTCUT, "NHRP shortcut"); static struct route_table *shortcut_rib[AFI_MAX]; -static int nhrp_shortcut_do_purge(struct thread *t); +static void nhrp_shortcut_do_purge(struct thread *t); static void nhrp_shortcut_delete(struct nhrp_shortcut *s); static void nhrp_shortcut_send_resolution_req(struct nhrp_shortcut *s); @@ -35,7 +35,7 @@ static void nhrp_shortcut_check_use(struct nhrp_shortcut *s) } } -static int nhrp_shortcut_do_expire(struct thread *t) +static void nhrp_shortcut_do_expire(struct thread *t) { struct nhrp_shortcut *s = THREAD_ARG(t); @@ -43,8 +43,6 @@ static int nhrp_shortcut_do_expire(struct thread *t) &s->t_timer); s->expiring = 1; nhrp_shortcut_check_use(s); - - return 0; } static void nhrp_shortcut_cache_notify(struct notifier_block *n, @@ -166,12 +164,11 @@ static void nhrp_shortcut_delete(struct nhrp_shortcut *s) } } -static int nhrp_shortcut_do_purge(struct thread *t) +static void nhrp_shortcut_do_purge(struct thread *t) { struct nhrp_shortcut *s = THREAD_ARG(t); s->t_timer = NULL; nhrp_shortcut_delete(s); - return 0; } static struct nhrp_shortcut *nhrp_shortcut_get(struct prefix *p) diff --git a/nhrpd/vici.c b/nhrpd/vici.c index 8fce828663..56adde406e 100644 --- a/nhrpd/vici.c +++ b/nhrpd/vici.c @@ -60,7 +60,7 @@ struct vici_message_ctx { int nsections; }; -static int vici_reconnect(struct thread *t); +static void vici_reconnect(struct thread *t); static void vici_submit_request(struct vici_conn *vici, const char *name, ...); static void vici_zbuf_puts(struct zbuf *obuf, const char *str) @@ -355,7 +355,7 @@ static void vici_recv_message(struct vici_conn *vici, struct zbuf *msg) } } -static int vici_read(struct thread *t) +static void vici_read(struct thread *t) { struct vici_conn *vici = THREAD_ARG(t); struct zbuf *ibuf = &vici->ibuf; @@ -363,7 +363,7 @@ static int vici_read(struct thread *t) if (zbuf_read(ibuf, vici->fd, (size_t)-1) < 0) { vici_connection_error(vici); - return 0; + return; } /* Process all messages in buffer */ @@ -383,10 +383,9 @@ static int vici_read(struct thread *t) } while (1); thread_add_read(master, vici_read, vici, vici->fd, &vici->t_read); - return 0; } -static int vici_write(struct thread *t) +static void vici_write(struct thread *t) { struct vici_conn *vici = THREAD_ARG(t); int r; @@ -398,8 +397,6 @@ static int vici_write(struct thread *t) } else if (r < 0) { vici_connection_error(vici); } - - return 0; } static void vici_submit(struct vici_conn *vici, struct zbuf *obuf) @@ -501,14 +498,14 @@ static char *vici_get_charon_filepath(void) return buff; } -static int vici_reconnect(struct thread *t) +static void vici_reconnect(struct thread *t) { struct vici_conn *vici = THREAD_ARG(t); int fd; char *file_path; if (vici->fd >= 0) - return 0; + return; fd = sock_open_unix(VICI_SOCKET); if (fd < 0) { @@ -522,7 +519,7 @@ static int vici_reconnect(struct thread *t) strerror(errno)); thread_add_timer(master, vici_reconnect, vici, 2, &vici->t_reconnect); - return 0; + return; } debugf(NHRP_DEBUG_COMMON, "VICI: Connected"); @@ -537,8 +534,6 @@ static int vici_reconnect(struct thread *t) vici_register_event(vici, "child-state-destroying"); vici_register_event(vici, "list-sa"); vici_submit_request(vici, "list-sas", VICI_END); - - return 0; } static struct vici_conn vici_connection; diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 1c0d948cca..40afd716c7 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -197,7 +197,7 @@ struct ospf6_lsa *ospf6_as_external_lsa_originate(struct ospf6_route *route, return lsa; } -int ospf6_orig_as_external_lsa(struct thread *thread) +void ospf6_orig_as_external_lsa(struct thread *thread) { struct ospf6_interface *oi; struct ospf6_lsa *lsa; @@ -206,9 +206,9 @@ int ospf6_orig_as_external_lsa(struct thread *thread) oi = (struct ospf6_interface *)THREAD_ARG(thread); if (oi->state == OSPF6_INTERFACE_DOWN) - return 0; + return; if (IS_AREA_NSSA(oi->area) || IS_AREA_STUB(oi->area)) - return 0; + return; type = htons(OSPF6_LSTYPE_AS_EXTERNAL); adv_router = oi->area->ospf6->router_id; @@ -222,8 +222,6 @@ int ospf6_orig_as_external_lsa(struct thread *thread) ospf6_flood_interface(NULL, lsa, oi); } - - return 0; } static route_tag_t ospf6_as_external_lsa_get_tag(struct ospf6_lsa *lsa) @@ -1084,7 +1082,7 @@ static void ospf6_asbr_routemap_unset(struct ospf6_redist *red) ROUTEMAP(red) = NULL; } -static int ospf6_asbr_routemap_update_timer(struct thread *thread) +static void ospf6_asbr_routemap_update_timer(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); struct ospf6_redist *red; @@ -1116,8 +1114,6 @@ static int ospf6_asbr_routemap_update_timer(struct thread *thread) UNSET_FLAG(red->flag, OSPF6_IS_RMAP_CHANGED); } - - return 0; } void ospf6_asbr_distribute_list_update(struct ospf6 *ospf6, @@ -3331,7 +3327,7 @@ ospf6_handle_external_aggr_add(struct ospf6 *ospf6) } } -static int ospf6_asbr_summary_process(struct thread *thread) +static void ospf6_asbr_summary_process(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); int operation = 0; @@ -3354,8 +3350,6 @@ static int ospf6_asbr_summary_process(struct thread *thread) default: break; } - - return OSPF6_SUCCESS; } static void diff --git a/ospf6d/ospf6_gr.c b/ospf6d/ospf6_gr.c index c3e6f62f06..d618ed86e0 100644 --- a/ospf6d/ospf6_gr.c +++ b/ospf6d/ospf6_gr.c @@ -455,14 +455,12 @@ static bool ospf6_gr_check_adjs(struct ospf6 *ospf6) } /* Handling of grace period expiry. */ -static int ospf6_gr_grace_period_expired(struct thread *thread) +static void ospf6_gr_grace_period_expired(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); ospf6->gr_info.t_grace_period = NULL; ospf6_gr_restart_exit(ospf6, "grace period has expired"); - - return 0; } /* diff --git a/ospf6d/ospf6_gr_helper.c b/ospf6d/ospf6_gr_helper.c index 84ee35a3ed..5f9b7f0294 100644 --- a/ospf6d/ospf6_gr_helper.c +++ b/ospf6d/ospf6_gr_helper.c @@ -208,12 +208,11 @@ static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa, * Returns: * Nothing */ -static int ospf6_handle_grace_timer_expiry(struct thread *thread) +static void ospf6_handle_grace_timer_expiry(struct thread *thread) { struct ospf6_neighbor *nbr = THREAD_ARG(thread); ospf6_gr_helper_exit(nbr, OSPF6_GR_HELPER_GRACE_TIMEOUT); - return OSPF6_SUCCESS; } /* diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index f39d208bb5..b9ee3c3403 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -731,7 +731,7 @@ static bool ifmaddr_check(ifindex_t ifindex, struct in6_addr *addr) #endif /* __FreeBSD__ */ /* Interface State Machine */ -int interface_up(struct thread *thread) +void interface_up(struct thread *thread) { struct ospf6_interface *oi; struct ospf6 *ospf6; @@ -752,7 +752,7 @@ int interface_up(struct thread *thread) if (!if_is_operative(oi->interface)) { zlog_warn("Interface %s is down, can't execute [InterfaceUp]", oi->interface->name); - return 0; + return; } /* check interface has a link-local address */ @@ -761,7 +761,7 @@ int interface_up(struct thread *thread) zlog_warn( "Interface %s has no link local address, can't execute [InterfaceUp]", oi->interface->name); - return 0; + return; } /* Recompute cost */ @@ -772,7 +772,7 @@ int interface_up(struct thread *thread) if (IS_OSPF6_DEBUG_INTERFACE) zlog_debug("Interface %s already enabled", oi->interface->name); - return 0; + return; } /* If no area assigned, return */ @@ -780,7 +780,7 @@ int interface_up(struct thread *thread) zlog_warn( "%s: Not scheduling Hello for %s as there is no area assigned yet", __func__, oi->interface->name); - return 0; + return; } #ifdef __FreeBSD__ @@ -799,7 +799,7 @@ int interface_up(struct thread *thread) thread_add_timer(master, interface_up, oi, OSPF6_INTERFACE_SSO_RETRY_INT, &oi->thread_sso); - return 0; + return; } #endif /* __FreeBSD__ */ @@ -817,7 +817,7 @@ int interface_up(struct thread *thread) OSPF6_INTERFACE_SSO_RETRY_INT, &oi->thread_sso); } - return 0; + return; } oi->sso_try_cnt = 0; /* Reset on success */ @@ -843,11 +843,9 @@ int interface_up(struct thread *thread) thread_add_timer(master, wait_timer, oi, oi->dead_interval, &oi->thread_wait_timer); } - - return 0; } -int wait_timer(struct thread *thread) +void wait_timer(struct thread *thread) { struct ospf6_interface *oi; @@ -860,11 +858,9 @@ int wait_timer(struct thread *thread) if (oi->state == OSPF6_INTERFACE_WAITING) ospf6_interface_state_change(dr_election(oi), oi); - - return 0; } -int backup_seen(struct thread *thread) +void backup_seen(struct thread *thread) { struct ospf6_interface *oi; @@ -877,11 +873,9 @@ int backup_seen(struct thread *thread) if (oi->state == OSPF6_INTERFACE_WAITING) ospf6_interface_state_change(dr_election(oi), oi); - - return 0; } -int neighbor_change(struct thread *thread) +void neighbor_change(struct thread *thread) { struct ospf6_interface *oi; @@ -896,11 +890,9 @@ int neighbor_change(struct thread *thread) || oi->state == OSPF6_INTERFACE_BDR || oi->state == OSPF6_INTERFACE_DR) ospf6_interface_state_change(dr_election(oi), oi); - - return 0; } -int interface_down(struct thread *thread) +void interface_down(struct thread *thread) { struct ospf6_interface *oi; struct listnode *node, *nnode; @@ -942,7 +934,7 @@ int interface_down(struct thread *thread) oi->bdrouter = oi->prev_bdrouter = htonl(0); if (oi->area == NULL) - return 0; + return; ospf6 = oi->area->ospf6; /* Leave AllSPFRouters */ @@ -960,8 +952,6 @@ int interface_down(struct thread *thread) } ospf6_interface_state_change(OSPF6_INTERFACE_DOWN, oi); - - return 0; } diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 59e4888a5f..9a57a7f4de 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -226,11 +226,11 @@ extern struct in6_addr * ospf6_interface_get_global_address(struct interface *ifp); /* interface event */ -extern int interface_up(struct thread *thread); -extern int interface_down(struct thread *thread); -extern int wait_timer(struct thread *thread); -extern int backup_seen(struct thread *thread); -extern int neighbor_change(struct thread *thread); +extern void interface_up(struct thread *thread); +extern void interface_down(struct thread *thread); +extern void wait_timer(struct thread *thread); +extern void backup_seen(struct thread *thread); +extern void neighbor_change(struct thread *thread); extern void ospf6_interface_init(void); extern void ospf6_interface_clear(struct interface *ifp); diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index da5cad0537..f3fd9dab66 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -224,7 +224,7 @@ int ospf6_router_is_stub_router(struct ospf6_lsa *lsa) return OSPF6_NOT_STUB_ROUTER; } -int ospf6_router_lsa_originate(struct thread *thread) +void ospf6_router_lsa_originate(struct thread *thread) { struct ospf6_area *oa; @@ -249,7 +249,7 @@ int ospf6_router_lsa_originate(struct thread *thread) if (IS_DEBUG_OSPF6_GR) zlog_debug( "Graceful Restart in progress, don't originate LSA"); - return 0; + return; } if (IS_OSPF6_DEBUG_ORIGINATE(ROUTER)) @@ -294,7 +294,7 @@ int ospf6_router_lsa_originate(struct thread *thread) + sizeof(struct ospf6_router_lsa)) { zlog_warn( "Size limit setting for Router-LSA too short"); - return 0; + return; } /* Fill LSA Header */ @@ -433,8 +433,6 @@ int ospf6_router_lsa_originate(struct thread *thread) if (count && !link_state_id) ospf6_spf_schedule(oa->ospf6, OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED); - - return 0; } /*******************************/ @@ -511,7 +509,7 @@ static int ospf6_network_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, return 0; } -int ospf6_network_lsa_originate(struct thread *thread) +void ospf6_network_lsa_originate(struct thread *thread) { struct ospf6_interface *oi; @@ -538,7 +536,7 @@ int ospf6_network_lsa_originate(struct thread *thread) if (IS_DEBUG_OSPF6_GR) zlog_debug( "Graceful Restart in progress, don't originate LSA"); - return 0; + return; } old = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_NETWORK), @@ -558,7 +556,7 @@ int ospf6_network_lsa_originate(struct thread *thread) oi->area->ospf6, OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED); } - return 0; + return; } if (IS_OSPF6_DEBUG_ORIGINATE(NETWORK)) @@ -577,7 +575,7 @@ int ospf6_network_lsa_originate(struct thread *thread) zlog_debug("Interface stub, ignore"); if (old) ospf6_lsa_purge(old); - return 0; + return; } /* prepare buffer */ @@ -635,8 +633,6 @@ int ospf6_network_lsa_originate(struct thread *thread) /* Originate */ ospf6_lsa_originate_area(lsa, oi->area); - - return 0; } @@ -765,7 +761,7 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, return 0; } -int ospf6_link_lsa_originate(struct thread *thread) +void ospf6_link_lsa_originate(struct thread *thread) { struct ospf6_interface *oi; @@ -785,7 +781,7 @@ int ospf6_link_lsa_originate(struct thread *thread) if (IS_DEBUG_OSPF6_GR) zlog_debug( "Graceful Restart in progress, don't originate LSA"); - return 0; + return; } @@ -797,7 +793,7 @@ int ospf6_link_lsa_originate(struct thread *thread) if (CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { if (old) ospf6_lsa_purge(old); - return 0; + return; } if (IS_OSPF6_DEBUG_ORIGINATE(LINK)) @@ -812,7 +808,7 @@ int ospf6_link_lsa_originate(struct thread *thread) oi->interface->name); if (old) ospf6_lsa_purge(old); - return 0; + return; } /* prepare buffer */ @@ -860,8 +856,6 @@ int ospf6_link_lsa_originate(struct thread *thread) /* Originate */ ospf6_lsa_originate_interface(lsa, oi); - - return 0; } @@ -1003,7 +997,7 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa, return 0; } -int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) +void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) { struct ospf6_area *oa; @@ -1028,7 +1022,7 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) if (IS_DEBUG_OSPF6_GR) zlog_debug( "Graceful Restart in progress, don't originate LSA"); - return 0; + return; } /* find previous LSA */ @@ -1051,7 +1045,7 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) oa->lsdb); } } - return 0; + return; } if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) @@ -1127,7 +1121,7 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) } } ospf6_route_table_delete(route_advertise); - return 0; + return; } /* Neighbor change to FULL, if INTRA-AREA-PREFIX LSA @@ -1212,7 +1206,7 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) zlog_debug( "Quit to Advertise Intra-Prefix: no route to advertise"); - return 0; + return; } intra_prefix_lsa->prefix_num = htons(prefix_num); @@ -1235,12 +1229,10 @@ int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread) /* Originate */ ospf6_lsa_originate_area(lsa, oa); - - return 0; } -int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) +void ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) { struct ospf6_interface *oi; @@ -1268,7 +1260,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) if (IS_DEBUG_OSPF6_GR) zlog_debug( "Graceful Restart in progress, don't originate LSA"); - return 0; + return; } /* find previous LSA */ @@ -1279,7 +1271,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) if (CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE)) { if (old) ospf6_lsa_purge(old); - return 0; + return; } if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) @@ -1304,7 +1296,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) zlog_debug(" Interface is not DR"); if (old) ospf6_lsa_purge(old); - return 0; + return; } full_count = 0; @@ -1317,7 +1309,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) zlog_debug(" Interface is stub"); if (old) ospf6_lsa_purge(old); - return 0; + return; } /* connected prefix to advertise */ @@ -1406,7 +1398,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX)) zlog_debug( "Quit to Advertise Intra-Prefix: no route to advertise"); - return 0; + return; } intra_prefix_lsa->prefix_num = htons(prefix_num); @@ -1429,8 +1421,6 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) /* Originate */ ospf6_lsa_originate_area(lsa, oi->area); - - return 0; } static void ospf6_intra_prefix_update_route_origin(struct ospf6_route *oa_route, diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h index f15bf0b9b4..73cc77a56d 100644 --- a/ospf6d/ospf6_intra.h +++ b/ospf6d/ospf6_intra.h @@ -235,14 +235,14 @@ extern char *ospf6_network_lsdesc_lookup(uint32_t router_id, struct ospf6_lsa *lsa); extern int ospf6_router_is_stub_router(struct ospf6_lsa *lsa); -extern int ospf6_router_lsa_originate(struct thread *thread); -extern int ospf6_network_lsa_originate(struct thread *thread); -extern int ospf6_link_lsa_originate(struct thread *thread); -extern int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread); -extern int ospf6_intra_prefix_lsa_originate_stub(struct thread *thread); +extern void ospf6_router_lsa_originate(struct thread *thread); +extern void ospf6_network_lsa_originate(struct thread *thread); +extern void ospf6_link_lsa_originate(struct thread *thread); +extern void ospf6_intra_prefix_lsa_originate_transit(struct thread *thread); +extern void ospf6_intra_prefix_lsa_originate_stub(struct thread *thread); extern void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa); extern void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa); -extern int ospf6_orig_as_external_lsa(struct thread *thread); +extern void ospf6_orig_as_external_lsa(struct thread *thread); extern void ospf6_intra_route_calculation(struct ospf6_area *oa); extern void ospf6_intra_brouter_calculation(struct ospf6_area *oa); extern void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 99d0de39cf..740a94ba84 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -829,7 +829,7 @@ struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa) /* ospf6 lsa expiry */ -int ospf6_lsa_expire(struct thread *thread) +void ospf6_lsa_expire(struct thread *thread) { struct ospf6_lsa *lsa; struct ospf6 *ospf6; @@ -848,7 +848,7 @@ int ospf6_lsa_expire(struct thread *thread) } if (CHECK_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY)) - return 0; /* dbexchange will do something ... */ + return; /* dbexchange will do something ... */ ospf6 = ospf6_get_by_lsdb(lsa); assert(ospf6); @@ -860,11 +860,9 @@ int ospf6_lsa_expire(struct thread *thread) /* schedule maxage remover */ ospf6_maxage_remove(ospf6); - - return 0; } -int ospf6_lsa_refresh(struct thread *thread) +void ospf6_lsa_refresh(struct thread *thread) { struct ospf6_lsa *old, *self, *new; struct ospf6_lsdb *lsdb_self; @@ -882,7 +880,7 @@ int ospf6_lsa_refresh(struct thread *thread) zlog_debug("Refresh: could not find self LSA, flush %s", old->name); ospf6_lsa_premature_aging(old); - return 0; + return; } /* Reset age, increment LS sequence number. */ @@ -907,8 +905,6 @@ int ospf6_lsa_refresh(struct thread *thread) ospf6_install_lsa(new); ospf6_flood(NULL, new); - - return 0; } void ospf6_flush_self_originated_lsas_now(struct ospf6 *ospf6) diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index aa1150afca..fea9aba270 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -256,8 +256,8 @@ extern struct ospf6_lsa *ospf6_lsa_copy(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_lock(struct ospf6_lsa *lsa); extern struct ospf6_lsa *ospf6_lsa_unlock(struct ospf6_lsa *lsa); -extern int ospf6_lsa_expire(struct thread *thread); -extern int ospf6_lsa_refresh(struct thread *thread); +extern void ospf6_lsa_expire(struct thread *thread); +extern void ospf6_lsa_refresh(struct thread *thread); extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsah); extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsah); diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 7ebfdd26e1..6645f83b00 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -1905,7 +1905,7 @@ static int ospf6_read_helper(int sockfd, struct ospf6 *ospf6) return OSPF6_READ_CONTINUE; } -int ospf6_receive(struct thread *thread) +void ospf6_receive(struct thread *thread) { int sockfd; struct ospf6 *ospf6; @@ -1922,13 +1922,11 @@ int ospf6_receive(struct thread *thread) count++; switch (ospf6_read_helper(sockfd, ospf6)) { case OSPF6_READ_ERROR: - return 0; + return; case OSPF6_READ_CONTINUE: break; } } - - return 0; } static void ospf6_fill_hdr_checksum(struct ospf6_interface *oi, @@ -2079,7 +2077,7 @@ static uint16_t ospf6_make_hello(struct ospf6_interface *oi, struct stream *s) return length; } -static int ospf6_write(struct thread *thread) +static void ospf6_write(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); struct ospf6_interface *oi; @@ -2096,7 +2094,7 @@ static int ospf6_write(struct thread *thread) if (ospf6->fd < 0) { zlog_warn("ospf6_write failed to send, fd %d", ospf6->fd); - return -1; + return; } node = listhead(ospf6->oi_write_q); @@ -2235,11 +2233,9 @@ static int ospf6_write(struct thread *thread) if (!list_isempty(ospf6->oi_write_q)) thread_add_write(master, ospf6_write, ospf6, ospf6->fd, &ospf6->t_write); - - return 0; } -int ospf6_hello_send(struct thread *thread) +void ospf6_hello_send(struct thread *thread) { struct ospf6_interface *oi; struct ospf6_packet *op; @@ -2252,7 +2248,7 @@ int ospf6_hello_send(struct thread *thread) if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND_HDR)) zlog_debug("Unable to send Hello on down interface %s", oi->interface->name); - return 0; + return; } op = ospf6_packet_new(oi->ifmtu); @@ -2264,7 +2260,7 @@ int ospf6_hello_send(struct thread *thread) if (length == OSPF6_HEADER_SIZE) { /* Hello overshooting MTU */ ospf6_packet_free(op); - return 0; + return; } /* Fill OSPF header. */ @@ -2287,8 +2283,6 @@ int ospf6_hello_send(struct thread *thread) &oi->thread_send_hello); OSPF6_MESSAGE_WRITE_ON(oi); - - return 0; } static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s) @@ -2339,7 +2333,7 @@ static uint16_t ospf6_make_dbdesc(struct ospf6_neighbor *on, struct stream *s) return length; } -int ospf6_dbdesc_send(struct thread *thread) +void ospf6_dbdesc_send(struct thread *thread) { struct ospf6_neighbor *on; uint16_t length = OSPF6_HEADER_SIZE; @@ -2353,7 +2347,7 @@ int ospf6_dbdesc_send(struct thread *thread) zlog_debug( "Quit to send DbDesc to neighbor %s state %s", on->name, ospf6_neighbor_state_str[on->state]); - return 0; + return; } /* set next thread if master */ @@ -2381,11 +2375,9 @@ int ospf6_dbdesc_send(struct thread *thread) ospf6_packet_add(on->ospf6_if, op); OSPF6_MESSAGE_WRITE_ON(on->ospf6_if); - - return 0; } -int ospf6_dbdesc_send_newone(struct thread *thread) +void ospf6_dbdesc_send_newone(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -2431,7 +2423,6 @@ int ospf6_dbdesc_send_newone(struct thread *thread) &on->thread_exchange_done); thread_execute(master, ospf6_dbdesc_send, on, 0); - return 0; } static uint16_t ospf6_make_lsreq(struct ospf6_neighbor *on, struct stream *s) @@ -2508,7 +2499,7 @@ static uint16_t ospf6_make_lsack_neighbor(struct ospf6_neighbor *on, return length; } -int ospf6_lsreq_send(struct thread *thread) +void ospf6_lsreq_send(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_packet *op; @@ -2524,13 +2515,13 @@ int ospf6_lsreq_send(struct thread *thread) zlog_debug("Quit to send LSReq to neighbor %s state %s", on->name, ospf6_neighbor_state_str[on->state]); - return 0; + return; } /* schedule loading_done if request list is empty */ if (on->request_list->count == 0) { thread_add_event(master, loading_done, on, 0, NULL); - return 0; + return; } op = ospf6_packet_new(on->ospf6_if->ifmtu); @@ -2541,7 +2532,7 @@ int ospf6_lsreq_send(struct thread *thread) if (length == OSPF6_HEADER_SIZE) { /* Hello overshooting MTU */ ospf6_packet_free(op); - return 0; + return; } /* Fill OSPF header. */ @@ -2566,8 +2557,6 @@ int ospf6_lsreq_send(struct thread *thread) on->ospf6_if->rxmt_interval, &on->thread_send_lsreq); } - - return 0; } static void ospf6_send_lsupdate(struct ospf6_neighbor *on, @@ -2689,7 +2678,7 @@ static uint16_t ospf6_make_ls_retrans_list(struct ospf6_neighbor *on, return length; } -int ospf6_lsupdate_send_neighbor(struct thread *thread) +void ospf6_lsupdate_send_neighbor(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_packet *op; @@ -2707,7 +2696,7 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) SEND_HDR)) zlog_debug("Quit to send (neighbor state %s)", ospf6_neighbor_state_str[on->state]); - return 0; + return; } /* first do lsupdate_list */ @@ -2755,7 +2744,6 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) on->ospf6_if->rxmt_interval, &on->thread_send_lsupdate); } - return 0; } int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on, @@ -2826,7 +2814,7 @@ static uint16_t ospf6_make_lsupdate_interface(struct ospf6_interface *oi, return length; } -int ospf6_lsupdate_send_interface(struct thread *thread) +void ospf6_lsupdate_send_interface(struct thread *thread) { struct ospf6_interface *oi; struct ospf6_packet *op; @@ -2843,12 +2831,12 @@ int ospf6_lsupdate_send_interface(struct thread *thread) "Quit to send LSUpdate to interface %s state %s", oi->interface->name, ospf6_interface_state_str[oi->state]); - return 0; + return; } /* if we have nothing to send, return */ if (oi->lsupdate_list->count == 0) - return 0; + return; op = ospf6_packet_new(oi->ifmtu); ospf6_make_header(OSPF6_MESSAGE_TYPE_LSUPDATE, oi, op->s); @@ -2866,11 +2854,9 @@ int ospf6_lsupdate_send_interface(struct thread *thread) thread_add_event(master, ospf6_lsupdate_send_interface, oi, 0, &oi->thread_send_lsupdate); } - - return 0; } -int ospf6_lsack_send_neighbor(struct thread *thread) +void ospf6_lsack_send_neighbor(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_packet *op; @@ -2884,12 +2870,12 @@ int ospf6_lsack_send_neighbor(struct thread *thread) zlog_debug("Quit to send LSAck to neighbor %s state %s", on->name, ospf6_neighbor_state_str[on->state]); - return 0; + return; } /* if we have nothing to send, return */ if (on->lsack_list->count == 0) - return 0; + return; op = ospf6_packet_new(on->ospf6_if->ifmtu); ospf6_make_header(OSPF6_MESSAGE_TYPE_LSACK, on->ospf6_if, op->s); @@ -2898,7 +2884,7 @@ int ospf6_lsack_send_neighbor(struct thread *thread) if (length == OSPF6_HEADER_SIZE) { ospf6_packet_free(op); - return 0; + return; } /* Fill OSPF header. */ @@ -2914,8 +2900,6 @@ int ospf6_lsack_send_neighbor(struct thread *thread) if (on->lsack_list->count > 0) thread_add_event(master, ospf6_lsack_send_neighbor, on, 0, &on->thread_send_lsack); - - return 0; } static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi, @@ -2949,7 +2933,7 @@ static uint16_t ospf6_make_lsack_interface(struct ospf6_interface *oi, return length; } -int ospf6_lsack_send_interface(struct thread *thread) +void ospf6_lsack_send_interface(struct thread *thread) { struct ospf6_interface *oi; struct ospf6_packet *op; @@ -2964,12 +2948,12 @@ int ospf6_lsack_send_interface(struct thread *thread) "Quit to send LSAck to interface %s state %s", oi->interface->name, ospf6_interface_state_str[oi->state]); - return 0; + return; } /* if we have nothing to send, return */ if (oi->lsack_list->count == 0) - return 0; + return; op = ospf6_packet_new(oi->ifmtu); ospf6_make_header(OSPF6_MESSAGE_TYPE_LSACK, oi, op->s); @@ -2978,7 +2962,7 @@ int ospf6_lsack_send_interface(struct thread *thread) if (length == OSPF6_HEADER_SIZE) { ospf6_packet_free(op); - return 0; + return; } /* Fill OSPF header. */ ospf6_fill_header(oi, op->s, length); @@ -2999,8 +2983,6 @@ int ospf6_lsack_send_interface(struct thread *thread) if (oi->lsack_list->count > 0) thread_add_event(master, ospf6_lsack_send_interface, oi, 0, &oi->thread_send_lsack); - - return 0; } /* Commands */ diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h index 437dd5685b..daab98640e 100644 --- a/ospf6d/ospf6_message.h +++ b/ospf6d/ospf6_message.h @@ -173,16 +173,16 @@ extern void ospf6_fifo_free(struct ospf6_fifo *fifo); extern int ospf6_iobuf_size(unsigned int size); extern void ospf6_message_terminate(void); -extern int ospf6_receive(struct thread *thread); - -extern int ospf6_hello_send(struct thread *thread); -extern int ospf6_dbdesc_send(struct thread *thread); -extern int ospf6_dbdesc_send_newone(struct thread *thread); -extern int ospf6_lsreq_send(struct thread *thread); -extern int ospf6_lsupdate_send_interface(struct thread *thread); -extern int ospf6_lsupdate_send_neighbor(struct thread *thread); -extern int ospf6_lsack_send_interface(struct thread *thread); -extern int ospf6_lsack_send_neighbor(struct thread *thread); +extern void ospf6_receive(struct thread *thread); + +extern void ospf6_hello_send(struct thread *thread); +extern void ospf6_dbdesc_send(struct thread *thread); +extern void ospf6_dbdesc_send_newone(struct thread *thread); +extern void ospf6_lsreq_send(struct thread *thread); +extern void ospf6_lsupdate_send_interface(struct thread *thread); +extern void ospf6_lsupdate_send_neighbor(struct thread *thread); +extern void ospf6_lsack_send_interface(struct thread *thread); +extern void ospf6_lsack_send_neighbor(struct thread *thread); extern int config_write_ospf6_debug_message(struct vty *); extern void install_element_ospf6_debug_message(void); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 5d14bfc981..8dca0913d3 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -272,7 +272,7 @@ static int need_adjacency(struct ospf6_neighbor *on) return 0; } -int hello_received(struct thread *thread) +void hello_received(struct thread *thread) { struct ospf6_neighbor *on; @@ -290,11 +290,9 @@ int hello_received(struct thread *thread) if (on->state <= OSPF6_NEIGHBOR_DOWN) ospf6_neighbor_state_change(OSPF6_NEIGHBOR_INIT, on, OSPF6_NEIGHBOR_EVENT_HELLO_RCVD); - - return 0; } -int twoway_received(struct thread *thread) +void twoway_received(struct thread *thread) { struct ospf6_neighbor *on; @@ -302,7 +300,7 @@ int twoway_received(struct thread *thread) assert(on); if (on->state > OSPF6_NEIGHBOR_INIT) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *2Way-Received*", on->name); @@ -312,7 +310,7 @@ int twoway_received(struct thread *thread) if (!need_adjacency(on)) { ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on, OSPF6_NEIGHBOR_EVENT_TWOWAY_RCVD); - return 0; + return; } ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXSTART, on, @@ -324,11 +322,9 @@ int twoway_received(struct thread *thread) THREAD_OFF(on->thread_send_dbdesc); thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); - - return 0; } -int negotiation_done(struct thread *thread) +void negotiation_done(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -337,7 +333,7 @@ int negotiation_done(struct thread *thread) assert(on); if (on->state != OSPF6_NEIGHBOR_EXSTART) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *NegotiationDone*", on->name); @@ -380,21 +376,17 @@ int negotiation_done(struct thread *thread) UNSET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT); ospf6_neighbor_state_change(OSPF6_NEIGHBOR_EXCHANGE, on, OSPF6_NEIGHBOR_EVENT_NEGOTIATION_DONE); - - return 0; } -static int ospf6_neighbor_last_dbdesc_release(struct thread *thread) +static void ospf6_neighbor_last_dbdesc_release(struct thread *thread) { struct ospf6_neighbor *on = THREAD_ARG(thread); assert(on); memset(&on->dbdesc_last, 0, sizeof(struct ospf6_dbdesc)); - - return 0; } -int exchange_done(struct thread *thread) +void exchange_done(struct thread *thread) { struct ospf6_neighbor *on; @@ -402,7 +394,7 @@ int exchange_done(struct thread *thread) assert(on); if (on->state != OSPF6_NEIGHBOR_EXCHANGE) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *ExchangeDone*", on->name); @@ -428,8 +420,6 @@ int exchange_done(struct thread *thread) thread_add_event(master, ospf6_lsreq_send, on, 0, &on->thread_send_lsreq); } - - return 0; } /* Check loading state. */ @@ -453,7 +443,7 @@ void ospf6_check_nbr_loading(struct ospf6_neighbor *on) } } -int loading_done(struct thread *thread) +void loading_done(struct thread *thread) { struct ospf6_neighbor *on; @@ -461,7 +451,7 @@ int loading_done(struct thread *thread) assert(on); if (on->state != OSPF6_NEIGHBOR_LOADING) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *LoadingDone*", on->name); @@ -470,11 +460,9 @@ int loading_done(struct thread *thread) ospf6_neighbor_state_change(OSPF6_NEIGHBOR_FULL, on, OSPF6_NEIGHBOR_EVENT_LOADING_DONE); - - return 0; } -int adj_ok(struct thread *thread) +void adj_ok(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -507,11 +495,9 @@ int adj_ok(struct thread *thread) ospf6_lsdb_remove(lsa, on->retrans_list); } } - - return 0; } -int seqnumber_mismatch(struct thread *thread) +void seqnumber_mismatch(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -520,7 +506,7 @@ int seqnumber_mismatch(struct thread *thread) assert(on); if (on->state < OSPF6_NEIGHBOR_EXCHANGE) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *SeqNumberMismatch*", on->name); @@ -544,11 +530,9 @@ int seqnumber_mismatch(struct thread *thread) on->thread_send_dbdesc = NULL; thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); - - return 0; } -int bad_lsreq(struct thread *thread) +void bad_lsreq(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -557,7 +541,7 @@ int bad_lsreq(struct thread *thread) assert(on); if (on->state < OSPF6_NEIGHBOR_EXCHANGE) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *BadLSReq*", on->name); @@ -582,10 +566,9 @@ int bad_lsreq(struct thread *thread) thread_add_event(master, ospf6_dbdesc_send, on, 0, &on->thread_send_dbdesc); - return 0; } -int oneway_received(struct thread *thread) +void oneway_received(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_lsa *lsa, *lsanext; @@ -594,7 +577,7 @@ int oneway_received(struct thread *thread) assert(on); if (on->state < OSPF6_NEIGHBOR_TWOWAY) - return 0; + return; if (IS_OSPF6_DEBUG_NEIGHBOR(EVENT)) zlog_debug("Neighbor Event %s: *1Way-Received*", on->name); @@ -616,11 +599,9 @@ int oneway_received(struct thread *thread) THREAD_OFF(on->thread_send_lsack); THREAD_OFF(on->thread_exchange_done); THREAD_OFF(on->thread_adj_ok); - - return 0; } -int inactivity_timer(struct thread *thread) +void inactivity_timer(struct thread *thread) { struct ospf6_neighbor *on; @@ -656,8 +637,6 @@ int inactivity_timer(struct thread *thread) on->ospf6_if->dead_interval, &on->inactivity_timer); } - - return 0; } diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h index 2dd640099c..ea4d424152 100644 --- a/ospf6d/ospf6_neighbor.h +++ b/ospf6d/ospf6_neighbor.h @@ -205,16 +205,16 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, void ospf6_neighbor_delete(struct ospf6_neighbor *on); /* Neighbor event */ -extern int hello_received(struct thread *thread); -extern int twoway_received(struct thread *thread); -extern int negotiation_done(struct thread *thread); -extern int exchange_done(struct thread *thread); -extern int loading_done(struct thread *thread); -extern int adj_ok(struct thread *thread); -extern int seqnumber_mismatch(struct thread *thread); -extern int bad_lsreq(struct thread *thread); -extern int oneway_received(struct thread *thread); -extern int inactivity_timer(struct thread *thread); +extern void hello_received(struct thread *thread); +extern void twoway_received(struct thread *thread); +extern void negotiation_done(struct thread *thread); +extern void exchange_done(struct thread *thread); +extern void loading_done(struct thread *thread); +extern void adj_ok(struct thread *thread); +extern void seqnumber_mismatch(struct thread *thread); +extern void bad_lsreq(struct thread *thread); +extern void oneway_received(struct thread *thread); +extern void inactivity_timer(struct thread *thread); extern void ospf6_check_nbr_loading(struct ospf6_neighbor *on); extern void ospf6_neighbor_init(void); diff --git a/ospf6d/ospf6_nssa.c b/ospf6d/ospf6_nssa.c index 042907d0f6..1220c32783 100644 --- a/ospf6d/ospf6_nssa.c +++ b/ospf6d/ospf6_nssa.c @@ -970,7 +970,7 @@ int ospf6_redistribute_check(struct ospf6 *ospf6, struct ospf6_route *route, } /* This function performs ABR related processing */ -static int ospf6_abr_task_timer(struct thread *thread) +static void ospf6_abr_task_timer(struct thread *thread) { struct ospf6 *ospf6 = THREAD_ARG(thread); @@ -982,8 +982,6 @@ static int ospf6_abr_task_timer(struct thread *thread) ospf6_abr_task(ospf6); /* if nssa-abr, then scan Type-7 LSDB */ ospf6_abr_nssa_task(ospf6); - - return 0; } void ospf6_schedule_abr_task(struct ospf6 *ospf6) diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index f9c47cbce5..2e8e9f2cdd 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -605,7 +605,7 @@ static void ospf6_spf_log_database(struct ospf6_area *oa) zlog_debug("%s", buffer); } -static int ospf6_spf_calculation_thread(struct thread *t) +static void ospf6_spf_calculation_thread(struct thread *t) { struct ospf6_area *oa; struct ospf6 *ospf6; @@ -681,7 +681,6 @@ static int ospf6_spf_calculation_thread(struct thread *t) ospf6->last_spf_reason = ospf6->spf_reason; ospf6_reset_spf_reason(ospf6); - return 0; } /* Add schedule for SPF calculation. To avoid frequenst SPF calc, we @@ -1245,7 +1244,7 @@ int ospf6_ase_calculate_route(struct ospf6 *ospf6, struct ospf6_lsa *lsa, return 0; } -static int ospf6_ase_calculate_timer(struct thread *t) +static void ospf6_ase_calculate_timer(struct thread *t) { struct ospf6 *ospf6; struct ospf6_lsa *lsa; @@ -1283,8 +1282,6 @@ static int ospf6_ase_calculate_timer(struct thread *t) ospf6_zebra_gr_disable(ospf6); ospf6->gr_info.finishing_restart = false; } - - return 0; } void ospf6_ase_calculate_timer_add(struct ospf6 *ospf6) diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 13f16efa66..e64bf24b66 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -586,7 +586,7 @@ void ospf6_master_init(struct thread_master *master) om6->master = master; } -static int ospf6_maxage_remover(struct thread *thread) +static void ospf6_maxage_remover(struct thread *thread) { struct ospf6 *o = (struct ospf6 *)THREAD_ARG(thread); struct ospf6_area *oa; @@ -603,7 +603,7 @@ static int ospf6_maxage_remover(struct thread *thread) continue; ospf6_maxage_remove(o); - return 0; + return; } } } @@ -627,8 +627,6 @@ static int ospf6_maxage_remover(struct thread *thread) if (reschedule) { ospf6_maxage_remove(o); } - - return 0; } void ospf6_maxage_remove(struct ospf6 *o) diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index 3ca1e132bd..3cfee7d573 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -82,7 +82,7 @@ struct my_opaque_lsa { * --------------------------------------------------------- */ -static int lsa_delete(struct thread *t) +static void lsa_delete(struct thread *t) { struct ospf_apiclient *oclient; struct in_addr area_id; @@ -93,7 +93,7 @@ static int lsa_delete(struct thread *t) rc = inet_aton(args[6], &area_id); if (rc <= 0) { printf("Address Specified: %s is invalid\n", args[6]); - return rc; + return; } printf("Deleting LSA... "); @@ -102,10 +102,9 @@ static int lsa_delete(struct thread *t) atoi(args[3]), /* opaque type */ atoi(args[4])); /* opaque ID */ printf("done, return code is = %d\n", rc); - return rc; } -static int lsa_inject(struct thread *t) +static void lsa_inject(struct thread *t) { struct ospf_apiclient *cl; struct in_addr ifaddr; @@ -124,13 +123,13 @@ static int lsa_inject(struct thread *t) rc = inet_aton(args[5], &ifaddr); if (rc <= 0) { printf("Ifaddr specified %s is invalid\n", args[5]); - return rc; + return; } rc = inet_aton(args[6], &area_id); if (rc <= 0) { printf("Area ID specified %s is invalid\n", args[6]); - return rc; + return; } lsa_type = atoi(args[2]); opaque_type = atoi(args[3]); @@ -146,14 +145,12 @@ static int lsa_inject(struct thread *t) printf("done, return code is %d\n", rc); counter++; - - return 0; } /* This thread handles asynchronous messages coming in from the OSPF API server */ -static int lsa_read(struct thread *thread) +static void lsa_read(struct thread *thread) { struct ospf_apiclient *oclient; int fd; @@ -173,8 +170,6 @@ static int lsa_read(struct thread *thread) /* Reschedule read thread */ thread_add_read(master, lsa_read, oclient, fd, NULL); - - return 0; } /* --------------------------------------------------------- diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index 8e59bd9ebd..7aa3a27c60 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -1829,7 +1829,7 @@ void ospf_abr_task(struct ospf *ospf) zlog_debug("ospf_abr_task(): Stop"); } -static int ospf_abr_task_timer(struct thread *thread) +static void ospf_abr_task_timer(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); @@ -1843,8 +1843,6 @@ static int ospf_abr_task_timer(struct thread *thread) ospf_abr_task(ospf); ospf_abr_nssa_task(ospf); /* if nssa-abr, then scan Type-7 LSDB */ - - return 0; } void ospf_schedule_abr_task(struct ospf *ospf) diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index a33ca95777..a624f4ce1e 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -278,7 +278,7 @@ struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async) return new; } -void ospf_apiserver_event(enum event event, int fd, +void ospf_apiserver_event(enum ospf_apiserver_event event, int fd, struct ospf_apiserver *apiserv) { switch (event) { @@ -362,13 +362,12 @@ void ospf_apiserver_free(struct ospf_apiserver *apiserv) XFREE(MTYPE_OSPF_APISERVER, apiserv); } -int ospf_apiserver_read(struct thread *thread) +void ospf_apiserver_read(struct thread *thread) { struct ospf_apiserver *apiserv; struct msg *msg; int fd; - int rc = -1; - enum event event; + enum ospf_apiserver_event event; apiserv = THREAD_ARG(thread); fd = THREAD_FD(thread); @@ -396,7 +395,7 @@ int ospf_apiserver_read(struct thread *thread) else { zlog_warn("ospf_apiserver_read: Unknown fd(%d)", fd); ospf_apiserver_free(apiserv); - goto out; + return; } /* Read message from fd. */ @@ -408,25 +407,22 @@ int ospf_apiserver_read(struct thread *thread) /* Perform cleanup. */ ospf_apiserver_free(apiserv); - goto out; + return; } if (IS_DEBUG_OSPF_EVENT) msg_print(msg); /* Dispatch to corresponding message handler. */ - rc = ospf_apiserver_handle_msg(apiserv, msg); + ospf_apiserver_handle_msg(apiserv, msg); /* Prepare for next message, add read thread. */ ospf_apiserver_event(event, fd, apiserv); msg_free(msg); - -out: - return rc; } -int ospf_apiserver_sync_write(struct thread *thread) +void ospf_apiserver_sync_write(struct thread *thread) { struct ospf_apiserver *apiserv; struct msg *msg; @@ -455,7 +451,7 @@ int ospf_apiserver_sync_write(struct thread *thread) if (!msg) { zlog_warn( "API: ospf_apiserver_sync_write: No message in Sync-FIFO?"); - return 0; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -485,12 +481,10 @@ out: /* Perform cleanup and disconnect with peer */ ospf_apiserver_free(apiserv); } - - return rc; } -int ospf_apiserver_async_write(struct thread *thread) +void ospf_apiserver_async_write(struct thread *thread) { struct ospf_apiserver *apiserv; struct msg *msg; @@ -519,7 +513,7 @@ int ospf_apiserver_async_write(struct thread *thread) if (!msg) { zlog_warn( "API: ospf_apiserver_async_write: No message in Async-FIFO?"); - return 0; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -549,8 +543,6 @@ out: /* Perform cleanup and disconnect with peer */ ospf_apiserver_free(apiserv); } - - return rc; } @@ -593,7 +585,7 @@ int ospf_apiserver_serv_sock_family(unsigned short port, int family) /* Accept connection request from external applications. For each accepted connection allocate own connection instance. */ -int ospf_apiserver_accept(struct thread *thread) +void ospf_apiserver_accept(struct thread *thread) { int accept_sock; int new_sync_sock; @@ -617,7 +609,7 @@ int ospf_apiserver_accept(struct thread *thread) if (new_sync_sock < 0) { zlog_warn("ospf_apiserver_accept: accept: %s", safe_strerror(errno)); - return -1; + return; } /* Get port address and port number of peer to make reverse connection. @@ -632,7 +624,7 @@ int ospf_apiserver_accept(struct thread *thread) zlog_warn("ospf_apiserver_accept: getpeername: %s", safe_strerror(errno)); close(new_sync_sock); - return -1; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -652,7 +644,7 @@ int ospf_apiserver_accept(struct thread *thread) &peer_async.sin_addr, ntohs(peer_async.sin_port)); close(new_sync_sock); - return -1; + return; } new_async_sock = socket(AF_INET, SOCK_STREAM, 0); @@ -660,7 +652,7 @@ int ospf_apiserver_accept(struct thread *thread) zlog_warn("ospf_apiserver_accept: socket: %s", safe_strerror(errno)); close(new_sync_sock); - return -1; + return; } ret = connect(new_async_sock, (struct sockaddr *)&peer_async, @@ -671,7 +663,7 @@ int ospf_apiserver_accept(struct thread *thread) safe_strerror(errno)); close(new_sync_sock); close(new_async_sock); - return -1; + return; } #ifdef USE_ASYNC_READ @@ -683,7 +675,7 @@ int ospf_apiserver_accept(struct thread *thread) safe_strerror(errno)); close(new_sync_sock); close(new_async_sock); - return -1; + return; } #endif /* USE_ASYNC_READ */ @@ -705,8 +697,6 @@ int ospf_apiserver_accept(struct thread *thread) if (IS_DEBUG_OSPF_EVENT) zlog_debug("API: New apiserv(%p), total#(%d)", (void *)apiserv, apiserver_list->count); - - return 0; } @@ -720,7 +710,7 @@ static int ospf_apiserver_send_msg(struct ospf_apiserver *apiserv, { struct msg_fifo *fifo; struct msg *msg2; - enum event event; + enum ospf_apiserver_event event; int fd; switch (msg->hdr.msgtype) { diff --git a/ospfd/ospf_apiserver.h b/ospfd/ospf_apiserver.h index 544a32a28c..3d57737080 100644 --- a/ospfd/ospf_apiserver.h +++ b/ospfd/ospf_apiserver.h @@ -68,7 +68,7 @@ struct ospf_apiserver { struct thread *t_async_write; }; -enum event { +enum ospf_apiserver_event { OSPF_APISERVER_ACCEPT, OSPF_APISERVER_SYNC_READ, #ifdef USE_ASYNC_READ @@ -88,13 +88,13 @@ extern int ospf_apiserver_init(void); extern void ospf_apiserver_term(void); extern struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async); extern void ospf_apiserver_free(struct ospf_apiserver *apiserv); -extern void ospf_apiserver_event(enum event event, int fd, +extern void ospf_apiserver_event(enum ospf_apiserver_event event, int fd, struct ospf_apiserver *apiserv); extern int ospf_apiserver_serv_sock_family(unsigned short port, int family); -extern int ospf_apiserver_accept(struct thread *thread); -extern int ospf_apiserver_read(struct thread *thread); -extern int ospf_apiserver_sync_write(struct thread *thread); -extern int ospf_apiserver_async_write(struct thread *thread); +extern void ospf_apiserver_accept(struct thread *thread); +extern void ospf_apiserver_read(struct thread *thread); +extern void ospf_apiserver_sync_write(struct thread *thread); +extern void ospf_apiserver_async_write(struct thread *thread); extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, uint32_t seqnr, uint8_t rc); diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c index db78e6d2df..70581b9085 100644 --- a/ospfd/ospf_asbr.c +++ b/ospfd/ospf_asbr.c @@ -279,7 +279,7 @@ void ospf_asbr_status_update(struct ospf *ospf, uint8_t status) /* If there's redistribution configured, we need to refresh external * LSAs in order to install Type-7 and flood to all NSSA Areas */ -static int ospf_asbr_nssa_redist_update_timer(struct thread *thread) +static void ospf_asbr_nssa_redist_update_timer(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); int type; @@ -305,8 +305,6 @@ static int ospf_asbr_nssa_redist_update_timer(struct thread *thread) } ospf_external_lsa_refresh_default(ospf); - - return 0; } void ospf_schedule_asbr_nssa_redist_update(struct ospf *ospf) @@ -1064,7 +1062,7 @@ static void ospf_handle_external_aggr_update(struct ospf *ospf) } } -static int ospf_asbr_external_aggr_process(struct thread *thread) +static void ospf_asbr_external_aggr_process(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); int operation = 0; @@ -1086,8 +1084,6 @@ static int ospf_asbr_external_aggr_process(struct thread *thread) default: break; } - - return OSPF_SUCCESS; } static void ospf_external_aggr_timer(struct ospf *ospf, struct ospf_external_aggr_rt *aggr, diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c index e9fb891d7e..23c7a1e706 100644 --- a/ospfd/ospf_ase.c +++ b/ospfd/ospf_ase.c @@ -564,7 +564,7 @@ static int ospf_ase_compare_tables(struct ospf *ospf, return 0; } -static int ospf_ase_calculate_timer(struct thread *t) +static void ospf_ase_calculate_timer(struct thread *t) { struct ospf *ospf; struct ospf_lsa *lsa; @@ -631,8 +631,6 @@ static int ospf_ase_calculate_timer(struct thread *t) ospf_zebra_gr_disable(ospf); ospf->gr_info.finishing_restart = false; } - - return 0; } void ospf_ase_calculate_schedule(struct ospf *ospf) diff --git a/ospfd/ospf_gr.c b/ospfd/ospf_gr.c index 6bfe48145f..ee1ca256e3 100644 --- a/ospfd/ospf_gr.c +++ b/ospfd/ospf_gr.c @@ -510,14 +510,12 @@ void ospf_gr_check_adjs(struct ospf *ospf) } /* Handling of grace period expiry. */ -static int ospf_gr_grace_period_expired(struct thread *thread) +static void ospf_gr_grace_period_expired(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); ospf->gr_info.t_grace_period = NULL; ospf_gr_restart_exit(ospf, "grace period has expired"); - - return 0; } /* diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c index 5eca591754..92236cf44f 100644 --- a/ospfd/ospf_gr_helper.c +++ b/ospfd/ospf_gr_helper.c @@ -346,14 +346,13 @@ static int ospf_extract_grace_lsa_fields(struct ospf_lsa *lsa, * Returns: * Nothing */ -static int ospf_handle_grace_timer_expiry(struct thread *thread) +static void ospf_handle_grace_timer_expiry(struct thread *thread) { struct ospf_neighbor *nbr = THREAD_ARG(thread); nbr->gr_helper_info.t_grace_timer = NULL; ospf_gr_helper_exit(nbr, OSPF_GR_HELPER_GRACE_TIMEOUT); - return OSPF_GR_SUCCESS; } /* diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index 1850d946b8..97da61034f 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -248,7 +248,7 @@ int ospf_dr_election(struct ospf_interface *oi) } -int ospf_hello_timer(struct thread *thread) +void ospf_hello_timer(struct thread *thread) { struct ospf_interface *oi; @@ -263,11 +263,9 @@ int ospf_hello_timer(struct thread *thread) /* Hello timer set. */ OSPF_HELLO_TIMER_ON(oi); - - return 0; } -static int ospf_wait_timer(struct thread *thread) +static void ospf_wait_timer(struct thread *thread) { struct ospf_interface *oi; @@ -278,8 +276,6 @@ static int ospf_wait_timer(struct thread *thread) zlog_debug("ISM[%s]: Timer (Wait timer expire)", IF_NAME(oi)); OSPF_ISM_EVENT_SCHEDULE(oi, ISM_WaitTimer); - - return 0; } /* Hook function called after ospf ISM event is occurred. And vty's @@ -575,7 +571,7 @@ static void ism_change_state(struct ospf_interface *oi, int state) } /* Execute ISM event process. */ -int ospf_ism_event(struct thread *thread) +void ospf_ism_event(struct thread *thread) { int event; int next_state; @@ -601,6 +597,4 @@ int ospf_ism_event(struct thread *thread) /* Make sure timer is set. */ ism_timer_set(oi); - - return 0; } diff --git a/ospfd/ospf_ism.h b/ospfd/ospf_ism.h index 5d0f95aed1..35fbd15d00 100644 --- a/ospfd/ospf_ism.h +++ b/ospfd/ospf_ism.h @@ -90,9 +90,9 @@ thread_execute(master, ospf_ism_event, (I), (E)) /* Prototypes. */ -extern int ospf_ism_event(struct thread *); +extern void ospf_ism_event(struct thread *thread); extern void ism_change_status(struct ospf_interface *, int); -extern int ospf_hello_timer(struct thread *thread); +extern void ospf_hello_timer(struct thread *thread); extern int ospf_dr_election(struct ospf_interface *oi); DECLARE_HOOK(ospf_ism_change, diff --git a/ospfd/ospf_ldp_sync.c b/ospfd/ospf_ldp_sync.c index 247ceb0a08..9b3498bc1e 100644 --- a/ospfd/ospf_ldp_sync.c +++ b/ospfd/ospf_ldp_sync.c @@ -353,7 +353,7 @@ static int ospf_ldp_sync_ism_change(struct ospf_interface *oi, int state, /* * LDP-SYNC holddown timer routines */ -static int ospf_ldp_sync_holddown_timer(struct thread *thread) +static void ospf_ldp_sync_holddown_timer(struct thread *thread) { struct interface *ifp; struct ospf_if_params *params; @@ -375,7 +375,6 @@ static int ospf_ldp_sync_holddown_timer(struct thread *thread) ospf_if_recalculate_output_cost(ifp); } - return 0; } void ospf_ldp_sync_holddown_timer_add(struct interface *ifp) diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index e3ba1f1dd1..48751dfba8 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -734,7 +734,7 @@ void ospf_router_lsa_body_set(struct stream **s, struct ospf_area *area) stream_putw_at(*s, putp, cnt); } -static int ospf_stub_router_timer(struct thread *t) +static void ospf_stub_router_timer(struct thread *t) { struct ospf_area *area = THREAD_ARG(t); @@ -746,13 +746,11 @@ static int ospf_stub_router_timer(struct thread *t) * clobber an administratively set stub-router state though. */ if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED)) - return 0; + return; UNSET_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED); ospf_router_lsa_update_area(area); - - return 0; } static void ospf_stub_router_check(struct ospf_area *area) @@ -2355,7 +2353,7 @@ void ospf_external_lsa_rid_change(struct ospf *ospf) continue; if (!ospf_external_lsa_originate(ospf, - NULL)) + ei)) flog_warn( EC_OSPF_LSA_INSTALL_FAILURE, "LSA: AS-external-LSA was not originated."); @@ -3025,7 +3023,7 @@ int ospf_check_nbr_status(struct ospf *ospf) } -static int ospf_maxage_lsa_remover(struct thread *thread) +static void ospf_maxage_lsa_remover(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); struct ospf_lsa *lsa, *old; @@ -3062,7 +3060,7 @@ static int ospf_maxage_lsa_remover(struct thread *thread) ospf_maxage_lsa_remover, 0); route_unlock_node( rn); /* route_top/route_next */ - return 0; + return; } /* Remove LSA from the LSDB */ @@ -3118,8 +3116,6 @@ static int ospf_maxage_lsa_remover(struct thread *thread) if (reschedule) OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover, ospf->maxage_delay); - - return 0; } /* This function checks whether an LSA with initial sequence number should be @@ -3275,7 +3271,7 @@ static int ospf_lsa_maxage_walker_remover(struct ospf *ospf, } /* Periodical check of MaxAge LSA. */ -int ospf_lsa_maxage_walker(struct thread *thread) +void ospf_lsa_maxage_walker(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); struct route_node *rn; @@ -3312,7 +3308,6 @@ int ospf_lsa_maxage_walker(struct thread *thread) OSPF_TIMER_ON(ospf->t_maxage_walker, ospf_lsa_maxage_walker, OSPF_LSA_MAXAGE_CHECK_INTERVAL); - return 0; } struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *lsdb, uint8_t type, @@ -3773,7 +3768,7 @@ struct lsa_action { struct ospf_lsa *lsa; }; -static int ospf_lsa_action(struct thread *t) +static void ospf_lsa_action(struct thread *t) { struct lsa_action *data; @@ -3794,7 +3789,6 @@ static int ospf_lsa_action(struct thread *t) ospf_lsa_unlock(&data->lsa); /* Message */ XFREE(MTYPE_OSPF_MESSAGE, data); - return 0; } void ospf_schedule_lsa_flood_area(struct ospf_area *area, struct ospf_lsa *lsa) @@ -3965,7 +3959,7 @@ void ospf_refresher_unregister_lsa(struct ospf *ospf, struct ospf_lsa *lsa) } } -int ospf_lsa_refresh_walker(struct thread *t) +void ospf_lsa_refresh_walker(struct thread *t) { struct list *refresh_list; struct listnode *node, *nnode; @@ -4044,8 +4038,6 @@ int ospf_lsa_refresh_walker(struct thread *t) if (IS_DEBUG_OSPF(lsa, LSA_REFRESH)) zlog_debug("LSA[Refresh]: ospf_lsa_refresh_walker(): end"); - - return 0; } /* Flush the LSAs for the specific area */ diff --git a/ospfd/ospf_lsa.h b/ospfd/ospf_lsa.h index d04d11841e..4b3be15382 100644 --- a/ospfd/ospf_lsa.h +++ b/ospfd/ospf_lsa.h @@ -308,7 +308,7 @@ extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t, extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *); extern uint32_t get_metric(uint8_t *); -extern int ospf_lsa_maxage_walker(struct thread *); +extern void ospf_lsa_maxage_walker(struct thread *thread); extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *); extern void ospf_external_lsa_refresh_default(struct ospf *); @@ -328,7 +328,7 @@ extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *); extern void ospf_refresher_register_lsa(struct ospf *, struct ospf_lsa *); extern void ospf_refresher_unregister_lsa(struct ospf *, struct ospf_lsa *); -extern int ospf_lsa_refresh_walker(struct thread *); +extern void ospf_lsa_refresh_walker(struct thread *thread); extern void ospf_lsa_maxage_delete(struct ospf *, struct ospf_lsa *); diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index e3cf1cfc8b..c538d1a09a 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -59,7 +59,7 @@ DEFINE_HOOK(ospf_nsm_change, static void nsm_clear_adj(struct ospf_neighbor *); /* OSPF NSM Timer functions. */ -static int ospf_inactivity_timer(struct thread *thread) +static void ospf_inactivity_timer(struct thread *thread) { struct ospf_neighbor *nbr; @@ -84,11 +84,9 @@ static int ospf_inactivity_timer(struct thread *thread) OSPF_NSM_TIMER_ON(nbr->t_inactivity, ospf_inactivity_timer, nbr->v_inactivity); } - - return 0; } -static int ospf_db_desc_timer(struct thread *thread) +static void ospf_db_desc_timer(struct thread *thread) { struct ospf_neighbor *nbr; @@ -106,8 +104,6 @@ static int ospf_db_desc_timer(struct thread *thread) /* DD Retransmit timer set. */ OSPF_NSM_TIMER_ON(nbr->t_db_desc, ospf_db_desc_timer, nbr->v_db_desc); - - return 0; } /* Hook function called after ospf NSM event is occurred. @@ -776,7 +772,7 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state) } /* Execute NSM event process. */ -int ospf_nsm_event(struct thread *thread) +void ospf_nsm_event(struct thread *thread) { int event; int next_state; @@ -846,8 +842,6 @@ int ospf_nsm_event(struct thread *thread) */ if (nbr->state == NSM_Deleted) ospf_nbr_delete(nbr); - - return 0; } /* Check loading state. */ diff --git a/ospfd/ospf_nsm.h b/ospfd/ospf_nsm.h index 798325f790..0b40b1f424 100644 --- a/ospfd/ospf_nsm.h +++ b/ospfd/ospf_nsm.h @@ -70,7 +70,7 @@ thread_execute(master, ospf_nsm_event, (N), (E)) /* Prototypes. */ -extern int ospf_nsm_event(struct thread *); +extern void ospf_nsm_event(struct thread *); extern void ospf_check_nbr_loading(struct ospf_neighbor *); extern int ospf_db_summary_isempty(struct ospf_neighbor *); extern int ospf_db_summary_count(struct ospf_neighbor *); diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index 4670316db4..b781c9edc1 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -1286,9 +1286,9 @@ out: * Followings are Opaque-LSA origination/refresh management functions. *------------------------------------------------------------------------*/ -static int ospf_opaque_type9_lsa_originate(struct thread *t); -static int ospf_opaque_type10_lsa_originate(struct thread *t); -static int ospf_opaque_type11_lsa_originate(struct thread *t); +static void ospf_opaque_type9_lsa_originate(struct thread *t); +static void ospf_opaque_type10_lsa_originate(struct thread *t); +static void ospf_opaque_type11_lsa_originate(struct thread *t); static void ospf_opaque_lsa_reoriginate_resume(struct list *listtop, void *arg); void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0) @@ -1460,10 +1460,9 @@ void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *delay0) *delay0 = delay; } -static int ospf_opaque_type9_lsa_originate(struct thread *t) +static void ospf_opaque_type9_lsa_originate(struct thread *t) { struct ospf_interface *oi; - int rc; oi = THREAD_ARG(t); oi->t_opaque_lsa_self = NULL; @@ -1472,15 +1471,12 @@ static int ospf_opaque_type9_lsa_originate(struct thread *t) zlog_debug("Timer[Type9-LSA]: Originate Opaque-LSAs for OI %s", IF_NAME(oi)); - rc = opaque_lsa_originate_callback(ospf_opaque_type9_funclist, oi); - - return rc; + opaque_lsa_originate_callback(ospf_opaque_type9_funclist, oi); } -static int ospf_opaque_type10_lsa_originate(struct thread *t) +static void ospf_opaque_type10_lsa_originate(struct thread *t) { struct ospf_area *area; - int rc; area = THREAD_ARG(t); area->t_opaque_lsa_self = NULL; @@ -1490,15 +1486,12 @@ static int ospf_opaque_type10_lsa_originate(struct thread *t) "Timer[Type10-LSA]: Originate Opaque-LSAs for Area %pI4", &area->area_id); - rc = opaque_lsa_originate_callback(ospf_opaque_type10_funclist, area); - - return rc; + opaque_lsa_originate_callback(ospf_opaque_type10_funclist, area); } -static int ospf_opaque_type11_lsa_originate(struct thread *t) +static void ospf_opaque_type11_lsa_originate(struct thread *t) { struct ospf *top; - int rc; top = THREAD_ARG(t); top->t_opaque_lsa_self = NULL; @@ -1507,9 +1500,7 @@ static int ospf_opaque_type11_lsa_originate(struct thread *t) zlog_debug( "Timer[Type11-LSA]: Originate AS-External Opaque-LSAs"); - rc = opaque_lsa_originate_callback(ospf_opaque_type11_funclist, top); - - return rc; + opaque_lsa_originate_callback(ospf_opaque_type11_funclist, top); } static void ospf_opaque_lsa_reoriginate_resume(struct list *listtop, void *arg) @@ -1665,10 +1656,10 @@ struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa) static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi, struct ospf_area *area, uint8_t lsa_type, uint8_t opaque_type); -static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t); -static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t); -static int ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t); -static int ospf_opaque_lsa_refresh_timer(struct thread *t); +static void ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t); +static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t); +static void ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t); +static void ospf_opaque_lsa_refresh_timer(struct thread *t); void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent, uint8_t lsa_type, uint8_t opaque_type) @@ -1679,7 +1670,7 @@ void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent, struct ospf_lsa *lsa; struct opaque_info_per_type *oipt; - int (*func)(struct thread * t) = NULL; + void (*func)(struct thread * t) = NULL; int delay; switch (lsa_type) { @@ -1846,13 +1837,12 @@ static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi, return &lsa; } -static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) +static void ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) { struct opaque_info_per_type *oipt; struct ospf_opaque_functab *functab; struct ospf *top; struct ospf_interface *oi; - int rc = -1; oipt = THREAD_ARG(t); @@ -1861,7 +1851,7 @@ static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) flog_warn( EC_OSPF_LSA, "ospf_opaque_type9_lsa_reoriginate_timer: No associated function?"); - goto out; + return; } oi = (struct ospf_interface *)oipt->owner; @@ -1869,7 +1859,7 @@ static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) flog_warn( EC_OSPF_LSA, "ospf_opaque_type9_lsa_reoriginate_timer: Something wrong?"); - goto out; + return; } if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE) @@ -1881,8 +1871,7 @@ static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) oipt->opaque_type); oipt->status = PROC_SUSPEND; - rc = 0; - goto out; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -1890,12 +1879,10 @@ static int ospf_opaque_type9_lsa_reoriginate_timer(struct thread *t) "Timer[Type9-LSA]: Re-originate Opaque-LSAs (opaque-type=%u) for OI (%s)", oipt->opaque_type, IF_NAME(oi)); - rc = (*functab->lsa_originator)(oi); -out: - return rc; + (*functab->lsa_originator)(oi); } -static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) +static void ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) { struct opaque_info_per_type *oipt; struct ospf_opaque_functab *functab; @@ -1903,7 +1890,7 @@ static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) struct ospf *top; struct ospf_area *area; struct ospf_interface *oi; - int n, rc = -1; + int n; oipt = THREAD_ARG(t); @@ -1912,7 +1899,7 @@ static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) flog_warn( EC_OSPF_LSA, "ospf_opaque_type10_lsa_reoriginate_timer: No associated function?"); - goto out; + return; } area = (struct ospf_area *)oipt->owner; @@ -1920,7 +1907,7 @@ static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) flog_warn( EC_OSPF_LSA, "ospf_opaque_type10_lsa_reoriginate_timer: Something wrong?"); - goto out; + return; } /* There must be at least one "opaque-capable, full-state" neighbor. */ @@ -1937,8 +1924,7 @@ static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) oipt->opaque_type); oipt->status = PROC_SUSPEND; - rc = 0; - goto out; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -1946,17 +1932,14 @@ static int ospf_opaque_type10_lsa_reoriginate_timer(struct thread *t) "Timer[Type10-LSA]: Re-originate Opaque-LSAs (opaque-type=%u) for Area %pI4", oipt->opaque_type, &area->area_id); - rc = (*functab->lsa_originator)(area); -out: - return rc; + (*functab->lsa_originator)(area); } -static int ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t) +static void ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t) { struct opaque_info_per_type *oipt; struct ospf_opaque_functab *functab; struct ospf *top; - int rc = -1; oipt = THREAD_ARG(t); @@ -1965,14 +1948,14 @@ static int ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t) flog_warn( EC_OSPF_LSA, "ospf_opaque_type11_lsa_reoriginate_timer: No associated function?"); - goto out; + return; } if ((top = (struct ospf *)oipt->owner) == NULL) { flog_warn( EC_OSPF_LSA, "ospf_opaque_type11_lsa_reoriginate_timer: Something wrong?"); - goto out; + return; } if (!CHECK_FLAG(top->config, OSPF_OPAQUE_CAPABLE)) { @@ -1982,8 +1965,7 @@ static int ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t) oipt->opaque_type); oipt->status = PROC_SUSPEND; - rc = 0; - goto out; + return; } if (IS_DEBUG_OSPF_EVENT) @@ -1991,9 +1973,7 @@ static int ospf_opaque_type11_lsa_reoriginate_timer(struct thread *t) "Timer[Type11-LSA]: Re-originate Opaque-LSAs (opaque-type=%u).", oipt->opaque_type); - rc = (*functab->lsa_originator)(top); -out: - return rc; + (*functab->lsa_originator)(top); } void ospf_opaque_lsa_refresh_schedule(struct ospf_lsa *lsa0) @@ -2064,7 +2044,7 @@ out: return; } -static int ospf_opaque_lsa_refresh_timer(struct thread *t) +static void ospf_opaque_lsa_refresh_timer(struct thread *t) { struct opaque_info_per_id *oipi; struct ospf_opaque_functab *functab; @@ -2079,8 +2059,6 @@ static int ospf_opaque_lsa_refresh_timer(struct thread *t) if ((functab = oipi->opqctl_type->functab) != NULL) if (functab->lsa_refresher != NULL) (*functab->lsa_refresher)(lsa); - - return 0; } void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa0) diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index e17e531098..c2bd7a0796 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -449,7 +449,7 @@ static int ospf_make_md5_digest(struct ospf_interface *oi, } -static int ospf_ls_req_timer(struct thread *thread) +static void ospf_ls_req_timer(struct thread *thread) { struct ospf_neighbor *nbr; @@ -462,8 +462,6 @@ static int ospf_ls_req_timer(struct thread *thread) /* Set Link State Request retransmission timer. */ OSPF_NSM_TIMER_ON(nbr->t_ls_req, ospf_ls_req_timer, nbr->v_ls_req); - - return 0; } void ospf_ls_req_event(struct ospf_neighbor *nbr) @@ -474,7 +472,7 @@ void ospf_ls_req_event(struct ospf_neighbor *nbr) /* Cyclic timer function. Fist registered in ospf_nbr_new () in ospf_neighbor.c */ -int ospf_ls_upd_timer(struct thread *thread) +void ospf_ls_upd_timer(struct thread *thread) { struct ospf_neighbor *nbr; @@ -530,11 +528,9 @@ int ospf_ls_upd_timer(struct thread *thread) /* Set LS Update retransmission timer. */ OSPF_NSM_TIMER_ON(nbr->t_ls_upd, ospf_ls_upd_timer, nbr->v_ls_upd); - - return 0; } -int ospf_ls_ack_timer(struct thread *thread) +void ospf_ls_ack_timer(struct thread *thread) { struct ospf_interface *oi; @@ -547,8 +543,6 @@ int ospf_ls_ack_timer(struct thread *thread) /* Set LS Ack timer. */ OSPF_ISM_TIMER_ON(oi->t_ls_ack, ospf_ls_ack_timer, oi->v_ls_ack); - - return 0; } #ifdef WANT_OSPF_WRITE_FRAGMENT @@ -625,7 +619,7 @@ static void ospf_write_frags(int fd, struct ospf_packet *op, struct ip *iph, } #endif /* WANT_OSPF_WRITE_FRAGMENT */ -static int ospf_write(struct thread *thread) +static void ospf_write(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); struct ospf_interface *oi; @@ -657,7 +651,7 @@ static int ospf_write(struct thread *thread) zlog_debug( "ospf_write failed to send, fd %d, instance %u", ospf->fd, ospf->oi_running); - return -1; + return; } node = listhead(ospf->oi_write_q); @@ -876,8 +870,6 @@ static int ospf_write(struct thread *thread) if (!list_isempty(ospf->oi_write_q)) thread_add_write(master, ospf_write, ospf, ospf->fd, &ospf->t_write); - - return 0; } /* OSPF Hello message read -- RFC2328 Section 10.5. */ @@ -3215,7 +3207,7 @@ static enum ospf_read_return_enum ospf_read_helper(struct ospf *ospf) } /* Starting point of packet process function. */ -int ospf_read(struct thread *thread) +void ospf_read(struct thread *thread) { struct ospf *ospf; int32_t count = 0; @@ -3232,13 +3224,11 @@ int ospf_read(struct thread *thread) ret = ospf_read_helper(ospf); switch (ret) { case OSPF_READ_ERROR: - return -1; + return; case OSPF_READ_CONTINUE: break; } } - - return 0; } /* Make OSPF header. */ @@ -3747,7 +3737,7 @@ static void ospf_poll_send(struct ospf_nbr_nbma *nbr_nbma) ospf_hello_send_sub(oi, nbr_nbma->addr.s_addr); } -int ospf_poll_timer(struct thread *thread) +void ospf_poll_timer(struct thread *thread) { struct ospf_nbr_nbma *nbr_nbma; @@ -3763,12 +3753,10 @@ int ospf_poll_timer(struct thread *thread) if (nbr_nbma->v_poll > 0) OSPF_POLL_TIMER_ON(nbr_nbma->t_poll, ospf_poll_timer, nbr_nbma->v_poll); - - return 0; } -int ospf_hello_reply_timer(struct thread *thread) +void ospf_hello_reply_timer(struct thread *thread) { struct ospf_neighbor *nbr; @@ -3780,8 +3768,6 @@ int ospf_hello_reply_timer(struct thread *thread) IF_NAME(nbr->oi), &nbr->router_id); ospf_hello_send_sub(nbr->oi, nbr->address.u.prefix4.s_addr); - - return 0; } /* Send OSPF Hello. */ @@ -4124,7 +4110,7 @@ static void ospf_ls_upd_queue_send(struct ospf_interface *oi, } } -static int ospf_ls_upd_send_queue_event(struct thread *thread) +static void ospf_ls_upd_send_queue_event(struct thread *thread) { struct ospf_interface *oi = THREAD_ARG(thread); struct route_node *rn; @@ -4167,8 +4153,6 @@ static int ospf_ls_upd_send_queue_event(struct thread *thread) if (IS_DEBUG_OSPF_EVENT) zlog_debug("ospf_ls_upd_send_queue stop"); - - return 0; } void ospf_ls_upd_send(struct ospf_neighbor *nbr, struct list *update, int flag, @@ -4272,7 +4256,7 @@ static void ospf_ls_ack_send_list(struct ospf_interface *oi, struct list *ack, OSPF_ISM_WRITE_ON(oi->ospf); } -static int ospf_ls_ack_send_event(struct thread *thread) +static void ospf_ls_ack_send_event(struct thread *thread) { struct ospf_interface *oi = THREAD_ARG(thread); @@ -4281,8 +4265,6 @@ static int ospf_ls_ack_send_event(struct thread *thread) while (listcount(oi->ls_ack_direct.ls_ack)) ospf_ls_ack_send_list(oi, oi->ls_ack_direct.ls_ack, oi->ls_ack_direct.dst); - - return 0; } void ospf_ls_ack_send(struct ospf_neighbor *nbr, struct ospf_lsa *lsa) diff --git a/ospfd/ospf_packet.h b/ospfd/ospf_packet.h index 72b87edafb..cefc9c21b6 100644 --- a/ospfd/ospf_packet.h +++ b/ospfd/ospf_packet.h @@ -139,7 +139,7 @@ extern struct ospf_packet *ospf_fifo_head(struct ospf_fifo *); extern void ospf_fifo_flush(struct ospf_fifo *); extern void ospf_fifo_free(struct ospf_fifo *); -extern int ospf_read(struct thread *); +extern void ospf_read(struct thread *thread); extern void ospf_hello_send(struct ospf_interface *); extern void ospf_db_desc_send(struct ospf_neighbor *); extern void ospf_db_desc_resend(struct ospf_neighbor *); @@ -152,10 +152,10 @@ extern void ospf_ls_ack_send_delayed(struct ospf_interface *); extern void ospf_ls_retransmit(struct ospf_interface *, struct ospf_lsa *); extern void ospf_ls_req_event(struct ospf_neighbor *); -extern int ospf_ls_upd_timer(struct thread *); -extern int ospf_ls_ack_timer(struct thread *); -extern int ospf_poll_timer(struct thread *); -extern int ospf_hello_reply_timer(struct thread *); +extern void ospf_ls_upd_timer(struct thread *thread); +extern void ospf_ls_ack_timer(struct thread *thread); +extern void ospf_poll_timer(struct thread *thread); +extern void ospf_hello_reply_timer(struct thread *thread); extern const struct message ospf_packet_type_str[]; extern const size_t ospf_packet_type_str_max; diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 8b4d55984c..f763400212 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -1809,7 +1809,7 @@ void ospf_spf_calculate_areas(struct ospf *ospf, struct route_table *new_table, } /* Worker for SPF calculation scheduler. */ -static int ospf_spf_calculate_schedule_worker(struct thread *thread) +static void ospf_spf_calculate_schedule_worker(struct thread *thread) { struct ospf *ospf = THREAD_ARG(thread); struct route_table *new_table, *new_rtrs; @@ -1929,8 +1929,6 @@ static int ospf_spf_calculate_schedule_worker(struct thread *thread) } ospf_clear_spf_reason_flags(); - - return 0; } /* diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index 181cc37f4f..e4059d05c2 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -470,7 +470,7 @@ int ospf_sr_local_block_release_label(mpls_label_t label) * * @return 1 on success */ -static int sr_start_label_manager(struct thread *start) +static void sr_start_label_manager(struct thread *start) { struct ospf *ospf; @@ -478,8 +478,6 @@ static int sr_start_label_manager(struct thread *start) /* re-attempt to start SR & Label Manager connection */ ospf_sr_start(ospf); - - return 1; } /* Segment Routing starter function */ diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 0b7c3c6831..780521bfe4 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -9705,7 +9705,7 @@ DEFUN (ospf_max_metric_router_lsa_startup, unsigned int seconds; if (argc < 4) { - vty_out(vty, "%% Must supply stub-router period"); + vty_out(vty, "%% Must supply stub-router period\n"); return CMD_WARNING_CONFIG_FAILED; } @@ -9761,7 +9761,7 @@ DEFUN (ospf_max_metric_router_lsa_shutdown, unsigned int seconds; if (argc < 4) { - vty_out(vty, "%% Must supply stub-router shutdown period"); + vty_out(vty, "%% Must supply stub-router shutdown period\n"); return CMD_WARNING_CONFIG_FAILED; } diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 66b7425a81..389d3647d0 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -524,7 +524,7 @@ bool ospf_external_default_routemap_apply_walk(struct ospf *ospf, * Function to originate or flush default after applying * route-map on all ei. */ -static int ospf_external_lsa_default_routemap_timer(struct thread *thread) +static void ospf_external_lsa_default_routemap_timer(struct thread *thread) { struct list *ext_list; struct ospf *ospf = THREAD_ARG(thread); @@ -545,7 +545,7 @@ static int ospf_external_lsa_default_routemap_timer(struct thread *thread) /* Nothing to be done here. */ if (IS_DEBUG_OSPF_DEFAULT_INFO) zlog_debug("Default originate info not present"); - return 0; + return; } /* For all the ei apply route-map */ @@ -570,8 +570,6 @@ static int ospf_external_lsa_default_routemap_timer(struct thread *thread) ospf_external_lsa_refresh(ospf, lsa, default_ei, true, false); else if (!ret && lsa) ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &default_ei->p, 0); - - return 1; } @@ -1522,7 +1520,7 @@ int ospf_distribute_list_out_unset(struct ospf *ospf, int type, } /* distribute-list update timer. */ -static int ospf_distribute_list_update_timer(struct thread *thread) +static void ospf_distribute_list_update_timer(struct thread *thread) { struct route_node *rn; struct external_info *ei; @@ -1532,7 +1530,7 @@ static int ospf_distribute_list_update_timer(struct thread *thread) struct ospf *ospf = THREAD_ARG(thread); if (ospf == NULL) - return 0; + return; ospf->t_distribute_update = NULL; @@ -1639,8 +1637,6 @@ static int ospf_distribute_list_update_timer(struct thread *thread) } if (default_refresh) ospf_external_lsa_refresh_default(ospf); - - return 0; } /* Update distribute-list and set timer to apply access-list. */ diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index b1bba9eb4e..221f6e7e4e 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -584,13 +584,11 @@ static void ospf_deferred_shutdown_finish(struct ospf *ospf) } /* Timer thread for G-R */ -static int ospf_deferred_shutdown_timer(struct thread *t) +static void ospf_deferred_shutdown_timer(struct thread *t) { struct ospf *ospf = THREAD_ARG(t); ospf_deferred_shutdown_finish(ospf); - - return 0; } /* Check whether deferred-shutdown must be scheduled, otherwise call diff --git a/pathd/path_pcep_controller.c b/pathd/path_pcep_controller.c index 162c53590f..b9f2ba3c63 100644 --- a/pathd/path_pcep_controller.c +++ b/pathd/path_pcep_controller.c @@ -92,10 +92,10 @@ struct get_pcep_session_args { /* Internal Functions Called From Main Thread */ static int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res); -static int pcep_refine_path_event_cb(struct thread *thread); +static void pcep_refine_path_event_cb(struct thread *thread); /* Internal Functions Called From Controller Thread */ -static int pcep_thread_finish_event_handler(struct thread *thread); +static void pcep_thread_finish_event_handler(struct thread *thread); /* Controller Thread Timer Handler */ static int schedule_thread_timer(struct ctrl_state *ctrl_state, int pcc_id, @@ -108,7 +108,7 @@ static int schedule_thread_timer_with_cb( enum pcep_ctrl_timer_type timer_type, enum pcep_ctrl_timeout_type timeout_type, uint32_t delay, void *payload, struct thread **thread, pcep_ctrl_thread_callback timer_cb); -static int pcep_thread_timer_handler(struct thread *thread); +static void pcep_thread_timer_handler(struct thread *thread); /* Controller Thread Socket read/write Handler */ static int schedule_thread_socket(struct ctrl_state *ctrl_state, int pcc_id, @@ -124,7 +124,7 @@ static int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id, enum pcep_ctrl_event_type type, uint32_t sub_type, void *payload, pcep_ctrl_thread_callback event_cb); -static int pcep_thread_event_handler(struct thread *thread); +static void pcep_thread_event_handler(struct thread *thread); static int pcep_thread_event_update_pcc_options(struct ctrl_state *ctrl_state, struct pcc_opts *opts); static int pcep_thread_event_update_pce_options(struct ctrl_state *ctrl_state, @@ -149,7 +149,7 @@ pcep_thread_path_refined_event(struct ctrl_state *ctrl_state, /* Main Thread Event Handler */ static int send_to_main(struct ctrl_state *ctrl_state, int pcc_id, enum pcep_main_event_type type, void *payload); -static int pcep_main_event_handler(struct thread *thread); +static void pcep_main_event_handler(struct thread *thread); /* Helper functions */ static void set_ctrl_state(struct frr_pthread *fpt, @@ -340,7 +340,7 @@ int pcep_ctrl_halt_cb(struct frr_pthread *fpt, void **res) return 0; } -int pcep_refine_path_event_cb(struct thread *thread) +void pcep_refine_path_event_cb(struct thread *thread) { struct pcep_refine_path_event_data *data = THREAD_ARG(thread); assert(data != NULL); @@ -351,7 +351,7 @@ int pcep_refine_path_event_cb(struct thread *thread) path_pcep_refine_path(path); - return send_to_thread(ctrl_state, pcc_id, EV_PATH_REFINED, 0, data); + send_to_thread(ctrl_state, pcc_id, EV_PATH_REFINED, 0, data); } @@ -507,7 +507,7 @@ void pcep_thread_path_refined_event(struct ctrl_state *ctrl_state, /* ------------ Internal Functions Called From Controller Thread ------------ */ -int pcep_thread_finish_event_handler(struct thread *thread) +void pcep_thread_finish_event_handler(struct thread *thread) { int i; struct frr_pthread *fpt = THREAD_ARG(thread); @@ -527,7 +527,6 @@ int pcep_thread_finish_event_handler(struct thread *thread) fpt->data = NULL; atomic_store_explicit(&fpt->running, false, memory_order_relaxed); - return 0; } /* ------------ Controller Thread Timer Handler ------------ */ @@ -566,7 +565,7 @@ int schedule_thread_timer(struct ctrl_state *ctrl_state, int pcc_id, thread, pcep_thread_timer_handler); } -int pcep_thread_timer_handler(struct thread *thread) +void pcep_thread_timer_handler(struct thread *thread) { /* data unpacking */ struct pcep_ctrl_timer_data *data = THREAD_ARG(thread); @@ -579,26 +578,25 @@ int pcep_thread_timer_handler(struct thread *thread) void *param = data->payload; XFREE(MTYPE_PCEP, data); - int ret = 0; struct pcc_state *pcc_state = NULL; switch (timer_type) { case TM_RECONNECT_PCC: pcc_state = pcep_pcc_get_pcc_by_id(ctrl_state->pcc, pcc_id); if (!pcc_state) - return ret; + return; pcep_pcc_reconnect(ctrl_state, pcc_state); break; case TM_TIMEOUT: pcc_state = pcep_pcc_get_pcc_by_id(ctrl_state->pcc, pcc_id); if (!pcc_state) - return ret; + return; pcep_pcc_timeout_handler(ctrl_state, pcc_state, timeout_type, param); break; case TM_CALCULATE_BEST_PCE: /* Previous best disconnect so new best should be synced */ - ret = pcep_pcc_timer_update_best_pce(ctrl_state, pcc_id); + pcep_pcc_timer_update_best_pce(ctrl_state, pcc_id); break; case TM_SESSION_TIMEOUT_PCC: pcc_state = pcep_pcc_get_pcc_by_id(ctrl_state->pcc, pcc_id); @@ -610,11 +608,9 @@ int pcep_thread_timer_handler(struct thread *thread) "Unknown controller timer triggered: %u", timer_type); break; } - - return ret; } -int pcep_thread_pcep_event(struct thread *thread) +void pcep_thread_pcep_event(struct thread *thread) { struct pcep_ctrl_event_data *data = THREAD_ARG(thread); assert(data != NULL); @@ -634,8 +630,6 @@ int pcep_thread_pcep_event(struct thread *thread) } } destroy_pcep_event(event); - - return 0; } /* ------------ Controller Thread Socket Functions ------------ */ @@ -725,7 +719,7 @@ int send_to_thread_with_cb(struct ctrl_state *ctrl_state, int pcc_id, return 0; } -int pcep_thread_event_handler(struct thread *thread) +void pcep_thread_event_handler(struct thread *thread) { /* data unpacking */ struct pcep_ctrl_event_data *data = THREAD_ARG(thread); @@ -738,8 +732,6 @@ int pcep_thread_event_handler(struct thread *thread) void *payload = data->payload; XFREE(MTYPE_PCEP, data); - int ret = 0; - /* Possible sub-type values */ enum pcep_pathd_event_type path_event_type = PCEP_PATH_UNDEFINED; @@ -757,29 +749,26 @@ int pcep_thread_event_handler(struct thread *thread) case EV_UPDATE_PCC_OPTS: assert(payload != NULL); pcc_opts = (struct pcc_opts *)payload; - ret = pcep_thread_event_update_pcc_options(ctrl_state, - pcc_opts); + pcep_thread_event_update_pcc_options(ctrl_state, pcc_opts); break; case EV_UPDATE_PCE_OPTS: assert(payload != NULL); pce_opts = (struct pce_opts *)payload; - ret = pcep_thread_event_update_pce_options(ctrl_state, pcc_id, - pce_opts); + pcep_thread_event_update_pce_options(ctrl_state, pcc_id, + pce_opts); break; case EV_REMOVE_PCC: pce_opts = (struct pce_opts *)payload; - ret = pcep_thread_event_remove_pcc(ctrl_state, pce_opts); - if (ret == 0) { - ret = pcep_pcc_multi_pce_remove_pcc(ctrl_state, - ctrl_state->pcc); - } + if (pcep_thread_event_remove_pcc(ctrl_state, pce_opts) == 0) + pcep_pcc_multi_pce_remove_pcc(ctrl_state, + ctrl_state->pcc); break; case EV_PATHD_EVENT: assert(payload != NULL); path_event_type = (enum pcep_pathd_event_type)sub_type; path = (struct path *)payload; - ret = pcep_thread_event_pathd_event(ctrl_state, path_event_type, - path); + pcep_thread_event_pathd_event(ctrl_state, path_event_type, + path); break; case EV_SYNC_PATH: assert(payload != NULL); @@ -789,14 +778,14 @@ int pcep_thread_event_handler(struct thread *thread) pcep_thread_event_sync_path(ctrl_state, pcc_id, path); break; case EV_SYNC_DONE: - ret = pcep_thread_event_sync_done(ctrl_state, pcc_id); + pcep_thread_event_sync_done(ctrl_state, pcc_id); break; case EV_RESET_PCC_SESSION: pcc_state = pcep_pcc_get_pcc_by_name(ctrl_state->pcc, (const char *)payload); if (pcc_state) { pcep_pcc_disable(ctrl_state, pcc_state); - ret = pcep_pcc_enable(ctrl_state, pcc_state); + pcep_pcc_enable(ctrl_state, pcc_state); } else { flog_warn(EC_PATH_PCEP_RECOVERABLE_INTERNAL_ERROR, "Cannot reset state for PCE: %s", @@ -840,8 +829,6 @@ int pcep_thread_event_handler(struct thread *thread) type); break; } - - return ret; } int pcep_thread_event_update_pcc_options(struct ctrl_state *ctrl_state, @@ -994,7 +981,7 @@ int send_to_main(struct ctrl_state *ctrl_state, int pcc_id, return 0; } -int pcep_main_event_handler(struct thread *thread) +void pcep_main_event_handler(struct thread *thread) { /* data unpacking */ struct pcep_main_event_data *data = THREAD_ARG(thread); @@ -1005,7 +992,7 @@ int pcep_main_event_handler(struct thread *thread) void *payload = data->payload; XFREE(MTYPE_PCEP, data); - return handler(type, pcc_id, payload); + handler(type, pcc_id, payload); } diff --git a/pathd/path_pcep_controller.h b/pathd/path_pcep_controller.h index f55cc0db72..de113feee9 100644 --- a/pathd/path_pcep_controller.h +++ b/pathd/path_pcep_controller.h @@ -90,7 +90,7 @@ struct pcep_ctrl_socket_data { void *payload; }; -typedef int (*pcep_ctrl_thread_callback)(struct thread *); +typedef void (*pcep_ctrl_thread_callback)(struct thread *); /* PCC connection information, populated in a thread-safe * manner with pcep_ctrl_get_pcc_info() */ @@ -174,7 +174,7 @@ int pcep_thread_socket_write(void *fpt, void **thread, int fd, void *payload, int pcep_thread_send_ctrl_event(void *fpt, void *payload, pcep_ctrl_thread_callback cb); -int pcep_thread_pcep_event(struct thread *thread); +void pcep_thread_pcep_event(struct thread *thread); int pcep_thread_pcc_count(struct ctrl_state *ctrl_state); /* Called by the PCC to refine a path in the main thread */ int pcep_thread_refine_path(struct ctrl_state *ctrl_state, int pcc_id, diff --git a/pathd/path_pcep_lib.c b/pathd/path_pcep_lib.c index 9fc8c091f8..8e3565d72d 100644 --- a/pathd/path_pcep_lib.c +++ b/pathd/path_pcep_lib.c @@ -45,8 +45,8 @@ static int pcep_lib_pceplib_socket_read_cb(void *fpt, void **thread, int fd, void *payload); static int pcep_lib_pceplib_socket_write_cb(void *fpt, void **thread, int fd, void *payload); -static int pcep_lib_socket_read_ready(struct thread *thread); -static int pcep_lib_socket_write_ready(struct thread *thread); +static void pcep_lib_socket_read_ready(struct thread *thread); +static void pcep_lib_socket_write_ready(struct thread *thread); /* pceplib pcep_event callbacks */ static void pcep_lib_pceplib_event_cb(void *fpt, pcep_event *event); @@ -241,26 +241,22 @@ int pcep_lib_pceplib_socket_read_cb(void *fpt, void **thread, int fd, /* Callbacks called by path_pcep_controller when a socket is ready to read/write */ -int pcep_lib_socket_write_ready(struct thread *thread) +void pcep_lib_socket_write_ready(struct thread *thread) { struct pcep_ctrl_socket_data *data = THREAD_ARG(thread); assert(data != NULL); - int retval = pceplib_external_socket_write(data->fd, data->payload); + pceplib_external_socket_write(data->fd, data->payload); XFREE(MTYPE_PCEP, data); - - return retval; } -int pcep_lib_socket_read_ready(struct thread *thread) +void pcep_lib_socket_read_ready(struct thread *thread) { struct pcep_ctrl_socket_data *data = THREAD_ARG(thread); assert(data != NULL); - int retval = pceplib_external_socket_read(data->fd, data->payload); + pceplib_external_socket_read(data->fd, data->payload); XFREE(MTYPE_PCEP, data); - - return retval; } /* Callback passed to pceplib when a pcep_event is ready */ diff --git a/pathd/path_ted.c b/pathd/path_ted.c index ff9bc82f39..3440b93399 100644 --- a/pathd/path_ted.c +++ b/pathd/path_ted.c @@ -39,8 +39,8 @@ static void path_ted_unregister_vty(void); static uint32_t path_ted_start_importing_igp(const char *daemon_str); static uint32_t path_ted_stop_importing_igp(void); static enum zclient_send_status path_ted_link_state_sync(void); -static int path_ted_timer_handler_sync(struct thread *thread); -static int path_ted_timer_handler_refresh(struct thread *thread); +static void path_ted_timer_handler_sync(struct thread *thread); +static void path_ted_timer_handler_refresh(struct thread *thread); static int path_ted_cli_debug_config_write(struct vty *vty); static int path_ted_cli_debug_set_all(uint32_t flags, bool set); @@ -602,14 +602,14 @@ enum zclient_send_status path_ted_link_state_sync(void) * * @return status */ -int path_ted_timer_handler_sync(struct thread *thread) +void path_ted_timer_handler_sync(struct thread *thread) { /* data unpacking */ struct ted_state *data = THREAD_ARG(thread); assert(data != NULL); /* Retry the sync */ - return path_ted_link_state_sync(); + path_ted_link_state_sync(); } /** @@ -639,10 +639,10 @@ int path_ted_segment_list_refresh(void) * * @return status */ -int path_ted_timer_handler_refresh(struct thread *thread) +void path_ted_timer_handler_refresh(struct thread *thread) { if (!path_ted_is_initialized()) - return MPLS_LABEL_NONE; + return; PATH_TED_DEBUG("%s: PATHD-TED: Refresh sid from current TED", __func__); /* data unpacking */ @@ -651,7 +651,6 @@ int path_ted_timer_handler_refresh(struct thread *thread) assert(data != NULL); srte_policy_update_ted_sid(); - return 0; } /** diff --git a/pathd/pathd.c b/pathd/pathd.c index f56da37b51..be2cfe8b01 100644 --- a/pathd/pathd.c +++ b/pathd/pathd.c @@ -45,9 +45,9 @@ DEFINE_HOOK(pathd_candidate_removed, (struct srte_candidate * candidate), (candidate)); static void trigger_pathd_candidate_created(struct srte_candidate *candidate); -static int trigger_pathd_candidate_created_timer(struct thread *thread); +static void trigger_pathd_candidate_created_timer(struct thread *thread); static void trigger_pathd_candidate_updated(struct srte_candidate *candidate); -static int trigger_pathd_candidate_updated_timer(struct thread *thread); +static void trigger_pathd_candidate_updated_timer(struct thread *thread); static void trigger_pathd_candidate_removed(struct srte_candidate *candidate); static const char * srte_candidate_metric_name(enum srte_candidate_metric_type type); @@ -1240,11 +1240,11 @@ void trigger_pathd_candidate_created(struct srte_candidate *candidate) (void *)candidate, HOOK_DELAY, &candidate->hook_timer); } -int trigger_pathd_candidate_created_timer(struct thread *thread) +void trigger_pathd_candidate_created_timer(struct thread *thread) { struct srte_candidate *candidate = THREAD_ARG(thread); candidate->hook_timer = NULL; - return hook_call(pathd_candidate_created, candidate); + hook_call(pathd_candidate_created, candidate); } void trigger_pathd_candidate_updated(struct srte_candidate *candidate) @@ -1260,11 +1260,11 @@ void trigger_pathd_candidate_updated(struct srte_candidate *candidate) (void *)candidate, HOOK_DELAY, &candidate->hook_timer); } -int trigger_pathd_candidate_updated_timer(struct thread *thread) +void trigger_pathd_candidate_updated_timer(struct thread *thread) { struct srte_candidate *candidate = THREAD_ARG(thread); candidate->hook_timer = NULL; - return hook_call(pathd_candidate_updated, candidate); + hook_call(pathd_candidate_updated, candidate); } void trigger_pathd_candidate_removed(struct srte_candidate *candidate) diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 21c1409e91..b5946bd40d 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -358,7 +358,7 @@ DEFPY(pbr_map_match_mark, pbr_map_match_mark_cmd, struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); #ifndef GNU_LINUX - vty_out(vty, "pbr marks are not supported on this platform"); + vty_out(vty, "pbr marks are not supported on this platform\n"); return CMD_WARNING_CONFIG_FAILED; #endif diff --git a/pceplib/test/pcep_msg_messages_test.c b/pceplib/test/pcep_msg_messages_test.c index 3fec24a225..e3a74f92d1 100644 --- a/pceplib/test/pcep_msg_messages_test.c +++ b/pceplib/test/pcep_msg_messages_test.c @@ -143,7 +143,7 @@ void test_pcep_msg_create_request() /* Test IPv6 */ rp_obj = pcep_obj_create_rp(0, false, false, false, false, 10, NULL); - struct in6_addr src_addr_ipv6, dst_addr_ipv6; + struct in6_addr src_addr_ipv6 = {}, dst_addr_ipv6 = {}; struct pcep_object_endpoints_ipv6 *ipv6_obj = pcep_obj_create_endpoint_ipv6(&src_addr_ipv6, &dst_addr_ipv6); message = pcep_msg_create_request_ipv6(rp_obj, ipv6_obj, NULL); diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c new file mode 100644 index 0000000000..06790d3d63 --- /dev/null +++ b/pimd/pim6_cmd.c @@ -0,0 +1,231 @@ +/* + * PIM for IPv6 FRR + * Copyright (C) 2022 Vmware, Inc. + * Mobashshera Rasool <mrasool@vmware.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> + +#include "lib/json.h" +#include "command.h" +#include "if.h" +#include "prefix.h" +#include "zclient.h" +#include "plist.h" +#include "hash.h" +#include "nexthop.h" +#include "vrf.h" +#include "ferr.h" + +#include "pimd.h" +#include "pim6_cmd.h" +#include "pim_vty.h" +#include "lib/northbound_cli.h" +#include "pim_errors.h" +#include "pim_nb.h" +#include "pim_cmd_common.h" + +#ifndef VTYSH_EXTRACT_PL +#include "pimd/pim6_cmd_clippy.c" +#endif + +DEFPY (ipv6_pim_joinprune_time, + ipv6_pim_joinprune_time_cmd, + "ipv6 pim join-prune-interval (1-65535)$jpi", + IPV6_STR + PIM_STR + "Join Prune Send Interval\n" + "Seconds\n") +{ + return pim_process_join_prune_cmd(vty, jpi_str); +} + +DEFPY (no_ipv6_pim_joinprune_time, + no_ipv6_pim_joinprune_time_cmd, + "no ipv6 pim join-prune-interval [(1-65535)]", + NO_STR + IPV6_STR + PIM_STR + "Join Prune Send Interval\n" + IGNORED_IN_NO_STR) +{ + return pim_process_no_join_prune_cmd(vty); +} + +DEFPY (ipv6_pim_spt_switchover_infinity, + ipv6_pim_spt_switchover_infinity_cmd, + "ipv6 pim spt-switchover infinity-and-beyond", + IPV6_STR + PIM_STR + "SPT-Switchover\n" + "Never switch to SPT Tree\n") +{ + return pim_process_spt_switchover_infinity_cmd(vty); +} + +DEFPY (ipv6_pim_spt_switchover_infinity_plist, + ipv6_pim_spt_switchover_infinity_plist_cmd, + "ipv6 pim spt-switchover infinity-and-beyond prefix-list WORD$plist", + IPV6_STR + PIM_STR + "SPT-Switchover\n" + "Never switch to SPT Tree\n" + "Prefix-List to control which groups to switch\n" + "Prefix-List name\n") +{ + return pim_process_spt_switchover_prefixlist_cmd(vty, plist); +} + +DEFPY (no_ipv6_pim_spt_switchover_infinity, + no_ipv6_pim_spt_switchover_infinity_cmd, + "no ipv6 pim spt-switchover infinity-and-beyond", + NO_STR + IPV6_STR + PIM_STR + "SPT_Switchover\n" + "Never switch to SPT Tree\n") +{ + return pim_process_no_spt_switchover_cmd(vty); +} + +DEFPY (no_ipv6_pim_spt_switchover_infinity_plist, + no_ipv6_pim_spt_switchover_infinity_plist_cmd, + "no ipv6 pim spt-switchover infinity-and-beyond prefix-list WORD", + NO_STR + IPV6_STR + PIM_STR + "SPT_Switchover\n" + "Never switch to SPT Tree\n" + "Prefix-List to control which groups to switch\n" + "Prefix-List name\n") +{ + return pim_process_no_spt_switchover_cmd(vty); +} + +DEFPY (ipv6_pim_packets, + ipv6_pim_packets_cmd, + "ipv6 pim packets (1-255)", + IPV6_STR + PIM_STR + "packets to process at one time per fd\n" + "Number of packets\n") +{ + return pim_process_pim_packet_cmd(vty, packets_str); +} + +DEFPY (no_ipv6_pim_packets, + no_ipv6_pim_packets_cmd, + "no ipv6 pim packets [(1-255)]", + NO_STR + IPV6_STR + PIM_STR + "packets to process at one time per fd\n" + IGNORED_IN_NO_STR) +{ + return pim_process_no_pim_packet_cmd(vty); +} + +DEFPY (ipv6_pim_keep_alive, + ipv6_pim_keep_alive_cmd, + "ipv6 pim keep-alive-timer (1-65535)$kat", + IPV6_STR + PIM_STR + "Keep alive Timer\n" + "Seconds\n") +{ + return pim_process_keepalivetimer_cmd(vty, kat_str); +} + +DEFPY (no_ipv6_pim_keep_alive, + no_ipv6_pim_keep_alive_cmd, + "no ipv6 pim keep-alive-timer [(1-65535)]", + NO_STR + IPV6_STR + PIM_STR + "Keep alive Timer\n" + IGNORED_IN_NO_STR) +{ + return pim_process_no_keepalivetimer_cmd(vty); +} + +DEFPY (ipv6_pim_rp_keep_alive, + ipv6_pim_rp_keep_alive_cmd, + "ipv6 pim rp keep-alive-timer (1-65535)$kat", + IPV6_STR + PIM_STR + "Rendevous Point\n" + "Keep alive Timer\n" + "Seconds\n") +{ + return pim_process_rp_kat_cmd(vty, kat_str); +} + +DEFPY (no_ipv6_pim_rp_keep_alive, + no_ipv6_pim_rp_keep_alive_cmd, + "no ipv6 pim rp keep-alive-timer [(1-65535)]", + NO_STR + IPV6_STR + PIM_STR + "Rendevous Point\n" + "Keep alive Timer\n" + IGNORED_IN_NO_STR) +{ + return pim_process_no_rp_kat_cmd(vty); +} + +DEFPY (ipv6_pim_register_suppress, + ipv6_pim_register_suppress_cmd, + "ipv6 pim register-suppress-time (1-65535)$rst", + IPV6_STR + PIM_STR + "Register Suppress Timer\n" + "Seconds\n") +{ + return pim_process_register_suppress_cmd(vty, rst_str); +} + +DEFPY (no_ipv6_pim_register_suppress, + no_ipv6_pim_register_suppress_cmd, + "no ipv6 pim register-suppress-time [(1-65535)]", + NO_STR + IPV6_STR + PIM_STR + "Register Suppress Timer\n" + IGNORED_IN_NO_STR) +{ + return pim_process_no_register_suppress_cmd(vty); +} + +void pim_cmd_init(void) +{ + if_cmd_init(pim_interface_config_write); + + install_element(CONFIG_NODE, &ipv6_pim_joinprune_time_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_joinprune_time_cmd); + install_element(CONFIG_NODE, &ipv6_pim_spt_switchover_infinity_cmd); + install_element(CONFIG_NODE, &ipv6_pim_spt_switchover_infinity_plist_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_spt_switchover_infinity_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_spt_switchover_infinity_plist_cmd); + install_element(CONFIG_NODE, &ipv6_pim_packets_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_packets_cmd); + install_element(CONFIG_NODE, &ipv6_pim_keep_alive_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_keep_alive_cmd); + install_element(CONFIG_NODE, &ipv6_pim_rp_keep_alive_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_rp_keep_alive_cmd); + install_element(CONFIG_NODE, &ipv6_pim_register_suppress_cmd); + install_element(CONFIG_NODE, &no_ipv6_pim_register_suppress_cmd); +} diff --git a/pimd/pim6_cmd.h b/pimd/pim6_cmd.h new file mode 100644 index 0000000000..e49045a1b5 --- /dev/null +++ b/pimd/pim6_cmd.h @@ -0,0 +1,44 @@ +/* + * PIM for IPv6 FRR + * Copyright (C) 2022 Vmware, Inc. + * Mobashshera Rasool <mrasool@vmware.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef PIM6_CMD_H +#define PIM6_CMD_H + +#define PIM_STR "PIM information\n" +#define MLD_STR "MLD information\n" +#define MLD_GROUP_STR "MLD groups information\n" +#define MLD_SOURCE_STR "MLD sources information\n" +#define IFACE_MLD_STR "Enable MLD operation\n" +#define IFACE_MLD_QUERY_INTERVAL_STR "MLD host query interval\n" +#define IFACE_MLD_QUERY_MAX_RESPONSE_TIME_STR \ + "MLD max query response value (seconds)\n" +#define IFACE_MLD_QUERY_MAX_RESPONSE_TIME_DSEC_STR \ + "MLD max query response value (deciseconds)\n" +#define IFACE_MLD_LAST_MEMBER_QUERY_INTERVAL_STR \ + "MLD last member query interval\n" +#define IFACE_MLD_LAST_MEMBER_QUERY_COUNT_STR "MLD last member query count\n" +#define MROUTE_STR "IP multicast routing table\n" +#define DEBUG_MLD_STR "MLD protocol activity\n" +#define DEBUG_MLD_EVENTS_STR "MLD protocol events\n" +#define DEBUG_MLD_PACKETS_STR "MLD protocol packets\n" +#define DEBUG_MLD_TRACE_STR "MLD internal daemon activity\n" + +void pim_cmd_init(void); + +#endif /* PIM6_CMD_H */ diff --git a/pimd/pim6_main.c b/pimd/pim6_main.c index 3d8ebd0d86..c9e3463969 100644 --- a/pimd/pim6_main.c +++ b/pimd/pim6_main.c @@ -36,6 +36,8 @@ #include "pim_errors.h" #include "pim_iface.h" #include "pim_zebra.h" +#include "pim_nb.h" +#include "pim6_cmd.h" zebra_capabilities_t _caps_p[] = { ZCAP_SYS_ADMIN, @@ -109,6 +111,9 @@ static const struct frr_yang_module_info *const pim6d_yang_modules[] = { &frr_route_map_info, &frr_vrf_info, &frr_routing_info, + &frr_pim_info, + &frr_pim_rp_info, + &frr_gmp_info, }; /* clang-format off */ @@ -172,9 +177,9 @@ int main(int argc, char **argv, char **envp) prefix_list_delete_hook(pim_prefix_list_update); pim_route_map_init(); - pim_init(); #endif - + /* pim_init(); */ + pim_cmd_init(); /* * Initialize zclient "update" and "lookup" sockets */ @@ -183,8 +188,8 @@ int main(int argc, char **argv, char **envp) /* TODO PIM6: next line is temporary since pim_cmd_init is disabled */ if_cmd_init(NULL); -#if 0 pim_zebra_init(); +#if 0 pim_bfd_init(); pim_mlag_init(); diff --git a/pimd/pim6_stubs.c b/pimd/pim6_stubs.c new file mode 100644 index 0000000000..9f68b7be3d --- /dev/null +++ b/pimd/pim6_stubs.c @@ -0,0 +1,135 @@ +/* + * PIMv6 temporary stubs + * Copyright (C) 2022 David Lamparter for NetDEF, Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> + +#include "pimd.h" +#include "pim_nht.h" +#include "pim_zlookup.h" +#include "pim_pim.h" +#include "pim_register.h" +#include "pim_cmd.h" + +/* + * NH lookup / NHT + */ +void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, + struct pim_nexthop_cache *pnc, int command) +{ +} + +int pim_ecmp_nexthop_lookup(struct pim_instance *pim, + struct pim_nexthop *nexthop, struct prefix *src, + struct prefix *grp, int neighbor_needed) +{ + return 0; +} + +int pim_find_or_track_nexthop(struct pim_instance *pim, struct prefix *addr, + struct pim_upstream *up, struct rp_info *rp, + struct pim_nexthop_cache *out_pnc) +{ + return 0; +} + +void pim_delete_tracked_nexthop(struct pim_instance *pim, struct prefix *addr, + struct pim_upstream *up, struct rp_info *rp) +{ +} + +struct pim_nexthop_cache *pim_nexthop_cache_find(struct pim_instance *pim, + struct pim_rpf *rpf) +{ + return NULL; +} + +void pim_rp_nexthop_del(struct rp_info *rp_info) +{ +} + +void pim_nht_bsr_add(struct pim_instance *pim, struct in_addr addr) +{ +} + +void pim_nht_bsr_del(struct pim_instance *pim, struct in_addr addr) +{ +} + +int zclient_lookup_nexthop(struct pim_instance *pim, + struct pim_zlookup_nexthop nexthop_tab[], + const int tab_size, pim_addr addr, + int max_lookup) +{ + return -1; +} + +void zclient_lookup_new(void) +{ +} + +void zclient_lookup_free(void) +{ +} + +/* + * packet handling + */ +int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, + int pim_msg_size, const char *ifname) +{ + return 0; +} + +int pim_hello_send(struct interface *ifp, uint16_t holdtime) +{ + return -1; +} + +void pim_hello_restart_now(struct interface *ifp) +{ +} + +void pim_hello_restart_triggered(struct interface *ifp) +{ +} + +int pim_sock_add(struct interface *ifp) +{ + return -1; +} + +void pim_sock_delete(struct interface *ifp, const char *delete_message) +{ +} + +/* + * PIM register + */ +void pim_register_join(struct pim_upstream *up) +{ +} + +void pim_null_register_send(struct pim_upstream *up) +{ +} + +void pim_reg_del_on_couldreg_fail(struct interface *ifp) +{ +} + diff --git a/pimd/pim_addr.c b/pimd/pim_addr.c index 2a6b4fe20f..6ba0947c2f 100644 --- a/pimd/pim_addr.c +++ b/pimd/pim_addr.c @@ -44,9 +44,6 @@ static ssize_t printfrr_pimaddr(struct fbuf *buf, struct printfrr_eargs *ea, #if PIM_IPV == 4 return bprintfrr(buf, "%pI4", addr); -#elif !defined(PIM_V6_TEMP_BREAK) - CPP_NOTICE("note IPv6 typing for pim_addr is temporarily disabled."); - return bprintfrr(buf, "%pI4", addr); #else return bprintfrr(buf, "%pI6", addr); #endif diff --git a/pimd/pim_addr.h b/pimd/pim_addr.h index 3c4b5a84d1..a278a46593 100644 --- a/pimd/pim_addr.h +++ b/pimd/pim_addr.h @@ -25,17 +25,15 @@ /* clang-format off */ -/* temporarily disable IPv6 types to keep code compiling. - * Defining PIM_V6_TEMP_BREAK will show a lot of compile errors - they are - * very useful to see TODOs. - */ -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 typedef struct in_addr pim_addr; #define PIM_ADDRSTRLEN INET_ADDRSTRLEN #define PIM_AF AF_INET #define PIM_AFI AFI_IP #define PIM_MAX_BITLEN IPV4_MAX_BITLEN +#define PIM_AF_NAME "ip" +#define FRR_PIM_AF_XPATH_VAL "frr-routing:ipv4" union pimprefixptr { prefixtype(pimprefixptr, struct prefix, p) @@ -54,6 +52,8 @@ typedef struct in6_addr pim_addr; #define PIM_AF AF_INET6 #define PIM_AFI AFI_IP6 #define PIM_MAX_BITLEN IPV6_MAX_BITLEN +#define PIM_AF_NAME "ipv6" +#define FRR_PIM_AF_XPATH_VAL "frr-routing:ipv6" union pimprefixptr { prefixtype(pimprefixptr, struct prefix, p) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 7d05403c36..e7fff4db6f 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -473,7 +473,7 @@ static int pim_assert_cancel(struct pim_ifchannel *ch) return pim_assert_do(ch, metric); } -static int on_assert_timer(struct thread *t) +static void on_assert_timer(struct thread *t) { struct pim_ifchannel *ch; struct interface *ifp; @@ -504,8 +504,6 @@ static int on_assert_timer(struct thread *t) ifp->name); } } - - return 0; } static void assert_timer_off(struct pim_ifchannel *ch) diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 3e3021dc4d..c1f8220db6 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -50,15 +50,15 @@ void pim_bfd_write_config(struct vty *vty, struct interface *ifp) if (pim_ifp->bfd_config.detection_multiplier != BFD_DEF_DETECT_MULT || pim_ifp->bfd_config.min_rx != BFD_DEF_MIN_RX || pim_ifp->bfd_config.min_tx != BFD_DEF_MIN_TX) - vty_out(vty, " ip pim bfd %d %d %d\n", + vty_out(vty, " " PIM_AF_NAME " pim bfd %d %d %d\n", pim_ifp->bfd_config.detection_multiplier, pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx); else #endif /* ! HAVE_BFDD */ - vty_out(vty, " ip pim bfd\n"); + vty_out(vty, " " PIM_AF_NAME " pim bfd\n"); if (pim_ifp->bfd_config.profile) - vty_out(vty, " ip pim bfd profile %s\n", + vty_out(vty, " " PIM_AF_NAME " pim bfd profile %s\n", pim_ifp->bfd_config.profile); } @@ -94,7 +94,7 @@ void pim_bfd_info_nbr_create(struct pim_interface *pim_ifp, bfd_sess_set_timers( neigh->bfd_session, pim_ifp->bfd_config.detection_multiplier, pim_ifp->bfd_config.min_rx, pim_ifp->bfd_config.min_tx); -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 bfd_sess_set_ipv4_addrs(neigh->bfd_session, NULL, &neigh->source_addr); #else bfd_sess_set_ipv6_addrs(neigh->bfd_session, NULL, &neigh->source_addr); diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index 0b993ec05e..c45823cb87 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -59,9 +59,9 @@ void pim_bsm_write_config(struct vty *vty, struct interface *ifp) if (pim_ifp) { if (!pim_ifp->bsm_enable) - vty_out(vty, " no ip pim bsm\n"); + vty_out(vty, " no " PIM_AF_NAME " pim bsm\n"); if (!pim_ifp->ucast_bsm_accept) - vty_out(vty, " no ip pim unicast-bsm\n"); + vty_out(vty, " no " PIM_AF_NAME " pim unicast-bsm\n"); } } @@ -157,7 +157,7 @@ static struct bsgrp_node *pim_bsm_new_bsgrp_node(struct route_table *rt, return bsgrp; } -static int pim_on_bs_timer(struct thread *t) +static void pim_on_bs_timer(struct thread *t) { struct route_node *rn; struct bsm_scope *scope; @@ -200,7 +200,6 @@ static int pim_on_bs_timer(struct thread *t) pim_bsm_rpinfos_free(bsgrp_node->partial_bsrp_list); bsgrp_node->pend_rp_cnt = 0; } - return 0; } static void pim_bs_timer_stop(struct bsm_scope *scope) @@ -276,7 +275,7 @@ static bool is_hold_time_elapsed(void *data) return true; } -static int pim_on_g2rp_timer(struct thread *t) +static void pim_on_g2rp_timer(struct thread *t) { struct bsm_rpinfo *bsrp; struct bsm_rpinfo *bsrp_node; @@ -312,14 +311,14 @@ static int pim_on_g2rp_timer(struct thread *t) if (!rn) { zlog_warn("%s: Route node doesn't exist", __func__); - return 0; + return; } rp_info = (struct rp_info *)rn->info; if (!rp_info) { route_unlock_node(rn); - return 0; + return; } if (rp_info->rp_src != RP_SRC_STATIC) { @@ -342,8 +341,6 @@ static int pim_on_g2rp_timer(struct thread *t) &bsgrp_node->group); pim_free_bsgrp_data(bsgrp_node); } - - return 0; } static void pim_g2rp_timer_start(struct bsm_rpinfo *bsrp, int hold_time) @@ -433,8 +430,8 @@ static void pim_instate_pend_list(struct bsgrp_node *bsgrp_node) * install the rp from head(if exists) of partial list. List is * is sorted such that head is the elected RP for the group. */ - if (!rn || (prefix_same(&rp_all->group, &bsgrp_node->group) - && pim_rpf_addr_is_inaddr_none(&rp_all->rp))) { + if (!rn || (prefix_same(&rp_all->group, &bsgrp_node->group) && + pim_rpf_addr_is_inaddr_any(&rp_all->rp))) { if (PIM_DEBUG_BSM) zlog_debug("%s: Route node doesn't exist", __func__); if (pend) @@ -637,8 +634,7 @@ void pim_bsm_clear(struct pim_instance *pim) rp_all = pim_rp_find_match_group(pim, &g_all); if (rp_all == rp_info) { - rp_all->rp.rpf_addr.family = AF_INET; - rp_all->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE; + pim_addr_to_prefix(&rp_all->rp.rpf_addr, PIMADDR_ANY); rp_all->i_am_rp = 0; } else { /* Delete the rp_info from rp-list */ @@ -671,7 +667,7 @@ void pim_bsm_clear(struct pim_instance *pim) trp_info = pim_rp_find_match_group(pim, &grp); /* RP not found for the group grp */ - if (pim_rpf_addr_is_inaddr_none(&trp_info->rp)) { + if (pim_rpf_addr_is_inaddr_any(&trp_info->rp)) { pim_upstream_rpf_clear(pim, up); pim_rp_set_upstream_addr(pim, &up->upstream_addr, up->sg.src, up->sg.grp); @@ -1374,7 +1370,12 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, } } - if (ip_hdr->ip_dst.s_addr == qpim_all_pim_routers_addr.s_addr) { +#if PIM_IPV == 4 + if (ip_hdr->ip_dst.s_addr == qpim_all_pim_routers_addr.s_addr) +#else + if (0) +#endif + { /* Multicast BSMs are only accepted if source interface & IP * match RPF towards the BSR's IP address, or they have * no-forward set diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 83ba74f69f..76f90cdba7 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -67,6 +67,7 @@ #include "lib/northbound_cli.h" #include "pim_errors.h" #include "pim_nb.h" +#include "pim_cmd_common.h" #ifndef VTYSH_EXTRACT_PL #include "pimd/pim_cmd_clippy.c" @@ -3761,32 +3762,6 @@ static void clear_interfaces(struct pim_instance *pim) } /** - * Get current node VRF name. - * - * NOTE: - * In case of failure it will print error message to user. - * - * \returns name or NULL if failed to get VRF. - */ -static const char *pim_cli_get_vrf_name(struct vty *vty) -{ - const struct lyd_node *vrf_node; - - /* Not inside any VRF context. */ - if (vty->xpath_index == 0) - return VRF_DEFAULT_NAME; - - vrf_node = yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH); - if (vrf_node == NULL) { - vty_out(vty, "%% Failed to get vrf dnode in configuration\n"); - return NULL; - } - - return yang_dnode_get_string(vrf_node, "./name"); -} - -#if PIM_IPV != 6 -/** * Compatibility function to keep the legacy mesh group CLI behavior: * Delete group when there are no more configurations in it. * @@ -3833,7 +3808,6 @@ static void pim_cli_legacy_mesh_group_behavior(struct vty *vty, /* No configurations found: delete it. */ nb_cli_enqueue_change(vty, xpath_value, NB_OP_DESTROY, NULL); } -#endif /* PIM_IPV != 6 */ DEFUN (clear_ip_interfaces, clear_ip_interfaces_cmd, @@ -3901,7 +3875,6 @@ static void clear_mroute(struct pim_instance *pim) /* scan interfaces */ FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; - struct gm_group *grp; struct pim_ifchannel *ch; if (!pim_ifp) @@ -3914,7 +3887,9 @@ static void clear_mroute(struct pim_instance *pim) pim_ifchannel_delete(ch); } +#if PIM_IPV == 4 /* clean up all igmp groups */ + struct gm_group *grp; if (pim_ifp->gm_group_list) { while (pim_ifp->gm_group_list->count) { @@ -3922,6 +3897,7 @@ static void clear_mroute(struct pim_instance *pim) igmp_group_delete(grp); } } +#endif } /* clean up all upstreams*/ @@ -6748,38 +6724,12 @@ DEFUN (ip_pim_spt_switchover_infinity, "SPT-Switchover\n" "Never switch to SPT Tree\n") { - const char *vrfname; - char spt_plist_xpath[XPATH_MAXLEN]; - char spt_action_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", - sizeof(spt_plist_xpath)); - - snprintf(spt_action_xpath, sizeof(spt_action_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_action_xpath, "/spt-switchover/spt-action", - sizeof(spt_action_xpath)); - - if (yang_dnode_exists(vty->candidate_config->dnode, spt_plist_xpath)) - nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, - NULL); - nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, - "PIM_SPT_INFINITY"); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_spt_switchover_infinity_cmd(vty); } -DEFUN (ip_pim_spt_switchover_infinity_plist, +DEFPY (ip_pim_spt_switchover_infinity_plist, ip_pim_spt_switchover_infinity_plist_cmd, - "ip pim spt-switchover infinity-and-beyond prefix-list WORD", + "ip pim spt-switchover infinity-and-beyond prefix-list WORD$plist", IP_STR PIM_STR "SPT-Switchover\n" @@ -6787,32 +6737,7 @@ DEFUN (ip_pim_spt_switchover_infinity_plist, "Prefix-List to control which groups to switch\n" "Prefix-List name\n") { - const char *vrfname; - char spt_plist_xpath[XPATH_MAXLEN]; - char spt_action_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", - sizeof(spt_plist_xpath)); - - snprintf(spt_action_xpath, sizeof(spt_action_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_action_xpath, "/spt-switchover/spt-action", - sizeof(spt_action_xpath)); - - nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, - "PIM_SPT_INFINITY"); - nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_MODIFY, - argv[5]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_spt_switchover_prefixlist_cmd(vty, plist); } DEFUN (no_ip_pim_spt_switchover_infinity, @@ -6824,31 +6749,7 @@ DEFUN (no_ip_pim_spt_switchover_infinity, "SPT_Switchover\n" "Never switch to SPT Tree\n") { - const char *vrfname; - char spt_plist_xpath[XPATH_MAXLEN]; - char spt_action_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", - sizeof(spt_plist_xpath)); - - snprintf(spt_action_xpath, sizeof(spt_action_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_action_xpath, "/spt-switchover/spt-action", - sizeof(spt_action_xpath)); - - nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, NULL); - nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, - "PIM_SPT_IMMEDIATE"); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_spt_switchover_cmd(vty); } DEFUN (no_ip_pim_spt_switchover_infinity_plist, @@ -6862,31 +6763,7 @@ DEFUN (no_ip_pim_spt_switchover_infinity_plist, "Prefix-List to control which groups to switch\n" "Prefix-List name\n") { - const char *vrfname; - char spt_plist_xpath[XPATH_MAXLEN]; - char spt_action_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", - sizeof(spt_plist_xpath)); - - snprintf(spt_action_xpath, sizeof(spt_action_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(spt_action_xpath, "/spt-switchover/spt-action", - sizeof(spt_action_xpath)); - - nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, NULL); - nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, - "PIM_SPT_IMMEDIATE"); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_spt_switchover_cmd(vty); } DEFPY (pim_register_accept_list, @@ -6921,23 +6798,15 @@ DEFPY (pim_register_accept_list, return nb_cli_apply_changes(vty, NULL); } -DEFUN (ip_pim_joinprune_time, +DEFPY (ip_pim_joinprune_time, ip_pim_joinprune_time_cmd, - "ip pim join-prune-interval (1-65535)", + "ip pim join-prune-interval (1-65535)$jpi", IP_STR "pim multicast routing\n" "Join Prune Send Interval\n" "Seconds\n") { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/join-prune-interval", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, argv[3]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_join_prune_cmd(vty, jpi_str); } DEFUN (no_ip_pim_joinprune_time, @@ -6949,34 +6818,18 @@ DEFUN (no_ip_pim_joinprune_time, "Join Prune Send Interval\n" IGNORED_IN_NO_STR) { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/join-prune-interval", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_join_prune_cmd(vty); } -DEFUN (ip_pim_register_suppress, +DEFPY (ip_pim_register_suppress, ip_pim_register_suppress_cmd, - "ip pim register-suppress-time (1-65535)", + "ip pim register-suppress-time (1-65535)$rst", IP_STR "pim multicast routing\n" "Register Suppress Timer\n" "Seconds\n") { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/register-suppress-time", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, argv[3]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_register_suppress_cmd(vty, rst_str); } DEFUN (no_ip_pim_register_suppress, @@ -6988,43 +6841,19 @@ DEFUN (no_ip_pim_register_suppress, "Register Suppress Timer\n" IGNORED_IN_NO_STR) { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/register-suppress-time", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_register_suppress_cmd(vty); } -DEFUN (ip_pim_rp_keep_alive, +DEFPY (ip_pim_rp_keep_alive, ip_pim_rp_keep_alive_cmd, - "ip pim rp keep-alive-timer (1-65535)", + "ip pim rp keep-alive-timer (1-65535)$kat", IP_STR "pim multicast routing\n" "Rendevous Point\n" "Keep alive Timer\n" "Seconds\n") { - const char *vrfname; - char rp_ka_timer_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", - sizeof(rp_ka_timer_xpath)); - - nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, - argv[4]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_rp_kat_cmd(vty, kat_str); } DEFUN (no_ip_pim_rp_keep_alive, @@ -7037,64 +6866,18 @@ DEFUN (no_ip_pim_rp_keep_alive, "Keep alive Timer\n" IGNORED_IN_NO_STR) { - const char *vrfname; - char rp_ka_timer[6]; - char rp_ka_timer_xpath[XPATH_MAXLEN]; - uint v; - char rs_timer_xpath[XPATH_MAXLEN]; - - snprintf(rs_timer_xpath, sizeof(rs_timer_xpath), - FRR_PIM_ROUTER_XPATH, "frr-routing:ipv4"); - strlcat(rs_timer_xpath, "/register-suppress-time", - sizeof(rs_timer_xpath)); - - /* RFC4601 */ - v = yang_dnode_get_uint16(vty->candidate_config->dnode, - rs_timer_xpath); - v = 3 * v + PIM_REGISTER_PROBE_TIME_DEFAULT; - if (v > UINT16_MAX) - v = UINT16_MAX; - snprintf(rp_ka_timer, sizeof(rp_ka_timer), "%u", v); - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), - FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, - "frr-routing:ipv4"); - strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", - sizeof(rp_ka_timer_xpath)); - - nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, - rp_ka_timer); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_rp_kat_cmd(vty); } -DEFUN (ip_pim_keep_alive, +DEFPY (ip_pim_keep_alive, ip_pim_keep_alive_cmd, - "ip pim keep-alive-timer (1-65535)", + "ip pim keep-alive-timer (1-65535)$kat", IP_STR "pim multicast routing\n" "Keep alive Timer\n" "Seconds\n") { - const char *vrfname; - char ka_timer_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, - "frr-pim:pimd", "pim", vrfname, "frr-routing:ipv4"); - strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); - - nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_MODIFY, - argv[3]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_keepalivetimer_cmd(vty, kat_str); } DEFUN (no_ip_pim_keep_alive, @@ -7106,23 +6889,10 @@ DEFUN (no_ip_pim_keep_alive, "Keep alive Timer\n" IGNORED_IN_NO_STR) { - const char *vrfname; - char ka_timer_xpath[XPATH_MAXLEN]; - - vrfname = pim_cli_get_vrf_name(vty); - if (vrfname == NULL) - return CMD_WARNING_CONFIG_FAILED; - - snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, - "frr-pim:pimd", "pim", vrfname, "frr-routing:ipv4"); - strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); - - nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_keepalivetimer_cmd(vty); } -DEFUN (ip_pim_packets, +DEFPY (ip_pim_packets, ip_pim_packets_cmd, "ip pim packets (1-255)", IP_STR @@ -7130,15 +6900,7 @@ DEFUN (ip_pim_packets, "packets to process at one time per fd\n" "Number of packets\n") { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/packets", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, argv[3]->arg); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_pim_packet_cmd(vty, packets_str); } DEFUN (no_ip_pim_packets, @@ -7150,15 +6912,7 @@ DEFUN (no_ip_pim_packets, "packets to process at one time per fd\n" IGNORED_IN_NO_STR) { - char xpath[XPATH_MAXLEN]; - - snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, - "frr-routing:ipv4"); - strlcat(xpath, "/packets", sizeof(xpath)); - - nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); - - return nb_cli_apply_changes(vty, NULL); + return pim_process_no_pim_packet_cmd(vty); } DEFPY (igmp_group_watermark, @@ -8236,6 +7990,7 @@ DEFPY_HIDDEN (interface_ip_igmp_query_generate, "IGMP version\n" "IGMP version number\n") { +#if PIM_IPV == 4 VTY_DECLVAR_CONTEXT(interface, ifp); int igmp_version; struct pim_interface *pim_ifp = ifp->info; @@ -8253,7 +8008,7 @@ DEFPY_HIDDEN (interface_ip_igmp_query_generate, igmp_version = atoi(argv[4]->arg); igmp_send_query_on_intf(ifp, igmp_version); - +#endif return CMD_SUCCESS; } @@ -9540,7 +9295,6 @@ ALIAS(no_ip_pim_bfd, no_ip_pim_bfd_param_cmd, "Desired min transmit interval\n") #endif /* !HAVE_BFDD */ -#if PIM_IPV != 6 DEFPY(ip_msdp_peer, ip_msdp_peer_cmd, "ip msdp peer A.B.C.D$peer source A.B.C.D$source", IP_STR @@ -10568,7 +10322,6 @@ DEFUN (show_ip_msdp_sa_sg_vrf_all, return CMD_SUCCESS; } -#endif /* PIM_IPV != 6 */ struct pim_sg_cache_walk_data { struct vty *vty; @@ -11002,12 +10755,10 @@ void pim_cmd_init(void) install_element(VRF_NODE, &ip_ssmpingd_cmd); install_element(CONFIG_NODE, &no_ip_ssmpingd_cmd); install_element(VRF_NODE, &no_ip_ssmpingd_cmd); -#if PIM_IPV != 6 install_element(CONFIG_NODE, &ip_msdp_peer_cmd); install_element(VRF_NODE, &ip_msdp_peer_cmd); install_element(CONFIG_NODE, &no_ip_msdp_peer_cmd); install_element(VRF_NODE, &no_ip_msdp_peer_cmd); -#endif /* PIM_IPV != 6 */ install_element(CONFIG_NODE, &ip_pim_ecmp_cmd); install_element(VRF_NODE, &ip_pim_ecmp_cmd); install_element(CONFIG_NODE, &no_ip_pim_ecmp_cmd); @@ -11176,14 +10927,12 @@ void pim_cmd_init(void) install_element(ENABLE_NODE, &no_debug_pim_mlag_cmd); install_element(ENABLE_NODE, &debug_pim_vxlan_cmd); install_element(ENABLE_NODE, &no_debug_pim_vxlan_cmd); -#if PIM_IPV != 6 install_element(ENABLE_NODE, &debug_msdp_cmd); install_element(ENABLE_NODE, &no_debug_msdp_cmd); install_element(ENABLE_NODE, &debug_msdp_events_cmd); install_element(ENABLE_NODE, &no_debug_msdp_events_cmd); install_element(ENABLE_NODE, &debug_msdp_packets_cmd); install_element(ENABLE_NODE, &no_debug_msdp_packets_cmd); -#endif /* PIM_IPV != 6 */ install_element(ENABLE_NODE, &debug_mtrace_cmd); install_element(ENABLE_NODE, &no_debug_mtrace_cmd); install_element(ENABLE_NODE, &debug_bsm_cmd); @@ -11229,20 +10978,17 @@ void pim_cmd_init(void) install_element(CONFIG_NODE, &no_debug_pim_mlag_cmd); install_element(CONFIG_NODE, &debug_pim_vxlan_cmd); install_element(CONFIG_NODE, &no_debug_pim_vxlan_cmd); -#if PIM_IPV != 6 install_element(CONFIG_NODE, &debug_msdp_cmd); install_element(CONFIG_NODE, &no_debug_msdp_cmd); install_element(CONFIG_NODE, &debug_msdp_events_cmd); install_element(CONFIG_NODE, &no_debug_msdp_events_cmd); install_element(CONFIG_NODE, &debug_msdp_packets_cmd); install_element(CONFIG_NODE, &no_debug_msdp_packets_cmd); -#endif /* PIM_IPV != 6 */ install_element(CONFIG_NODE, &debug_mtrace_cmd); install_element(CONFIG_NODE, &no_debug_mtrace_cmd); install_element(CONFIG_NODE, &debug_bsm_cmd); install_element(CONFIG_NODE, &no_debug_bsm_cmd); -#if PIM_IPV != 6 install_element(CONFIG_NODE, &ip_msdp_timers_cmd); install_element(VRF_NODE, &ip_msdp_timers_cmd); install_element(CONFIG_NODE, &no_ip_msdp_timers_cmd); @@ -11265,7 +11011,6 @@ void pim_cmd_init(void) install_element(VIEW_NODE, &show_ip_msdp_sa_sg_vrf_all_cmd); install_element(VIEW_NODE, &show_ip_msdp_mesh_group_cmd); install_element(VIEW_NODE, &show_ip_msdp_mesh_group_vrf_all_cmd); -#endif /* PIM_IPV != 6 */ install_element(VIEW_NODE, &show_ip_pim_ssm_range_cmd); install_element(VIEW_NODE, &show_ip_pim_group_type_cmd); install_element(VIEW_NODE, &show_ip_pim_vxlan_sg_cmd); diff --git a/pimd/pim_cmd_common.c b/pimd/pim_cmd_common.c new file mode 100644 index 0000000000..6adea54a61 --- /dev/null +++ b/pimd/pim_cmd_common.c @@ -0,0 +1,328 @@ +/* + * PIM for IPv6 FRR + * Copyright (C) 2022 Vmware, Inc. + * Mobashshera Rasool <mrasool@vmware.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> + +#include "lib/json.h" +#include "command.h" +#include "if.h" +#include "prefix.h" +#include "zclient.h" +#include "plist.h" +#include "hash.h" +#include "nexthop.h" +#include "vrf.h" +#include "ferr.h" + +#include "pimd.h" +#include "pim_vty.h" +#include "lib/northbound_cli.h" +#include "pim_errors.h" +#include "pim_nb.h" +#include "pim_cmd_common.h" + +/** + * Get current node VRF name. + * + * NOTE: + * In case of failure it will print error message to user. + * + * \returns name or NULL if failed to get VRF. + */ +const char *pim_cli_get_vrf_name(struct vty *vty) +{ + const struct lyd_node *vrf_node; + + /* Not inside any VRF context. */ + if (vty->xpath_index == 0) + return VRF_DEFAULT_NAME; + + vrf_node = yang_dnode_get(vty->candidate_config->dnode, VTY_CURR_XPATH); + if (vrf_node == NULL) { + vty_out(vty, "%% Failed to get vrf dnode in configuration\n"); + return NULL; + } + + return yang_dnode_get_string(vrf_node, "./name"); +} + +int pim_process_join_prune_cmd(struct vty *vty, const char *jpi_str) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/join-prune-interval", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, jpi_str); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_join_prune_cmd(struct vty *vty) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/join-prune-interval", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_spt_switchover_infinity_cmd(struct vty *vty) +{ + const char *vrfname; + char spt_plist_xpath[XPATH_MAXLEN]; + char spt_action_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", + sizeof(spt_plist_xpath)); + + snprintf(spt_action_xpath, sizeof(spt_action_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_action_xpath, "/spt-switchover/spt-action", + sizeof(spt_action_xpath)); + + if (yang_dnode_exists(vty->candidate_config->dnode, spt_plist_xpath)) + nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, + NULL); + nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, + "PIM_SPT_INFINITY"); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_spt_switchover_prefixlist_cmd(struct vty *vty, + const char *plist) +{ + const char *vrfname; + char spt_plist_xpath[XPATH_MAXLEN]; + char spt_action_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", + sizeof(spt_plist_xpath)); + + snprintf(spt_action_xpath, sizeof(spt_action_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_action_xpath, "/spt-switchover/spt-action", + sizeof(spt_action_xpath)); + + nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, + "PIM_SPT_INFINITY"); + nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_MODIFY, + plist); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_spt_switchover_cmd(struct vty *vty) +{ + const char *vrfname; + char spt_plist_xpath[XPATH_MAXLEN]; + char spt_action_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(spt_plist_xpath, sizeof(spt_plist_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_plist_xpath, "/spt-switchover/spt-infinity-prefix-list", + sizeof(spt_plist_xpath)); + + snprintf(spt_action_xpath, sizeof(spt_action_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(spt_action_xpath, "/spt-switchover/spt-action", + sizeof(spt_action_xpath)); + + nb_cli_enqueue_change(vty, spt_plist_xpath, NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, spt_action_xpath, NB_OP_MODIFY, + "PIM_SPT_IMMEDIATE"); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_pim_packet_cmd(struct vty *vty, const char *packet) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/packets", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, packet); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_pim_packet_cmd(struct vty *vty) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/packets", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_keepalivetimer_cmd(struct vty *vty, const char *kat) +{ + const char *vrfname; + char ka_timer_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, + "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL); + strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); + + nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_MODIFY, + kat); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_keepalivetimer_cmd(struct vty *vty) +{ + const char *vrfname; + char ka_timer_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(ka_timer_xpath, sizeof(ka_timer_xpath), FRR_PIM_VRF_XPATH, + "frr-pim:pimd", "pim", vrfname, FRR_PIM_AF_XPATH_VAL); + strlcat(ka_timer_xpath, "/keep-alive-timer", sizeof(ka_timer_xpath)); + + nb_cli_enqueue_change(vty, ka_timer_xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_rp_kat_cmd(struct vty *vty, const char *rpkat) +{ + const char *vrfname; + char rp_ka_timer_xpath[XPATH_MAXLEN]; + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", + sizeof(rp_ka_timer_xpath)); + + nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, + rpkat); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_rp_kat_cmd(struct vty *vty) +{ + const char *vrfname; + char rp_ka_timer[6]; + char rp_ka_timer_xpath[XPATH_MAXLEN]; + uint v; + char rs_timer_xpath[XPATH_MAXLEN]; + + snprintf(rs_timer_xpath, sizeof(rs_timer_xpath), + FRR_PIM_ROUTER_XPATH, FRR_PIM_AF_XPATH_VAL); + strlcat(rs_timer_xpath, "/register-suppress-time", + sizeof(rs_timer_xpath)); + + /* RFC4601 */ + v = yang_dnode_get_uint16(vty->candidate_config->dnode, + rs_timer_xpath); + v = 3 * v + PIM_REGISTER_PROBE_TIME_DEFAULT; + if (v > UINT16_MAX) + v = UINT16_MAX; + snprintf(rp_ka_timer, sizeof(rp_ka_timer), "%u", v); + + vrfname = pim_cli_get_vrf_name(vty); + if (vrfname == NULL) + return CMD_WARNING_CONFIG_FAILED; + + snprintf(rp_ka_timer_xpath, sizeof(rp_ka_timer_xpath), + FRR_PIM_VRF_XPATH, "frr-pim:pimd", "pim", vrfname, + FRR_PIM_AF_XPATH_VAL); + strlcat(rp_ka_timer_xpath, "/rp-keep-alive-timer", + sizeof(rp_ka_timer_xpath)); + + nb_cli_enqueue_change(vty, rp_ka_timer_xpath, NB_OP_MODIFY, + rp_ka_timer); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_register_suppress_cmd(struct vty *vty, const char *rst) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/register-suppress-time", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, rst); + + return nb_cli_apply_changes(vty, NULL); +} + +int pim_process_no_register_suppress_cmd(struct vty *vty) +{ + char xpath[XPATH_MAXLEN]; + + snprintf(xpath, sizeof(xpath), FRR_PIM_ROUTER_XPATH, + FRR_PIM_AF_XPATH_VAL); + strlcat(xpath, "/register-suppress-time", sizeof(xpath)); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} diff --git a/pimd/pim_cmd_common.h b/pimd/pim_cmd_common.h new file mode 100644 index 0000000000..49fc6bcbeb --- /dev/null +++ b/pimd/pim_cmd_common.h @@ -0,0 +1,39 @@ +/* + * PIM for IPv6 FRR + * Copyright (C) 2022 Vmware, Inc. + * Mobashshera Rasool <mrasool@vmware.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef PIM_CMD_COMMON_H +#define PIM_CMD_COMMON_H + +const char *pim_cli_get_vrf_name(struct vty *vty); +int pim_process_join_prune_cmd(struct vty *vty, const char *jpi_str); +int pim_process_no_join_prune_cmd(struct vty *vty); +int pim_process_spt_switchover_infinity_cmd(struct vty *vty); +int pim_process_spt_switchover_prefixlist_cmd(struct vty *vty, + const char *plist); +int pim_process_no_spt_switchover_cmd(struct vty *vty); +int pim_process_pim_packet_cmd(struct vty *vty, const char *packet); +int pim_process_no_pim_packet_cmd(struct vty *vty); +int pim_process_keepalivetimer_cmd(struct vty *vty, const char *kat); +int pim_process_no_keepalivetimer_cmd(struct vty *vty); +int pim_process_rp_kat_cmd(struct vty *vty, const char *rpkat); +int pim_process_no_rp_kat_cmd(struct vty *vty); +int pim_process_register_suppress_cmd(struct vty *vty, const char *rst); +int pim_process_no_register_suppress_cmd(struct vty *vty); + +#endif /* PIM_CMD_COMMON_H */ diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 57fe97816e..5425aec233 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -50,10 +50,12 @@ #include "pim_igmp_join.h" #include "pim_vxlan.h" +#if PIM_IPV == 4 static void pim_if_igmp_join_del_all(struct interface *ifp); static int igmp_join_sock(const char *ifname, ifindex_t ifindex, struct in_addr group_addr, struct in_addr source_addr); +#endif void pim_if_init(struct pim_instance *pim) { @@ -83,6 +85,7 @@ static void pim_sec_addr_free(struct pim_secondary_addr *sec_addr) XFREE(MTYPE_PIM_SEC_ADDR, sec_addr); } +__attribute__((unused)) static int pim_sec_addr_comp(const void *p1, const void *p2) { const struct pim_secondary_addr *sec1 = p1; @@ -124,6 +127,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, pim_ifp->pim = ifp->vrf->info; pim_ifp->mroute_vif_index = -1; +#if PIM_IPV == 4 pim_ifp->igmp_version = IGMP_DEFAULT_VERSION; pim_ifp->gm_default_robustness_variable = IGMP_DEFAULT_ROBUSTNESS_VARIABLE; @@ -185,6 +189,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, pim_sock_reset(ifp); pim_if_add_vif(ifp, ispimreg, is_vxlan_term); +#endif pim_ifp->pim->mcast_if_count++; return pim_ifp; @@ -198,6 +203,8 @@ void pim_if_delete(struct interface *ifp) pim_ifp = ifp->info; assert(pim_ifp); + pim_ifp->pim->mcast_if_count--; +#if PIM_IPV == 4 if (pim_ifp->gm_join_list) { pim_if_igmp_join_del_all(ifp); } @@ -208,7 +215,6 @@ void pim_if_delete(struct interface *ifp) pim_neighbor_delete_all(ifp, "Interface removed from configuration"); pim_if_del_vif(ifp); - pim_ifp->pim->mcast_if_count--; pim_igmp_if_fini(pim_ifp); @@ -218,6 +224,7 @@ void pim_if_delete(struct interface *ifp) XFREE(MTYPE_PIM_INTERFACE, pim_ifp->boundary_oil_plist); XFREE(MTYPE_PIM_INTERFACE, pim_ifp); +#endif ifp->info = NULL; } @@ -486,7 +493,6 @@ void pim_if_addr_add(struct connected *ifc) { struct pim_interface *pim_ifp; struct interface *ifp; - struct in_addr ifaddr; bool vxlan_term; assert(ifc); @@ -507,13 +513,14 @@ void pim_if_addr_add(struct connected *ifc) ? "secondary" : "primary"); - ifaddr = ifc->address->u.prefix4; - detect_address_change(ifp, 0, __func__); // if (ifc->address->family != AF_INET) // return; +#if PIM_IPV == 4 + struct in_addr ifaddr = ifc->address->u.prefix4; + if (PIM_IF_TEST_IGMP(pim_ifp->options)) { struct gm_sock *igmp; @@ -579,6 +586,7 @@ void pim_if_addr_add(struct connected *ifc) true); } } /* igmp mtrace only */ +#endif if (PIM_IF_TEST_PIM(pim_ifp->options)) { @@ -630,6 +638,7 @@ void pim_if_addr_add(struct connected *ifc) static void pim_if_addr_del_igmp(struct connected *ifc) { +#if PIM_IPV == 4 struct pim_interface *pim_ifp = ifc->ifp->info; struct gm_sock *igmp; struct in_addr ifaddr; @@ -652,6 +661,7 @@ static void pim_if_addr_del_igmp(struct connected *ifc) /* if addr found, del IGMP socket */ igmp_sock_delete(igmp); } +#endif } static void pim_if_addr_del_pim(struct connected *ifc) @@ -1140,6 +1150,7 @@ long pim_if_t_suppressed_msec(struct interface *ifp) return t_suppressed_msec; } +#if PIM_IPV == 4 static void igmp_join_free(struct gm_join *ij) { XFREE(MTYPE_PIM_IGMP_JOIN, ij); @@ -1330,6 +1341,7 @@ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, return 0; } +__attribute__((unused)) static void pim_if_igmp_join_del_all(struct interface *ifp) { struct pim_interface *pim_ifp; @@ -1350,6 +1362,19 @@ static void pim_if_igmp_join_del_all(struct interface *ifp) for (ALL_LIST_ELEMENTS(pim_ifp->gm_join_list, node, nextnode, ij)) pim_if_igmp_join_del(ifp, ij->group_addr, ij->source_addr); } +#else /* PIM_IPV != 4 */ +ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, + struct in_addr source_addr) +{ + return ferr_ok(); +} + +int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, + struct in_addr source_addr) +{ + return 0; +} +#endif /* PIM_IPV != 4 */ /* RFC 4601 @@ -1524,6 +1549,7 @@ static int pim_ifp_create(struct interface *ifp) */ if (pim_ifp) pim_ifp->pim = pim; +#if PIM_IPV == 4 pim_if_addr_add_all(ifp); /* @@ -1535,8 +1561,10 @@ static int pim_ifp_create(struct interface *ifp) * this is a no-op if it's already been done. */ pim_if_create_pimreg(pim); +#endif } +#if PIM_IPV == 4 /* * If we are a vrf device that is up, open up the pim_socket for * listening @@ -1564,6 +1592,7 @@ static int pim_ifp_create(struct interface *ifp) "%s: Cannot enable pim on %s. MAXVIFS(%d) reached. Deleting and readding the vxlan termimation device after unconfiguring pim from other interfaces may succeed.", __func__, ifp->name, MAXVIFS); } +#endif return 0; } @@ -1572,7 +1601,6 @@ static int pim_ifp_up(struct interface *ifp) { struct pim_interface *pim_ifp; struct pim_instance *pim; - uint32_t table_id; if (PIM_DEBUG_ZEBRA) { zlog_debug( @@ -1593,6 +1621,9 @@ static int pim_ifp_up(struct interface *ifp) if (pim_ifp) pim_ifp->pim = pim; +#if PIM_IPV == 4 + uint32_t table_id; + /* pim_if_addr_add_all() suffices for bringing up both IGMP and PIM @@ -1621,6 +1652,7 @@ static int pim_ifp_up(struct interface *ifp) } } } +#endif return 0; } @@ -1634,6 +1666,7 @@ static int pim_ifp_down(struct interface *ifp) ifp->mtu, if_is_operative(ifp)); } +#if PIM_IPV == 4 if (!if_is_operative(ifp)) { pim_ifchannel_delete_all(ifp); /* @@ -1656,14 +1689,13 @@ static int pim_ifp_down(struct interface *ifp) pim_if_del_vif(ifp); pim_ifstat_reset(ifp); } +#endif return 0; } static int pim_ifp_destroy(struct interface *ifp) { - struct pim_instance *pim; - if (PIM_DEBUG_ZEBRA) { zlog_debug( "%s: %s index %d vrf %s(%u) flags %ld metric %d mtu %d operative %d", @@ -1672,12 +1704,16 @@ static int pim_ifp_destroy(struct interface *ifp) ifp->mtu, if_is_operative(ifp)); } +#if PIM_IPV == 4 + struct pim_instance *pim; + if (!if_is_operative(ifp)) pim_if_addr_del_all(ifp); pim = ifp->vrf->info; if (pim && pim->vxlan.term_if == ifp) pim_vxlan_del_term_dev(pim); +#endif return 0; } diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index a613c89b7e..956ab0d67c 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -269,7 +269,7 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch, if (old_state == new_state) { if (PIM_DEBUG_PIM_EVENTS) { zlog_debug( - "%s calledby %s: non-transition on state %d (%s)", + "%s called by %s: non-transition on state %d (%s)", __func__, caller, new_state, pim_ifchannel_ifjoin_name(new_state, 0)); } @@ -306,8 +306,8 @@ void pim_ifchannel_ifjoin_switch(const char *caller, struct pim_ifchannel *ch, * supplying the implied * if channel. So remove it. */ - if (c_oil->oil.mfcc_ttls - [pim_ifp->mroute_vif_index]) + if (oil_if_has(c_oil, + pim_ifp->mroute_vif_index)) pim_channel_del_inherited_oif( c_oil, ch->interface, __func__); @@ -644,7 +644,7 @@ static void ifjoin_to_noinfo(struct pim_ifchannel *ch) delete_on_noinfo(ch); } -static int on_ifjoin_expiry_timer(struct thread *t) +static void on_ifjoin_expiry_timer(struct thread *t) { struct pim_ifchannel *ch; @@ -656,11 +656,9 @@ static int on_ifjoin_expiry_timer(struct thread *t) ifjoin_to_noinfo(ch); /* ch may have been deleted */ - - return 0; } -static int on_ifjoin_prune_pending_timer(struct thread *t) +static void on_ifjoin_prune_pending_timer(struct thread *t) { struct pim_ifchannel *ch; int send_prune_echo; /* boolean */ @@ -726,8 +724,6 @@ static int on_ifjoin_prune_pending_timer(struct thread *t) } /* from here ch may have been deleted */ } - - return 0; } static void check_recv_upstream(int is_join, struct interface *recv_ifp, @@ -768,8 +764,7 @@ static void check_recv_upstream(int is_join, struct interface *recv_ifp, if (is_join) { /* Join(S,G) to RPF'(S,G) */ - pim_upstream_join_suppress(up, up->rpf.rpf_addr.u.prefix4, - holdtime); + pim_upstream_join_suppress(up, up->rpf.rpf_addr, holdtime); return; } @@ -1291,7 +1286,7 @@ void pim_ifchannel_local_membership_del(struct interface *ifp, pim_sgaddr *sg) if (!pim_upstream_evaluate_join_desired_interface( child, ch, starch) || (!chchannel && - c_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index])) { + oil_if_has(c_oil, pim_ifp->mroute_vif_index))) { pim_channel_del_inherited_oif(c_oil, ifp, __func__); } diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index 512384d642..5cdefd2828 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -40,7 +40,7 @@ #include "pim_zebra.h" static void group_timer_off(struct gm_group *group); -static int pim_igmp_general_query(struct thread *t); +static void pim_igmp_general_query(struct thread *t); /* This socket is used for TXing IGMP packets only, IGMP RX happens * in pim_mroute_msg() @@ -141,7 +141,7 @@ struct gm_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list, return NULL; } -static int pim_igmp_other_querier_expire(struct thread *t) +static void pim_igmp_other_querier_expire(struct thread *t) { struct gm_sock *igmp; @@ -166,8 +166,6 @@ static int pim_igmp_other_querier_expire(struct thread *t) Query, Set Gen. Query. timer) */ pim_igmp_general_query(t); - - return 0; } void pim_igmp_other_querier_timer_on(struct gm_sock *igmp) @@ -528,17 +526,6 @@ bool pim_igmp_verify_header(struct ip *ip_hdr, size_t len, size_t *hlen) } } - if ((msg_type == PIM_IGMP_V3_MEMBERSHIP_REPORT) - || ((msg_type == PIM_IGMP_MEMBERSHIP_QUERY) - && (igmp_msg_len >= IGMP_V3_SOURCES_OFFSET))) { - /* All IGMPv3 messages must be received with TOS set to 0xC0*/ - if (ip_hdr->ip_tos != IPTOS_PREC_INTERNETCONTROL) { - zlog_warn("Received IGMP Packet with invalid TOS %u", - ip_hdr->ip_tos); - return false; - } - } - return true; } @@ -705,7 +692,7 @@ void pim_igmp_general_query_off(struct gm_sock *igmp) } /* Issue IGMP general query */ -static int pim_igmp_general_query(struct thread *t) +static void pim_igmp_general_query(struct thread *t) { struct gm_sock *igmp; struct in_addr dst_addr; @@ -759,8 +746,6 @@ static int pim_igmp_general_query(struct thread *t) igmp->querier_query_interval); pim_igmp_general_query_on(igmp); - - return 0; } static void sock_close(struct gm_sock *igmp) @@ -1027,7 +1012,7 @@ static struct gm_sock *igmp_sock_new(int fd, struct in_addr ifaddr, static void igmp_read_on(struct gm_sock *igmp); -static int pim_igmp_read(struct thread *t) +static void pim_igmp_read(struct thread *t) { uint8_t buf[10000]; struct gm_sock *igmp = (struct gm_sock *)THREAD_ARG(t); @@ -1053,7 +1038,6 @@ static int pim_igmp_read(struct thread *t) done: igmp_read_on(igmp); - return 0; } static void igmp_read_on(struct gm_sock *igmp) @@ -1123,7 +1107,7 @@ struct gm_sock *pim_igmp_sock_add(struct list *igmp_sock_list, source records. Source records whose timers are zero (from the previous EXCLUDE mode) are deleted. */ -static int igmp_group_timer(struct thread *t) +static void igmp_group_timer(struct thread *t) { struct gm_group *group; @@ -1157,8 +1141,6 @@ static int igmp_group_timer(struct thread *t) if (listcount(group->group_source_list) < 1) { igmp_group_delete_empty_include(group); } - - return 0; } static void group_timer_off(struct gm_group *group) diff --git a/pimd/pim_igmp.h b/pimd/pim_igmp.h index b82b62ea74..5c35996634 100644 --- a/pimd/pim_igmp.h +++ b/pimd/pim_igmp.h @@ -105,6 +105,7 @@ struct gm_sock { struct pim_interface; +#if PIM_IPV == 4 void pim_igmp_if_init(struct pim_interface *pim_ifp, struct interface *ifp); void pim_igmp_if_reset(struct pim_interface *pim_ifp); void pim_igmp_if_fini(struct pim_interface *pim_ifp); @@ -126,6 +127,24 @@ void pim_igmp_other_querier_timer_off(struct gm_sock *igmp); int igmp_validate_checksum(char *igmp_msg, int igmp_msg_len); +#else /* PIM_IPV != 4 */ +static inline void pim_igmp_general_query_on(struct gm_sock *igmp) +{ +} + +static inline void pim_igmp_general_query_off(struct gm_sock *igmp) +{ +} + +static inline void pim_igmp_other_querier_timer_on(struct gm_sock *igmp) +{ +} + +static inline void pim_igmp_other_querier_timer_off(struct gm_sock *igmp) +{ +} +#endif /* PIM_IPV == 4 */ + #define IGMP_SOURCE_MASK_FORWARDING (1 << 0) #define IGMP_SOURCE_MASK_DELETE (1 << 1) #define IGMP_SOURCE_MASK_SEND (1 << 2) @@ -184,6 +203,7 @@ struct gm_group { int64_t last_igmp_v2_report_dsec; }; +#if PIM_IPV == 4 struct gm_group *find_group_by_addr(struct gm_sock *igmp, struct in_addr group_addr); struct gm_group *igmp_add_group_by_addr(struct gm_sock *igmp, @@ -210,4 +230,11 @@ void igmp_send_query(int igmp_version, struct gm_group *group, int fd, void igmp_group_delete(struct gm_group *group); void igmp_send_query_on_intf(struct interface *ifp, int igmp_ver); + +#else /* PIM_IPV != 4 */ +static inline void igmp_startup_mode_on(struct gm_sock *igmp) +{ +} +#endif /* PIM_IPV != 4 */ + #endif /* PIM_IGMP_H */ diff --git a/pimd/pim_igmp_join.h b/pimd/pim_igmp_join.h index c323902764..8027b8b94b 100644 --- a/pimd/pim_igmp_join.h +++ b/pimd/pim_igmp_join.h @@ -39,9 +39,9 @@ struct group_source_req { }; #endif -static int pim_igmp_join_source(int fd, ifindex_t ifindex, - struct in_addr group_addr, - struct in_addr source_addr) +static inline int pim_igmp_join_source(int fd, ifindex_t ifindex, + struct in_addr group_addr, + struct in_addr source_addr) { struct group_source_req req; struct sockaddr_in group; diff --git a/pimd/pim_igmp_stats.h b/pimd/pim_igmp_stats.h index 57b5cc62f4..a70a433557 100644 --- a/pimd/pim_igmp_stats.h +++ b/pimd/pim_igmp_stats.h @@ -35,7 +35,17 @@ struct igmp_stats { uint32_t unsupported; }; +#if PIM_IPV == 4 void igmp_stats_init(struct igmp_stats *stats); void igmp_stats_add(struct igmp_stats *a, struct igmp_stats *b); +#else +static inline void igmp_stats_init(struct igmp_stats *stats) +{ +} + +static inline void igmp_stats_add(struct igmp_stats *a, struct igmp_stats *b) +{ +} +#endif #endif /* PIM_IGMP_STATS_H */ diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index fafca5a148..87554bc8ba 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -118,7 +118,7 @@ void igmp_group_reset_gmi(struct gm_group *group) igmp_group_timer_on(group, group_membership_interval_msec, ifp->name); } -static int igmp_source_timer(struct thread *t) +static void igmp_source_timer(struct thread *t) { struct gm_source *source; struct gm_group *group; @@ -179,8 +179,6 @@ static int igmp_source_timer(struct thread *t) igmp_group_delete_empty_include(group); } } - - return 0; } static void source_timer_off(struct gm_group *group, struct gm_source *source) @@ -1212,7 +1210,7 @@ static int group_retransmit_sources(struct gm_group *group, return num_retransmit_sources_left; } -static int igmp_group_retransmit(struct thread *t) +static void igmp_group_retransmit(struct thread *t) { struct gm_group *group; int num_retransmit_sources_left; @@ -1262,8 +1260,6 @@ static int igmp_group_retransmit(struct thread *t) || (group->group_specific_query_retransmit_count > 0)) { group_retransmit_timer_on(group); } - - return 0; } /* diff --git a/pimd/pim_igmpv3.h b/pimd/pim_igmpv3.h index 7449e420e4..5041e54cb4 100644 --- a/pimd/pim_igmpv3.h +++ b/pimd/pim_igmpv3.h @@ -53,6 +53,7 @@ /* OHPI: Older Host Present Interval */ #define PIM_IGMP_OHPI_DSEC(qrv,qqi,qri_dsec) ((qrv) * (10 * (qqi)) + (qri_dsec)) +#if PIM_IPV == 4 void igmp_group_reset_gmi(struct gm_group *group); void igmp_source_reset_gmi(struct gm_group *group, struct gm_source *source); @@ -98,4 +99,16 @@ void igmp_v3_recv_query(struct gm_sock *igmp, const char *from_str, int igmp_v3_recv_report(struct gm_sock *igmp, struct in_addr from, const char *from_str, char *igmp_msg, int igmp_msg_len); +#else /* PIM_IPV != 4 */ +static inline void igmp_group_reset_gmi(struct gm_group *group) +{ +} + + +static inline void igmp_source_reset_gmi(struct gm_group *group, + struct gm_source *source) +{ +} +#endif + #endif /* PIM_IGMPV3_H */ diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 51a3ceee15..929beea26b 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -148,8 +148,7 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, } int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, - struct in_addr src_addr, uint8_t *tlv_buf, - int tlv_buf_size) + pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size) { pim_addr msg_upstream_addr; bool wrong_af = false; @@ -174,10 +173,8 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, addr_offset = pim_parse_addr_ucast(&msg_upstream_addr, buf, pastend - buf, &wrong_af); if (addr_offset < 1) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); - zlog_warn("%s: pim_parse_addr_ucast() failure: from %s on %s", - __func__, src_str, ifp->name); + zlog_warn("%s: pim_parse_addr_ucast() failure: from %pPA on %s", + __func__, &src_addr, ifp->name); return -1; } buf += addr_offset; @@ -186,21 +183,17 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, Check upstream address family */ if (wrong_af) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn( - "%s: ignoring join/prune directed to unexpected addr family from %s on %s", - __func__, src_str, ifp->name); + "%s: ignoring join/prune directed to unexpected addr family from %pPA on %s", + __func__, &src_addr, ifp->name); return -2; } remain = pastend - buf; if (remain < 4) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); zlog_warn( - "%s: short join/prune message buffer for group list: size=%d minimum=%d from %s on %s", - __func__, remain, 4, src_str, ifp->name); + "%s: short join/prune message buffer for group list: size=%d minimum=%d from %pPA on %s", + __func__, remain, 4, &src_addr, ifp->name); return -4; } @@ -211,14 +204,11 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, ++buf; ++buf; - if (PIM_DEBUG_PIM_J_P) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, sizeof(src_str)); + if (PIM_DEBUG_PIM_J_P) zlog_debug( - "%s: join/prune upstream=%pPAs groups=%d holdtime=%d from %s on %s", + "%s: join/prune upstream=%pPAs groups=%d holdtime=%d from %pPA on %s", __func__, &msg_upstream_addr, msg_num_groups, - msg_holdtime, src_str, ifp->name); - } + msg_holdtime, &src_addr, ifp->name); /* Scan groups */ for (group = 0; group < msg_num_groups; ++group) { @@ -239,12 +229,9 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, remain = pastend - buf; if (remain < 4) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, - sizeof(src_str)); zlog_warn( - "%s: short join/prune buffer for source list: size=%d minimum=%d from %s on %s", - __func__, remain, 4, src_str, ifp->name); + "%s: short join/prune buffer for source list: size=%d minimum=%d from %pPA on %s", + __func__, remain, 4, &src_addr, ifp->name); return -6; } @@ -253,16 +240,12 @@ int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, msg_num_pruned_sources = ntohs(*(const uint16_t *)buf); buf += 2; - if (PIM_DEBUG_PIM_J_P) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src_addr, src_str, - sizeof(src_str)); + if (PIM_DEBUG_PIM_J_P) zlog_debug( - "%s: join/prune upstream=%pPAs group=%pPA/32 join_src=%d prune_src=%d from %s on %s", + "%s: join/prune upstream=%pPAs group=%pPA/32 join_src=%d prune_src=%d from %pPA on %s", __func__, &msg_upstream_addr, &sg.grp, msg_num_joined_sources, msg_num_pruned_sources, - src_str, ifp->name); - } + &src_addr, ifp->name); /* boundary check */ filtered = pim_is_group_filtered(pim_ifp, &sg.grp); diff --git a/pimd/pim_join.h b/pimd/pim_join.h index 5d28f2ba3c..b359f2e5b7 100644 --- a/pimd/pim_join.h +++ b/pimd/pim_join.h @@ -27,8 +27,7 @@ #include "pim_neighbor.h" int pim_joinprune_recv(struct interface *ifp, struct pim_neighbor *neigh, - struct in_addr src_addr, uint8_t *tlv_buf, - int tlv_buf_size); + pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size); int pim_joinprune_send(struct pim_rpf *nexthop, struct list *groups); diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index 42ad5dcd1e..7cbd0304ae 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -109,6 +109,7 @@ pim_jp_agg_get_interface_upstream_switch_list(struct pim_rpf *rpf) struct pim_interface *pim_ifp; struct pim_iface_upstream_switch *pius; struct listnode *node, *nnode; + pim_addr rpf_addr; if (!ifp) return NULL; @@ -119,16 +120,18 @@ pim_jp_agg_get_interface_upstream_switch_list(struct pim_rpf *rpf) if (!pim_ifp) return NULL; + rpf_addr = pim_addr_from_prefix(&rpf->rpf_addr); + for (ALL_LIST_ELEMENTS(pim_ifp->upstream_switch_list, node, nnode, pius)) { - if (pius->address.s_addr == rpf->rpf_addr.u.prefix4.s_addr) + if (!pim_addr_cmp(pius->address, rpf_addr)) break; } if (!pius) { pius = XCALLOC(MTYPE_PIM_JP_AGG_GROUP, sizeof(struct pim_iface_upstream_switch)); - pius->address.s_addr = rpf->rpf_addr.u.prefix4.s_addr; + pius->address = rpf_addr; pius->us = list_new(); listnode_add_sort(pim_ifp->upstream_switch_list, pius); } diff --git a/pimd/pim_mlag.c b/pimd/pim_mlag.c index f4ddc1bf64..68f77ad6d9 100644 --- a/pimd/pim_mlag.c +++ b/pimd/pim_mlag.c @@ -930,12 +930,12 @@ int pim_zebra_mlag_process_down(ZAPI_CALLBACK_ARGS) return 0; } -static int pim_mlag_register_handler(struct thread *thread) +static void pim_mlag_register_handler(struct thread *thread) { uint32_t bit_mask = 0; if (!zclient) - return -1; + return; SET_FLAG(bit_mask, (1 << MLAG_STATUS_UPDATE)); SET_FLAG(bit_mask, (1 << MLAG_MROUTE_ADD)); @@ -952,7 +952,6 @@ static int pim_mlag_register_handler(struct thread *thread) __func__, bit_mask); zclient_send_mlag_register(zclient, bit_mask); - return 0; } void pim_mlag_register(void) @@ -966,17 +965,16 @@ void pim_mlag_register(void) NULL); } -static int pim_mlag_deregister_handler(struct thread *thread) +static void pim_mlag_deregister_handler(struct thread *thread) { if (!zclient) - return -1; + return; if (PIM_DEBUG_MLAG) zlog_debug("%s: Posting Client De-Register to MLAG from PIM", __func__); router->connected_to_mlag = false; zclient_send_mlag_deregister(zclient); - return 0; } void pim_mlag_deregister(void) diff --git a/pimd/pim_mlag.h b/pimd/pim_mlag.h index 996e4d473f..0555c7d3ff 100644 --- a/pimd/pim_mlag.h +++ b/pimd/pim_mlag.h @@ -28,6 +28,7 @@ #include "mlag.h" #include "pim_iface.h" +#if PIM_IPV == 4 extern void pim_mlag_init(void); extern void pim_mlag_terminate(void); extern void pim_instance_mlag_init(struct pim_instance *pim); @@ -52,4 +53,49 @@ extern void pim_mlag_up_local_del(struct pim_instance *pim, extern bool pim_mlag_up_df_role_update(struct pim_instance *pim, struct pim_upstream *up, bool is_df, const char *reason); +#else /* PIM_IPV == 4 */ +static inline void pim_mlag_terminate(void) +{ +} + +static inline void pim_instance_mlag_init(struct pim_instance *pim) +{ +} + +static inline void pim_instance_mlag_terminate(struct pim_instance *pim) +{ +} + +static inline void pim_if_configure_mlag_dualactive( + struct pim_interface *pim_ifp) +{ +} + +static inline void pim_if_unconfigure_mlag_dualactive( + struct pim_interface *pim_ifp) +{ +} + +static inline void pim_mlag_register(void) +{ +} + +static inline void pim_mlag_up_local_add(struct pim_instance *pim, + struct pim_upstream *upstream) +{ +} + +static inline void pim_mlag_up_local_del(struct pim_instance *pim, + struct pim_upstream *upstream) +{ +} + +static inline bool pim_mlag_up_df_role_update(struct pim_instance *pim, + struct pim_upstream *up, + bool is_df, const char *reason) +{ + return false; +} +#endif + #endif diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 91b997f44a..f381a764cc 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -145,6 +145,7 @@ static int pim_mroute_set(struct pim_instance *pim, int enable) return 0; } +#if PIM_IPV == 4 static const char *const igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; @@ -162,7 +163,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, * the Interface type is SSM we don't need to * do anything here */ - if (!rpg || pim_rpf_addr_is_inaddr_none(rpg)) { + if (!rpg || pim_rpf_addr_is_inaddr_any(rpg)) { if (PIM_DEBUG_MROUTE_DETAIL) zlog_debug( "%s: Interface is not configured correctly to handle incoming packet: Could be !pim_ifp, !SM, !RP", @@ -227,7 +228,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, up->channel_oil->cc.pktcnt++; // resolve mfcc_parent prior to mroute_add in channel_add_oif if (up->rpf.source_nexthop.interface && - up->channel_oil->oil.mfcc_parent >= MAXVIFS) { + *oil_parent(up->channel_oil) >= MAXVIFS) { pim_upstream_mroute_iif_update(up->channel_oil, __func__); } pim_register_join(up); @@ -299,8 +300,8 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, rpg = pim_ifp ? RP(pim_ifp->pim, sg.grp) : NULL; - if ((pim_rpf_addr_is_inaddr_none(rpg)) || (!pim_ifp) - || (!(PIM_I_am_DR(pim_ifp)))) { + if ((pim_rpf_addr_is_inaddr_any(rpg)) || (!pim_ifp) || + (!(PIM_I_am_DR(pim_ifp)))) { if (PIM_DEBUG_MROUTE) { zlog_debug("%s: Failed Check send packet", __func__); } @@ -580,12 +581,8 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, int buf_size, ifindex_t ifindex) { struct interface *ifp; - struct pim_interface *pim_ifp; const struct ip *ip_hdr; const struct igmpmsg *msg; - struct in_addr ifaddr; - struct gm_sock *igmp; - const struct prefix *connected_src; if (buf_size < (int)sizeof(struct ip)) return 0; @@ -593,6 +590,11 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, ip_hdr = (const struct ip *)buf; if (ip_hdr->ip_p == IPPROTO_IGMP) { +#if PIM_IPV == 4 + struct pim_interface *pim_ifp; + struct in_addr ifaddr; + struct gm_sock *igmp; + const struct prefix *connected_src; /* We have the IP packet but we do not know which interface this * packet was @@ -632,6 +634,7 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, zlog_debug("No IGMP socket on interface: %s with connected source: %pFX", ifp->name, connected_src); } +#endif } else if (ip_hdr->ip_p) { if (PIM_DEBUG_MROUTE_DETAIL) { zlog_debug( @@ -676,13 +679,20 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf, return 0; } +#else /* PIM_IPV != 4 */ + +static int pim_mroute_msg(struct pim_instance *pim, const char *buf, + int buf_size, ifindex_t ifindex) +{ + return 0; +} +#endif /* PIM_IPV != 4 */ -static int mroute_read(struct thread *t) +static void mroute_read(struct thread *t) { struct pim_instance *pim; static long long count; char buf[10000]; - int result = 0; int cont = 1; int rd; ifindex_t ifindex; @@ -705,7 +715,7 @@ static int mroute_read(struct thread *t) goto done; } - result = pim_mroute_msg(pim, buf, rd, ifindex); + pim_mroute_msg(pim, buf, rd, ifindex); count++; if (count % router->packet_process == 0) @@ -714,8 +724,6 @@ static int mroute_read(struct thread *t) /* Keep reading */ done: mroute_read_on(pim); - - return result; } static void mroute_read_on(struct pim_instance *pim) @@ -800,7 +808,7 @@ int pim_mroute_socket_disable(struct pim_instance *pim) would be used for multicast forwarding, a corresponding multicast interface must be added to the kernel. */ -int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, +int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, unsigned char flags) { struct pim_interface *pim_ifp = ifp->info; @@ -839,15 +847,10 @@ int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_ADD_VIF, (void *)&vc, sizeof(vc)); if (err) { - char ifaddr_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("<ifaddr?>", ifaddr, ifaddr_str, - sizeof(ifaddr_str)); - zlog_warn( - "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%s,flag=%d): errno=%d: %s", + "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%pPAs,flag=%d): errno=%d: %s", __func__, pim_ifp->pim->mroute_socket, ifp->ifindex, - ifaddr_str, flags, errno, safe_strerror(errno)); + &ifaddr, flags, errno, safe_strerror(errno)); return -2; } @@ -921,26 +924,26 @@ bool pim_mroute_allow_iif_in_oil(struct channel_oil *c_oil, #endif } -static inline void pim_mroute_copy(struct mfcctl *oil, - struct channel_oil *c_oil) +static inline void pim_mroute_copy(struct channel_oil *out, + struct channel_oil *in) { int i; - oil->mfcc_origin = c_oil->oil.mfcc_origin; - oil->mfcc_mcastgrp = c_oil->oil.mfcc_mcastgrp; - oil->mfcc_parent = c_oil->oil.mfcc_parent; + *oil_origin(out) = *oil_origin(in); + *oil_mcastgrp(out) = *oil_mcastgrp(in); + *oil_parent(out) = *oil_parent(in); for (i = 0; i < MAXVIFS; ++i) { - if ((oil->mfcc_parent == i) && - !pim_mroute_allow_iif_in_oil(c_oil, i)) { - oil->mfcc_ttls[i] = 0; + if (*oil_parent(out) == i && + !pim_mroute_allow_iif_in_oil(in, i)) { + oil_if_set(out, i, 0); continue; } - if (c_oil->oif_flags[i] & PIM_OIF_FLAG_MUTE) - oil->mfcc_ttls[i] = 0; + if (in->oif_flags[i] & PIM_OIF_FLAG_MUTE) + oil_if_set(out, i, 0); else - oil->mfcc_ttls[i] = c_oil->oil.mfcc_ttls[i]; + oil_if_set(out, i, oil_if_has(in, i)); } } @@ -950,7 +953,7 @@ static inline void pim_mroute_copy(struct mfcctl *oil, static int pim_mroute_add(struct channel_oil *c_oil, const char *name) { struct pim_instance *pim = c_oil->pim; - struct mfcctl tmp_oil = { {0} }; + struct channel_oil tmp_oil[1] = { }; int err; pim->mroute_add_last = pim_time_monotonic_sec(); @@ -959,14 +962,14 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) /* Copy the oil to a temporary structure to fixup (without need to * later restore) before sending the mroute add to the dataplane */ - pim_mroute_copy(&tmp_oil, c_oil); + pim_mroute_copy(tmp_oil, c_oil); /* The linux kernel *expects* the incoming * vif to be part of the outgoing list * in the case of a (*,G). */ - if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY) { - tmp_oil.mfcc_ttls[c_oil->oil.mfcc_parent] = 1; + if (pim_addr_is_any(*oil_origin(c_oil))) { + oil_if_set(tmp_oil, *oil_parent(c_oil), 1); } /* @@ -976,19 +979,19 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) * the packets to be forwarded. Then set it * to the correct IIF afterwords. */ - if (!c_oil->installed && c_oil->oil.mfcc_origin.s_addr != INADDR_ANY - && c_oil->oil.mfcc_parent != 0) { - tmp_oil.mfcc_parent = 0; + if (!c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) + && *oil_parent(c_oil) != 0) { + *oil_parent(tmp_oil) = 0; } err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, - &tmp_oil, sizeof(tmp_oil)); + &tmp_oil->oil, sizeof(tmp_oil->oil)); if (!err && !c_oil->installed - && c_oil->oil.mfcc_origin.s_addr != INADDR_ANY - && c_oil->oil.mfcc_parent != 0) { - tmp_oil.mfcc_parent = c_oil->oil.mfcc_parent; + && !pim_addr_is_any(*oil_origin(c_oil)) + && *oil_parent(c_oil) != 0) { + *oil_parent(tmp_oil) = *oil_parent(c_oil); err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, - &tmp_oil, sizeof(tmp_oil)); + &tmp_oil->oil, sizeof(tmp_oil->oil)); } if (err) { @@ -1043,7 +1046,7 @@ static int pim_upstream_mroute_update(struct channel_oil *c_oil, { char buf[1000]; - if (c_oil->oil.mfcc_parent >= MAXVIFS) { + if (*oil_parent(c_oil) >= MAXVIFS) { /* the c_oil cannot be installed as a mroute yet */ if (PIM_DEBUG_MROUTE) zlog_debug( @@ -1090,13 +1093,13 @@ int pim_upstream_mroute_add(struct channel_oil *c_oil, const char *name) iif = pim_upstream_get_mroute_iif(c_oil, name); - if (c_oil->oil.mfcc_parent != iif) { - c_oil->oil.mfcc_parent = iif; - if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY && + if (*oil_parent(c_oil) != iif) { + *oil_parent(c_oil) = iif; + if (pim_addr_is_any(*oil_origin(c_oil)) && c_oil->up) pim_upstream_all_sources_iif_update(c_oil->up); } else { - c_oil->oil.mfcc_parent = iif; + *oil_parent(c_oil) = iif; } return pim_upstream_mroute_update(c_oil, name); @@ -1111,13 +1114,13 @@ int pim_upstream_mroute_iif_update(struct channel_oil *c_oil, const char *name) char buf[1000]; iif = pim_upstream_get_mroute_iif(c_oil, name); - if (c_oil->oil.mfcc_parent == iif) { + if (*oil_parent(c_oil) == iif) { /* no change */ return 0; } - c_oil->oil.mfcc_parent = iif; + *oil_parent(c_oil) = iif; - if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY && + if (pim_addr_is_any(*oil_origin(c_oil)) && c_oil->up) pim_upstream_all_sources_iif_update(c_oil->up); @@ -1140,10 +1143,10 @@ void pim_static_mroute_iif_update(struct channel_oil *c_oil, int input_vif_index, const char *name) { - if (c_oil->oil.mfcc_parent == input_vif_index) + if (*oil_parent(c_oil) == input_vif_index) return; - c_oil->oil.mfcc_parent = input_vif_index; + *oil_parent(c_oil) = input_vif_index; if (input_vif_index == MAXVIFS) pim_mroute_del(c_oil, name); else @@ -1163,7 +1166,7 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) char buf[1000]; zlog_debug( "%s %s: vifi %d for route is %s not installed, do not need to send del req. ", - __FILE__, __func__, c_oil->oil.mfcc_parent, + __FILE__, __func__, *oil_parent(c_oil), pim_channel_oil_dump(c_oil, buf, sizeof(buf))); } return -2; @@ -1196,7 +1199,6 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) void pim_mroute_update_counters(struct channel_oil *c_oil) { struct pim_instance *pim = c_oil->pim; - struct sioc_sg_req sgreq; c_oil->cc.oldpktcnt = c_oil->cc.pktcnt; c_oil->cc.oldbytecnt = c_oil->cc.bytecnt; @@ -1207,24 +1209,27 @@ void pim_mroute_update_counters(struct channel_oil *c_oil) if (PIM_DEBUG_MROUTE) { pim_sgaddr sg; - sg.src = c_oil->oil.mfcc_origin; - sg.grp = c_oil->oil.mfcc_mcastgrp; + sg.src = *oil_origin(c_oil); + sg.grp = *oil_mcastgrp(c_oil); zlog_debug("Channel%pSG is not installed no need to collect data from kernel", &sg); } return; } +#if PIM_IPV == 4 + struct sioc_sg_req sgreq; + memset(&sgreq, 0, sizeof(sgreq)); - sgreq.src = c_oil->oil.mfcc_origin; - sgreq.grp = c_oil->oil.mfcc_mcastgrp; + sgreq.src = *oil_origin(c_oil); + sgreq.grp = *oil_mcastgrp(c_oil); pim_zlookup_sg_statistics(c_oil); if (ioctl(pim->mroute_socket, SIOCGETSGCNT, &sgreq)) { pim_sgaddr sg; - sg.src = c_oil->oil.mfcc_origin; - sg.grp = c_oil->oil.mfcc_mcastgrp; + sg.src = *oil_origin(c_oil); + sg.grp = *oil_mcastgrp(c_oil); zlog_warn("ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=%pSG: errno=%d: %s", (unsigned long)SIOCGETSGCNT, &sg, @@ -1235,6 +1240,6 @@ void pim_mroute_update_counters(struct channel_oil *c_oil) c_oil->cc.pktcnt = sgreq.pktcnt; c_oil->cc.bytecnt = sgreq.bytecnt; c_oil->cc.wrong_if = sgreq.wrong_if; - +#endif return; } diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h index 4cd6b9f0ac..14b0a8ccaf 100644 --- a/pimd/pim_mroute.h +++ b/pimd/pim_mroute.h @@ -37,6 +37,7 @@ #define PIM_MROUTE_MIN_TTL (1) +#if PIM_IPV == 4 #if defined(HAVE_LINUX_MROUTE_H) #include <linux/mroute.h> #else @@ -157,6 +158,19 @@ struct igmpmsg { struct in_addr im_src, im_dst; }; #endif + +#endif /* HAVE_LINUX_MROUTE_H */ + +typedef struct mfcctl pim_mfcctl; + +#else /* PIM_IPV != 4 */ +#if defined(HAVE_LINUX_MROUTE6_H) +#include <linux/mroute6.h> +#endif + +typedef struct mf6cctl pim_mfcctl; + +#define MAXVIFS IF_SETSIZE #endif #ifndef IGMPMSG_WRVIFWHOLE @@ -172,7 +186,7 @@ struct channel_oil; int pim_mroute_socket_enable(struct pim_instance *pim); int pim_mroute_socket_disable(struct pim_instance *pim); -int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, +int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, unsigned char flags); int pim_mroute_del_vif(struct interface *ifp); diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index eb89040d42..7c1c80f71a 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -66,7 +66,7 @@ static void pim_msdp_sa_timer_expiry_log(struct pim_msdp_sa *sa, } /* RFC-3618:Sec-5.1 - global active source advertisement timer */ -static int pim_msdp_sa_adv_timer_cb(struct thread *t) +static void pim_msdp_sa_adv_timer_cb(struct thread *t) { struct pim_instance *pim = THREAD_ARG(t); @@ -76,8 +76,8 @@ static int pim_msdp_sa_adv_timer_cb(struct thread *t) pim_msdp_sa_adv_timer_setup(pim, true /* start */); pim_msdp_pkt_sa_tx(pim); - return 0; } + static void pim_msdp_sa_adv_timer_setup(struct pim_instance *pim, bool start) { THREAD_OFF(pim->msdp.sa_adv_timer); @@ -89,7 +89,7 @@ static void pim_msdp_sa_adv_timer_setup(struct pim_instance *pim, bool start) } /* RFC-3618:Sec-5.3 - SA cache state timer */ -static int pim_msdp_sa_state_timer_cb(struct thread *t) +static void pim_msdp_sa_state_timer_cb(struct thread *t) { struct pim_msdp_sa *sa; @@ -100,8 +100,8 @@ static int pim_msdp_sa_state_timer_cb(struct thread *t) } pim_msdp_sa_deref(sa, PIM_MSDP_SAF_PEER); - return 0; } + static void pim_msdp_sa_state_timer_setup(struct pim_msdp_sa *sa, bool start) { THREAD_OFF(sa->sa_state_timer); @@ -873,7 +873,7 @@ static void pim_msdp_peer_timer_expiry_log(struct pim_msdp_peer *mp, } /* RFC-3618:Sec-5.4 - peer hold timer */ -static int pim_msdp_peer_hold_timer_cb(struct thread *t) +static void pim_msdp_peer_hold_timer_cb(struct thread *t) { struct pim_msdp_peer *mp; @@ -884,14 +884,13 @@ static int pim_msdp_peer_hold_timer_cb(struct thread *t) } if (mp->state != PIM_MSDP_ESTABLISHED) { - return 0; + return; } if (PIM_DEBUG_MSDP_EVENTS) { pim_msdp_peer_state_chg_log(mp); } pim_msdp_peer_reset_tcp_conn(mp, "ht-expired"); - return 0; } static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start) @@ -906,7 +905,7 @@ static void pim_msdp_peer_hold_timer_setup(struct pim_msdp_peer *mp, bool start) /* RFC-3618:Sec-5.5 - peer keepalive timer */ -static int pim_msdp_peer_ka_timer_cb(struct thread *t) +static void pim_msdp_peer_ka_timer_cb(struct thread *t) { struct pim_msdp_peer *mp; @@ -918,8 +917,8 @@ static int pim_msdp_peer_ka_timer_cb(struct thread *t) pim_msdp_pkt_ka_tx(mp); pim_msdp_peer_ka_timer_setup(mp, true /* start */); - return 0; } + static void pim_msdp_peer_ka_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->ka_timer); @@ -967,7 +966,7 @@ static void pim_msdp_peer_active_connect(struct pim_msdp_peer *mp) } /* RFC-3618:Sec-5.6 - connection retry on active peer */ -static int pim_msdp_peer_cr_timer_cb(struct thread *t) +static void pim_msdp_peer_cr_timer_cb(struct thread *t) { struct pim_msdp_peer *mp; @@ -978,12 +977,12 @@ static int pim_msdp_peer_cr_timer_cb(struct thread *t) } if (mp->state != PIM_MSDP_CONNECTING || PIM_MSDP_PEER_IS_LISTENER(mp)) { - return 0; + return; } pim_msdp_peer_active_connect(mp); - return 0; } + static void pim_msdp_peer_cr_timer_setup(struct pim_msdp_peer *mp, bool start) { THREAD_OFF(mp->cr_timer); diff --git a/pimd/pim_msdp.h b/pimd/pim_msdp.h index d2501adc4e..4e1114aff2 100644 --- a/pimd/pim_msdp.h +++ b/pimd/pim_msdp.h @@ -240,7 +240,7 @@ void pim_msdp_peer_established(struct pim_msdp_peer *mp); void pim_msdp_peer_pkt_rxed(struct pim_msdp_peer *mp); void pim_msdp_peer_stop_tcp_conn(struct pim_msdp_peer *mp, bool chg_state); void pim_msdp_peer_reset_tcp_conn(struct pim_msdp_peer *mp, const char *rc_str); -int pim_msdp_write(struct thread *thread); +void pim_msdp_write(struct thread *thread); int pim_msdp_config_write(struct pim_instance *pim, struct vty *vty, const char *spaces); bool pim_msdp_peer_config_write(struct vty *vty, struct pim_instance *pim, diff --git a/pimd/pim_msdp_packet.c b/pimd/pim_msdp_packet.c index 395bbf6f26..03284ffa56 100644 --- a/pimd/pim_msdp_packet.c +++ b/pimd/pim_msdp_packet.c @@ -182,7 +182,7 @@ static void pim_msdp_write_proceed_actions(struct pim_msdp_peer *mp) } } -int pim_msdp_write(struct thread *thread) +void pim_msdp_write(struct thread *thread) { struct pim_msdp_peer *mp; struct stream *s; @@ -199,19 +199,19 @@ int pim_msdp_write(struct thread *thread) zlog_debug("MSDP peer %s pim_msdp_write", mp->key_str); } if (mp->fd < 0) { - return -1; + return; } /* check if TCP connection is established */ if (mp->state != PIM_MSDP_ESTABLISHED) { pim_msdp_connect_check(mp); - return 0; + return; } s = stream_fifo_head(mp->obuf); if (!s) { pim_msdp_write_proceed_actions(mp); - return 0; + return; } sockopt_cork(mp->fd, 1); @@ -237,7 +237,7 @@ int pim_msdp_write(struct thread *thread) } pim_msdp_peer_reset_tcp_conn(mp, "pkt-tx-failed"); - return 0; + return; } if (num != writenum) { @@ -286,8 +286,6 @@ int pim_msdp_write(struct thread *thread) zlog_debug("MSDP peer %s pim_msdp_write wrote %d packets", mp->key_str, work_cnt); } - - return 0; } static void pim_msdp_pkt_send(struct pim_msdp_peer *mp, struct stream *s) @@ -674,7 +672,7 @@ static int pim_msdp_read_packet(struct pim_msdp_peer *mp) return 0; } -int pim_msdp_read(struct thread *thread) +void pim_msdp_read(struct thread *thread) { struct pim_msdp_peer *mp; int rc; @@ -688,13 +686,13 @@ int pim_msdp_read(struct thread *thread) } if (mp->fd < 0) { - return -1; + return; } /* check if TCP connection is established */ if (mp->state != PIM_MSDP_ESTABLISHED) { pim_msdp_connect_check(mp); - return 0; + return; } PIM_MSDP_PEER_READ_ON(mp); @@ -706,32 +704,27 @@ int pim_msdp_read(struct thread *thread) if (stream_get_endp(mp->ibuf) < PIM_MSDP_HEADER_SIZE) { /* start by reading the TLV header */ rc = pim_msdp_read_packet(mp); - if (rc < 0) { - goto pim_msdp_read_end; - } + if (rc < 0) + return; /* Find TLV type and len */ stream_getc(mp->ibuf); len = stream_getw(mp->ibuf); if (len < PIM_MSDP_HEADER_SIZE) { pim_msdp_pkt_rxed_with_fatal_error(mp); - goto pim_msdp_read_end; + return; } /* read complete TLV */ mp->packet_size = len; } rc = pim_msdp_read_packet(mp); - if (rc < 0) { - goto pim_msdp_read_end; - } + if (rc < 0) + return; pim_msdp_pkt_rx(mp); /* reset input buffers and get ready for the next packet */ mp->packet_size = 0; stream_reset(mp->ibuf); - -pim_msdp_read_end: - return 0; } diff --git a/pimd/pim_msdp_packet.h b/pimd/pim_msdp_packet.h index e2c4b0e6b5..00324a2913 100644 --- a/pimd/pim_msdp_packet.h +++ b/pimd/pim_msdp_packet.h @@ -64,7 +64,7 @@ #define PIM_MSDP_PKT_TYPE_STRLEN 16 void pim_msdp_pkt_ka_tx(struct pim_msdp_peer *mp); -int pim_msdp_read(struct thread *thread); +void pim_msdp_read(struct thread *thread); void pim_msdp_pkt_sa_tx(struct pim_instance *pim); void pim_msdp_pkt_sa_tx_one(struct pim_msdp_sa *sa); void pim_msdp_pkt_sa_tx_to_one_peer(struct pim_msdp_peer *mp); diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index 5fff9fca0e..facb771c25 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -62,7 +62,7 @@ static void pim_msdp_update_sock_send_buffer_size(int fd) } /* passive peer socket accept */ -static int pim_msdp_sock_accept(struct thread *thread) +static void pim_msdp_sock_accept(struct thread *thread) { union sockunion su; struct pim_instance *pim = THREAD_ARG(thread); @@ -77,7 +77,7 @@ static int pim_msdp_sock_accept(struct thread *thread) if (accept_sock < 0) { flog_err(EC_LIB_DEVELOPMENT, "accept_sock is negative value %d", accept_sock); - return -1; + return; } pim->msdp.listener.thread = NULL; thread_add_read(router->master, pim_msdp_sock_accept, pim, accept_sock, @@ -88,7 +88,7 @@ static int pim_msdp_sock_accept(struct thread *thread) if (msdp_sock < 0) { flog_err_sys(EC_LIB_SOCKET, "pim_msdp_sock_accept failed (%s)", safe_strerror(errno)); - return -1; + return; } /* see if have peer config for this */ @@ -100,7 +100,7 @@ static int pim_msdp_sock_accept(struct thread *thread) "msdp peer connection refused from %pSU", &su); } close(msdp_sock); - return -1; + return; } if (PIM_DEBUG_MSDP_INTERNAL) { @@ -122,7 +122,6 @@ static int pim_msdp_sock_accept(struct thread *thread) set_nonblocking(mp->fd); pim_msdp_update_sock_send_buffer_size(mp->fd); pim_msdp_peer_established(mp); - return 0; } /* global listener for the MSDP well know TCP port */ diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index e25cf11549..a0653e1a57 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -138,7 +138,7 @@ uint8_t *pim_msg_addr_encode_ipv6_group(uint8_t *buf, struct in6_addr addr) return buf; } -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 #define pim_msg_addr_encode(what) pim_msg_addr_encode_ipv4_##what #else #define pim_msg_addr_encode(what) pim_msg_addr_encode_ipv6_##what diff --git a/pimd/pim_nb_config.c b/pimd/pim_nb_config.c index 3766157295..27cac0c1a7 100644 --- a/pimd/pim_nb_config.c +++ b/pimd/pim_nb_config.c @@ -31,6 +31,7 @@ #include "pim_ssm.h" #include "pim_ssmpingd.h" #include "pim_vxlan.h" +#include "pim_util.h" #include "log.h" #include "lib_errors.h" @@ -45,9 +46,13 @@ int funcname(struct argtype *args) \ } \ MACRO_REQUIRE_SEMICOLON() +#define yang_dnode_get_pimaddr yang_dnode_get_ipv6 + #else /* PIM_IPV != 6 */ #define pim6_msdp_err(funcname, argtype) \ MACRO_REQUIRE_SEMICOLON() + +#define yang_dnode_get_pimaddr yang_dnode_get_ipv4 #endif /* PIM_IPV != 6 */ static void pim_if_membership_clear(struct interface *ifp) @@ -172,8 +177,7 @@ static int pim_cmd_interface_delete(struct interface *ifp) } static int interface_pim_use_src_cmd_worker(struct interface *ifp, - struct in_addr source_addr, - char *errmsg, size_t errmsg_len) + pim_addr source_addr, char *errmsg, size_t errmsg_len) { int result; int ret = NB_OK; @@ -396,15 +400,10 @@ static void igmp_sock_query_interval_reconfig(struct gm_sock *igmp) ifp = igmp->interface; pim_ifp = ifp->info; - if (PIM_DEBUG_IGMP_TRACE) { - char ifaddr_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, - sizeof(ifaddr_str)); - zlog_debug("%s: Querier %s on %s reconfig query_interval=%d", - __func__, ifaddr_str, ifp->name, + if (PIM_DEBUG_IGMP_TRACE) + zlog_debug("%s: Querier %pPAs on %s reconfig query_interval=%d", + __func__, &igmp->ifaddr, ifp->name, pim_ifp->gm_default_query_interval); - } /* * igmp_startup_mode_on() will reset QQI: @@ -2015,7 +2014,7 @@ int lib_interface_pim_address_family_use_source_modify( struct nb_cb_modify_args *args) { struct interface *ifp; - struct ipaddr source_addr; + pim_addr source_addr; int result; const struct lyd_node *if_dnode; @@ -2033,10 +2032,14 @@ int lib_interface_pim_address_family_use_source_modify( break; case NB_EV_APPLY: ifp = nb_running_get_entry(args->dnode, NULL, true); - yang_dnode_get_ip(&source_addr, args->dnode, NULL); +#if PIM_IPV == 4 + yang_dnode_get_ipv4(&source_addr, args->dnode, NULL); +#else + yang_dnode_get_ipv6(&source_addr, args->dnode, NULL); +#endif result = interface_pim_use_src_cmd_worker( - ifp, source_addr.ip._v4_addr, + ifp, source_addr, args->errmsg, args->errmsg_len); if (result != PIM_SUCCESS) @@ -2052,7 +2055,6 @@ int lib_interface_pim_address_family_use_source_destroy( struct nb_cb_destroy_args *args) { struct interface *ifp; - struct in_addr source_addr = {INADDR_ANY}; int result; const struct lyd_node *if_dnode; @@ -2071,7 +2073,7 @@ int lib_interface_pim_address_family_use_source_destroy( case NB_EV_APPLY: ifp = nb_running_get_entry(args->dnode, NULL, true); - result = interface_pim_use_src_cmd_worker(ifp, source_addr, + result = interface_pim_use_src_cmd_worker(ifp, PIMADDR_ANY, args->errmsg, args->errmsg_len); @@ -2179,8 +2181,8 @@ int lib_interface_pim_address_family_mroute_destroy( struct interface *iif; struct interface *oif; const char *oifname; - struct ipaddr source_addr; - struct ipaddr group_addr; + pim_addr source_addr; + pim_addr group_addr; const struct lyd_node *if_dnode; switch (args->event) { @@ -2210,11 +2212,10 @@ int lib_interface_pim_address_family_mroute_destroy( return NB_ERR_INCONSISTENCY; } - yang_dnode_get_ip(&source_addr, args->dnode, "./source-addr"); - yang_dnode_get_ip(&group_addr, args->dnode, "./group-addr"); + yang_dnode_get_pimaddr(&source_addr, args->dnode, "./source-addr"); + yang_dnode_get_pimaddr(&group_addr, args->dnode, "./group-addr"); - if (pim_static_del(pim, iif, oif, group_addr.ip._v4_addr, - source_addr.ip._v4_addr)) { + if (pim_static_del(pim, iif, oif, group_addr, source_addr)) { snprintf(args->errmsg, args->errmsg_len, "Failed to remove static mroute"); return NB_ERR_INCONSISTENCY; @@ -2237,8 +2238,8 @@ int lib_interface_pim_address_family_mroute_oif_modify( struct interface *iif; struct interface *oif; const char *oifname; - struct ipaddr source_addr; - struct ipaddr group_addr; + pim_addr source_addr; + pim_addr group_addr; const struct lyd_node *if_dnode; switch (args->event) { @@ -2287,11 +2288,10 @@ int lib_interface_pim_address_family_mroute_oif_modify( return NB_ERR_INCONSISTENCY; } - yang_dnode_get_ip(&source_addr, args->dnode, "../source-addr"); - yang_dnode_get_ip(&group_addr, args->dnode, "../group-addr"); + yang_dnode_get_pimaddr(&source_addr, args->dnode, "../source-addr"); + yang_dnode_get_pimaddr(&group_addr, args->dnode, "../group-addr"); - if (pim_static_add(pim, iif, oif, group_addr.ip._v4_addr, - source_addr.ip._v4_addr)) { + if (pim_static_add(pim, iif, oif, group_addr, source_addr)) { snprintf(args->errmsg, args->errmsg_len, "Failed to add static mroute"); return NB_ERR_INCONSISTENCY; @@ -2833,6 +2833,14 @@ int lib_interface_gmp_address_family_static_group_create( ifp_name); return NB_ERR_VALIDATION; } + + yang_dnode_get_ip(&group_addr, args->dnode, "./group-addr"); + if (pim_is_group_224_0_0_0_24(group_addr.ip._v4_addr)) { + snprintf( + args->errmsg, args->errmsg_len, + "Groups within 224.0.0.0/24 are reserved and cannot be joined"); + return NB_ERR_VALIDATION; + } break; case NB_EV_PREPARE: case NB_EV_ABORT: diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 6e3d2739e7..84b532d345 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -200,7 +200,7 @@ static void update_dr_priority(struct pim_neighbor *neigh, } } -static int on_neighbor_timer(struct thread *t) +static void on_neighbor_timer(struct thread *t) { struct pim_neighbor *neigh; struct interface *ifp; @@ -226,8 +226,6 @@ static int on_neighbor_timer(struct thread *t) router's own DR Priority changes. */ pim_if_dr_election(ifp); // neighbor times out - - return 0; } void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime) @@ -252,7 +250,7 @@ void pim_neighbor_timer_reset(struct pim_neighbor *neigh, uint16_t holdtime) neigh->holdtime, &neigh->t_expire_timer); } -static int on_neighbor_jp_timer(struct thread *t) +static void on_neighbor_jp_timer(struct thread *t) { struct pim_neighbor *neigh = THREAD_ARG(t); struct pim_rpf rpf; @@ -269,8 +267,6 @@ static int on_neighbor_jp_timer(struct thread *t) thread_add_timer(router->master, on_neighbor_jp_timer, neigh, router->t_periodic, &neigh->jp_timer); - - return 0; } static void pim_neighbor_start_jp_timer(struct pim_neighbor *neigh) diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index beaa5c802b..48dd565b25 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -42,6 +42,7 @@ #include "pim_zebra.h" #include "pim_zlookup.h" #include "pim_rp.h" +#include "pim_addr.h" /** * pim_sendmsg_zebra_rnh -- Format and send a nexthop register/Unregister @@ -75,10 +76,7 @@ struct pim_nexthop_cache *pim_nexthop_cache_find(struct pim_instance *pim, struct pim_nexthop_cache *pnc = NULL; struct pim_nexthop_cache lookup; - lookup.rpf.rpf_addr.family = rpf->rpf_addr.family; - lookup.rpf.rpf_addr.prefixlen = rpf->rpf_addr.prefixlen; - lookup.rpf.rpf_addr.u.prefix4.s_addr = rpf->rpf_addr.u.prefix4.s_addr; - + lookup.rpf.rpf_addr = rpf->rpf_addr; pnc = hash_lookup(pim->rpf_hash, &lookup); return pnc; @@ -92,10 +90,7 @@ static struct pim_nexthop_cache *pim_nexthop_cache_add(struct pim_instance *pim, pnc = XCALLOC(MTYPE_PIM_NEXTHOP_CACHE, sizeof(struct pim_nexthop_cache)); - pnc->rpf.rpf_addr.family = rpf_addr->rpf_addr.family; - pnc->rpf.rpf_addr.prefixlen = rpf_addr->rpf_addr.prefixlen; - pnc->rpf.rpf_addr.u.prefix4.s_addr = - rpf_addr->rpf_addr.u.prefix4.s_addr; + pnc->rpf.rpf_addr = rpf_addr->rpf_addr; pnc = hash_get(pim->rpf_hash, pnc, hash_alloc_intern); @@ -119,9 +114,7 @@ static struct pim_nexthop_cache *pim_nht_get(struct pim_instance *pim, zclient = pim_zebra_zclient_get(); memset(&rpf, 0, sizeof(struct pim_rpf)); - rpf.rpf_addr.family = addr->family; - rpf.rpf_addr.prefixlen = addr->prefixlen; - rpf.rpf_addr.u.prefix4 = addr->u.prefix4; + rpf.rpf_addr = *addr; pnc = pim_nexthop_cache_find(pim, &rpf); if (!pnc) { @@ -361,7 +354,7 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, pim_addr nhaddr; switch (nh->type) { -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 case NEXTHOP_TYPE_IPV4: if (nh->ifindex == IFINDEX_INTERNAL) continue; @@ -409,8 +402,8 @@ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, void pim_rp_nexthop_del(struct rp_info *rp_info) { rp_info->rp.source_nexthop.interface = NULL; - rp_info->rp.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr = - PIM_NET_INADDR_ANY; + pim_addr_to_prefix(&rp_info->rp.source_nexthop.mrib_nexthop_addr, + PIMADDR_ANY); rp_info->rp.source_nexthop.mrib_metric_preference = router->infinite_assert_metric.metric_preference; rp_info->rp.source_nexthop.mrib_route_metric = @@ -426,7 +419,7 @@ static void pim_update_rp_nh(struct pim_instance *pim, /*Traverse RP list and update each RP Nexthop info */ for (ALL_LIST_ELEMENTS_RO(pnc->rp_list, node, rp_info)) { - if (rp_info->rp.rpf_addr.u.prefix4.s_addr == INADDR_NONE) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; // Compute PIM RPF using cached nexthop @@ -523,6 +516,9 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, uint32_t hash_val = 0, mod_val = 0; uint8_t nh_iter = 0, found = 0; uint32_t i, num_nbrs = 0; + pim_addr nh_addr = pim_addr_from_prefix(&(nexthop->mrib_nexthop_addr)); + pim_addr src_addr = pim_addr_from_prefix(src); + pim_addr grp_addr = pim_addr_from_prefix(grp); if (!pnc || !pnc->nexthop_num || !nexthop) return 0; @@ -530,10 +526,10 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, memset(&nbrs, 0, sizeof(nbrs)); memset(&ifps, 0, sizeof(ifps)); + // Current Nexthop is VALID, check to stay on the current path. - if (nexthop->interface && nexthop->interface->info - && nexthop->mrib_nexthop_addr.u.prefix4.s_addr - != PIM_NET_INADDR_ANY) { + if (nexthop->interface && nexthop->interface->info && + (!pim_addr_is_any(nh_addr))) { /* User configured knob to explicitly switch to new path is disabled or current path metric is less than nexthop update. @@ -573,23 +569,13 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, pnc->distance; nexthop->mrib_route_metric = pnc->metric; - if (PIM_DEBUG_PIM_NHT) { - char src_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", - src->u.prefix4, - src_str, - sizeof(src_str)); - char grp_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", - grp->u.prefix4, - grp_str, - sizeof(grp_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: (%s,%s)(%s) current nexthop %s is valid, skipping new path selection", - __func__, src_str, - grp_str, pim->vrf->name, + "%s: (%pPA,%pPA)(%s) current nexthop %s is valid, skipping new path selection", + __func__, &src_addr, + &grp_addr, + pim->vrf->name, nexthop->interface->name); - } return 1; } } @@ -605,15 +591,14 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, ifps[i] = if_lookup_by_index(nh_node->ifindex, pim->vrf->vrf_id); if (ifps[i]) { -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 pim_addr nhaddr = nh_node->gate.ipv4; #else pim_addr nhaddr = nh_node->gate.ipv6; #endif nbrs[i] = pim_neighbor_find(ifps[i], nhaddr); - if (nbrs[i] || pim_if_connected_to_source(ifps[i], - - src->u.prefix4)) + if (nbrs[i] || + pim_if_connected_to_source(ifps[i], src_addr)) num_nbrs++; } } @@ -636,38 +621,30 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, first_ifindex = nh_node->ifindex; ifp = ifps[nh_iter]; if (!ifp) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", src->u.prefix4, - addr_str, sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s %s: could not find interface for ifindex %d (address %s(%s))", + "%s %s: could not find interface for ifindex %d (address %pPA(%s))", __FILE__, __func__, first_ifindex, - addr_str, pim->vrf->name); - } + &src_addr, pim->vrf->name); if (nh_iter == mod_val) mod_val++; // Select nexthpath nh_iter++; continue; } if (!ifp->info) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", src->u.prefix4, - addr_str, sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", + "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %pPA)", __func__, ifp->name, pim->vrf->name, - first_ifindex, addr_str); - } + first_ifindex, &src_addr); if (nh_iter == mod_val) mod_val++; // Select nexthpath nh_iter++; continue; } - if (neighbor_needed - && !pim_if_connected_to_source(ifp, src->u.prefix4)) { + if (neighbor_needed && + !pim_if_connected_to_source(ifp, src_addr)) { nbr = nbrs[nh_iter]; if (!nbr && !if_is_loopback(ifp)) { if (PIM_DEBUG_PIM_NHT) @@ -684,34 +661,27 @@ static int pim_ecmp_nexthop_search(struct pim_instance *pim, if (nh_iter == mod_val) { nexthop->interface = ifp; - nexthop->mrib_nexthop_addr.family = AF_INET; - nexthop->mrib_nexthop_addr.prefixlen = IPV4_MAX_BITLEN; + nexthop->mrib_nexthop_addr.family = PIM_AF; + nexthop->mrib_nexthop_addr.prefixlen = PIM_MAX_BITLEN; +#if PIM_IPV == 4 nexthop->mrib_nexthop_addr.u.prefix4 = nh_node->gate.ipv4; +#else + nexthop->mrib_nexthop_addr.u.prefix6 = + nh_node->gate->ipv6; +#endif nexthop->mrib_metric_preference = pnc->distance; nexthop->mrib_route_metric = pnc->metric; - nexthop->last_lookup = src->u.prefix4; + nexthop->last_lookup = src_addr; nexthop->last_lookup_time = pim_time_monotonic_usec(); nexthop->nbr = nbr; found = 1; - if (PIM_DEBUG_PIM_NHT) { - char buf[INET_ADDRSTRLEN]; - char buf2[INET_ADDRSTRLEN]; - char buf3[INET_ADDRSTRLEN]; - pim_inet4_dump("<src?>", src->u.prefix4, buf2, - sizeof(buf2)); - pim_inet4_dump("<grp?>", grp->u.prefix4, buf3, - sizeof(buf3)); - pim_inet4_dump( - "<rpf?>", - nexthop->mrib_nexthop_addr.u.prefix4, - buf, sizeof(buf)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: (%s,%s)(%s) selected nhop interface %s addr %s mod_val %u iter %d ecmp %d", - __func__, buf2, buf3, pim->vrf->name, - ifp->name, buf, mod_val, nh_iter, - pim->ecmp_enable); - } + "%s: (%pPA,%pPA)(%s) selected nhop interface %s addr %pPAs mod_val %u iter %d ecmp %d", + __func__, &src_addr, &grp_addr, + pim->vrf->name, ifp->name, &nh_addr, + mod_val, nh_iter, pim->ecmp_enable); } nh_iter++; } @@ -785,9 +755,15 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) * RPF address from nexthop cache (i.e. * destination) as PIM nexthop. */ +#if PIM_IPV == 4 nexthop->type = NEXTHOP_TYPE_IPV4_IFINDEX; nexthop->gate.ipv4 = pnc->rpf.rpf_addr.u.prefix4; +#else + nexthop->type = NEXTHOP_TYPE_IPV6_IFINDEX; + nexthop->gate.ipv6 = + pnc->rpf.rpf_addr.u.prefix6; +#endif break; case NEXTHOP_TYPE_IPV6_IFINDEX: ifp1 = if_lookup_by_index(nexthop->ifindex, @@ -799,7 +775,7 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) nbr = pim_neighbor_find_if(ifp1); /* Overwrite with Nbr address as NH addr */ if (nbr) -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 nexthop->gate.ipv4 = nbr->source_addr; #else nexthop->gate.ipv6 = nbr->source_addr; @@ -807,8 +783,11 @@ int pim_parse_nexthop_update(ZAPI_CALLBACK_ARGS) else { // Mark nexthop address to 0 until PIM // Nbr is resolved. - nexthop->gate.ipv4.s_addr = - PIM_NET_INADDR_ANY; +#if PIM_IPV == 4 + nexthop->gate.ipv4 = PIMADDR_ANY; +#else + nexthop->gate.ipv6 = PIMADDR_ANY; +#endif } break; @@ -918,20 +897,14 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, uint8_t i = 0; uint32_t hash_val = 0, mod_val = 0; uint32_t num_nbrs = 0; - char addr_str[PREFIX_STRLEN]; + pim_addr src_addr = pim_addr_from_prefix(src); - if (PIM_DEBUG_PIM_NHT) { - pim_inet4_dump("<addr?>", src->u.prefix4, addr_str, - sizeof(addr_str)); - zlog_debug("%s: Looking up: %s(%s), last lookup time: %lld", - __func__, addr_str, pim->vrf->name, + if (PIM_DEBUG_PIM_NHT) + zlog_debug("%s: Looking up: %pPA(%s), last lookup time: %lld", + __func__, &src_addr, pim->vrf->name, nexthop->last_lookup_time); - } - memset(&rpf, 0, sizeof(struct pim_rpf)); - rpf.rpf_addr.family = AF_INET; - rpf.rpf_addr.prefixlen = IPV4_MAX_BITLEN; - rpf.rpf_addr.u.prefix4 = src->u.prefix4; + rpf.rpf_addr = *src; pnc = pim_nexthop_cache_find(pim, &rpf); if (pnc) { @@ -942,14 +915,13 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, memset(nexthop_tab, 0, sizeof(struct pim_zlookup_nexthop) * MULTIPATH_NUM); - num_ifindex = - zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, - src->u.prefix4, PIM_NEXTHOP_LOOKUP_MAX); + num_ifindex = zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, + src_addr, PIM_NEXTHOP_LOOKUP_MAX); if (num_ifindex < 1) { if (PIM_DEBUG_PIM_NHT) zlog_warn( - "%s: could not find nexthop ifindex for address %s(%s)", - __func__, addr_str, pim->vrf->name); + "%s: could not find nexthop ifindex for address %pPA(%s)", + __func__, &src_addr, pim->vrf->name); return 0; } @@ -966,9 +938,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (ifps[i]) { nbrs[i] = pim_neighbor_find_prefix( ifps[i], &nexthop_tab[i].nexthop_addr); - if (nbrs[i] - || pim_if_connected_to_source(ifps[i], - src->u.prefix4)) + if (nbrs[i] || + pim_if_connected_to_source(ifps[i], src_addr)) num_nbrs++; } } @@ -998,9 +969,9 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (!ifp) { if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s %s: could not find interface for ifindex %d (address %s(%s))", + "%s %s: could not find interface for ifindex %d (address %pPA(%s))", __FILE__, __func__, first_ifindex, - addr_str, pim->vrf->name); + &src_addr, pim->vrf->name); if (i == mod_val) mod_val++; i++; @@ -1010,16 +981,16 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, if (!ifp->info) { if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %s)", + "%s: multicast not enabled on input interface %s(%s) (ifindex=%d, RPF for source %pPA)", __func__, ifp->name, pim->vrf->name, - first_ifindex, addr_str); + first_ifindex, &src_addr); if (i == mod_val) mod_val++; i++; continue; } - if (neighbor_needed - && !pim_if_connected_to_source(ifp, src->u.prefix4)) { + if (neighbor_needed && + !pim_if_connected_to_source(ifp, src_addr)) { nbr = nbrs[i]; if (PIM_DEBUG_PIM_NHT_DETAIL) zlog_debug("ifp name: %s(%s), pim nbr: %p", @@ -1030,9 +1001,9 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, i++; if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: NBR not found on input interface %s(%s) (RPF for source %s)", + "%s: NBR not found on input interface %s(%s) (RPF for source %pPA)", __func__, ifp->name, - pim->vrf->name, addr_str); + pim->vrf->name, &src_addr); continue; } } @@ -1045,8 +1016,8 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, &nexthop_tab[i].nexthop_addr, nexthop_str, sizeof(nexthop_str)); zlog_debug( - "%s: found nhop %s for addr %s interface %s(%s) metric %d dist %d", - __func__, nexthop_str, addr_str, + "%s: found nhop %s for addr %pPA interface %s(%s) metric %d dist %d", + __func__, nexthop_str, &src_addr, ifp->name, pim->vrf->name, nexthop_tab[i].route_metric, nexthop_tab[i].protocol_distance); @@ -1059,7 +1030,7 @@ int pim_ecmp_nexthop_lookup(struct pim_instance *pim, nexthop_tab[i].protocol_distance; nexthop->mrib_route_metric = nexthop_tab[i].route_metric; - nexthop->last_lookup = src->u.prefix4; + nexthop->last_lookup = src_addr; nexthop->last_lookup_time = pim_time_monotonic_usec(); nexthop->nbr = nbr; found = 1; @@ -1079,36 +1050,36 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim, struct pim_nexthop nhop; int vif_index; ifindex_t ifindex; - char addr_str[PREFIX_STRLEN]; + pim_addr src_addr; - if (PIM_DEBUG_PIM_NHT) - pim_inet4_dump("<addr?>", src->u.prefix4, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) { + src_addr = pim_addr_from_prefix(src); + } memset(&nhop, 0, sizeof(nhop)); if (!pim_ecmp_nexthop_lookup(pim, &nhop, src, grp, 1)) { if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: could not find nexthop ifindex for address %s(%s)", - __func__, addr_str, pim->vrf->name); + "%s: could not find nexthop ifindex for address %pPA(%s)", + __func__, &src_addr, pim->vrf->name); return -1; } ifindex = nhop.interface->ifindex; if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: found nexthop ifindex=%d (interface %s(%s)) for address %s", + "%s: found nexthop ifindex=%d (interface %s(%s)) for address %pPA", __func__, ifindex, ifindex2ifname(ifindex, pim->vrf->vrf_id), - pim->vrf->name, addr_str); + pim->vrf->name, &src_addr); vif_index = pim_if_find_vifindex_by_ifindex(pim, ifindex); if (vif_index < 0) { if (PIM_DEBUG_PIM_NHT) { zlog_debug( - "%s: low vif_index=%d(%s) < 1 nexthop for address %s", - __func__, vif_index, pim->vrf->name, addr_str); + "%s: low vif_index=%d(%s) < 1 nexthop for address %pPA", + __func__, vif_index, pim->vrf->name, &src_addr); } return -2; } diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index b17f821dd6..a499c884b4 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -42,15 +42,15 @@ char *pim_channel_oil_dump(struct channel_oil *c_oil, char *buf, size_t size) pim_sgaddr sg; int i; - sg.src = c_oil->oil.mfcc_origin; - sg.grp = c_oil->oil.mfcc_mcastgrp; - ifp = pim_if_find_by_vif_index(c_oil->pim, c_oil->oil.mfcc_parent); + sg.src = *oil_origin(c_oil); + sg.grp = *oil_mcastgrp(c_oil); + ifp = pim_if_find_by_vif_index(c_oil->pim, *oil_parent(c_oil)); snprintfrr(buf, size, "%pSG IIF: %s, OIFS: ", &sg, ifp ? ifp->name : "(?)"); out = buf + strlen(buf); for (i = 0; i < MAXVIFS; i++) { - if (c_oil->oil.mfcc_ttls[i] != 0) { + if (oil_if_has(c_oil, i) != 0) { ifp = pim_if_find_by_vif_index(c_oil->pim, i); snprintf(out, buf + size - out, "%s ", ifp ? ifp->name : "(?)"); @@ -61,25 +61,19 @@ char *pim_channel_oil_dump(struct channel_oil *c_oil, char *buf, size_t size) return buf; } -int pim_channel_oil_compare(const struct channel_oil *c1, - const struct channel_oil *c2) +int pim_channel_oil_compare(const struct channel_oil *cc1, + const struct channel_oil *cc2) { - if (ntohl(c1->oil.mfcc_mcastgrp.s_addr) - < ntohl(c2->oil.mfcc_mcastgrp.s_addr)) - return -1; - - if (ntohl(c1->oil.mfcc_mcastgrp.s_addr) - > ntohl(c2->oil.mfcc_mcastgrp.s_addr)) - return 1; - - if (ntohl(c1->oil.mfcc_origin.s_addr) - < ntohl(c2->oil.mfcc_origin.s_addr)) - return -1; - - if (ntohl(c1->oil.mfcc_origin.s_addr) - > ntohl(c2->oil.mfcc_origin.s_addr)) - return 1; - + struct channel_oil *c1 = (struct channel_oil *)cc1; + struct channel_oil *c2 = (struct channel_oil *)cc2; + int rv; + + rv = pim_addr_cmp(*oil_mcastgrp(c1), *oil_mcastgrp(c2)); + if (rv) + return rv; + rv = pim_addr_cmp(*oil_origin(c1), *oil_origin(c2)); + if (rv) + return rv; return 0; } @@ -109,8 +103,8 @@ struct channel_oil *pim_find_channel_oil(struct pim_instance *pim, struct channel_oil *c_oil = NULL; struct channel_oil lookup; - lookup.oil.mfcc_mcastgrp = sg->grp; - lookup.oil.mfcc_origin = sg->src; + *oil_mcastgrp(&lookup) = sg->grp; + *oil_origin(&lookup) = sg->src; c_oil = rb_pim_oil_find(&pim->channel_oil_head, &lookup); @@ -151,10 +145,10 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, c_oil = XCALLOC(MTYPE_PIM_CHANNEL_OIL, sizeof(*c_oil)); - c_oil->oil.mfcc_mcastgrp = sg->grp; - c_oil->oil.mfcc_origin = sg->src; + *oil_mcastgrp(c_oil) = sg->grp; + *oil_origin(c_oil) = sg->src; - c_oil->oil.mfcc_parent = MAXVIFS; + *oil_parent(c_oil) = MAXVIFS; c_oil->oil_ref_count = 1; c_oil->installed = 0; c_oil->up = pim_upstream_find(pim, sg); @@ -172,8 +166,8 @@ struct channel_oil *pim_channel_oil_del(struct channel_oil *c_oil, const char *name) { if (PIM_DEBUG_MROUTE) { - pim_sgaddr sg = {.src = c_oil->oil.mfcc_mcastgrp, - .grp = c_oil->oil.mfcc_origin}; + pim_sgaddr sg = {.src = *oil_mcastgrp(c_oil), + .grp = *oil_origin(c_oil)}; zlog_debug( "%s(%s): Del oil for %pSG, Ref Count: %d (Predecrement)", @@ -228,23 +222,15 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, */ if (!(channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask)) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: no existing protocol mask %u(%u) for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", + "%s %s: no existing protocol mask %u(%u) for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, proto_mask, channel_oil ->oif_flags[pim_ifp->mroute_vif_index], oif->name, pim_ifp->mroute_vif_index, - channel_oil->oil - .mfcc_ttls[pim_ifp->mroute_vif_index], - source_str, group_str); + oil_if_has(channel_oil, pim_ifp->mroute_vif_index), + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } return 0; } @@ -254,44 +240,29 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & PIM_OIF_FLAG_PROTO_ANY) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: other protocol masks remain for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", + "%s %s: other protocol masks remain for requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, oif->name, pim_ifp->mroute_vif_index, - channel_oil->oil - .mfcc_ttls[pim_ifp->mroute_vif_index], - source_str, group_str); + oil_if_has(channel_oil, pim_ifp->mroute_vif_index), + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } return 0; } - channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = 0; + oil_if_set(channel_oil, pim_ifp->mroute_vif_index, false); /* clear mute; will be re-evaluated when the OIF becomes valid again */ channel_oil->oif_flags[pim_ifp->mroute_vif_index] &= ~PIM_OIF_FLAG_MUTE; if (pim_upstream_mroute_add(channel_oil, __func__)) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: could not remove output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", + "%s %s: could not remove output interface %s (vif_index=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, oif->name, - pim_ifp->mroute_vif_index, source_str, - group_str); + pim_ifp->mroute_vif_index, + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } return -1; } @@ -299,16 +270,12 @@ int pim_channel_del_oif(struct channel_oil *channel_oil, struct interface *oif, --channel_oil->oil_size; if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, - source_str, sizeof(source_str)); zlog_debug( - "%s(%s): (S,G)=(%s,%s): proto_mask=%u IIF:%d OIF=%s vif_index=%d", - __func__, caller, source_str, group_str, proto_mask, - channel_oil->oil.mfcc_parent, oif->name, + "%s(%s): (S,G)=(%pPAs,%pPAs): proto_mask=%u IIF:%d OIF=%s vif_index=%d", + __func__, caller, oil_origin(channel_oil), + oil_mcastgrp(channel_oil), + proto_mask, + *oil_parent(channel_oil), oif->name, pim_ifp->mroute_vif_index); } @@ -397,7 +364,7 @@ void pim_channel_update_oif_mute(struct channel_oil *c_oil, bool new_mute; /* If pim_ifp is not a part of the OIL there is nothing to do */ - if (!c_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index]) + if (!oil_if_has(c_oil, pim_ifp->mroute_vif_index)) return; old_mute = !!(c_oil->oif_flags[pim_ifp->mroute_vif_index] & @@ -455,21 +422,13 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, channel (S,G) multiple times */ if (channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", + "%s %s: existing protocol mask %u requested OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, proto_mask, oif->name, pim_ifp->mroute_vif_index, - channel_oil->oil - .mfcc_ttls[pim_ifp->mroute_vif_index], - source_str, group_str); + oil_if_has(channel_oil, pim_ifp->mroute_vif_index), + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } return -3; } @@ -487,36 +446,21 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask; /* Check the OIF really exists before returning, and only log warning otherwise */ - if (channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] < 1) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); + if (oil_if_has(channel_oil, pim_ifp->mroute_vif_index) < 1) { zlog_warn( - "%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%s,%s)", + "%s %s: new protocol mask %u requested nonexistent OIF %s (vif_index=%d, min_ttl=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, proto_mask, oif->name, pim_ifp->mroute_vif_index, - channel_oil->oil - .mfcc_ttls[pim_ifp->mroute_vif_index], - source_str, group_str); + oil_if_has(channel_oil, pim_ifp->mroute_vif_index), + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s(%s): (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d added to 0x%x", - __func__, caller, source_str, group_str, + "%s(%s): (S,G)=(%pPAs,%pPAs): proto_mask=%u OIF=%s vif_index=%d added to 0x%x", + __func__, caller, oil_origin(channel_oil), + oil_mcastgrp(channel_oil), proto_mask, oif->name, pim_ifp->mroute_vif_index, channel_oil @@ -525,29 +469,21 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, return 0; } - old_ttl = channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index]; + old_ttl = oil_if_has(channel_oil, pim_ifp->mroute_vif_index); if (old_ttl > 0) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%s,%s)", + "%s %s: interface %s (vif_index=%d) is existing output for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, oif->name, - pim_ifp->mroute_vif_index, source_str, - group_str); + pim_ifp->mroute_vif_index, + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } return -4; } - channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] = - PIM_MROUTE_MIN_TTL; + oil_if_set(channel_oil, pim_ifp->mroute_vif_index, PIM_MROUTE_MIN_TTL); /* Some OIFs are held in a muted state i.e. the PIM state machine * decided to include the OIF but additional status check such as @@ -564,26 +500,19 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, /* channel_oil->oil.mfcc_parent != MAXVIFS indicate this entry is not * valid to get installed in kernel. */ - if (channel_oil->oil.mfcc_parent != MAXVIFS) { + if (*oil_parent(channel_oil) != MAXVIFS) { if (pim_upstream_mroute_add(channel_oil, __func__)) { if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", - channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", - channel_oil->oil.mfcc_origin, source_str, - sizeof(source_str)); zlog_debug( - "%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%s,%s)", + "%s %s: could not add output interface %s (vif_index=%d) for channel (S,G)=(%pPAs,%pPAs)", __FILE__, __func__, oif->name, - pim_ifp->mroute_vif_index, source_str, - group_str); + pim_ifp->mroute_vif_index, + oil_origin(channel_oil), + oil_mcastgrp(channel_oil)); } - channel_oil->oil.mfcc_ttls[pim_ifp->mroute_vif_index] - = old_ttl; + oil_if_set(channel_oil, pim_ifp->mroute_vif_index, + old_ttl); return -5; } } @@ -594,15 +523,11 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask; if (PIM_DEBUG_MROUTE) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, - group_str, sizeof(group_str)); - pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, - source_str, sizeof(source_str)); zlog_debug( - "%s(%s): (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE", - __func__, caller, source_str, group_str, proto_mask, + "%s(%s): (S,G)=(%pPAs,%pPAs): proto_mask=%u OIF=%s vif_index=%d: DONE", + __func__, caller, oil_origin(channel_oil), + oil_mcastgrp(channel_oil), + proto_mask, oif->name, pim_ifp->mroute_vif_index); } @@ -611,8 +536,6 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, int pim_channel_oil_empty(struct channel_oil *c_oil) { - static struct mfcctl null_oil; - if (!c_oil) return 1; @@ -620,6 +543,13 @@ int pim_channel_oil_empty(struct channel_oil *c_oil) * non-NULL. * pimreg device (in all vrfs) uses a vifi of * 0 (PIM_OIF_PIM_REGISTER_VIF) so we simply mfcc_ttls[0] */ +#if PIM_IPV == 4 + static pim_mfcctl null_oil; + return !memcmp(&c_oil->oil.mfcc_ttls[1], &null_oil.mfcc_ttls[1], sizeof(null_oil.mfcc_ttls) - sizeof(null_oil.mfcc_ttls[0])); +#else + CPP_NOTICE("FIXME STUB"); + return false; +#endif } diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h index 696ef70645..a52e23351e 100644 --- a/pimd/pim_oil.h +++ b/pimd/pim_oil.h @@ -98,7 +98,7 @@ struct channel_oil { struct rb_pim_oil_item oil_rb; - struct mfcctl oil; + pim_mfcctl oil; int installed; int oil_inherited_rescan; int oil_size; @@ -110,6 +110,61 @@ struct channel_oil { time_t mroute_creation; }; +#if PIM_IPV == 4 +static inline pim_addr *oil_origin(struct channel_oil *c_oil) +{ + return &c_oil->oil.mfcc_origin; +} + +static inline pim_addr *oil_mcastgrp(struct channel_oil *c_oil) +{ + return &c_oil->oil.mfcc_mcastgrp; +} + +static inline vifi_t *oil_parent(struct channel_oil *c_oil) +{ + return &c_oil->oil.mfcc_parent; +} + +static inline uint8_t oil_if_has(struct channel_oil *c_oil, vifi_t ifi) +{ + return c_oil->oil.mfcc_ttls[ifi]; +} + +static inline void oil_if_set(struct channel_oil *c_oil, vifi_t ifi, uint8_t set) +{ + c_oil->oil.mfcc_ttls[ifi] = set; +} +#else +static inline pim_addr *oil_origin(struct channel_oil *c_oil) +{ + return &c_oil->oil.mf6cc_origin.sin6_addr; +} + +static inline pim_addr *oil_mcastgrp(struct channel_oil *c_oil) +{ + return &c_oil->oil.mf6cc_mcastgrp.sin6_addr; +} + +static inline mifi_t *oil_parent(struct channel_oil *c_oil) +{ + return &c_oil->oil.mf6cc_parent; +} + +static inline bool oil_if_has(struct channel_oil *c_oil, mifi_t ifi) +{ + return !!IF_ISSET(ifi, &c_oil->oil.mf6cc_ifset); +} + +static inline void oil_if_set(struct channel_oil *c_oil, mifi_t ifi, bool set) +{ + if (set) + IF_SET(ifi, &c_oil->oil.mf6cc_ifset); + else + IF_CLR(ifi, &c_oil->oil.mf6cc_ifset); +} +#endif + extern int pim_channel_oil_compare(const struct channel_oil *c1, const struct channel_oil *c2); DECLARE_RBTREE_UNIQ(rb_pim_oil, struct channel_oil, oil_rb, diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 93ccfd78df..5cc0d63e31 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -42,7 +42,7 @@ #include "pim_errors.h" #include "pim_bsm.h" -static int on_pim_hello_send(struct thread *t); +static void on_pim_hello_send(struct thread *t); static const char *pim_pim_msgtype2str(enum pim_msg_type type) { @@ -326,7 +326,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) static void pim_sock_read_on(struct interface *ifp); -static int pim_sock_read(struct thread *t) +static void pim_sock_read(struct thread *t) { struct interface *ifp, *orig_ifp; struct pim_interface *pim_ifp; @@ -398,8 +398,6 @@ done: if (result) { ++pim_ifp->pim_ifstat_hello_recvfail; } - - return result; } static void pim_sock_read_on(struct interface *ifp) @@ -745,7 +743,7 @@ static void hello_resched(struct interface *ifp) /* Periodic hello timer */ -static int on_pim_hello_send(struct thread *t) +static void on_pim_hello_send(struct thread *t) { struct pim_interface *pim_ifp; struct interface *ifp; @@ -761,7 +759,7 @@ static int on_pim_hello_send(struct thread *t) /* * Send hello */ - return pim_hello_send(ifp, PIM_IF_DEFAULT_HOLDTIME(pim_ifp)); + pim_hello_send(ifp, PIM_IF_DEFAULT_HOLDTIME(pim_ifp)); } /* diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index a5183c9e9b..06b2216072 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -122,9 +122,7 @@ void pim_rp_init(struct pim_instance *pim) return; } rp_info->group.family = AF_INET; - rp_info->rp.rpf_addr.family = AF_INET; - rp_info->rp.rpf_addr.prefixlen = IPV4_MAX_BITLEN; - rp_info->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE; + pim_addr_to_prefix(&rp_info->rp.rpf_addr, PIMADDR_ANY); listnode_add(pim->rp_list, rp_info); @@ -414,9 +412,8 @@ void pim_upstream_update(struct pim_instance *pim, struct pim_upstream *up) } -int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, - struct prefix group, const char *plist, - enum rp_source rp_src_flag) +int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, struct prefix group, + const char *plist, enum rp_source rp_src_flag) { int result = 0; char rp[INET_ADDRSTRLEN]; @@ -431,8 +428,7 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, struct pim_upstream *up; bool upstream_updated = false; - if (rp_addr.s_addr == INADDR_ANY || - rp_addr.s_addr == INADDR_NONE) + if (rp_addr.s_addr == INADDR_ANY) return PIM_RP_BAD_ADDRESS; rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); @@ -514,10 +510,10 @@ int pim_rp_new(struct pim_instance *pim, struct in_addr rp_addr, } /* - * Take over the 224.0.0.0/4 group if the rp is INADDR_NONE + * Take over the 224.0.0.0/4 group if the rp is INADDR_ANY */ - if (prefix_same(&rp_all->group, &rp_info->group) - && pim_rpf_addr_is_inaddr_none(&rp_all->rp)) { + if (prefix_same(&rp_all->group, &rp_info->group) && + pim_rpf_addr_is_inaddr_any(&rp_all->rp)) { rp_all->rp.rpf_addr = rp_info->rp.rpf_addr; rp_all->rp_src = rp_src_flag; XFREE(MTYPE_PIM_RP, rp_info); @@ -789,8 +785,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, } } } - rp_all->rp.rpf_addr.family = AF_INET; - rp_all->rp.rpf_addr.u.prefix4.s_addr = INADDR_NONE; + pim_addr_to_prefix(&rp_all->rp.rpf_addr, PIMADDR_ANY); rp_all->i_am_rp = 0; return PIM_SUCCESS; } @@ -834,7 +829,7 @@ int pim_rp_del(struct pim_instance *pim, struct in_addr rp_addr, trp_info = pim_rp_find_match_group(pim, &grp); /* RP not found for the group grp */ - if (pim_rpf_addr_is_inaddr_none(&trp_info->rp)) { + if (pim_rpf_addr_is_inaddr_any(&trp_info->rp)) { pim_upstream_rpf_clear(pim, up); pim_rp_set_upstream_addr( pim, &up->upstream_addr, up->sg.src, @@ -956,7 +951,7 @@ void pim_rp_setup(struct pim_instance *pim) struct prefix nht_p; for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (rp_info->rp.rpf_addr.u.prefix4.s_addr == INADDR_NONE) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; nht_p.family = AF_INET; @@ -987,7 +982,7 @@ void pim_rp_check_on_if_add(struct pim_interface *pim_ifp) return; for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (pim_rpf_addr_is_inaddr_none(&rp_info->rp)) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; /* if i_am_rp is already set nothing to be done (adding new @@ -1029,7 +1024,7 @@ void pim_i_am_rp_re_evaluate(struct pim_instance *pim) return; for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (pim_rpf_addr_is_inaddr_none(&rp_info->rp)) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; old_i_am_rp = rp_info->i_am_rp; @@ -1142,8 +1137,8 @@ int pim_rp_set_upstream_addr(struct pim_instance *pim, pim_addr *up, rp_info = pim_rp_find_match_group(pim, &g); - if (!rp_info || ((pim_rpf_addr_is_inaddr_none(&rp_info->rp)) - && (source.s_addr == INADDR_ANY))) { + if (!rp_info || ((pim_rpf_addr_is_inaddr_any(&rp_info->rp)) && + (source.s_addr == INADDR_ANY))) { if (PIM_DEBUG_PIM_NHT_RP) zlog_debug("%s: Received a (*,G) with no RP configured", __func__); @@ -1185,7 +1180,7 @@ int pim_rp_config_write(struct pim_instance *pim, struct vty *vty, int count = 0; for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (pim_rpf_addr_is_inaddr_none(&rp_info->rp)) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; if (rp_info->rp_src == RP_SRC_BSR) @@ -1227,7 +1222,7 @@ void pim_rp_show_information(struct pim_instance *pim, struct vty *vty, bool uj) vty_out(vty, "RP address group/prefix-list OIF I am RP Source\n"); for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (!pim_rpf_addr_is_inaddr_none(&rp_info->rp)) { + if (!pim_rpf_addr_is_inaddr_any(&rp_info->rp)) { char buf[48]; if (rp_info->rp_src == RP_SRC_STATIC) @@ -1345,7 +1340,7 @@ void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr) struct pim_nexthop_cache pnc; for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) { - if (rp_info->rp.rpf_addr.u.prefix4.s_addr == INADDR_NONE) + if (pim_rpf_addr_is_inaddr_any(&rp_info->rp)) continue; nht_p.family = AF_INET; @@ -1366,7 +1361,7 @@ void pim_resolve_rp_nh(struct pim_instance *pim, struct pim_neighbor *nbr) if (nbr->interface != ifp1) continue; -#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) +#if PIM_IPV == 4 nh_node->gate.ipv4 = nbr->source_addr; #else nh_node->gate.ipv6 = nbr->source_addr; diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 2e8fc8e661..a99f5536b7 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -39,7 +39,7 @@ #include "pim_oil.h" #include "pim_mlag.h" -static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up); +static pim_addr pim_rpf_find_rpf_addr(struct pim_upstream *up); void pim_rpf_set_refresh_time(struct pim_instance *pim) { @@ -51,7 +51,7 @@ void pim_rpf_set_refresh_time(struct pim_instance *pim) } bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, - struct in_addr addr, int neighbor_needed) + pim_addr addr, int neighbor_needed) { struct pim_zlookup_nexthop nexthop_tab[MULTIPATH_NUM]; struct pim_neighbor *nbr = NULL; @@ -61,40 +61,35 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, int found = 0; int i = 0; +#if PIM_IPV == 4 /* * We should not attempt to lookup a * 255.255.255.255 address, since * it will never work */ - if (addr.s_addr == INADDR_NONE) + if (pim_addr_is_any(addr)) return false; +#endif - if ((nexthop->last_lookup.s_addr == addr.s_addr) + if (!pim_addr_cmp(nexthop->last_lookup, addr) && (nexthop->last_lookup_time > pim->last_route_change_time)) { if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); char nexthop_str[PREFIX_STRLEN]; pim_addr_dump("<nexthop?>", &nexthop->mrib_nexthop_addr, nexthop_str, sizeof(nexthop_str)); zlog_debug( - "%s: Using last lookup for %s at %lld, %" PRId64" addr %s", - __func__, addr_str, nexthop->last_lookup_time, + "%s: Using last lookup for %pPAs at %lld, %" PRId64" addr %s", + __func__, &addr, nexthop->last_lookup_time, pim->last_route_change_time, nexthop_str); } pim->nexthop_lookups_avoided++; return true; } else { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: Looking up: %s, last lookup time: %lld, %" PRId64, - __func__, addr_str, nexthop->last_lookup_time, + "%s: Looking up: %pPAs, last lookup time: %lld, %" PRId64, + __func__, &addr, nexthop->last_lookup_time, pim->last_route_change_time); - } } memset(nexthop_tab, 0, @@ -102,11 +97,9 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, num_ifindex = zclient_lookup_nexthop(pim, nexthop_tab, MULTIPATH_NUM, addr, PIM_NEXTHOP_LOOKUP_MAX); if (num_ifindex < 1) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_warn( - "%s %s: could not find nexthop ifindex for address %s", - __FILE__, __func__, addr_str); + "%s %s: could not find nexthop ifindex for address %pPAs", + __FILE__, __func__, &addr); return false; } @@ -115,29 +108,21 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id); if (!ifp) { - if (PIM_DEBUG_ZEBRA) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_ZEBRA) zlog_debug( - "%s %s: could not find interface for ifindex %d (address %s)", + "%s %s: could not find interface for ifindex %d (address %pPAs)", __FILE__, __func__, first_ifindex, - addr_str); - } + &addr); i++; continue; } if (!ifp->info) { - if (PIM_DEBUG_ZEBRA) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_ZEBRA) zlog_debug( - "%s: multicast not enabled on input interface %s (ifindex=%d, RPF for source %s)", + "%s: multicast not enabled on input interface %s (ifindex=%d, RPF for source %pPAs)", __func__, ifp->name, first_ifindex, - addr_str); - } + &addr); i++; } else if (neighbor_needed && !pim_if_connected_to_source(ifp, addr)) { @@ -157,15 +142,12 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, if (found) { if (PIM_DEBUG_ZEBRA) { char nexthop_str[PREFIX_STRLEN]; - char addr_str[INET_ADDRSTRLEN]; pim_addr_dump("<nexthop?>", &nexthop_tab[i].nexthop_addr, nexthop_str, sizeof(nexthop_str)); - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); zlog_debug( - "%s %s: found nexthop %s for address %s: interface %s ifindex=%d metric=%d pref=%d", - __FILE__, __func__, nexthop_str, addr_str, + "%s %s: found nexthop %s for address %pPAs: interface %s ifindex=%d metric=%d pref=%d", + __FILE__, __func__, nexthop_str, &addr, ifp->name, first_ifindex, nexthop_tab[i].route_metric, nexthop_tab[i].protocol_distance); @@ -187,11 +169,13 @@ bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, static int nexthop_mismatch(const struct pim_nexthop *nh1, const struct pim_nexthop *nh2) { - return (nh1->interface != nh2->interface) - || (nh1->mrib_nexthop_addr.u.prefix4.s_addr - != nh2->mrib_nexthop_addr.u.prefix4.s_addr) - || (nh1->mrib_metric_preference != nh2->mrib_metric_preference) - || (nh1->mrib_route_metric != nh2->mrib_route_metric); + pim_addr nh_addr1 = pim_addr_from_prefix(&nh1->mrib_nexthop_addr); + pim_addr nh_addr2 = pim_addr_from_prefix(&nh2->mrib_nexthop_addr); + + return (nh1->interface != nh2->interface) || + (pim_addr_cmp(nh_addr1, nh_addr2)) || + (nh1->mrib_metric_preference != nh2->mrib_metric_preference) || + (nh1->mrib_route_metric != nh2->mrib_route_metric); } static void pim_rpf_cost_change(struct pim_instance *pim, @@ -230,6 +214,8 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, struct prefix src, grp; bool neigh_needed = true; uint32_t saved_mrib_route_metric; + pim_addr rpf_addr; + pim_addr saved_rpf_addr; if (PIM_UPSTREAM_FLAG_TEST_STATIC_IIF(up->flags)) return PIM_RPF_OK; @@ -265,8 +251,9 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, return PIM_RPF_FAILURE; } - rpf->rpf_addr.family = AF_INET; - rpf->rpf_addr.u.prefix4 = pim_rpf_find_rpf_addr(up); + rpf_addr = pim_rpf_find_rpf_addr(up); + pim_addr_to_prefix(&rpf->rpf_addr, rpf_addr); + if (pim_rpf_addr_is_inaddr_any(rpf) && PIM_DEBUG_ZEBRA) { /* RPF'(S,G) not found */ zlog_debug("%s(%s): RPF'%s not found: won't send join upstream", @@ -313,9 +300,11 @@ enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, } /* detect change in RPF'(S,G) */ - if (saved.rpf_addr.u.prefix4.s_addr != rpf->rpf_addr.u.prefix4.s_addr - || saved.source_nexthop - .interface != rpf->source_nexthop.interface) { + + saved_rpf_addr = pim_addr_from_prefix(&saved.rpf_addr); + + if (pim_addr_cmp(saved_rpf_addr, rpf_addr) || + saved.source_nexthop.interface != rpf->source_nexthop.interface) { pim_rpf_cost_change(pim, up, saved_mrib_route_metric); return PIM_RPF_CHANGED; } @@ -343,13 +332,13 @@ void pim_upstream_rpf_clear(struct pim_instance *pim, if (up->rpf.source_nexthop.interface) { pim_upstream_switch(pim, up, PIM_UPSTREAM_NOTJOINED); up->rpf.source_nexthop.interface = NULL; - up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr = - PIM_NET_INADDR_ANY; + pim_addr_to_prefix(&up->rpf.source_nexthop.mrib_nexthop_addr, + PIMADDR_ANY); up->rpf.source_nexthop.mrib_metric_preference = router->infinite_assert_metric.metric_preference; up->rpf.source_nexthop.mrib_route_metric = router->infinite_assert_metric.route_metric; - up->rpf.rpf_addr.u.prefix4.s_addr = PIM_NET_INADDR_ANY; + pim_addr_to_prefix(&up->rpf.rpf_addr, PIMADDR_ANY); pim_upstream_mroute_iif_update(up->channel_oil, __func__); } } @@ -369,18 +358,17 @@ void pim_upstream_rpf_clear(struct pim_instance *pim, packets should be coming and to which joins should be sent on the RP tree and SPT, respectively. */ -static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) +static pim_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) { struct pim_ifchannel *rpf_ch; struct pim_neighbor *neigh; - struct in_addr rpf_addr; + pim_addr rpf_addr; if (!up->rpf.source_nexthop.interface) { zlog_warn("%s: missing RPF interface for upstream (S,G)=%s", __func__, up->sg_str); - rpf_addr.s_addr = PIM_NET_INADDR_ANY; - return rpf_addr; + return PIMADDR_ANY; } rpf_ch = pim_ifchannel_find(up->rpf.source_nexthop.interface, &up->sg); @@ -400,32 +388,19 @@ static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) if (neigh) rpf_addr = neigh->source_addr; else - rpf_addr.s_addr = PIM_NET_INADDR_ANY; + rpf_addr = PIMADDR_ANY; return rpf_addr; } -int pim_rpf_addr_is_inaddr_none(struct pim_rpf *rpf) -{ - switch (rpf->rpf_addr.family) { - case AF_INET: - return rpf->rpf_addr.u.prefix4.s_addr == INADDR_NONE; - case AF_INET6: - zlog_warn("%s: v6 Unimplmeneted", __func__); - return 1; - default: - return 0; - } -} - int pim_rpf_addr_is_inaddr_any(struct pim_rpf *rpf) { + pim_addr rpf_addr = pim_addr_from_prefix(&rpf->rpf_addr); + switch (rpf->rpf_addr.family) { case AF_INET: - return rpf->rpf_addr.u.prefix4.s_addr == INADDR_ANY; case AF_INET6: - zlog_warn("%s: v6 Unimplmented", __func__); - return 1; + return pim_addr_is_any(rpf_addr); default: return 0; } @@ -443,7 +418,12 @@ unsigned int pim_rpf_hash_key(const void *arg) { const struct pim_nexthop_cache *r = arg; +#if PIM_IPV == 4 || !defined(PIM_V6_TEMP_BREAK) return jhash_1word(r->rpf.rpf_addr.u.prefix4.s_addr, 0); +#else + return jhash2(r->rpf.rpf_addr.u.prefix6.s6_addr32, + array_size(r->rpf.rpf_addr.u.prefix6.s6_addr32), 0); +#endif } bool pim_rpf_equal(const void *arg1, const void *arg2) diff --git a/pimd/pim_rpf.h b/pimd/pim_rpf.h index d6a8880ffb..74aca43d54 100644 --- a/pimd/pim_rpf.h +++ b/pimd/pim_rpf.h @@ -58,13 +58,12 @@ unsigned int pim_rpf_hash_key(const void *arg); bool pim_rpf_equal(const void *arg1, const void *arg2); bool pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, - struct in_addr addr, int neighbor_needed); + pim_addr addr, int neighbor_needed); enum pim_rpf_result pim_rpf_update(struct pim_instance *pim, struct pim_upstream *up, struct pim_rpf *old, const char *caller); void pim_upstream_rpf_clear(struct pim_instance *pim, struct pim_upstream *up); -int pim_rpf_addr_is_inaddr_none(struct pim_rpf *rpf); int pim_rpf_addr_is_inaddr_any(struct pim_rpf *rpf); int pim_rpf_is_same(struct pim_rpf *rpf1, struct pim_rpf *rpf2); diff --git a/pimd/pim_ssm.c b/pimd/pim_ssm.c index 45aac7756a..688d38c84c 100644 --- a/pimd/pim_ssm.c +++ b/pimd/pim_ssm.c @@ -32,6 +32,7 @@ static void pim_ssm_range_reevaluate(struct pim_instance *pim) { +#if PIM_IPV == 4 /* 1. Setup register state for (S,G) entries if G has changed from SSM * to * ASM. @@ -50,6 +51,7 @@ static void pim_ssm_range_reevaluate(struct pim_instance *pim) */ pim_upstream_register_reevaluate(pim); igmp_source_forward_reevaluate_all(pim); +#endif } void pim_ssm_prefix_list_update(struct pim_instance *pim, diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index abd95e648e..596b06cb38 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -315,19 +315,16 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) return 0; } -static int ssmpingd_sock_read(struct thread *t) +static void ssmpingd_sock_read(struct thread *t) { struct ssmpingd_sock *ss; - int result; ss = THREAD_ARG(t); - result = ssmpingd_read_msg(ss); + ssmpingd_read_msg(ss); /* Keep reading */ ssmpingd_read_on(ss); - - return result; } static void ssmpingd_read_on(struct ssmpingd_sock *ss) diff --git a/pimd/pim_static.c b/pimd/pim_static.c index be06a25bea..d3b31771a0 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -43,8 +43,8 @@ static struct static_route *static_route_alloc(void) } static struct static_route *static_route_new(ifindex_t iif, ifindex_t oif, - struct in_addr group, - struct in_addr source) + pim_addr group, + pim_addr source) { struct static_route *s_route; s_route = static_route_alloc(); @@ -54,10 +54,10 @@ static struct static_route *static_route_new(ifindex_t iif, ifindex_t oif, s_route->iif = iif; s_route->oif_ttls[oif] = 1; s_route->c_oil.oil_ref_count = 1; - s_route->c_oil.oil.mfcc_origin = source; - s_route->c_oil.oil.mfcc_mcastgrp = group; - s_route->c_oil.oil.mfcc_parent = iif; - s_route->c_oil.oil.mfcc_ttls[oif] = 1; + *oil_origin(&s_route->c_oil) = source; + *oil_mcastgrp(&s_route->c_oil) = group; + *oil_parent(&s_route->c_oil) = iif; + oil_if_set(&s_route->c_oil, oif, 1); s_route->c_oil.oif_creation[oif] = pim_time_monotonic_sec(); return s_route; @@ -65,8 +65,7 @@ static struct static_route *static_route_new(ifindex_t iif, ifindex_t oif, int pim_static_add(struct pim_instance *pim, struct interface *iif, - struct interface *oif, struct in_addr group, - struct in_addr source) + struct interface *oif, pim_addr group, pim_addr source) { struct listnode *node = NULL; struct static_route *s_route = NULL; @@ -97,20 +96,14 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, } for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) { - if (s_route->group.s_addr == group.s_addr - && s_route->source.s_addr == source.s_addr) { + if (!pim_addr_cmp(s_route->group, group) + && !pim_addr_cmp(s_route->source, source)) { if (s_route->iif == iif_index && s_route->oif_ttls[oif_index]) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_warn( - "%s %s: Unable to add static route: Route already exists (iif=%d,oif=%d,group=%s,source=%s)", + "%s %s: Unable to add static route: Route already exists (iif=%d,oif=%d,group=%pPAs,source=%pPAs)", __FILE__, __func__, iif_index, - oif_index, gifaddr_str, sifaddr_str); + oif_index, &group, &source); return -3; } @@ -130,7 +123,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, * adding a new output interface */ if (s_route->iif == iif_index) { s_route->oif_ttls[oif_index] = 1; - s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; + oil_if_set(&s_route->c_oil, oif_index, 1); s_route->c_oil.oif_creation[oif_index] = pim_time_monotonic_sec(); ++s_route->c_oil.oil_ref_count; @@ -147,8 +140,8 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, s_route->oif_ttls[iif_index] = 0; s_route->c_oil.oif_creation[iif_index] = 0; - s_route->c_oil.oil - .mfcc_ttls[iif_index] = 0; + oil_if_set(&s_route->c_oil, iif_index, + 0); --s_route->c_oil.oil_ref_count; } #endif @@ -158,8 +151,8 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, s_route->oif_ttls[oif_index] = 1; s_route->c_oil.oif_creation[oif_index] = pim_time_monotonic_sec(); - s_route->c_oil.oil - .mfcc_ttls[oif_index] = 1; + oil_if_set(&s_route->c_oil, oif_index, + 1); ++s_route->c_oil.oil_ref_count; } } @@ -178,16 +171,10 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, s_route->c_oil.pim = pim; if (pim_static_mroute_add(&s_route->c_oil, __func__)) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_warn( - "%s %s: Unable to add static route(iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __func__, iif_index, oif_index, gifaddr_str, - sifaddr_str); + "%s %s: Unable to add static route(iif=%d,oif=%d,group=%pPAs,source=%pPAs)", + __FILE__, __func__, iif_index, oif_index, &group, + &source); /* Need to put s_route back to the way it was */ if (original_s_route) { @@ -213,24 +200,17 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, } if (PIM_DEBUG_STATIC) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_debug( - "%s: Static route added(iif=%d,oif=%d,group=%s,source=%s)", - __func__, iif_index, oif_index, gifaddr_str, - sifaddr_str); + "%s: Static route added(iif=%d,oif=%d,group=%pPAs,source=%pPAs)", + __func__, iif_index, oif_index, &group, + &source); } return 0; } int pim_static_del(struct pim_instance *pim, struct interface *iif, - struct interface *oif, struct in_addr group, - struct in_addr source) + struct interface *oif, pim_addr group, pim_addr source) { struct listnode *node = NULL; struct listnode *nextnode = NULL; @@ -249,11 +229,11 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, for (ALL_LIST_ELEMENTS(pim->static_routes, node, nextnode, s_route)) { if (s_route->iif == iif_index - && s_route->group.s_addr == group.s_addr - && s_route->source.s_addr == source.s_addr + && !pim_addr_cmp(s_route->group, group) + && !pim_addr_cmp(s_route->source, source) && s_route->oif_ttls[oif_index]) { s_route->oif_ttls[oif_index] = 0; - s_route->c_oil.oil.mfcc_ttls[oif_index] = 0; + oil_if_set(&s_route->c_oil, oif_index, 0); --s_route->c_oil.oil_ref_count; /* If there are no more outputs then delete the whole @@ -263,19 +243,13 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, ? pim_mroute_del(&s_route->c_oil, __func__) : pim_static_mroute_add(&s_route->c_oil, __func__)) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_warn( - "%s %s: Unable to remove static route(iif=%d,oif=%d,group=%s,source=%s)", + "%s %s: Unable to remove static route(iif=%d,oif=%d,group=%pPAs,source=%pPAs)", __FILE__, __func__, iif_index, - oif_index, gifaddr_str, sifaddr_str); + oif_index, &group, &source); s_route->oif_ttls[oif_index] = 1; - s_route->c_oil.oil.mfcc_ttls[oif_index] = 1; + oil_if_set(&s_route->c_oil, oif_index, 1); ++s_route->c_oil.oil_ref_count; return -1; @@ -289,16 +263,10 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, } if (PIM_DEBUG_STATIC) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_debug( - "%s: Static route removed(iif=%d,oif=%d,group=%s,source=%s)", + "%s: Static route removed(iif=%d,oif=%d,group=%pPAs,source=%pPAs)", __func__, iif_index, oif_index, - gifaddr_str, sifaddr_str); + &group, &source); } break; @@ -306,16 +274,10 @@ int pim_static_del(struct pim_instance *pim, struct interface *iif, } if (!node) { - char gifaddr_str[INET_ADDRSTRLEN]; - char sifaddr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<ifaddr?>", group, gifaddr_str, - sizeof(gifaddr_str)); - pim_inet4_dump("<ifaddr?>", source, sifaddr_str, - sizeof(sifaddr_str)); zlog_warn( - "%s %s: Unable to remove static route: Route does not exist(iif=%d,oif=%d,group=%s,source=%s)", - __FILE__, __func__, iif_index, oif_index, gifaddr_str, - sifaddr_str); + "%s %s: Unable to remove static route: Route does not exist(iif=%d,oif=%d,group=%pPAs,source=%pPAs)", + __FILE__, __func__, iif_index, oif_index, &group, + &source); return -3; } @@ -329,15 +291,11 @@ int pim_static_write_mroute(struct pim_instance *pim, struct vty *vty, struct listnode *node; struct static_route *sroute; int count = 0; - char sbuf[INET_ADDRSTRLEN]; - char gbuf[INET_ADDRSTRLEN]; if (!pim_ifp) return 0; for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, sroute)) { - pim_inet4_dump("<ifaddr?>", sroute->group, gbuf, sizeof(gbuf)); - pim_inet4_dump("<ifaddr?>", sroute->source, sbuf, sizeof(sbuf)); if (sroute->iif == pim_ifp->mroute_vif_index) { int i; for (i = 0; i < MAXVIFS; i++) @@ -345,14 +303,15 @@ int pim_static_write_mroute(struct pim_instance *pim, struct vty *vty, struct interface *oifp = pim_if_find_by_vif_index(pim, i); - if (sroute->source.s_addr == INADDR_ANY) + if (pim_addr_is_any(sroute->source)) vty_out(vty, - " ip mroute %s %s\n", - oifp->name, gbuf); + " " PIM_AF_NAME " mroute %s %pPA\n", + oifp->name, &sroute->group); else vty_out(vty, - " ip mroute %s %s %s\n", - oifp->name, gbuf, sbuf); + " " PIM_AF_NAME " mroute %s %pPA %pPA\n", + oifp->name, &sroute->group, + &sroute->source); count++; } } diff --git a/pimd/pim_static.h b/pimd/pim_static.h index 953ec0a70a..56bfbd4e4f 100644 --- a/pimd/pim_static.h +++ b/pimd/pim_static.h @@ -26,8 +26,8 @@ struct static_route { /* Each static route is unique by these pair of addresses */ - struct in_addr group; - struct in_addr source; + pim_addr group; + pim_addr source; struct channel_oil c_oil; ifindex_t iif; @@ -37,11 +37,9 @@ struct static_route { void pim_static_route_free(struct static_route *s_route); int pim_static_add(struct pim_instance *pim, struct interface *iif, - struct interface *oif, struct in_addr group, - struct in_addr source); + struct interface *oif, pim_addr group, pim_addr source); int pim_static_del(struct pim_instance *pim, struct interface *iif, - struct interface *oif, struct in_addr group, - struct in_addr source); + struct interface *oif, pim_addr group, pim_addr source); int pim_static_write_mroute(struct pim_instance *pim, struct vty *vty, struct interface *ifp); diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index a410a1c2ce..24833f5a63 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -302,7 +302,7 @@ void pim_upstream_send_join(struct pim_upstream *up) pim_jp_agg_single_upstream_send(&up->rpf, up, 1 /* join */); } -static int on_join_timer(struct thread *t) +static void on_join_timer(struct thread *t) { struct pim_upstream *up; @@ -312,14 +312,14 @@ static int on_join_timer(struct thread *t) if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: up %s RPF is not present", __func__, up->sg_str); - return 0; + return; } /* * In the case of a HFR we will not ahve anyone to send this to. */ if (PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) - return 0; + return; /* * Don't send the join if the outgoing interface is a loopback @@ -330,8 +330,6 @@ static int on_join_timer(struct thread *t) pim_upstream_send_join(up); join_timer_start(up); - - return 0; } static void join_timer_stop(struct pim_upstream *up) @@ -424,8 +422,8 @@ void pim_update_suppress_timers(uint32_t suppress_time) } } -void pim_upstream_join_suppress(struct pim_upstream *up, - struct in_addr rpf_addr, int holdtime) +void pim_upstream_join_suppress(struct pim_upstream *up, struct prefix rpf, + int holdtime) { long t_joinsuppress_msec; long join_timer_remain_msec = 0; @@ -457,7 +455,8 @@ void pim_upstream_join_suppress(struct pim_upstream *up, if (PIM_DEBUG_PIM_TRACE) { char rpf_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<rpf?>", rpf_addr, rpf_str, sizeof(rpf_str)); + + pim_addr_dump("<rpf?>", &rpf, rpf_str, sizeof(rpf_str)); zlog_debug( "%s %s: detected Join%s to RPF'(S,G)=%s: join_timer=%ld msec t_joinsuppress=%ld msec", __FILE__, __func__, up->sg_str, rpf_str, @@ -514,8 +513,10 @@ void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, if (PIM_DEBUG_PIM_TRACE) { char rpf_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<rpf?>", up->rpf.rpf_addr.u.prefix4, rpf_str, - sizeof(rpf_str)); + + pim_addr_dump("<rpf?>", &up->rpf.rpf_addr, rpf_str, + sizeof(rpf_str)); + zlog_debug( "%s: to RPF'%s=%s: join_timer=%ld msec t_override=%d msec", debug_label, up->sg_str, rpf_str, @@ -831,9 +832,8 @@ void pim_upstream_fill_static_iif(struct pim_upstream *up, up->rpf.source_nexthop.interface = incoming; /* reset other parameters to matched a connected incoming interface */ - up->rpf.source_nexthop.mrib_nexthop_addr.family = AF_INET; - up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr = - PIM_NET_INADDR_ANY; + pim_addr_to_prefix(&up->rpf.source_nexthop.mrib_nexthop_addr, + PIMADDR_ANY); up->rpf.source_nexthop.mrib_metric_preference = ZEBRA_CONNECT_DISTANCE_DEFAULT; up->rpf.source_nexthop.mrib_route_metric = 0; @@ -893,16 +893,13 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, up->sptbit = PIM_UPSTREAM_SPTBIT_FALSE; up->rpf.source_nexthop.interface = NULL; - up->rpf.source_nexthop.mrib_nexthop_addr.family = AF_INET; - up->rpf.source_nexthop.mrib_nexthop_addr.u.prefix4.s_addr = - PIM_NET_INADDR_ANY; + pim_addr_to_prefix(&up->rpf.source_nexthop.mrib_nexthop_addr, + PIMADDR_ANY); up->rpf.source_nexthop.mrib_metric_preference = router->infinite_assert_metric.metric_preference; up->rpf.source_nexthop.mrib_route_metric = router->infinite_assert_metric.route_metric; - up->rpf.rpf_addr.family = AF_INET; - up->rpf.rpf_addr.u.prefix4.s_addr = PIM_NET_INADDR_ANY; - + pim_addr_to_prefix(&up->rpf.rpf_addr, PIMADDR_ANY); up->ifchannels = list_new(); up->ifchannels->cmp = (int (*)(void *, void *))pim_ifchannel_compare; @@ -962,7 +959,7 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, if (PIM_DEBUG_PIM_TRACE) { zlog_debug( - "%s: Created Upstream %s upstream_addr %pI4 ref count %d increment", + "%s: Created Upstream %s upstream_addr %pPAs ref count %d increment", __func__, up->sg_str, &up->upstream_addr, up->ref_count); } @@ -1263,7 +1260,7 @@ void pim_upstream_update_join_desired(struct pim_instance *pim, it so that it expires after t_override seconds. */ void pim_upstream_rpf_genid_changed(struct pim_instance *pim, - struct in_addr neigh_addr) + pim_addr neigh_addr) { struct pim_upstream *up; @@ -1271,24 +1268,24 @@ void pim_upstream_rpf_genid_changed(struct pim_instance *pim, * Scan all (S,G) upstreams searching for RPF'(S,G)=neigh_addr */ frr_each (rb_pim_upstream, &pim->upstream_head, up) { - if (PIM_DEBUG_PIM_TRACE) { - char rpf_addr_str[PREFIX_STRLEN]; - pim_addr_dump("<rpf?>", &up->rpf.rpf_addr, rpf_addr_str, - sizeof(rpf_addr_str)); + pim_addr rpf_addr; + + rpf_addr = pim_addr_from_prefix(&up->rpf.rpf_addr); + + if (PIM_DEBUG_PIM_TRACE) zlog_debug( - "%s: matching neigh=%pI4 against upstream (S,G)=%s[%s] joined=%d rpf_addr=%s", + "%s: matching neigh=%pPA against upstream (S,G)=%s[%s] joined=%d rpf_addr=%pPA", __func__, &neigh_addr, up->sg_str, pim->vrf->name, up->join_state == PIM_UPSTREAM_JOINED, - rpf_addr_str); - } + &rpf_addr); /* consider only (S,G) upstream in Joined state */ if (up->join_state != PIM_UPSTREAM_JOINED) continue; /* match RPF'(S,G)=neigh_addr */ - if (up->rpf.rpf_addr.u.prefix4.s_addr != neigh_addr.s_addr) + if (pim_addr_cmp(rpf_addr, neigh_addr)) continue; pim_upstream_join_timer_decrease_to_t_override( @@ -1482,7 +1479,7 @@ struct pim_upstream *pim_upstream_keep_alive_timer_proc( return up; } -static int pim_upstream_keep_alive_timer(struct thread *t) +static void pim_upstream_keep_alive_timer(struct thread *t) { struct pim_upstream *up; @@ -1491,10 +1488,9 @@ static int pim_upstream_keep_alive_timer(struct thread *t) /* pull the stats and re-check */ if (pim_upstream_sg_running_proc(up)) /* kat was restarted because of new activity */ - return 0; + return; pim_upstream_keep_alive_timer_proc(up); - return 0; } void pim_upstream_keep_alive_timer_start(struct pim_upstream *up, uint32_t time) @@ -1516,15 +1512,15 @@ void pim_upstream_keep_alive_timer_start(struct pim_upstream *up, uint32_t time) } /* MSDP on RP needs to know if a source is registerable to this RP */ -static int pim_upstream_msdp_reg_timer(struct thread *t) +static void pim_upstream_msdp_reg_timer(struct thread *t) { struct pim_upstream *up = THREAD_ARG(t); struct pim_instance *pim = up->channel_oil->pim; /* source is no longer active - pull the SA from MSDP's cache */ pim_msdp_sa_local_del(pim, &up->sg); - return 1; } + void pim_upstream_msdp_reg_timer_start(struct pim_upstream *up) { THREAD_OFF(up->t_msdp_reg_timer); @@ -1702,7 +1698,7 @@ const char *pim_reg_state2str(enum pim_reg_state reg_state, char *state_str, return state_str; } -static int pim_upstream_register_stop_timer(struct thread *t) +static void pim_upstream_register_stop_timer(struct thread *t) { struct pim_interface *pim_ifp; struct pim_instance *pim; @@ -1735,7 +1731,7 @@ static int pim_upstream_register_stop_timer(struct thread *t) zlog_debug("%s: up %s RPF is not present", __func__, up->sg_str); up->reg_state = PIM_REG_NOINFO; - return 0; + return; } pim_ifp = up->rpf.source_nexthop.interface->info; @@ -1745,7 +1741,7 @@ static int pim_upstream_register_stop_timer(struct thread *t) "%s: Interface: %s is not configured for pim", __func__, up->rpf.source_nexthop.interface->name); - return 0; + return; } up->reg_state = PIM_REG_JOIN_PENDING; pim_upstream_start_register_stop_timer(up, 1); @@ -1757,15 +1753,13 @@ static int pim_upstream_register_stop_timer(struct thread *t) zlog_debug( "%s: Stop sending the register, because I am the RP and we haven't seen a packet in a while", __func__); - return 0; + return; } pim_null_register_send(up); break; case PIM_REG_NOINFO: break; } - - return 0; } void pim_upstream_start_register_stop_timer(struct pim_upstream *up, @@ -1997,7 +1991,7 @@ static bool pim_upstream_kat_start_ok(struct pim_upstream *up) return false; pim_ifp = ifp->info; - if (pim_ifp->mroute_vif_index != c_oil->oil.mfcc_parent) + if (pim_ifp->mroute_vif_index != *oil_parent(c_oil)) return false; if (pim_if_connected_to_source(up->rpf.source_nexthop.interface, diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h index 25ff3bffe7..8feffb8fdb 100644 --- a/pimd/pim_upstream.h +++ b/pimd/pim_upstream.h @@ -317,8 +317,8 @@ void pim_upstream_update_join_desired(struct pim_instance *pim, struct pim_upstream *up); void pim_update_suppress_timers(uint32_t suppress_time); -void pim_upstream_join_suppress(struct pim_upstream *up, - struct in_addr rpf_addr, int holdtime); +void pim_upstream_join_suppress(struct pim_upstream *up, struct prefix rpf, + int holdtime); void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, struct pim_upstream *up); @@ -326,7 +326,7 @@ void pim_upstream_join_timer_decrease_to_t_override(const char *debug_label, void pim_upstream_join_timer_restart(struct pim_upstream *up, struct pim_rpf *old); void pim_upstream_rpf_genid_changed(struct pim_instance *pim, - struct in_addr neigh_addr); + pim_addr neigh_addr); void pim_upstream_rpf_interface_changed(struct pim_upstream *up, struct interface *old_rpf_ifp); diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index 8130aac872..6de3a04b66 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -193,30 +193,30 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) if (pim->vrf->vrf_id == VRF_DEFAULT) { if (router->register_suppress_time != PIM_REGISTER_SUPPRESSION_TIME_DEFAULT) { - vty_out(vty, "%sip pim register-suppress-time %d\n", - spaces, router->register_suppress_time); + vty_out(vty, "%s" PIM_AF_NAME " pim register-suppress-time %d\n", + spaces, router->register_suppress_time); ++writes; } if (router->t_periodic != PIM_DEFAULT_T_PERIODIC) { - vty_out(vty, "%sip pim join-prune-interval %d\n", + vty_out(vty, "%s" PIM_AF_NAME " pim join-prune-interval %d\n", spaces, router->t_periodic); ++writes; } if (router->packet_process != PIM_DEFAULT_PACKET_PROCESS) { - vty_out(vty, "%sip pim packets %d\n", spaces, + vty_out(vty, "%s" PIM_AF_NAME " pim packets %d\n", spaces, router->packet_process); ++writes; } } if (pim->keep_alive_time != PIM_KEEPALIVE_PERIOD) { - vty_out(vty, "%sip pim keep-alive-timer %d\n", spaces, - pim->keep_alive_time); + vty_out(vty, "%s" PIM_AF_NAME " pim keep-alive-timer %d\n", + spaces, pim->keep_alive_time); ++writes; } if (pim->rp_keep_alive_time != (unsigned int)PIM_RP_KEEPALIVE_PERIOD) { - vty_out(vty, "%sip pim rp keep-alive-timer %d\n", spaces, - pim->rp_keep_alive_time); + vty_out(vty, "%s" PIM_AF_NAME " pim rp keep-alive-timer %d\n", + spaces, pim->rp_keep_alive_time); ++writes; } if (ssm->plist_name) { @@ -232,11 +232,11 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) if (pim->spt.switchover == PIM_SPT_INFINITY) { if (pim->spt.plist) vty_out(vty, - "%sip pim spt-switchover infinity-and-beyond prefix-list %s\n", + "%s" PIM_AF_NAME " pim spt-switchover infinity-and-beyond prefix-list %s\n", spaces, pim->spt.plist); else vty_out(vty, - "%sip pim spt-switchover infinity-and-beyond\n", + "%s" PIM_AF_NAME " pim spt-switchover infinity-and-beyond\n", spaces); ++writes; } @@ -281,6 +281,134 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) return writes; } +#if PIM_IPV == 4 +static int pim_igmp_config_write(struct vty *vty, int writes, + struct pim_interface *pim_ifp) +{ + /* IF ip igmp */ + if (PIM_IF_TEST_IGMP(pim_ifp->options)) { + vty_out(vty, " ip igmp\n"); + ++writes; + } + + /* ip igmp version */ + if (pim_ifp->igmp_version != IGMP_DEFAULT_VERSION) { + vty_out(vty, " ip igmp version %d\n", pim_ifp->igmp_version); + ++writes; + } + + /* IF ip igmp query-max-response-time */ + if (pim_ifp->gm_query_max_response_time_dsec != + IGMP_QUERY_MAX_RESPONSE_TIME_DSEC) { + vty_out(vty, " ip igmp query-max-response-time %d\n", + pim_ifp->gm_query_max_response_time_dsec); + ++writes; + } + + /* IF ip igmp query-interval */ + if (pim_ifp->gm_default_query_interval != IGMP_GENERAL_QUERY_INTERVAL) { + vty_out(vty, " ip igmp query-interval %d\n", + pim_ifp->gm_default_query_interval); + ++writes; + } + + /* IF ip igmp last-member_query-count */ + if (pim_ifp->gm_last_member_query_count != + IGMP_DEFAULT_ROBUSTNESS_VARIABLE) { + vty_out(vty, " ip igmp last-member-query-count %d\n", + pim_ifp->gm_last_member_query_count); + ++writes; + } + + /* IF ip igmp last-member_query-interval */ + if (pim_ifp->gm_specific_query_max_response_time_dsec != + IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC) { + vty_out(vty, " ip igmp last-member-query-interval %d\n", + pim_ifp->gm_specific_query_max_response_time_dsec); + ++writes; + } + + /* IF ip igmp join */ + if (pim_ifp->gm_join_list) { + struct listnode *node; + struct gm_join *ij; + for (ALL_LIST_ELEMENTS_RO(pim_ifp->gm_join_list, node, ij)) { + char group_str[INET_ADDRSTRLEN]; + char source_str[INET_ADDRSTRLEN]; + pim_inet4_dump("<grp?>", ij->group_addr, group_str, + sizeof(group_str)); + if (ij->source_addr.s_addr == INADDR_ANY) { + vty_out(vty, " ip igmp join %s\n", group_str); + } else { + inet_ntop(AF_INET, &ij->source_addr, source_str, + sizeof(source_str)); + vty_out(vty, " ip igmp join %s %s\n", group_str, + source_str); + } + ++writes; + } + } + + return writes; +} +#endif + +int pim_config_write(struct vty *vty, int writes, struct interface *ifp, + struct pim_instance *pim) +{ + struct pim_interface *pim_ifp = ifp->info; + + if (PIM_IF_TEST_PIM(pim_ifp->options)) { + vty_out(vty, " " PIM_AF_NAME " pim\n"); + ++writes; + } + + /* IF ip pim drpriority */ + if (pim_ifp->pim_dr_priority != PIM_DEFAULT_DR_PRIORITY) { + vty_out(vty, " " PIM_AF_NAME " pim drpriority %u\n", + pim_ifp->pim_dr_priority); + ++writes; + } + + /* IF ip pim hello */ + if (pim_ifp->pim_hello_period != PIM_DEFAULT_HELLO_PERIOD) { + vty_out(vty, " " PIM_AF_NAME " pim hello %d", pim_ifp->pim_hello_period); + if (pim_ifp->pim_default_holdtime != -1) + vty_out(vty, " %d", pim_ifp->pim_default_holdtime); + vty_out(vty, "\n"); + ++writes; + } + +#if PIM_IPV == 4 + writes += pim_igmp_config_write(vty, writes, pim_ifp); +#endif + + /* update source */ + if (!pim_addr_is_any(pim_ifp->update_source)) { + vty_out(vty, " " PIM_AF_NAME " pim use-source %pPA\n", + &pim_ifp->update_source); + ++writes; + } + + if (pim_ifp->activeactive) + vty_out(vty, " " PIM_AF_NAME " pim active-active\n"); + + /* boundary */ + if (pim_ifp->boundary_oil_plist) { + vty_out(vty, " " PIM_AF_NAME " multicast boundary oil %s\n", + pim_ifp->boundary_oil_plist); + ++writes; + } + + writes += pim_static_write_mroute(pim, vty, ifp); + pim_bsm_write_config(vty, ifp); + ++writes; + pim_bfd_write_config(vty, ifp); + ++writes; + + return writes; +} + int pim_interface_config_write(struct vty *vty) { struct pim_instance *pim; @@ -312,142 +440,10 @@ int pim_interface_config_write(struct vty *vty) } if (ifp->info) { - struct pim_interface *pim_ifp = ifp->info; - - if (PIM_IF_TEST_PIM(pim_ifp->options)) { - vty_out(vty, " ip pim\n"); - ++writes; - } - - /* IF ip pim drpriority */ - if (pim_ifp->pim_dr_priority - != PIM_DEFAULT_DR_PRIORITY) { - vty_out(vty, " ip pim drpriority %u\n", - pim_ifp->pim_dr_priority); - ++writes; - } - - /* IF ip pim hello */ - if (pim_ifp->pim_hello_period - != PIM_DEFAULT_HELLO_PERIOD) { - vty_out(vty, " ip pim hello %d", - pim_ifp->pim_hello_period); - if (pim_ifp->pim_default_holdtime != -1) - vty_out(vty, " %d", - pim_ifp->pim_default_holdtime); - vty_out(vty, "\n"); - ++writes; - } - - /* update source */ - if (!pim_addr_is_any(pim_ifp->update_source)) { - vty_out(vty, - " ip pim use-source %pPA\n", - &pim_ifp->update_source); - ++writes; - } - - /* IF ip igmp */ - if (PIM_IF_TEST_IGMP(pim_ifp->options)) { - vty_out(vty, " ip igmp\n"); - ++writes; - } - - /* ip igmp version */ - if (pim_ifp->igmp_version - != IGMP_DEFAULT_VERSION) { - vty_out(vty, " ip igmp version %d\n", - pim_ifp->igmp_version); - ++writes; - } - - /* IF ip igmp query-max-response-time */ - if (pim_ifp->gm_query_max_response_time_dsec != - IGMP_QUERY_MAX_RESPONSE_TIME_DSEC) { - vty_out(vty, - " ip igmp query-max-response-time %d\n", - pim_ifp->gm_query_max_response_time_dsec); - ++writes; - } - - /* IF ip igmp query-interval */ - if (pim_ifp->gm_default_query_interval != - IGMP_GENERAL_QUERY_INTERVAL) { - vty_out(vty, - " ip igmp query-interval %d\n", - pim_ifp->gm_default_query_interval); - ++writes; - } - - /* IF ip igmp last-member_query-count */ - if (pim_ifp->gm_last_member_query_count != - IGMP_DEFAULT_ROBUSTNESS_VARIABLE) { - vty_out(vty, - " ip igmp last-member-query-count %d\n", - pim_ifp->gm_last_member_query_count); - ++writes; - } - - /* IF ip igmp last-member_query-interval */ - if (pim_ifp->gm_specific_query_max_response_time_dsec != - IGMP_SPECIFIC_QUERY_MAX_RESPONSE_TIME_DSEC) { - vty_out(vty, - " ip igmp last-member-query-interval %d\n", - pim_ifp->gm_specific_query_max_response_time_dsec); - ++writes; - } - - /* IF ip igmp join */ - if (pim_ifp->gm_join_list) { - struct listnode *node; - struct gm_join *ij; - for (ALL_LIST_ELEMENTS_RO( - pim_ifp->gm_join_list, - node, ij)) { - char group_str[INET_ADDRSTRLEN]; - char source_str - [INET_ADDRSTRLEN]; - pim_inet4_dump( - "<grp?>", - ij->group_addr, - group_str, - sizeof(group_str)); - if (ij->source_addr.s_addr == INADDR_ANY) { - vty_out(vty, - " ip igmp join %s\n", - group_str); - } else { - inet_ntop(AF_INET, - &ij->source_addr, - source_str, - sizeof(source_str)); - vty_out(vty, - " ip igmp join %s %s\n", - group_str, source_str); - } - ++writes; - } - } - - if (pim_ifp->activeactive) - vty_out(vty, " ip pim active-active\n"); - - /* boundary */ - if (pim_ifp->boundary_oil_plist) { - vty_out(vty, - " ip multicast boundary oil %s\n", - pim_ifp->boundary_oil_plist); - ++writes; - } - - writes += - pim_static_write_mroute(pim, vty, ifp); - pim_bsm_write_config(vty, ifp); - ++writes; - pim_bfd_write_config(vty, ifp); - ++writes; + pim_config_write(vty, writes, ifp, pim); } if_vty_config_end(vty); + ++writes; } } diff --git a/pimd/pim_vty.h b/pimd/pim_vty.h index 22ac3333e4..c192ba3bbd 100644 --- a/pimd/pim_vty.h +++ b/pimd/pim_vty.h @@ -25,5 +25,6 @@ int pim_debug_config_write(struct vty *vty); int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty); int pim_interface_config_write(struct vty *vty); - +int pim_config_write(struct vty *vty, int writes, struct interface *ifp, + struct pim_instance *pim); #endif /* PIM_VTY_H */ diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c index 39a1a32a5b..5e55b9f9c8 100644 --- a/pimd/pim_vxlan.c +++ b/pimd/pim_vxlan.c @@ -184,11 +184,10 @@ void pim_vxlan_update_sg_reg_state(struct pim_instance *pim, pim_vxlan_del_work(vxlan_sg); } -static int pim_vxlan_work_timer_cb(struct thread *t) +static void pim_vxlan_work_timer_cb(struct thread *t) { pim_vxlan_do_reg_work(); pim_vxlan_work_timer_setup(true /* start */); - return 0; } /* global 1second timer used for periodic processing */ diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 11b13db318..0acd3c0694 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -55,6 +55,7 @@ struct zclient *zclient; /* Router-id update message from zebra. */ +__attribute__((unused)) static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS) { struct prefix router_id; @@ -64,6 +65,7 @@ static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS) return 0; } +__attribute__((unused)) static int pim_zebra_interface_vrf_update(ZAPI_CALLBACK_ARGS) { struct interface *ifp; @@ -112,7 +114,6 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) struct connected *c; struct prefix *p; struct pim_interface *pim_ifp; - struct pim_instance *pim; /* zebra api notifies address adds/dels events by using the same call @@ -141,6 +142,7 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) #endif } +#if PIM_IPV == 4 if (p->family != PIM_AF) SET_FLAG(c->flags, ZEBRA_IFA_SECONDARY); else if (!CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY)) { @@ -159,6 +161,8 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) pim_if_addr_add(c); if (pim_ifp) { + struct pim_instance *pim; + pim = pim_get_pim_instance(vrf_id); pim_ifp->pim = pim; @@ -174,7 +178,10 @@ static int pim_zebra_if_address_add(ZAPI_CALLBACK_ARGS) pim_if_addr_add_all(ifp); } } - +#else /* PIM_IPV != 4 */ + /* unused - for now */ + (void)pim_ifp; +#endif return 0; } @@ -183,11 +190,9 @@ static int pim_zebra_if_address_del(ZAPI_CALLBACK_ARGS) struct connected *c; struct prefix *p; struct vrf *vrf = vrf_lookup_by_id(vrf_id); - struct pim_instance *pim; if (!vrf) return 0; - pim = vrf->info; /* zebra api notifies address adds/dels events by using the same call @@ -202,24 +207,29 @@ static int pim_zebra_if_address_del(ZAPI_CALLBACK_ARGS) return 0; p = c->address; - if (p->family == AF_INET) { - if (PIM_DEBUG_ZEBRA) { - zlog_debug( - "%s: %s(%u) disconnected IP address %pFX flags %u %s", - __func__, c->ifp->name, vrf_id, p, c->flags, - CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) - ? "secondary" - : "primary"); + if (PIM_DEBUG_ZEBRA) { + zlog_debug( + "%s: %s(%u) disconnected IP address %pFX flags %u %s", + __func__, c->ifp->name, vrf_id, p, c->flags, + CHECK_FLAG(c->flags, ZEBRA_IFA_SECONDARY) + ? "secondary" + : "primary"); #ifdef PIM_DEBUG_IFADDR_DUMP - dump_if_address(c->ifp); + dump_if_address(c->ifp); #endif - } + } + +#if PIM_IPV == 4 + if (p->family == AF_INET) { + struct pim_instance *pim; + pim = vrf->info; pim_if_addr_del(c, 0); pim_rp_setup(pim); pim_i_am_rp_re_evaluate(pim); } +#endif connected_free(&c); return 0; @@ -242,7 +252,7 @@ void pim_zebra_update_all_interfaces(struct pim_instance *pim) struct pim_rpf rpf; rpf.source_nexthop.interface = ifp; - rpf.rpf_addr.u.prefix4 = us->address; + pim_addr_to_prefix(&rpf.rpf_addr, us->address); pim_joinprune_send(&rpf, us->us); pim_jp_agg_clear_group(us->us); } @@ -325,6 +335,7 @@ void pim_zebra_upstream_rpf_changed(struct pim_instance *pim, pim_upstream_update_join_desired(pim, up); } +__attribute__((unused)) static int pim_zebra_vxlan_sg_proc(ZAPI_CALLBACK_ARGS) { struct stream *s; @@ -354,6 +365,7 @@ static int pim_zebra_vxlan_sg_proc(ZAPI_CALLBACK_ARGS) return 0; } +__attribute__((unused)) static void pim_zebra_vxlan_replay(void) { struct stream *s = NULL; @@ -382,7 +394,7 @@ void pim_scan_oil(struct pim_instance *pim) pim_upstream_mroute_iif_update(c_oil, __func__); } -static int on_rpf_cache_refresh(struct thread *t) +static void on_rpf_cache_refresh(struct thread *t) { struct pim_instance *pim = THREAD_ARG(t); @@ -394,7 +406,6 @@ static int on_rpf_cache_refresh(struct thread *t) // It is called as part of pim_neighbor_add // pim_rp_setup (); - return 0; } void sched_rpf_cache_refresh(struct pim_instance *pim) @@ -422,13 +433,17 @@ void sched_rpf_cache_refresh(struct pim_instance *pim) static void pim_zebra_connected(struct zclient *zclient) { +#if PIM_IPV == 4 /* Send the client registration */ bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, router->vrf_id); +#endif zclient_send_reg_requests(zclient, router->vrf_id); +#if PIM_IPV == 4 /* request for VxLAN BUM group addresses */ pim_zebra_vxlan_replay(); +#endif } static void pim_zebra_capabilities(struct zclient_capabilities *cap) @@ -437,9 +452,10 @@ static void pim_zebra_capabilities(struct zclient_capabilities *cap) } static zclient_handler *const pim_handlers[] = { - [ZEBRA_ROUTER_ID_UPDATE] = pim_router_id_update_zebra, [ZEBRA_INTERFACE_ADDRESS_ADD] = pim_zebra_if_address_add, [ZEBRA_INTERFACE_ADDRESS_DELETE] = pim_zebra_if_address_del, +#if PIM_IPV == 4 + [ZEBRA_ROUTER_ID_UPDATE] = pim_router_id_update_zebra, [ZEBRA_INTERFACE_VRF_UPDATE] = pim_zebra_interface_vrf_update, [ZEBRA_NEXTHOP_UPDATE] = pim_parse_nexthop_update, @@ -449,6 +465,7 @@ static zclient_handler *const pim_handlers[] = { [ZEBRA_MLAG_PROCESS_UP] = pim_zebra_mlag_process_up, [ZEBRA_MLAG_PROCESS_DOWN] = pim_zebra_mlag_process_down, [ZEBRA_MLAG_FORWARD_MSG] = pim_zebra_mlag_handle_msg, +#endif }; void pim_zebra_init(void) @@ -468,6 +485,7 @@ void pim_zebra_init(void) zclient_lookup_new(); } +#if PIM_IPV == 4 void igmp_anysource_forward_start(struct pim_instance *pim, struct gm_group *group) { @@ -794,6 +812,7 @@ void igmp_source_forward_stop(struct gm_source *source) IGMP_SOURCE_DONT_FORWARDING(source->source_flags); } +#endif /* PIM_IPV == 4 */ void pim_forward_start(struct pim_ifchannel *ch) { diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index b169335a3a..c33e6032bf 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -36,22 +36,23 @@ #include "pim_str.h" #include "pim_oil.h" #include "pim_zlookup.h" +#include "pim_addr.h" static struct zclient *zlookup = NULL; struct thread *zlookup_read; static void zclient_lookup_sched(struct zclient *zlookup, int delay); -static int zclient_lookup_read_pipe(struct thread *thread); +static void zclient_lookup_read_pipe(struct thread *thread); /* Connect to zebra for nexthop lookup. */ -static int zclient_lookup_connect(struct thread *t) +static void zclient_lookup_connect(struct thread *t) { struct zclient *zlookup; zlookup = THREAD_ARG(t); if (zlookup->sock >= 0) { - return 0; + return; } if (zclient_socket_connect(zlookup) < 0) { @@ -73,12 +74,11 @@ static int zclient_lookup_connect(struct thread *t) if (zlookup->sock < 0) { /* Since last connect failed, retry within 10 secs */ zclient_lookup_sched(zlookup, 10); - return -1; + return; } thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60, &zlookup_read); - return 0; } /* Schedule connection with delay. */ @@ -381,7 +381,7 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, return zclient_read_nexthop(pim, zlookup, nexthop_tab, tab_size, addr); } -int zclient_lookup_read_pipe(struct thread *thread) +void zclient_lookup_read_pipe(struct thread *thread) { struct zclient *zlookup = THREAD_ARG(thread); struct pim_instance *pim = pim_get_pim_instance(VRF_DEFAULT); @@ -391,13 +391,11 @@ int zclient_lookup_read_pipe(struct thread *thread) zclient_lookup_nexthop_once(pim, nexthop_tab, 10, l); thread_add_timer(router->master, zclient_lookup_read_pipe, zlookup, 60, &zlookup_read); - - return 1; } int zclient_lookup_nexthop(struct pim_instance *pim, struct pim_zlookup_nexthop nexthop_tab[], - const int tab_size, struct in_addr addr, + const int tab_size, pim_addr addr, int max_lookup) { int lookup; @@ -414,15 +412,11 @@ int zclient_lookup_nexthop(struct pim_instance *pim, num_ifindex = zclient_lookup_nexthop_once(pim, nexthop_tab, tab_size, addr); if (num_ifindex < 1) { - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: lookup=%d/%d: could not find nexthop ifindex for address %s(%s)", - __func__, lookup, max_lookup, addr_str, + "%s: lookup=%d/%d: could not find nexthop ifindex for address %pPA(%s)", + __func__, lookup, max_lookup, &addr, pim->vrf->name); - } return -1; } @@ -451,23 +445,19 @@ int zclient_lookup_nexthop(struct pim_instance *pim, if (lookup > 0) { /* Report non-recursive success after first * lookup */ - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, - addr_str, - sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_debug( - "%s: lookup=%d/%d: found non-recursive ifindex=%d for address %s(%s) dist=%d met=%d", + "%s: lookup=%d/%d: found non-recursive ifindex=%d for address %pPA(%s) dist=%d met=%d", __func__, lookup, max_lookup, - first_ifindex, addr_str, + first_ifindex, &addr, pim->vrf->name, nexthop_tab[0] .protocol_distance, nexthop_tab[0].route_metric); - } /* use last address as nexthop address */ - nexthop_tab[0].nexthop_addr.u.prefix4 = addr; + pim_addr_to_prefix( + &(nexthop_tab[0].nexthop_addr), addr); /* report original route metric/distance */ nexthop_tab[0].route_metric = route_metric; @@ -486,25 +476,22 @@ int zclient_lookup_nexthop(struct pim_instance *pim, pim_addr_dump("<nexthop?>", &nexthop_addr, nexthop_str, sizeof(nexthop_str)); zlog_debug( - "%s: lookup=%d/%d: zebra returned recursive nexthop %s for address %s(%s) dist=%d met=%d", + "%s: lookup=%d/%d: zebra returned recursive nexthop %s for address %pPA(%s) dist=%d met=%d", __func__, lookup, max_lookup, nexthop_str, - addr_str, pim->vrf->name, + &addr, pim->vrf->name, nexthop_tab[0].protocol_distance, nexthop_tab[0].route_metric); } - addr = nexthop_addr.u.prefix4; /* use nexthop addr for - recursive lookup */ + addr = pim_addr_from_prefix(&(nexthop_addr)); /* use nexthop + addr for recursive lookup */ } /* for (max_lookup) */ - if (PIM_DEBUG_PIM_NHT) { - char addr_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); + if (PIM_DEBUG_PIM_NHT) zlog_warn( - "%s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %s(%s)", - __func__, lookup, max_lookup, addr_str, pim->vrf->name); - } + "%s: lookup=%d/%d: failure searching recursive nexthop ifindex for address %pPA(%s)", + __func__, lookup, max_lookup, &addr, pim->vrf->name); return -2; } diff --git a/pimd/pim_zlookup.h b/pimd/pim_zlookup.h index 09e8dcd51f..c3818dbdbc 100644 --- a/pimd/pim_zlookup.h +++ b/pimd/pim_zlookup.h @@ -39,7 +39,7 @@ void zclient_lookup_free(void); int zclient_lookup_nexthop(struct pim_instance *pim, struct pim_zlookup_nexthop nexthop_tab[], - const int tab_size, struct in_addr addr, + const int tab_size, pim_addr addr, int max_lookup); void pim_zlookup_show_ip_multicast(struct vty *vty); diff --git a/pimd/pim_zpthread.c b/pimd/pim_zpthread.c index 518b024749..a342931085 100644 --- a/pimd/pim_zpthread.c +++ b/pimd/pim_zpthread.c @@ -140,7 +140,7 @@ static void pim_mlag_zebra_check_for_buffer_flush(uint32_t curr_msg_type, * Thsi thread reads the clients data from the Gloabl queue and encodes with * protobuf and pass on to the MLAG socket. */ -static int pim_mlag_zthread_handler(struct thread *event) +static void pim_mlag_zthread_handler(struct thread *event) { struct stream *read_s; uint32_t wr_count = 0; @@ -155,7 +155,7 @@ static int pim_mlag_zthread_handler(struct thread *event) __func__, wr_count); if (wr_count == 0) - return 0; + return; for (wr_count = 0; wr_count < PIM_MLAG_POST_LIMIT; wr_count++) { /* FIFO is empty,wait for teh message to be add */ @@ -207,8 +207,6 @@ stream_failure: if (wr_count >= PIM_MLAG_POST_LIMIT) pim_mlag_signal_zpthread(); - - return 0; } diff --git a/pimd/pimd.c b/pimd/pimd.c index 9621f9794d..58e874fd11 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -32,7 +32,11 @@ #include "bfd.h" #include "pimd.h" +#if PIM_IPV == 4 #include "pim_cmd.h" +#else +#include "pim6_cmd.h" +#endif #include "pim_str.h" #include "pim_oil.h" #include "pim_pim.h" diff --git a/pimd/subdir.am b/pimd/subdir.am index 6c267f290c..0fe40912b1 100644 --- a/pimd/subdir.am +++ b/pimd/subdir.am @@ -6,8 +6,12 @@ if PIMD sbin_PROGRAMS += pimd/pimd bin_PROGRAMS += pimd/mtracebis noinst_PROGRAMS += pimd/test_igmpv3_join -vtysh_scan += pimd/pim_cmd.c +vtysh_scan += \ + pimd/pim_cmd.c \ + pimd/pim6_cmd.c \ + #end vtysh_daemons += pimd +vtysh_daemons += pim6d man8 += $(MANBUILD)/frr-pimd.8 man8 += $(MANBUILD)/mtracebis.8 endif @@ -18,32 +22,23 @@ pim_common = \ pimd/pim_bfd.c \ pimd/pim_br.c \ pimd/pim_bsm.c \ - pimd/pim_cmd.c \ + pimd/pim_cmd_common.c \ pimd/pim_errors.c \ pimd/pim_hello.c \ pimd/pim_iface.c \ pimd/pim_ifchannel.c \ - pimd/pim_igmp.c \ - pimd/pim_igmp_mtrace.c \ - pimd/pim_igmp_stats.c \ - pimd/pim_igmpv2.c \ - pimd/pim_igmpv3.c \ pimd/pim_instance.c \ pimd/pim_int.c \ pimd/pim_join.c \ pimd/pim_jp_agg.c \ pimd/pim_macro.c \ pimd/pim_memory.c \ - pimd/pim_mlag.c \ pimd/pim_mroute.c \ pimd/pim_msg.c \ pimd/pim_nb.c \ pimd/pim_nb_config.c \ pimd/pim_neighbor.c \ - pimd/pim_nht.c \ pimd/pim_oil.c \ - pimd/pim_pim.c \ - pimd/pim_register.c \ pimd/pim_routemap.c \ pimd/pim_rp.c \ pimd/pim_rpf.c \ @@ -58,19 +53,29 @@ pim_common = \ pimd/pim_util.c \ pimd/pim_vty.c \ pimd/pim_zebra.c \ - pimd/pim_zlookup.c \ pimd/pim_vxlan.c \ - pimd/pim_zpthread.c \ pimd/pimd.c \ # end pimd_pimd_SOURCES = \ $(pim_common) \ + pimd/pim_cmd.c \ + pimd/pim_igmp.c \ + pimd/pim_igmp_mtrace.c \ + pimd/pim_igmp_stats.c \ + pimd/pim_igmpv2.c \ + pimd/pim_igmpv3.c \ pimd/pim_main.c \ + pimd/pim_mlag.c \ pimd/pim_msdp.c \ pimd/pim_msdp_packet.c \ pimd/pim_msdp_socket.c \ + pimd/pim_nht.c \ + pimd/pim_pim.c \ + pimd/pim_register.c \ pimd/pim_signals.c \ + pimd/pim_zlookup.c \ + pimd/pim_zpthread.c \ # end nodist_pimd_pimd_SOURCES = \ @@ -82,9 +87,14 @@ nodist_pimd_pimd_SOURCES = \ pimd_pim6d_SOURCES = \ $(pim_common) \ pimd/pim6_main.c \ + pimd/pim6_stubs.c \ + pimd/pim6_cmd.c \ # end nodist_pimd_pim6d_SOURCES = \ + yang/frr-pim.yang.c \ + yang/frr-pim-rp.yang.c \ + yang/frr-gmp.yang.c \ # end noinst_HEADERS += \ @@ -94,6 +104,7 @@ noinst_HEADERS += \ pimd/pim_br.h \ pimd/pim_bsm.h \ pimd/pim_cmd.h \ + pimd/pim_cmd_common.h \ pimd/pim_errors.h \ pimd/pim_hello.h \ pimd/pim_iface.h \ @@ -142,10 +153,12 @@ noinst_HEADERS += \ pimd/pimd.h \ pimd/mtracebis_netlink.h \ pimd/mtracebis_routeget.h \ + pimd/pim6_cmd.h \ # end clippy_scan += \ pimd/pim_cmd.c \ + pimd/pim6_cmd.c \ # end pimd_pimd_CFLAGS = $(AM_CFLAGS) -DPIM_IPV=4 @@ -158,7 +171,7 @@ if DEV_BUILD # (change noinst_ to sbin_ below to install it.) # noinst_PROGRAMS += pimd/pim6d -pimd_pim6d_CFLAGS = $(AM_CFLAGS) -DPIM_IPV=6 $(and $(PIM_V6_TEMP_BREAK),-DPIM_V6_TEMP_BREAK) +pimd_pim6d_CFLAGS = $(AM_CFLAGS) -DPIM_IPV=6 pimd_pim6d_LDADD = lib/libfrr.la $(LIBCAP) endif endif diff --git a/python/clidef.py b/python/clidef.py index b57a00fc89..101c9a5ae3 100644 --- a/python/clidef.py +++ b/python/clidef.py @@ -241,24 +241,51 @@ def get_always_args(token, always_args, args=[], stack=[]): class Macros(dict): + def __init__(self): + super().__init__() + self._loc = {} + def load(self, filename): filedata = clippy.parse(filename) for entry in filedata["data"]: if entry["type"] != "PREPROC": continue - ppdir = entry["line"].lstrip().split(None, 1) - if ppdir[0] != "define" or len(ppdir) != 2: - continue - ppdef = ppdir[1].split(None, 1) - name = ppdef[0] - if "(" in name: - continue - val = ppdef[1] if len(ppdef) == 2 else "" - - val = val.strip(" \t\n\\") - if name in self: - sys.stderr.write("warning: macro %s redefined!\n" % (name)) + self.load_preproc(filename, entry) + + def setup(self, key, val, where="built-in"): + self[key] = val + self._loc[key] = (where, 0) + + def load_preproc(self, filename, entry): + ppdir = entry["line"].lstrip().split(None, 1) + if ppdir[0] != "define" or len(ppdir) != 2: + return + ppdef = ppdir[1].split(None, 1) + name = ppdef[0] + if "(" in name: + return + val = ppdef[1] if len(ppdef) == 2 else "" + + val = val.strip(" \t\n\\") + if self.get(name, val) != val: + sys.stderr.write( + "%s:%d: warning: macro %s redefined!\n" + % ( + filename, + entry["lineno"], + name, + ) + ) + sys.stderr.write( + "%s:%d: note: previously defined here\n" + % ( + self._loc[name][0], + self._loc[name][1], + ) + ) + else: self[name] = val + self._loc[name] = (filename, entry["lineno"]) def process_file(fn, ofd, dumpfd, all_defun, macros): @@ -283,6 +310,11 @@ def process_file(fn, ofd, dumpfd, all_defun, macros): cond_stack.append(prev_line + line) elif tokens[0] in ["endif"]: cond_stack.pop(-1) + elif tokens[0] in ["define"]: + if not cond_stack: + macros.load_preproc(fn, entry) + elif len(cond_stack) == 1 and cond_stack[0] == "#ifdef CLIPPY\n": + macros.load_preproc(fn, entry) continue if entry["type"].startswith("DEFPY") or ( all_defun and entry["type"].startswith("DEFUN") @@ -454,9 +486,9 @@ if __name__ == "__main__": macros.load(os.path.join(basepath, "lib/command.h")) macros.load(os.path.join(basepath, "bgpd/bgp_vty.h")) # sigh :( - macros["PROTO_REDIST_STR"] = "FRR_REDIST_STR_ISISD" - macros["PROTO_IP_REDIST_STR"] = "FRR_IP_REDIST_STR_ISISD" - macros["PROTO_IP6_REDIST_STR"] = "FRR_IP6_REDIST_STR_ISISD" + macros.setup("PROTO_REDIST_STR", "FRR_REDIST_STR_ISISD") + macros.setup("PROTO_IP_REDIST_STR", "FRR_IP_REDIST_STR_ISISD") + macros.setup("PROTO_IP6_REDIST_STR", "FRR_IP6_REDIST_STR_ISISD") errors = process_file(args.cfile, ofd, dumpfd, args.all_defun, macros) if errors != 0: diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 8fd64f2874..1269f25b35 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -789,7 +789,7 @@ int rip_enable_if_delete(struct rip *rip, const char *ifname) } /* Join to multicast group and send request to the interface. */ -static int rip_interface_wakeup(struct thread *t) +static void rip_interface_wakeup(struct thread *t) { struct interface *ifp; struct rip_interface *ri; @@ -804,7 +804,7 @@ static int rip_interface_wakeup(struct thread *t) flog_err_sys(EC_LIB_SOCKET, "multicast join failed, interface %s not running", ifp->name); - return 0; + return; } /* Set running flag. */ @@ -812,8 +812,6 @@ static int rip_interface_wakeup(struct thread *t) /* Send RIP request to the interface. */ rip_request_interface(ifp); - - return 0; } static void rip_connect_set(struct interface *ifp, int set) diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 12c4edd436..8febb436e7 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -67,15 +67,13 @@ struct rip_peer *rip_peer_lookup_next(struct rip *rip, struct in_addr *addr) } /* RIP peer is timeout. */ -static int rip_peer_timeout(struct thread *t) +static void rip_peer_timeout(struct thread *t) { struct rip_peer *peer; peer = THREAD_ARG(t); listnode_delete(peer->rip->peer_list, peer); rip_peer_free(peer); - - return 0; } /* Get RIP peer. At the same time update timeout thread. */ diff --git a/ripd/ripd.c b/ripd/ripd.c index b7b62e28e1..2a05f30bc8 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -65,7 +65,7 @@ DEFINE_MTYPE_STATIC(RIPD, RIP_DISTANCE, "RIP distance"); /* Prototypes. */ static void rip_output_process(struct connected *, struct sockaddr_in *, int, uint8_t); -static int rip_triggered_update(struct thread *); +static void rip_triggered_update(struct thread *); static int rip_update_jitter(unsigned long); static void rip_distance_table_node_cleanup(struct route_table *table, struct route_node *node); @@ -136,7 +136,7 @@ struct rip *rip_info_get_instance(const struct rip_info *rinfo) } /* RIP route garbage collect timer. */ -static int rip_garbage_collect(struct thread *t) +static void rip_garbage_collect(struct thread *t) { struct rip_info *rinfo; struct route_node *rp; @@ -158,8 +158,6 @@ static int rip_garbage_collect(struct thread *t) /* Free RIP routing information. */ rip_info_free(rinfo); - - return 0; } static void rip_timeout_update(struct rip *rip, struct rip_info *rinfo); @@ -224,13 +222,15 @@ struct rip_info *rip_ecmp_replace(struct rip *rip, struct rip_info *rinfo_new) rip_zebra_ipv4_delete(rip, rp); /* Re-use the first entry, and delete the others. */ - for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo)) - if (tmp_rinfo != rinfo) { - RIP_TIMER_OFF(tmp_rinfo->t_timeout); - RIP_TIMER_OFF(tmp_rinfo->t_garbage_collect); - list_delete_node(list, node); - rip_info_free(tmp_rinfo); - } + for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo)) { + if (tmp_rinfo == rinfo) + continue; + + RIP_TIMER_OFF(tmp_rinfo->t_timeout); + RIP_TIMER_OFF(tmp_rinfo->t_garbage_collect); + list_delete_node(list, node); + rip_info_free(tmp_rinfo); + } RIP_TIMER_OFF(rinfo->t_timeout); RIP_TIMER_OFF(rinfo->t_garbage_collect); @@ -302,14 +302,12 @@ struct rip_info *rip_ecmp_delete(struct rip *rip, struct rip_info *rinfo) } /* Timeout RIP routes. */ -static int rip_timeout(struct thread *t) +static void rip_timeout(struct thread *t) { struct rip_info *rinfo = THREAD_ARG(t); struct rip *rip = rip_info_get_instance(rinfo); rip_ecmp_delete(rip, rinfo); - - return 0; } static void rip_timeout_update(struct rip *rip, struct rip_info *rinfo) @@ -332,61 +330,56 @@ static int rip_filter(int rip_distribute, struct prefix_ipv4 *p, const char *inout = rip_distribute == RIP_FILTER_OUT ? "out" : "in"; /* Input distribute-list filtering. */ - if (ri->list[rip_distribute]) { - if (access_list_apply(ri->list[rip_distribute], - (struct prefix *)p) - == FILTER_DENY) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug("%pFX filtered by distribute %s", p, - inout); - return -1; - } + if (ri->list[rip_distribute] && + access_list_apply(ri->list[rip_distribute], (struct prefix *)p) == + FILTER_DENY) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug("%pFX filtered by distribute %s", p, inout); + return -1; } - if (ri->prefix[rip_distribute]) { - if (prefix_list_apply(ri->prefix[rip_distribute], - (struct prefix *)p) - == PREFIX_DENY) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug("%pFX filtered by prefix-list %s", p, - inout); - return -1; - } + + if (ri->prefix[rip_distribute] && + prefix_list_apply(ri->prefix[rip_distribute], (struct prefix *)p) == + PREFIX_DENY) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug("%pFX filtered by prefix-list %s", p, inout); + return -1; } /* All interface filter check. */ dist = distribute_lookup(ri->rip->distribute_ctx, NULL); - if (dist) { - if (dist->list[distribute]) { - alist = access_list_lookup(AFI_IP, - dist->list[distribute]); + if (!dist) + return 0; - if (alist) { - if (access_list_apply(alist, (struct prefix *)p) - == FILTER_DENY) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "%pFX filtered by distribute %s", - p, inout); - return -1; - } + if (dist->list[distribute]) { + alist = access_list_lookup(AFI_IP, dist->list[distribute]); + + if (alist) { + if (access_list_apply(alist, (struct prefix *)p) == + FILTER_DENY) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "%pFX filtered by distribute %s", + p, inout); + return -1; } } - if (dist->prefix[distribute]) { - plist = prefix_list_lookup(AFI_IP, - dist->prefix[distribute]); - - if (plist) { - if (prefix_list_apply(plist, (struct prefix *)p) - == PREFIX_DENY) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "%pFX filtered by prefix-list %s", - p, inout); - return -1; - } + } + if (dist->prefix[distribute]) { + plist = prefix_list_lookup(AFI_IP, dist->prefix[distribute]); + + if (plist) { + if (prefix_list_apply(plist, (struct prefix *)p) == + PREFIX_DENY) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "%pFX filtered by prefix-list %s", + p, inout); + return -1; } } } + return 0; } @@ -532,46 +525,46 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from, && IPV4_ADDR_SAME(&rinfo->nh.gate.ipv4, nexthop)) break; - if (!listnextnode(node)) { - /* Not found in the list */ + if (listnextnode(node)) + continue; - if (rte->metric > rinfo->metric) { - /* New route has a greater metric. - * Discard it. */ - route_unlock_node(rp); - return; - } + /* Not found in the list */ - if (rte->metric < rinfo->metric) - /* New route has a smaller metric. - * Replace the ECMP list - * with the new one in below. */ - break; + if (rte->metric > rinfo->metric) { + /* New route has a greater metric. + * Discard it. */ + route_unlock_node(rp); + return; + } - /* Metrics are same. We compare the distances. - */ - old_dist = rinfo->distance - ? rinfo->distance + if (rte->metric < rinfo->metric) + /* New route has a smaller metric. + * Replace the ECMP list + * with the new one in below. */ + break; + + /* Metrics are same. We compare the distances. + */ + old_dist = rinfo->distance ? rinfo->distance : ZEBRA_RIP_DISTANCE_DEFAULT; - if (new_dist > old_dist) { - /* New route has a greater distance. - * Discard it. */ - route_unlock_node(rp); - return; - } + if (new_dist > old_dist) { + /* New route has a greater distance. + * Discard it. */ + route_unlock_node(rp); + return; + } - if (new_dist < old_dist) - /* New route has a smaller distance. - * Replace the ECMP list - * with the new one in below. */ - break; + if (new_dist < old_dist) + /* New route has a smaller distance. + * Replace the ECMP list + * with the new one in below. */ + break; - /* Metrics and distances are both same. Keep - * "rinfo" null and - * the new route is added in the ECMP list in - * below. */ - } + /* Metrics and distances are both same. Keep + * "rinfo" null and + * the new route is added in the ECMP list in + * below. */ } if (rinfo) { @@ -1278,15 +1271,14 @@ static void rip_response_process(struct rip_packet *packet, int size, } /* For RIPv1, there won't be a valid netmask. - - This is a best guess at the masks. If everyone was using old - Ciscos before the 'ip subnet zero' option, it would be almost - right too :-) - - Cisco summarize ripv1 advertisements to the classful boundary - (/16 for class B's) except when the RIP packet does to inside - the classful network in question. */ - + * This is a best guess at the masks. If everyone was using old + * Ciscos before the 'ip subnet zero' option, it would be almost + * right too :-) + * + * Cisco summarize ripv1 advertisements to the classful boundary + * (/16 for class B's) except when the RIP packet does to inside + * the classful network in question. + */ if ((packet->version == RIPv1 && rte->prefix.s_addr != INADDR_ANY) || (packet->version == RIPv2 @@ -1467,19 +1459,16 @@ static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to, if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_SECONDARY)) { /* * ZEBRA_IFA_SECONDARY is set on linux when an interface is - * configured - * with multiple addresses on the same subnet: the first address - * on the subnet is configured "primary", and all subsequent - * addresses - * on that subnet are treated as "secondary" addresses. - * In order to avoid routing-table bloat on other rip listeners, - * we do not send out RIP packets with ZEBRA_IFA_SECONDARY - * source addrs. + * configured with multiple addresses on the same + * subnet: the first address on the subnet is configured + * "primary", and all subsequent addresses on that subnet + * are treated as "secondary" addresses. In order to avoid + * routing-table bloat on other rip listeners, we do not send + * out RIP packets with ZEBRA_IFA_SECONDARY source addrs. * XXX Since Linux is the only system for which the - * ZEBRA_IFA_SECONDARY - * flag is set, we would end up sending a packet for a - * "secondary" - * source address on non-linux systems. + * ZEBRA_IFA_SECONDARY flag is set, we would end up + * sending a packet for a "secondary" source address on + * non-linux systems. */ if (IS_RIP_DEBUG_PACKET) zlog_debug("duplicate dropped"); @@ -1725,7 +1714,7 @@ static void rip_request_process(struct rip_packet *packet, int size, } /* First entry point of RIP packet. */ -static int rip_read(struct thread *t) +static void rip_read(struct thread *t) { struct rip *rip = THREAD_ARG(t); int sock; @@ -1757,7 +1746,7 @@ static int rip_read(struct thread *t) if (len < 0) { zlog_info("recvfrom failed (VRF %s): %s", rip->vrf_name, safe_strerror(errno)); - return len; + return; } /* Check is this packet comming from myself? */ @@ -1765,7 +1754,7 @@ static int rip_read(struct thread *t) if (IS_RIP_DEBUG_PACKET) zlog_debug("ignore packet comes from myself (VRF %s)", rip->vrf_name); - return -1; + return; } /* Which interface is this packet comes from. */ @@ -1786,7 +1775,7 @@ static int rip_read(struct thread *t) "rip_read: cannot find interface for packet from %pI4 port %d (VRF %s)", &from.sin_addr, ntohs(from.sin_port), rip->vrf_name); - return -1; + return; } p.family = AF_INET; @@ -1800,7 +1789,7 @@ static int rip_read(struct thread *t) "rip_read: cannot find connected address for packet from %pI4 port %d on interface %s (VRF %s)", &from.sin_addr, ntohs(from.sin_port), ifp->name, rip->vrf_name); - return -1; + return; } /* Packet length check. */ @@ -1808,13 +1797,13 @@ static int rip_read(struct thread *t) zlog_warn("packet size %d is smaller than minimum size %d", len, RIP_PACKET_MINSIZ); rip_peer_bad_packet(rip, &from); - return len; + return; } if (len > RIP_PACKET_MAXSIZ) { zlog_warn("packet size %d is larger than max size %d", len, RIP_PACKET_MAXSIZ); rip_peer_bad_packet(rip, &from); - return len; + return; } /* Packet alignment check. */ @@ -1822,7 +1811,7 @@ static int rip_read(struct thread *t) zlog_warn("packet size %d is wrong for RIP packet alignment", len); rip_peer_bad_packet(rip, &from); - return len; + return; } /* Set RTE number. */ @@ -1836,7 +1825,7 @@ static int rip_read(struct thread *t) zlog_info("version 0 with command %d received.", packet->command); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* Dump RIP packet. */ @@ -1857,7 +1846,7 @@ static int rip_read(struct thread *t) zlog_debug("RIP is not enabled on interface %s.", ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* RIP Version check. RFC2453, 4.6 and 5.1 */ @@ -1871,7 +1860,7 @@ static int rip_read(struct thread *t) " packet's v%d doesn't fit to if version spec", packet->version); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* RFC2453 5.2 If the router is not configured to authenticate RIP-2 @@ -1886,7 +1875,7 @@ static int rip_read(struct thread *t) packet->version); ripd_notif_send_auth_type_failure(ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* RFC: @@ -1922,7 +1911,7 @@ static int rip_read(struct thread *t) "RIPv1 dropped because authentication enabled"); ripd_notif_send_auth_type_failure(ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } } else if (ri->auth_type != RIP_NO_AUTH) { const char *auth_desc; @@ -1935,7 +1924,7 @@ static int rip_read(struct thread *t) "RIPv2 authentication failed: no auth RTE in packet"); ripd_notif_send_auth_type_failure(ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* First RTE must be an Authentication Family RTE */ @@ -1945,7 +1934,7 @@ static int rip_read(struct thread *t) "RIPv2 dropped because authentication enabled"); ripd_notif_send_auth_type_failure(ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } /* Check RIPv2 authentication. */ @@ -1981,7 +1970,7 @@ static int rip_read(struct thread *t) auth_desc); ripd_notif_send_auth_failure(ifp->name); rip_peer_bad_packet(rip, &from); - return -1; + return; } } @@ -2011,8 +2000,6 @@ static int rip_read(struct thread *t) rip_peer_bad_packet(rip, &from); break; } - - return len; } /* Write routing table entry to the stream and return next index of @@ -2123,270 +2110,240 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, subnetted = 1; } - for (rp = route_top(rip->table); rp; rp = route_next(rp)) - if ((list = rp->info) != NULL && listcount(list) != 0) { - rinfo = listgetdata(listhead(list)); - /* For RIPv1, if we are subnetted, output subnets in our - * network */ - /* that have the same mask as the output "interface". - * For other */ - /* networks, only the classfull version is output. */ + for (rp = route_top(rip->table); rp; rp = route_next(rp)) { + list = rp->info; - if (version == RIPv1) { - p = (struct prefix_ipv4 *)&rp->p; + if (list == NULL) + continue; - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "RIPv1 mask check, %pFX considered for output", - &rp->p); - - if (subnetted - && prefix_match( - (struct prefix *)&ifaddrclass, - &rp->p)) { - if ((ifc->address->prefixlen - != rp->p.prefixlen) - && (rp->p.prefixlen - != IPV4_MAX_BITLEN)) - continue; - } else { - memcpy(&classfull, &rp->p, - sizeof(struct prefix_ipv4)); - apply_classful_mask_ipv4(&classfull); - if (rp->p.u.prefix4.s_addr != INADDR_ANY - && classfull.prefixlen - != rp->p.prefixlen) - continue; - } - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "RIPv1 mask check, %pFX made it through", - &rp->p); - } else - p = (struct prefix_ipv4 *)&rp->p; + if (listcount(list) == 0) + continue; - /* Apply output filters. */ - ret = rip_filter(RIP_FILTER_OUT, p, ri); - if (ret < 0) - continue; + rinfo = listgetdata(listhead(list)); + /* + * For RIPv1, if we are subnetted, output subnets in our + * network that have the same mask as the output "interface". + * For other networks, only the classfull version is output. + */ + if (version == RIPv1) { + p = (struct prefix_ipv4 *)&rp->p; - /* Changed route only output. */ - if (route_type == rip_changed_route - && (!(rinfo->flags & RIP_RTF_CHANGED))) - continue; + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "RIPv1 mask check, %pFX considered for output", + &rp->p); + + if (subnetted && + prefix_match((struct prefix *)&ifaddrclass, + &rp->p)) { + if ((ifc->address->prefixlen != + rp->p.prefixlen) && + (rp->p.prefixlen != IPV4_MAX_BITLEN)) + continue; + } else { + memcpy(&classfull, &rp->p, + sizeof(struct prefix_ipv4)); + apply_classful_mask_ipv4(&classfull); + if (rp->p.u.prefix4.s_addr != INADDR_ANY && + classfull.prefixlen != rp->p.prefixlen) + continue; + } + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "RIPv1 mask check, %pFX made it through", + &rp->p); + } else + p = (struct prefix_ipv4 *)&rp->p; - /* Split horizon. */ - /* if (split_horizon == rip_split_horizon) */ - if (ri->split_horizon == RIP_SPLIT_HORIZON) { - /* - * We perform split horizon for RIP and - * connected route. - * For rip routes, we want to suppress the route - * if we would - * end up sending the route back on the - * interface that we - * learned it from, with a higher metric. For - * connected routes, - * we suppress the route if the prefix is a - * subset of the - * source address that we are going to use for - * the packet - * (in order to handle the case when multiple - * subnets are - * configured on the same interface). - */ - int suppress = 0; - struct rip_info *tmp_rinfo = NULL; - struct connected *tmp_ifc = NULL; - - for (ALL_LIST_ELEMENTS_RO(list, listnode, - tmp_rinfo)) - if (tmp_rinfo->type == ZEBRA_ROUTE_RIP - && tmp_rinfo->nh.ifindex - == ifc->ifp->ifindex) { - suppress = 1; - break; - } + /* Apply output filters. */ + ret = rip_filter(RIP_FILTER_OUT, p, ri); + if (ret < 0) + continue; + + /* Changed route only output. */ + if (route_type == rip_changed_route && + (!(rinfo->flags & RIP_RTF_CHANGED))) + continue; - if (!suppress - && rinfo->type == ZEBRA_ROUTE_CONNECT) { - for (ALL_LIST_ELEMENTS_RO( - ifc->ifp->connected, - listnode, tmp_ifc)) - if (prefix_match( - (struct prefix *)p, - tmp_ifc->address)) { - suppress = 1; - break; - } + /* Split horizon. */ + if (ri->split_horizon == RIP_SPLIT_HORIZON) { + /* + * We perform split horizon for RIP and connected + * route. For rip routes, we want to suppress the + * route if we would end up sending the route back on + * the interface that we learned it from, with a + * higher metric. For connected routes, we suppress + * the route if the prefix is a subset of the source + * address that we are going to use for the packet + * (in order to handle the case when multiple subnets + * are configured on the same interface). + */ + int suppress = 0; + struct rip_info *tmp_rinfo = NULL; + struct connected *tmp_ifc = NULL; + + for (ALL_LIST_ELEMENTS_RO(list, listnode, tmp_rinfo)) + if (tmp_rinfo->type == ZEBRA_ROUTE_RIP && + tmp_rinfo->nh.ifindex == + ifc->ifp->ifindex) { + suppress = 1; + break; } - if (suppress) - continue; + if (!suppress && rinfo->type == ZEBRA_ROUTE_CONNECT) { + for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, + listnode, tmp_ifc)) + if (prefix_match((struct prefix *)p, + tmp_ifc->address)) { + suppress = 1; + break; + } } - /* Preparation for route-map. */ - rinfo->metric_set = 0; - rinfo->nexthop_out.s_addr = 0; - rinfo->metric_out = rinfo->metric; - rinfo->tag_out = rinfo->tag; - rinfo->ifindex_out = ifc->ifp->ifindex; - - /* In order to avoid some local loops, - * if the RIP route has a nexthop via this interface, - * keep the nexthop, - * otherwise set it to 0. The nexthop should not be - * propagated - * beyond the local broadcast/multicast area in order - * to avoid an IGP multi-level recursive look-up. - * see (4.4) - */ - if (rinfo->nh.ifindex == ifc->ifp->ifindex) - rinfo->nexthop_out = rinfo->nh.gate.ipv4; + if (suppress) + continue; + } - /* Interface route-map */ - if (ri->routemap[RIP_FILTER_OUT]) { - ret = route_map_apply( - ri->routemap[RIP_FILTER_OUT], - (struct prefix *)p, rinfo); + /* Preparation for route-map. */ + rinfo->metric_set = 0; + rinfo->nexthop_out.s_addr = 0; + rinfo->metric_out = rinfo->metric; + rinfo->tag_out = rinfo->tag; + rinfo->ifindex_out = ifc->ifp->ifindex; + + /* In order to avoid some local loops, if the RIP route has + * a nexthop via this interface, keep the nexthop, otherwise + * set it to 0. The nexthop should not be propagated beyond + * the local broadcast/multicast area in order to avoid an + * IGP multi-level recursive look-up. see (4.4) + */ + if (rinfo->nh.ifindex == ifc->ifp->ifindex) + rinfo->nexthop_out = rinfo->nh.gate.ipv4; - if (ret == RMAP_DENYMATCH) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "RIP %pFX is filtered by route-map out", - p); - continue; - } + /* Interface route-map */ + if (ri->routemap[RIP_FILTER_OUT]) { + ret = route_map_apply(ri->routemap[RIP_FILTER_OUT], + (struct prefix *)p, rinfo); + + if (ret == RMAP_DENYMATCH) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "RIP %pFX is filtered by route-map out", + p); + continue; } + } - /* Apply redistribute route map - continue, if deny */ - if (rip->redist[rinfo->type].route_map.name - && rinfo->sub_type != RIP_ROUTE_INTERFACE) { - ret = route_map_apply( - rip->redist[rinfo->type].route_map.map, - (struct prefix *)p, rinfo); + /* Apply redistribute route map - continue, if deny */ + if (rip->redist[rinfo->type].route_map.name && + rinfo->sub_type != RIP_ROUTE_INTERFACE) { + ret = route_map_apply( + rip->redist[rinfo->type].route_map.map, + (struct prefix *)p, rinfo); - if (ret == RMAP_DENYMATCH) { - if (IS_RIP_DEBUG_PACKET) - zlog_debug( - "%pFX is filtered by route-map", - p); - continue; - } + if (ret == RMAP_DENYMATCH) { + if (IS_RIP_DEBUG_PACKET) + zlog_debug( + "%pFX is filtered by route-map", + p); + continue; } + } - /* When route-map does not set metric. */ - if (!rinfo->metric_set) { - /* If redistribute metric is set. */ - if (rip->redist[rinfo->type].metric_config - && rinfo->metric != RIP_METRIC_INFINITY) { - rinfo->metric_out = - rip->redist[rinfo->type].metric; - } else { - /* If the route is not connected or - localy generated - one, use default-metric value*/ - if (rinfo->type != ZEBRA_ROUTE_RIP - && rinfo->type - != ZEBRA_ROUTE_CONNECT - && rinfo->metric - != RIP_METRIC_INFINITY) - rinfo->metric_out = - rip->default_metric; - } + /* When route-map does not set metric. */ + if (!rinfo->metric_set) { + /* If redistribute metric is set. */ + if (rip->redist[rinfo->type].metric_config && + rinfo->metric != RIP_METRIC_INFINITY) { + rinfo->metric_out = + rip->redist[rinfo->type].metric; + } else { + /* If the route is not connected or localy + * generated one, use default-metric value + */ + if (rinfo->type != ZEBRA_ROUTE_RIP && + rinfo->type != ZEBRA_ROUTE_CONNECT && + rinfo->metric != RIP_METRIC_INFINITY) + rinfo->metric_out = rip->default_metric; } + } - /* Apply offset-list */ - if (rinfo->metric != RIP_METRIC_INFINITY) - rip_offset_list_apply_out(p, ifc->ifp, - &rinfo->metric_out); - - if (rinfo->metric_out > RIP_METRIC_INFINITY) - rinfo->metric_out = RIP_METRIC_INFINITY; - - /* Perform split-horizon with poisoned reverse - * for RIP and connected routes. - **/ - if (ri->split_horizon - == RIP_SPLIT_HORIZON_POISONED_REVERSE) { - /* - * We perform split horizon for RIP and - * connected route. - * For rip routes, we want to suppress the route - * if we would - * end up sending the route back on the - * interface that we - * learned it from, with a higher metric. For - * connected routes, - * we suppress the route if the prefix is a - * subset of the - * source address that we are going to use for - * the packet - * (in order to handle the case when multiple - * subnets are - * configured on the same interface). - */ - struct rip_info *tmp_rinfo = NULL; - struct connected *tmp_ifc = NULL; - - for (ALL_LIST_ELEMENTS_RO(list, listnode, - tmp_rinfo)) - if (tmp_rinfo->type == ZEBRA_ROUTE_RIP - && tmp_rinfo->nh.ifindex - == ifc->ifp->ifindex) + /* Apply offset-list */ + if (rinfo->metric != RIP_METRIC_INFINITY) + rip_offset_list_apply_out(p, ifc->ifp, + &rinfo->metric_out); + + if (rinfo->metric_out > RIP_METRIC_INFINITY) + rinfo->metric_out = RIP_METRIC_INFINITY; + + /* Perform split-horizon with poisoned reverse + * for RIP and connected routes. + **/ + if (ri->split_horizon == RIP_SPLIT_HORIZON_POISONED_REVERSE) { + /* + * We perform split horizon for RIP and connected + * route. For rip routes, we want to suppress the + * route if we would end up sending the route back + * on the interface that we learned it from, with a + * higher metric. For connected routes, we suppress + * the route if the prefix is a subset of the source + * address that we are going to use for the packet + * (in order to handle the case when multiple + * subnets are configured on the same interface). + */ + struct rip_info *tmp_rinfo = NULL; + struct connected *tmp_ifc = NULL; + + for (ALL_LIST_ELEMENTS_RO(list, listnode, tmp_rinfo)) + if (tmp_rinfo->type == ZEBRA_ROUTE_RIP && + tmp_rinfo->nh.ifindex == ifc->ifp->ifindex) + rinfo->metric_out = RIP_METRIC_INFINITY; + + if (rinfo->metric_out != RIP_METRIC_INFINITY && + rinfo->type == ZEBRA_ROUTE_CONNECT) { + for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, + listnode, tmp_ifc)) + if (prefix_match((struct prefix *)p, + tmp_ifc->address)) { rinfo->metric_out = RIP_METRIC_INFINITY; - - if (rinfo->metric_out != RIP_METRIC_INFINITY - && rinfo->type == ZEBRA_ROUTE_CONNECT) { - for (ALL_LIST_ELEMENTS_RO( - ifc->ifp->connected, - listnode, tmp_ifc)) - if (prefix_match( - (struct prefix *)p, - tmp_ifc->address)) { - rinfo->metric_out = - RIP_METRIC_INFINITY; - break; - } - } + break; + } } + } - /* Prepare preamble, auth headers, if needs be */ - if (num == 0) { - stream_putc(s, RIP_RESPONSE); - stream_putc(s, version); - stream_putw(s, 0); - - /* auth header for !v1 && !no_auth */ - if ((ri->auth_type != RIP_NO_AUTH) - && (version != RIPv1)) - doff = rip_auth_header_write( - s, ri, key, auth_str, - RIP_AUTH_SIMPLE_SIZE); - } + /* Prepare preamble, auth headers, if needs be */ + if (num == 0) { + stream_putc(s, RIP_RESPONSE); + stream_putc(s, version); + stream_putw(s, 0); + + /* auth header for !v1 && !no_auth */ + if ((ri->auth_type != RIP_NO_AUTH) && + (version != RIPv1)) + doff = rip_auth_header_write( + s, ri, key, auth_str, + RIP_AUTH_SIMPLE_SIZE); + } - /* Write RTE to the stream. */ - num = rip_write_rte(num, s, p, version, rinfo); - if (num == rtemax) { - if (version == RIPv2 - && ri->auth_type == RIP_AUTH_MD5) - rip_auth_md5_set(s, ri, doff, auth_str, - RIP_AUTH_SIMPLE_SIZE); - - ret = rip_send_packet(STREAM_DATA(s), - stream_get_endp(s), to, - ifc); - - if (ret >= 0 && IS_RIP_DEBUG_SEND) - rip_packet_dump((struct rip_packet *) - STREAM_DATA(s), - stream_get_endp(s), - "SEND"); - num = 0; - stream_reset(s); - } + /* Write RTE to the stream. */ + num = rip_write_rte(num, s, p, version, rinfo); + if (num == rtemax) { + if (version == RIPv2 && ri->auth_type == RIP_AUTH_MD5) + rip_auth_md5_set(s, ri, doff, auth_str, + RIP_AUTH_SIMPLE_SIZE); + + ret = rip_send_packet(STREAM_DATA(s), + stream_get_endp(s), to, ifc); + + if (ret >= 0 && IS_RIP_DEBUG_SEND) + rip_packet_dump( + (struct rip_packet *)STREAM_DATA(s), + stream_get_endp(s), "SEND"); + num = 0; + stream_reset(s); } + } /* Flush unwritten RTE. */ if (num != 0) { @@ -2482,65 +2439,63 @@ static void rip_update_process(struct rip *rip, int route_type) if (ri->passive) continue; - if (ri->running) { - /* - * If there is no version configuration in the - * interface, - * use rip's version setting. - */ - int vsend = ((ri->ri_send == RI_RIP_UNSPEC) - ? rip->version_send - : ri->ri_send); + if (!ri->running) + continue; - if (IS_RIP_DEBUG_EVENT) - zlog_debug("SEND UPDATE to %s ifindex %d", - ifp->name, ifp->ifindex); - - /* send update on each connected network */ - for (ALL_LIST_ELEMENTS(ifp->connected, ifnode, ifnnode, - connected)) { - if (connected->address->family == AF_INET) { - if (vsend & RIPv1) - rip_update_interface( - connected, RIPv1, - route_type); - if ((vsend & RIPv2) - && if_is_multicast(ifp)) - rip_update_interface( - connected, RIPv2, - route_type); - } + /* + * If there is no version configuration in the + * interface, use rip's version setting. + */ + int vsend = ((ri->ri_send == RI_RIP_UNSPEC) ? rip->version_send + : ri->ri_send); + + if (IS_RIP_DEBUG_EVENT) + zlog_debug("SEND UPDATE to %s ifindex %d", ifp->name, + ifp->ifindex); + + /* send update on each connected network */ + for (ALL_LIST_ELEMENTS(ifp->connected, ifnode, ifnnode, + connected)) { + if (connected->address->family == AF_INET) { + if (vsend & RIPv1) + rip_update_interface(connected, RIPv1, + route_type); + if ((vsend & RIPv2) && if_is_multicast(ifp)) + rip_update_interface(connected, RIPv2, + route_type); } } } /* RIP send updates to each neighbor. */ - for (rp = route_top(rip->neighbor); rp; rp = route_next(rp)) - if (rp->info != NULL) { - p = &rp->p; - - connected = if_lookup_address(&p->u.prefix4, AF_INET, - rip->vrf->vrf_id); - if (!connected) { - zlog_warn( - "Neighbor %pI4 doesn't have connected interface!", - &p->u.prefix4); - continue; - } + for (rp = route_top(rip->neighbor); rp; rp = route_next(rp)) { + if (rp->info == NULL) + continue; - /* Set destination address and port */ - memset(&to, 0, sizeof(struct sockaddr_in)); - to.sin_addr = p->u.prefix4; - to.sin_port = htons(RIP_PORT_DEFAULT); + p = &rp->p; - /* RIP version is rip's configuration. */ - rip_output_process(connected, &to, route_type, - rip->version_send); + connected = if_lookup_address(&p->u.prefix4, AF_INET, + rip->vrf->vrf_id); + if (!connected) { + zlog_warn( + "Neighbor %pI4 doesn't have connected interface!", + &p->u.prefix4); + continue; } + + /* Set destination address and port */ + memset(&to, 0, sizeof(struct sockaddr_in)); + to.sin_addr = p->u.prefix4; + to.sin_port = htons(RIP_PORT_DEFAULT); + + /* RIP version is rip's configuration. */ + rip_output_process(connected, &to, route_type, + rip->version_send); + } } /* RIP's periodical timer. */ -static int rip_update(struct thread *t) +static void rip_update(struct thread *t) { struct rip *rip = THREAD_ARG(t); @@ -2557,8 +2512,6 @@ static int rip_update(struct thread *t) /* Register myself. */ rip_event(rip, RIP_UPDATE_EVENT, 0); - - return 0; } /* Walk down the RIP routing table then clear changed flag. */ @@ -2569,18 +2522,22 @@ static void rip_clear_changed_flag(struct rip *rip) struct list *list = NULL; struct listnode *listnode = NULL; - for (rp = route_top(rip->table); rp; rp = route_next(rp)) - if ((list = rp->info) != NULL) - for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { - UNSET_FLAG(rinfo->flags, RIP_RTF_CHANGED); - /* This flag can be set only on the first entry. - */ - break; - } + for (rp = route_top(rip->table); rp; rp = route_next(rp)) { + list = rp->info; + + if (list == NULL) + continue; + + for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { + UNSET_FLAG(rinfo->flags, RIP_RTF_CHANGED); + /* This flag can be set only on the first entry. */ + break; + } + } } /* Triggered update interval timer. */ -static int rip_triggered_interval(struct thread *t) +static void rip_triggered_interval(struct thread *t) { struct rip *rip = THREAD_ARG(t); @@ -2588,11 +2545,10 @@ static int rip_triggered_interval(struct thread *t) rip->trigger = 0; rip_triggered_update(t); } - return 0; } /* Execute triggered update. */ -static int rip_triggered_update(struct thread *t) +static void rip_triggered_update(struct thread *t) { struct rip *rip = THREAD_ARG(t); int interval; @@ -2621,8 +2577,6 @@ static int rip_triggered_update(struct thread *t) thread_add_timer(master, rip_triggered_interval, rip, interval, &rip->t_triggered_interval); - - return 0; } /* Withdraw redistributed route. */ @@ -2632,34 +2586,39 @@ void rip_redistribute_withdraw(struct rip *rip, int type) struct rip_info *rinfo = NULL; struct list *list = NULL; - for (rp = route_top(rip->table); rp; rp = route_next(rp)) - if ((list = rp->info) != NULL) { - rinfo = listgetdata(listhead(list)); - if (rinfo->type == type - && rinfo->sub_type != RIP_ROUTE_INTERFACE) { - /* Perform poisoned reverse. */ - rinfo->metric = RIP_METRIC_INFINITY; - RIP_TIMER_ON(rinfo->t_garbage_collect, - rip_garbage_collect, - rip->garbage_time); - RIP_TIMER_OFF(rinfo->t_timeout); - rinfo->flags |= RIP_RTF_CHANGED; + for (rp = route_top(rip->table); rp; rp = route_next(rp)) { + list = rp->info; - if (IS_RIP_DEBUG_EVENT) { - struct prefix_ipv4 *p = - (struct prefix_ipv4 *)&rp->p; + if (list == NULL) + continue; - zlog_debug( - "Poisone %pFX on the interface %s with an infinity metric [withdraw]", - p, - ifindex2ifname( - rinfo->nh.ifindex, - rip->vrf->vrf_id)); - } + rinfo = listgetdata(listhead(list)); - rip_event(rip, RIP_TRIGGERED_UPDATE, 0); - } + if (rinfo->type != type) + continue; + + if (rinfo->sub_type == RIP_ROUTE_INTERFACE) + continue; + + /* Perform poisoned reverse. */ + rinfo->metric = RIP_METRIC_INFINITY; + RIP_TIMER_ON(rinfo->t_garbage_collect, rip_garbage_collect, + rip->garbage_time); + RIP_TIMER_OFF(rinfo->t_timeout); + rinfo->flags |= RIP_RTF_CHANGED; + + if (IS_RIP_DEBUG_EVENT) { + struct prefix_ipv4 *p = (struct prefix_ipv4 *)&rp->p; + + zlog_debug( + "Poisone %pFX on the interface %s with an infinity metric [withdraw]", + p, + ifindex2ifname(rinfo->nh.ifindex, + rip->vrf->vrf_id)); } + + rip_event(rip, RIP_TRIGGERED_UPDATE, 0); + } } struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id) @@ -2916,19 +2875,20 @@ static void rip_distance_show(struct vty *vty, struct rip *rip) vty_out(vty, " Distance: (default is %u)\n", rip->distance ? rip->distance : ZEBRA_RIP_DISTANCE_DEFAULT); - for (rn = route_top(rip->distance_table); rn; rn = route_next(rn)) - if ((rdistance = rn->info) != NULL) { - if (header) { - vty_out(vty, - " Address Distance List\n"); - header = 0; - } - snprintfrr(buf, sizeof(buf), "%pFX", &rn->p); - vty_out(vty, " %-20s %4d %s\n", buf, - rdistance->distance, - rdistance->access_list ? rdistance->access_list - : ""); + for (rn = route_top(rip->distance_table); rn; rn = route_next(rn)) { + rdistance = rn->info; + + if (rdistance == NULL) + continue; + + if (header) { + vty_out(vty, " Address Distance List\n"); + header = 0; } + snprintfrr(buf, sizeof(buf), "%pFX", &rn->p); + vty_out(vty, " %-20s %4d %s\n", buf, rdistance->distance, + rdistance->access_list ? rdistance->access_list : ""); + } } /* Update ECMP routes to zebra when ECMP is disabled. */ @@ -2939,31 +2899,38 @@ void rip_ecmp_disable(struct rip *rip) struct list *list; struct listnode *node, *nextnode; - for (rp = route_top(rip->table); rp; rp = route_next(rp)) - if ((list = rp->info) != NULL && listcount(list) > 1) { - rinfo = listgetdata(listhead(list)); - if (!rip_route_rte(rinfo)) - continue; + for (rp = route_top(rip->table); rp; rp = route_next(rp)) { + list = rp->info; - /* Drop all other entries, except the first one. */ - for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo)) - if (tmp_rinfo != rinfo) { - RIP_TIMER_OFF(tmp_rinfo->t_timeout); - RIP_TIMER_OFF( - tmp_rinfo->t_garbage_collect); - list_delete_node(list, node); - rip_info_free(tmp_rinfo); - } + if (!list) + continue; + if (listcount(list) == 0) + continue; - /* Update zebra. */ - rip_zebra_ipv4_add(rip, rp); + rinfo = listgetdata(listhead(list)); + if (!rip_route_rte(rinfo)) + continue; - /* Set the route change flag. */ - SET_FLAG(rinfo->flags, RIP_RTF_CHANGED); + /* Drop all other entries, except the first one. */ + for (ALL_LIST_ELEMENTS(list, node, nextnode, tmp_rinfo)) { + if (tmp_rinfo == rinfo) + continue; - /* Signal the output process to trigger an update. */ - rip_event(rip, RIP_TRIGGERED_UPDATE, 0); + RIP_TIMER_OFF(tmp_rinfo->t_timeout); + RIP_TIMER_OFF(tmp_rinfo->t_garbage_collect); + list_delete_node(list, node); + rip_info_free(tmp_rinfo); } + + /* Update zebra. */ + rip_zebra_ipv4_add(rip, rp); + + /* Set the route change flag. */ + SET_FLAG(rinfo->flags, RIP_RTF_CHANGED); + + /* Signal the output process to trigger an update. */ + rip_event(rip, RIP_TRIGGERED_UPDATE, 0); + } } /* Print out routes update time. */ @@ -3044,82 +3011,77 @@ DEFUN (show_ip_rip, " (i) - interface\n\n" " Network Next Hop Metric From Tag Time\n"); - for (np = route_top(rip->table); np; np = route_next(np)) - if ((list = np->info) != NULL) - for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { - int len; - - len = vty_out( - vty, "%c(%s) %pFX", - /* np->lock, For debugging. */ - zebra_route_char(rinfo->type), - rip_route_type_print(rinfo->sub_type), - &np->p); - - len = 24 - len; - - if (len > 0) - vty_out(vty, "%*s", len, " "); - - switch (rinfo->nh.type) { - case NEXTHOP_TYPE_IPV4: - case NEXTHOP_TYPE_IPV4_IFINDEX: - vty_out(vty, "%-20pI4 %2d ", - &rinfo->nh.gate.ipv4, - rinfo->metric); - break; - case NEXTHOP_TYPE_IFINDEX: - vty_out(vty, - "0.0.0.0 %2d ", - rinfo->metric); - break; - case NEXTHOP_TYPE_BLACKHOLE: - vty_out(vty, - "blackhole %2d ", - rinfo->metric); - break; - case NEXTHOP_TYPE_IPV6: - case NEXTHOP_TYPE_IPV6_IFINDEX: - vty_out(vty, - "V6 Address Hidden %2d ", - rinfo->metric); - break; - } + for (np = route_top(rip->table); np; np = route_next(np)) { + list = np->info; - /* Route which exist in kernel routing table. */ - if ((rinfo->type == ZEBRA_ROUTE_RIP) - && (rinfo->sub_type == RIP_ROUTE_RTE)) { - vty_out(vty, "%-15pI4 ", - &rinfo->from); - vty_out(vty, "%3" ROUTE_TAG_PRI " ", - (route_tag_t)rinfo->tag); - rip_vty_out_uptime(vty, rinfo); - } else if (rinfo->metric - == RIP_METRIC_INFINITY) { - vty_out(vty, "self "); - vty_out(vty, "%3" ROUTE_TAG_PRI " ", - (route_tag_t)rinfo->tag); - rip_vty_out_uptime(vty, rinfo); - } else { - if (rinfo->external_metric) { - len = vty_out( - vty, "self (%s:%d)", - zebra_route_string( - rinfo->type), - rinfo->external_metric); - len = 16 - len; - if (len > 0) - vty_out(vty, "%*s", len, - " "); - } else - vty_out(vty, - "self "); - vty_out(vty, "%3" ROUTE_TAG_PRI, - (route_tag_t)rinfo->tag); - } + if (!list) + continue; + + for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { + int len; - vty_out(vty, "\n"); + len = vty_out(vty, "%c(%s) %pFX", + /* np->lock, For debugging. */ + zebra_route_char(rinfo->type), + rip_route_type_print(rinfo->sub_type), + &np->p); + + len = 24 - len; + + if (len > 0) + vty_out(vty, "%*s", len, " "); + + switch (rinfo->nh.type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + vty_out(vty, "%-20pI4 %2d ", + &rinfo->nh.gate.ipv4, rinfo->metric); + break; + case NEXTHOP_TYPE_IFINDEX: + vty_out(vty, "0.0.0.0 %2d ", + rinfo->metric); + break; + case NEXTHOP_TYPE_BLACKHOLE: + vty_out(vty, "blackhole %2d ", + rinfo->metric); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + vty_out(vty, "V6 Address Hidden %2d ", + rinfo->metric); + break; + } + + /* Route which exist in kernel routing table. */ + if ((rinfo->type == ZEBRA_ROUTE_RIP) && + (rinfo->sub_type == RIP_ROUTE_RTE)) { + vty_out(vty, "%-15pI4 ", &rinfo->from); + vty_out(vty, "%3" ROUTE_TAG_PRI " ", + (route_tag_t)rinfo->tag); + rip_vty_out_uptime(vty, rinfo); + } else if (rinfo->metric == RIP_METRIC_INFINITY) { + vty_out(vty, "self "); + vty_out(vty, "%3" ROUTE_TAG_PRI " ", + (route_tag_t)rinfo->tag); + rip_vty_out_uptime(vty, rinfo); + } else { + if (rinfo->external_metric) { + len = vty_out( + vty, "self (%s:%d)", + zebra_route_string(rinfo->type), + rinfo->external_metric); + len = 16 - len; + if (len > 0) + vty_out(vty, "%*s", len, " "); + } else + vty_out(vty, "self "); + vty_out(vty, "%3" ROUTE_TAG_PRI, + (route_tag_t)rinfo->tag); } + + vty_out(vty, "\n"); + } + } return CMD_SUCCESS; } @@ -3219,20 +3181,17 @@ DEFUN (show_ip_rip_status, vty_out(vty, " Routing for Networks:\n"); rip_show_network_config(vty, rip); - { - int found_passive = 0; - FOR_ALL_INTERFACES (rip->vrf, ifp) { - ri = ifp->info; - - if ((ri->enable_network || ri->enable_interface) - && ri->passive) { - if (!found_passive) { - vty_out(vty, - " Passive Interface(s):\n"); - found_passive = 1; - } - vty_out(vty, " %s\n", ifp->name); + int found_passive = 0; + FOR_ALL_INTERFACES (rip->vrf, ifp) { + ri = ifp->info; + + if ((ri->enable_network || ri->enable_interface) && + ri->passive) { + if (!found_passive) { + vty_out(vty, " Passive Interface(s):\n"); + found_passive = 1; } + vty_out(vty, " %s\n", ifp->name); } } diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index a6d379fda4..57bc40f005 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -601,7 +601,7 @@ int ripng_enable_if_delete(struct ripng *ripng, const char *ifname) } /* Wake up interface. */ -static int ripng_interface_wakeup(struct thread *t) +static void ripng_interface_wakeup(struct thread *t) { struct interface *ifp; struct ripng_interface *ri; @@ -616,7 +616,7 @@ static int ripng_interface_wakeup(struct thread *t) flog_err_sys(EC_LIB_SOCKET, "multicast join failed, interface %s not running", ifp->name); - return 0; + return; } /* Set running flag. */ @@ -624,8 +624,6 @@ static int ripng_interface_wakeup(struct thread *t) /* Send RIP request to the interface. */ ripng_request(ifp); - - return 0; } static void ripng_connect_set(struct interface *ifp, int set) diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index 554b1d68f6..010fdda89e 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -75,15 +75,13 @@ struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng, /* RIPng peer is timeout. * Garbage collector. **/ -static int ripng_peer_timeout(struct thread *t) +static void ripng_peer_timeout(struct thread *t) { struct ripng_peer *peer; peer = THREAD_ARG(t); listnode_delete(peer->ripng->peer_list, peer); ripng_peer_free(peer); - - return 0; } /* Get RIPng peer. At the same time update timeout thread. */ diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 27cffd4321..e103cdc3a8 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -61,7 +61,7 @@ void ripng_output_process(struct interface *, struct sockaddr_in6 *, int); static void ripng_instance_enable(struct ripng *ripng, struct vrf *vrf, int sock); static void ripng_instance_disable(struct ripng *ripng); -int ripng_triggered_update(struct thread *); +static void ripng_triggered_update(struct thread *); static void ripng_if_rmap_update(struct if_rmap_ctx *ctx, struct if_rmap *if_rmap); @@ -423,7 +423,7 @@ static int ripng_lladdr_check(struct interface *ifp, struct in6_addr *addr) } /* RIPng route garbage collect timer. */ -static int ripng_garbage_collect(struct thread *t) +static void ripng_garbage_collect(struct thread *t) { struct ripng_info *rinfo; struct agg_node *rp; @@ -445,8 +445,6 @@ static int ripng_garbage_collect(struct thread *t) /* Free RIPng routing information. */ ripng_info_free(rinfo); - - return 0; } static void ripng_timeout_update(struct ripng *ripng, struct ripng_info *rinfo); @@ -602,14 +600,12 @@ struct ripng_info *ripng_ecmp_delete(struct ripng *ripng, } /* Timeout RIPng routes. */ -static int ripng_timeout(struct thread *t) +static void ripng_timeout(struct thread *t) { struct ripng_info *rinfo = THREAD_ARG(t); struct ripng *ripng = ripng_info_get_instance(rinfo); ripng_ecmp_delete(ripng, rinfo); - - return 0; } static void ripng_timeout_update(struct ripng *ripng, struct ripng_info *rinfo) @@ -1301,7 +1297,7 @@ static void ripng_request_process(struct ripng_packet *packet, int size, } /* First entry point of reading RIPng packet. */ -static int ripng_read(struct thread *thread) +static void ripng_read(struct thread *thread) { struct ripng *ripng = THREAD_ARG(thread); int len; @@ -1330,7 +1326,7 @@ static int ripng_read(struct thread *thread) if (len < 0) { zlog_warn("RIPng recvfrom failed (VRF %s): %s.", ripng->vrf_name, safe_strerror(errno)); - return len; + return; } /* Check RTE boundary. RTE size (Packet length - RIPng header size @@ -1339,7 +1335,7 @@ static int ripng_read(struct thread *thread) zlog_warn("RIPng invalid packet size %d from %pI6 (VRF %s)", len, &from.sin6_addr, ripng->vrf_name); ripng_peer_bad_packet(ripng, &from); - return 0; + return; } packet = (struct ripng_packet *)STREAM_DATA(ripng->ibuf); @@ -1361,7 +1357,7 @@ static int ripng_read(struct thread *thread) zlog_warn( "RIPng packet comes from unknown interface %d (VRF %s)", ifindex, ripng->vrf_name); - return 0; + return; } /* Packet version mismatch checking. */ @@ -1370,7 +1366,7 @@ static int ripng_read(struct thread *thread) "RIPng packet version %d doesn't fit to my version %d (VRF %s)", packet->version, ripng->version, ripng->vrf_name); ripng_peer_bad_packet(ripng, &from); - return 0; + return; } /* Process RIPng packet. */ @@ -1387,7 +1383,6 @@ static int ripng_read(struct thread *thread) ripng_peer_bad_packet(ripng, &from); break; } - return 0; } /* Walk down the RIPng routing table then clear changed flag. */ @@ -1410,7 +1405,7 @@ static void ripng_clear_changed_flag(struct ripng *ripng) /* Regular update of RIPng route. Send all routing formation to RIPng enabled interface. */ -static int ripng_update(struct thread *t) +static void ripng_update(struct thread *t) { struct ripng *ripng = THREAD_ARG(t); struct interface *ifp; @@ -1455,12 +1450,10 @@ static int ripng_update(struct thread *t) /* Reset flush event. */ ripng_event(ripng, RIPNG_UPDATE_EVENT, 0); - - return 0; } /* Triggered update interval timer. */ -static int ripng_triggered_interval(struct thread *t) +static void ripng_triggered_interval(struct thread *t) { struct ripng *ripng = THREAD_ARG(t); @@ -1468,11 +1461,10 @@ static int ripng_triggered_interval(struct thread *t) ripng->trigger = 0; ripng_triggered_update(t); } - return 0; } /* Execute triggered update. */ -int ripng_triggered_update(struct thread *t) +void ripng_triggered_update(struct thread *t) { struct ripng *ripng = THREAD_ARG(t); struct interface *ifp; @@ -1518,8 +1510,6 @@ int ripng_triggered_update(struct thread *t) thread_add_timer(master, ripng_triggered_interval, ripng, interval, &ripng->t_triggered_interval); - - return 0; } /* Write routing table entry to the stream and return next index of diff --git a/sharpd/sharp_logpump.c b/sharpd/sharp_logpump.c index 322d802b8a..ad1051f224 100644 --- a/sharpd/sharp_logpump.c +++ b/sharpd/sharp_logpump.c @@ -43,7 +43,7 @@ static struct vty *lp_vty; extern struct thread_master *master; -static int logpump_done(struct thread *thread) +static void logpump_done(struct thread *thread) { double x; @@ -67,7 +67,6 @@ static int logpump_done(struct thread *thread) frr_pthread_stop(lpt, NULL); frr_pthread_destroy(lpt); lpt = NULL; - return 0; } static void *logpump_run(void *arg) diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index ceed9cf739..78cc57cc44 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -540,7 +540,7 @@ DEFPY(vrf_label, vrf_label_cmd, vrf = vrf_lookup_by_name(vrf_name); if (!vrf) { - vty_out(vty, "Unable to find vrf you silly head"); + vty_out(vty, "Unable to find vrf you silly head\n"); return CMD_WARNING_CONFIG_FAILED; } diff --git a/snapcraft/snapcraft.yaml.in b/snapcraft/snapcraft.yaml.in index 51252ede0c..01033d0413 100644 --- a/snapcraft/snapcraft.yaml.in +++ b/snapcraft/snapcraft.yaml.in @@ -306,6 +306,7 @@ parts: - make - gawk - libreadline-dev + - libelf-dev - texinfo - libncurses5-dev - texlive-latex-base diff --git a/staticd/static_main.c b/staticd/static_main.c index 3bd784b594..7badd50049 100644 --- a/staticd/static_main.c +++ b/staticd/static_main.c @@ -43,7 +43,6 @@ char backup_config_file[256]; bool mpls_enabled; -uint32_t zebra_ecmp_count = MULTIPATH_NUM; zebra_capabilities_t _caps_p[] = { }; diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index b75e1a1cdf..f937492ec2 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -47,6 +47,7 @@ /* Zebra structure to hold current status. */ struct zclient *zclient; static struct hash *static_nht_hash; +uint32_t zebra_ecmp_count = MULTIPATH_NUM; /* Inteface addition message from zebra. */ static int static_ifp_create(struct interface *ifp) @@ -302,12 +303,14 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) static_nht_hash_alloc); nhtd->refcount++; - DEBUGD(&static_dbg_route, - "Registered nexthop(%pFX) for %pRN %d", &p, rn, - nhtd->nh_num); - if (nhtd->refcount > 1 && nhtd->nh_num) { - static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num, afi, - nh->nh_vrf_id); + if (nhtd->refcount > 1) { + DEBUGD(&static_dbg_route, + "Already registered nexthop(%pFX) for %pRN %d", + &p, rn, nhtd->nh_num); + if (nhtd->nh_num) + static_nht_update(&rn->p, nhtd->nh, + nhtd->nh_num, afi, + nh->nh_vrf_id); return; } } else { @@ -323,6 +326,9 @@ void static_zebra_nht_register(struct static_nexthop *nh, bool reg) static_nht_hash_free(nhtd); } + DEBUGD(&static_dbg_route, "%s nexthop(%pFX) for %pRN", + reg ? "Registering" : "Unregistering", &p, rn); + if (zclient_send_rnh(zclient, cmd, &p, false, false, nh->nh_vrf_id) == ZCLIENT_SEND_FAILURE) zlog_warn("%s: Failure to send nexthop to zebra", __func__); diff --git a/tests/helpers/c/main.c b/tests/helpers/c/main.c index 64ecab9132..ca6b18ecda 100644 --- a/tests/helpers/c/main.c +++ b/tests/helpers/c/main.c @@ -47,13 +47,12 @@ DEFUN (daemon_exit, } static int timer_count; -static int test_timer(struct thread *thread) +static void test_timer(struct thread *thread) { int *count = THREAD_ARG(thread); printf("run %d of timer\n", (*count)++); thread_add_timer(master, test_timer, count, 5, NULL); - return 0; } static void test_timer_init(void) diff --git a/tests/lib/subdir.am b/tests/lib/subdir.am index 6c897b132e..62b194439f 100644 --- a/tests/lib/subdir.am +++ b/tests/lib/subdir.am @@ -148,7 +148,7 @@ check_PROGRAMS += tests/lib/test_checksum tests_lib_test_checksum_CFLAGS = $(TESTS_CFLAGS) tests_lib_test_checksum_CPPFLAGS = $(TESTS_CPPFLAGS) tests_lib_test_checksum_LDADD = $(ALL_TESTS_LDADD) -tests_lib_test_checksum_SOURCES = tests/lib/test_checksum.c +tests_lib_test_checksum_SOURCES = tests/lib/test_checksum.c tests/helpers/c/prng.c check_PROGRAMS += tests/lib/test_graph diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c index 301078867a..9a7f2b1472 100644 --- a/tests/lib/test_checksum.c +++ b/tests/lib/test_checksum.c @@ -24,6 +24,7 @@ #include "checksum.h" #include "network.h" +#include "prng.h" struct thread_master *master; @@ -468,45 +469,88 @@ int main(int argc, char **argv) uint8_t buffer[BUFSIZE]; int exercise = 0; #define EXERCISESTEP 257 - srandom(time(NULL)); + struct prng *prng = prng_new(0); while (1) { uint16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc; - int i, j; + int i; exercise += EXERCISESTEP; exercise %= MAXDATALEN; - for (i = 0; i < exercise; i += sizeof(long int)) { - long int rand = frr_weak_random(); + printf("\rexercising length %d\033[K", exercise); - for (j = sizeof(long int); j > 0; j--) - buffer[i + (sizeof(long int) - j)] = - (rand >> (j * 8)) & 0xff; - } + for (i = 0; i < exercise; i++) + buffer[i] = prng_rand(prng); in_csum = in_cksum(buffer, exercise); in_csum_res = in_cksum_optimized(buffer, exercise); in_csum_rfc = in_cksum_rfc(buffer, exercise); if (in_csum_res != in_csum || in_csum != in_csum_rfc) - printf("verify: in_chksum failed in_csum:%x, in_csum_res:%x,in_csum_rfc %x, len:%d\n", + printf("\nverify: in_chksum failed in_csum:%x, in_csum_res:%x,in_csum_rfc %x, len:%d\n", in_csum, in_csum_res, in_csum_rfc, exercise); + struct iovec iov[3]; + uint16_t in_csum_iov; + + iov[0].iov_base = buffer; + iov[0].iov_len = exercise / 2; + iov[1].iov_base = buffer + iov[0].iov_len; + iov[1].iov_len = exercise - iov[0].iov_len; + + in_csum_iov = in_cksumv(iov, 2); + if (in_csum_iov != in_csum) + printf("\nverify: in_cksumv failed, lens: %zu+%zu\n", + iov[0].iov_len, iov[1].iov_len); + + if (exercise >= 6) { + /* force split with byte leftover */ + iov[0].iov_base = buffer; + iov[0].iov_len = (exercise / 2) | 1; + iov[1].iov_base = buffer + iov[0].iov_len; + iov[1].iov_len = 2; + iov[2].iov_base = buffer + iov[0].iov_len + 2; + iov[2].iov_len = exercise - iov[0].iov_len - 2; + + in_csum_iov = in_cksumv(iov, 3); + if (in_csum_iov != in_csum) + printf("\nverify: in_cksumv failed, lens: %zu+%zu+%zu, got %04x, expected %04x\n", + iov[0].iov_len, iov[1].iov_len, + iov[2].iov_len, in_csum_iov, in_csum); + + /* force split without byte leftover */ + iov[0].iov_base = buffer; + iov[0].iov_len = (exercise / 2) & ~1UL; + iov[1].iov_base = buffer + iov[0].iov_len; + iov[1].iov_len = 2; + iov[2].iov_base = buffer + iov[0].iov_len + 2; + iov[2].iov_len = exercise - iov[0].iov_len - 2; + + in_csum_iov = in_cksumv(iov, 3); + if (in_csum_iov != in_csum) + printf("\nverify: in_cksumv failed, lens: %zu+%zu+%zu, got %04x, expected %04x\n", + iov[0].iov_len, iov[1].iov_len, + iov[2].iov_len, in_csum_iov, in_csum); + } + + if (exercise >= FLETCHER_CHECKSUM_VALIDATE) + continue; + ospfd = ospfd_checksum(buffer, exercise + sizeof(uint16_t), exercise); if (verify(buffer, exercise + sizeof(uint16_t))) - printf("verify: ospfd failed\n"); + printf("\nverify: ospfd failed\n"); isisd = iso_csum_create(buffer, exercise + sizeof(uint16_t), exercise); if (verify(buffer, exercise + sizeof(uint16_t))) - printf("verify: isisd failed\n"); + printf("\nverify: isisd failed\n"); lib = fletcher_checksum(buffer, exercise + sizeof(uint16_t), exercise); if (verify(buffer, exercise + sizeof(uint16_t))) - printf("verify: lib failed\n"); + printf("\nverify: lib failed\n"); if (ospfd != lib) { - printf("Mismatch in values at size %d\n" + printf("\nMismatch in values at size %d\n" "ospfd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" "isisd: 0x%04x\tc0: %d\tc1: %d\tx: %d\ty: %d\n" "lib: 0x%04x\n", diff --git a/tests/lib/test_grpc.cpp b/tests/lib/test_grpc.cpp index 0aa1bbb7e1..88372f45a5 100644 --- a/tests/lib/test_grpc.cpp +++ b/tests/lib/test_grpc.cpp @@ -79,7 +79,7 @@ static const struct frr_yang_module_info *const staticd_yang_modules[] = { &frr_staticd_info, &frr_vrf_info, }; -static int grpc_thread_stop(struct thread *thread); +static void grpc_thread_stop(struct thread *thread); static void _err_print(const void *cookie, const char *errstr) { @@ -499,7 +499,7 @@ void *grpc_client_test_start(void *arg) return NULL; } -static int grpc_thread_start(struct thread *thread) +static void grpc_thread_start(struct thread *thread) { struct frr_pthread_attr client = { .start = grpc_client_test_start, @@ -509,11 +509,9 @@ static int grpc_thread_start(struct thread *thread) auto pth = frr_pthread_new(&client, "GRPC Client thread", "grpc"); frr_pthread_run(pth, NULL); frr_pthread_wait_running(pth); - - return 0; } -static int grpc_thread_stop(struct thread *thread) +static void grpc_thread_stop(struct thread *thread) { std::cout << __func__ << ": frr_pthread_stop_all" << std::endl; frr_pthread_stop_all(); diff --git a/tests/lib/test_heavy_thread.c b/tests/lib/test_heavy_thread.c index d516ed0de0..466f9a7d97 100644 --- a/tests/lib/test_heavy_thread.c +++ b/tests/lib/test_heavy_thread.c @@ -70,7 +70,7 @@ static void slow_func(struct vty *vty, const char *str, const int i) printf("%s did %d, x = %g\n", str, i, x); } -static int clear_something(struct thread *thread) +static void clear_something(struct thread *thread) { struct work_state *ws = THREAD_ARG(thread); @@ -84,14 +84,13 @@ static int clear_something(struct thread *thread) if (thread_should_yield(thread)) { thread_add_timer_msec(master, clear_something, ws, 0, NULL); - return 0; + return; } } /* All done! */ XFREE(MTYPE_TMP, ws->str); XFREE(MTYPE_TMP, ws); - return 0; } DEFUN (clear_foo, diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index 494a162a45..92c9f7a2ea 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -62,10 +62,9 @@ void func3(void) func2(6, buf); } -static int threadfunc(struct thread *thread) +static void threadfunc(struct thread *thread) { func3(); - return 0; } int main(void) diff --git a/tests/lib/test_timer_correctness.c b/tests/lib/test_timer_correctness.c index 1756d87a6f..4172ca3001 100644 --- a/tests/lib/test_timer_correctness.c +++ b/tests/lib/test_timer_correctness.c @@ -76,7 +76,7 @@ static void terminate_test(void) exit(exit_code); } -static int timer_func(struct thread *thread) +static void timer_func(struct thread *thread) { int rv; @@ -90,8 +90,6 @@ static int timer_func(struct thread *thread) timers_pending--; if (!timers_pending) terminate_test(); - - return 0; } static int cmp_timeval(const void *a, const void *b) diff --git a/tests/lib/test_timer_performance.c b/tests/lib/test_timer_performance.c index f9d634b6a6..c1dd07b899 100644 --- a/tests/lib/test_timer_performance.c +++ b/tests/lib/test_timer_performance.c @@ -35,9 +35,8 @@ struct thread_master *master; -static int dummy_func(struct thread *thread) +static void dummy_func(struct thread *thread) { - return 0; } int main(int argc, char **argv) diff --git a/tests/topotests/bgp_conditional_advertisement/r2/bgpd.conf b/tests/topotests/bgp_conditional_advertisement/r2/bgpd.conf index 82525fac64..73f837c69b 100644 --- a/tests/topotests/bgp_conditional_advertisement/r2/bgpd.conf +++ b/tests/topotests/bgp_conditional_advertisement/r2/bgpd.conf @@ -19,6 +19,7 @@ route-map ADV-MAP-1 permit 20 ! route-map ADV-MAP-2 permit 10 match ip address prefix-list IP2 + set metric 911 ! route-map EXIST-MAP permit 10 match community DEFAULT-ROUTE diff --git a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py index e9b393ba7f..6153aee418 100644 --- a/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py +++ b/tests/topotests/bgp_conditional_advertisement/test_bgp_conditional_advertisement.py @@ -334,7 +334,7 @@ def test_bgp_conditional_advertisement(): "192.0.2.1/32": None, "192.0.2.5/32": None, "10.139.224.0/20": None, - "203.0.113.1/32": [{"protocol": "bgp"}], + "203.0.113.1/32": [{"protocol": "bgp", "metric": 911}], } return topotest.json_cmp(output, expected) diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index f538b5a52b..c0572fca4c 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -1195,7 +1195,7 @@ def add_interfaces_to_vlan(tgen, input_dict): # Assigning IP address ifaddr = ipaddress.ip_interface( - u"{}/{}".format( + "{}/{}".format( frr_unicode(data["ip"]), frr_unicode(data["subnet"]) ) ) @@ -1626,7 +1626,7 @@ def create_interface_in_kernel( ifaddr = ipaddress.ip_interface(frr_unicode(ip_addr)) else: ifaddr = ipaddress.ip_interface( - u"{}/{}".format(frr_unicode(ip_addr), frr_unicode(netmask)) + "{}/{}".format(frr_unicode(ip_addr), frr_unicode(netmask)) ) cmd = "ip -{0} a flush {1} scope global && ip a add {2} dev {1} && ip l set {1} up".format( ifaddr.version, name, ifaddr @@ -4921,8 +4921,13 @@ def verify_ip_nht(tgen, input_dict): for nh in nh_list: if nh in show_ip_nht: - logger.info("Nexthop %s is resolved on %s", nh, router) - return True + nht = run_frr_cmd(rnode, f"show ip nht {nh}") + if "unresolved" in nht: + errormsg = "Nexthop {} became unresolved on {}".format(nh, router) + return errormsg + else: + logger.info("Nexthop %s is resolved on %s", nh, router) + return True else: errormsg = "Nexthop {} is resolved on {}".format(nh, router) return errormsg diff --git a/tests/topotests/lib/micronet.py b/tests/topotests/lib/micronet.py index 8567bd3b4b..59dd80ff7b 100644 --- a/tests/topotests/lib/micronet.py +++ b/tests/topotests/lib/micronet.py @@ -358,11 +358,14 @@ class Commander(object): # pylint: disable=R0205 # wait for not supported in screen for now channel = None cmd = [self.get_exec_path("screen")] + if title: + cmd.append("-t") + cmd.append(title) if not os.path.exists( "/run/screen/S-{}/{}".format(os.environ["USER"], os.environ["STY"]) ): cmd = ["sudo", "-u", os.environ["SUDO_USER"]] + cmd - cmd.append(nscmd) + cmd.extend(nscmd.split(" ")) elif "DISPLAY" in os.environ: # We need it broken up for xterm user_cmd = cmd diff --git a/tests/topotests/lib/micronet_cli.py b/tests/topotests/lib/micronet_cli.py index 6459d5d151..4292f47ce0 100644 --- a/tests/topotests/lib/micronet_cli.py +++ b/tests/topotests/lib/micronet_cli.py @@ -113,11 +113,11 @@ def doline(unet, line, writef): hosts = [unet.hosts[x] for x in args] for host in hosts: if cmd == "t" or cmd == "term": - host.run_in_window("bash") + host.run_in_window("bash", title="sh-%s" % host) elif cmd == "v" or cmd == "vtysh": - host.run_in_window("vtysh") + host.run_in_window("vtysh", title="vt-%s" % host) elif cmd == "x" or cmd == "xterm": - host.run_in_window("bash", forcex=True) + host.run_in_window("bash", title="sh-%s" % host, forcex=True) elif cmd == "sh": hosts, cmd = host_cmd_split(unet, oargs) for host in hosts: diff --git a/tests/topotests/lib/topogen.py b/tests/topotests/lib/topogen.py index 33e1388639..a83ae7071f 100644 --- a/tests/topotests/lib/topogen.py +++ b/tests/topotests/lib/topogen.py @@ -706,6 +706,7 @@ class TopoRouter(TopoGear): ] # Router Daemon enumeration definition. + RD_FRR = 0 # not a daemon, but use to setup unified configs RD_ZEBRA = 1 RD_RIP = 2 RD_RIPNG = 3 @@ -725,6 +726,7 @@ class TopoRouter(TopoGear): RD_PATH = 17 RD_SNMP = 18 RD = { + RD_FRR: "frr", RD_ZEBRA: "zebra", RD_RIP: "ripd", RD_RIPNG: "ripngd", @@ -789,6 +791,28 @@ class TopoRouter(TopoGear): self.logger.info('check capability {} for "{}"'.format(param, daemonstr)) return self.net.checkCapability(daemonstr, param) + def load_frr_config(self, source, daemons=None): + """ + Loads the unified configuration file source + Start the daemons in the list + If daemons is None, try to infer daemons from the config file + """ + self.load_config(self.RD_FRR, source) + if not daemons: + # Always add zebra + self.load_config(self.RD_ZEBRA) + for daemon in self.RD: + # This will not work for all daemons + daemonstr = self.RD.get(daemon).rstrip("d") + result = self.run( + "grep 'router {}' {}".format(daemonstr, source) + ).strip() + if result: + self.load_config(daemon) + else: + for daemon in daemons: + self.load_config(daemon) + def load_config(self, daemon, source=None, param=None): """Loads daemon configuration from the specified source Possible daemon values are: TopoRouter.RD_ZEBRA, TopoRouter.RD_RIP, diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 6be644ac00..4e5fe4c90b 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -1319,6 +1319,7 @@ class Router(Node): self.daemondir = None self.hasmpls = False self.routertype = "frr" + self.unified_config = None self.daemons = { "zebra": 0, "ripd": 0, @@ -1521,21 +1522,28 @@ class Router(Node): ) # print "Daemons before:", self.daemons - if daemon in self.daemons.keys(): - self.daemons[daemon] = 1 + if daemon in self.daemons.keys() or daemon == "frr": + if daemon == "frr": + self.unified_config = 1 + else: + self.daemons[daemon] = 1 if param is not None: self.daemons_options[daemon] = param conf_file = "/etc/{}/{}.conf".format(self.routertype, daemon) if source is None or not os.path.exists(source): - self.cmd_raises("rm -f " + conf_file) - self.cmd_raises("touch " + conf_file) + if daemon == "frr" or not self.unified_config: + self.cmd_raises("rm -f " + conf_file) + self.cmd_raises("touch " + conf_file) else: self.cmd_raises("cp {} {}".format(source, conf_file)) - self.cmd_raises("chown {0}:{0} {1}".format(self.routertype, conf_file)) - self.cmd_raises("chmod 664 {}".format(conf_file)) + + if not self.unified_config or daemon == "frr": + self.cmd_raises("chown {0}:{0} {1}".format(self.routertype, conf_file)) + self.cmd_raises("chmod 664 {}".format(conf_file)) + if (daemon == "snmpd") and (self.routertype == "frr"): # /etc/snmp is private mount now - self.cmd('echo "agentXSocket /etc/frr/agentx" > /etc/snmp/frr.conf') + self.cmd('echo "agentXSocket /etc/frr/agentx" >> /etc/snmp/frr.conf') self.cmd('echo "mibs +ALL" > /etc/snmp/snmp.conf') if (daemon == "zebra") and (self.daemons["staticd"] == 0): @@ -1557,11 +1565,18 @@ class Router(Node): return self.run_in_window(cmd, title) def startRouter(self, tgen=None): - # Disable integrated-vtysh-config - self.cmd( - 'echo "no service integrated-vtysh-config" >> /etc/%s/vtysh.conf' - % self.routertype - ) + if self.unified_config: + self.cmd( + 'echo "service integrated-vtysh-config" >> /etc/%s/vtysh.conf' + % self.routertype + ) + else: + # Disable integrated-vtysh-config + self.cmd( + 'echo "no service integrated-vtysh-config" >> /etc/%s/vtysh.conf' + % self.routertype + ) + self.cmd( "chown %s:%svty /etc/%s/vtysh.conf" % (self.routertype, self.routertype, self.routertype) @@ -1613,7 +1628,7 @@ class Router(Node): shell_routers = g_extra_config["shell"] if "all" in shell_routers or self.name in shell_routers: - self.run_in_window(os.getenv("SHELL", "bash")) + self.run_in_window(os.getenv("SHELL", "bash"), title="sh-%s" % self.name) if self.daemons["eigrpd"] == 1: eigrpd_path = os.path.join(self.daemondir, "eigrpd") @@ -1631,7 +1646,10 @@ class Router(Node): vtysh_routers = g_extra_config["vtysh"] if "all" in vtysh_routers or self.name in vtysh_routers: - self.run_in_window("vtysh") + self.run_in_window("vtysh", title="vt-%s" % self.name) + + if self.unified_config: + self.cmd("vtysh -f /etc/frr/frr.conf") return status diff --git a/tests/topotests/ospf_topo1_vrf/__init__.py b/tests/topotests/ospf_netns_vrf/__init__.py index e69de29bb2..e69de29bb2 100755 --- a/tests/topotests/ospf_topo1_vrf/__init__.py +++ b/tests/topotests/ospf_netns_vrf/__init__.py diff --git a/tests/topotests/ospf_topo1_vrf/r1/ospfd.conf b/tests/topotests/ospf_netns_vrf/r1/ospfd.conf index e1e2bfb99a..e1e2bfb99a 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r1/ospfd.conf diff --git a/tests/topotests/ospf_topo1_vrf/r1/ospfroute.txt b/tests/topotests/ospf_netns_vrf/r1/ospfroute.txt index d617ab36d9..d617ab36d9 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/ospfroute.txt +++ b/tests/topotests/ospf_netns_vrf/r1/ospfroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r1/ospfroute_down.txt b/tests/topotests/ospf_netns_vrf/r1/ospfroute_down.txt index 4f7fd699cf..4f7fd699cf 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/ospfroute_down.txt +++ b/tests/topotests/ospf_netns_vrf/r1/ospfroute_down.txt diff --git a/tests/topotests/ospf_topo1_vrf/r1/zebra.conf b/tests/topotests/ospf_netns_vrf/r1/zebra.conf index 56d7a9764e..56d7a9764e 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/zebra.conf +++ b/tests/topotests/ospf_netns_vrf/r1/zebra.conf diff --git a/tests/topotests/ospf_topo1_vrf/r1/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt index 979af20c59..979af20c59 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r1/zebraroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r1/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt index ec99fad762..ec99fad762 100644 --- a/tests/topotests/ospf_topo1_vrf/r1/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r1/zebraroutedown.txt diff --git a/tests/topotests/ospf_topo1_vrf/r2/ospfd.conf b/tests/topotests/ospf_netns_vrf/r2/ospfd.conf index c1984276f4..c1984276f4 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r2/ospfd.conf diff --git a/tests/topotests/ospf_topo1_vrf/r2/ospfroute.txt b/tests/topotests/ospf_netns_vrf/r2/ospfroute.txt index 89763ff733..89763ff733 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/ospfroute.txt +++ b/tests/topotests/ospf_netns_vrf/r2/ospfroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r2/ospfroute_down.txt b/tests/topotests/ospf_netns_vrf/r2/ospfroute_down.txt index d946f02dfd..d946f02dfd 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/ospfroute_down.txt +++ b/tests/topotests/ospf_netns_vrf/r2/ospfroute_down.txt diff --git a/tests/topotests/ospf_topo1_vrf/r2/zebra.conf b/tests/topotests/ospf_netns_vrf/r2/zebra.conf index 6ff72d1267..6ff72d1267 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/zebra.conf +++ b/tests/topotests/ospf_netns_vrf/r2/zebra.conf diff --git a/tests/topotests/ospf_topo1_vrf/r2/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt index df66e92abc..df66e92abc 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r2/zebraroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r2/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt index 4afc354ca7..4afc354ca7 100644 --- a/tests/topotests/ospf_topo1_vrf/r2/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r2/zebraroutedown.txt diff --git a/tests/topotests/ospf_topo1_vrf/r3/ospfd.conf b/tests/topotests/ospf_netns_vrf/r3/ospfd.conf index b73d547e3e..b73d547e3e 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/ospfd.conf +++ b/tests/topotests/ospf_netns_vrf/r3/ospfd.conf diff --git a/tests/topotests/ospf_topo1_vrf/r3/ospfroute.txt b/tests/topotests/ospf_netns_vrf/r3/ospfroute.txt index 917702b14c..917702b14c 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/ospfroute.txt +++ b/tests/topotests/ospf_netns_vrf/r3/ospfroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r3/ospfroute_down.txt b/tests/topotests/ospf_netns_vrf/r3/ospfroute_down.txt index 966185e495..966185e495 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/ospfroute_down.txt +++ b/tests/topotests/ospf_netns_vrf/r3/ospfroute_down.txt diff --git a/tests/topotests/ospf_topo1_vrf/r3/zebra.conf b/tests/topotests/ospf_netns_vrf/r3/zebra.conf index 1534150048..1534150048 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/zebra.conf +++ b/tests/topotests/ospf_netns_vrf/r3/zebra.conf diff --git a/tests/topotests/ospf_topo1_vrf/r3/zebraroute.txt b/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt index b435c2ebe5..b435c2ebe5 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/zebraroute.txt +++ b/tests/topotests/ospf_netns_vrf/r3/zebraroute.txt diff --git a/tests/topotests/ospf_topo1_vrf/r3/zebraroutedown.txt b/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt index f30a4be6c6..f30a4be6c6 100644 --- a/tests/topotests/ospf_topo1_vrf/r3/zebraroutedown.txt +++ b/tests/topotests/ospf_netns_vrf/r3/zebraroutedown.txt diff --git a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1-vrf.dot b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.dot index 789fdd7c09..789fdd7c09 100644 --- a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1-vrf.dot +++ b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.dot diff --git a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.jpg b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.jpg Binary files differindex 85f2e52f8e..85f2e52f8e 100644 --- a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.jpg +++ b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.jpg diff --git a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.py index 44de61d82a..621d8079dc 100644 --- a/tests/topotests/ospf_topo1_vrf/test_ospf_topo1_vrf.py +++ b/tests/topotests/ospf_netns_vrf/test_ospf_netns_vrf.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# test_ospf_topo1.py +# test_ospf_netns_vrf.py # Part of NetDEF Topology Tests # # Copyright (c) 2017 by @@ -23,7 +23,7 @@ # """ -test_ospf_topo1.py: Test the FRR OSPF routing daemon. +test_ospf_netns_vrf.py: Test OSPF with Network Namespace VRFs. """ import os diff --git a/tests/topotests/ospf_topo2/r1/ospf-route.json b/tests/topotests/ospf_unnumbered/r1/ospf-route.json index 6beb7e9bed..6beb7e9bed 100644 --- a/tests/topotests/ospf_topo2/r1/ospf-route.json +++ b/tests/topotests/ospf_unnumbered/r1/ospf-route.json diff --git a/tests/topotests/ospf_topo2/r1/ospfd.conf b/tests/topotests/ospf_unnumbered/r1/ospfd.conf index 65843cbb83..65843cbb83 100644 --- a/tests/topotests/ospf_topo2/r1/ospfd.conf +++ b/tests/topotests/ospf_unnumbered/r1/ospfd.conf diff --git a/tests/topotests/ospf_topo2/r1/v4_route.json b/tests/topotests/ospf_unnumbered/r1/v4_route.json index 76c6396169..76c6396169 100644 --- a/tests/topotests/ospf_topo2/r1/v4_route.json +++ b/tests/topotests/ospf_unnumbered/r1/v4_route.json diff --git a/tests/topotests/ospf_topo2/r1/zebra.conf b/tests/topotests/ospf_unnumbered/r1/zebra.conf index d96d9707c1..d96d9707c1 100644 --- a/tests/topotests/ospf_topo2/r1/zebra.conf +++ b/tests/topotests/ospf_unnumbered/r1/zebra.conf diff --git a/tests/topotests/ospf_topo2/r2/ospf-route.json b/tests/topotests/ospf_unnumbered/r2/ospf-route.json index 3cfd255bfd..3cfd255bfd 100644 --- a/tests/topotests/ospf_topo2/r2/ospf-route.json +++ b/tests/topotests/ospf_unnumbered/r2/ospf-route.json diff --git a/tests/topotests/ospf_topo2/r2/ospfd.conf b/tests/topotests/ospf_unnumbered/r2/ospfd.conf index b032f1a8ac..b032f1a8ac 100644 --- a/tests/topotests/ospf_topo2/r2/ospfd.conf +++ b/tests/topotests/ospf_unnumbered/r2/ospfd.conf diff --git a/tests/topotests/ospf_topo2/r2/v4_route.json b/tests/topotests/ospf_unnumbered/r2/v4_route.json index 1638536388..1638536388 100644 --- a/tests/topotests/ospf_topo2/r2/v4_route.json +++ b/tests/topotests/ospf_unnumbered/r2/v4_route.json diff --git a/tests/topotests/ospf_topo2/r2/zebra.conf b/tests/topotests/ospf_unnumbered/r2/zebra.conf index f9dd2c4471..f9dd2c4471 100644 --- a/tests/topotests/ospf_topo2/r2/zebra.conf +++ b/tests/topotests/ospf_unnumbered/r2/zebra.conf diff --git a/tests/topotests/ospf_topo2/test_ospf_topo2.py b/tests/topotests/ospf_unnumbered/test_ospf_unnumbered.py index 1ad62ff18e..a9640adca3 100644 --- a/tests/topotests/ospf_topo2/test_ospf_topo2.py +++ b/tests/topotests/ospf_unnumbered/test_ospf_unnumbered.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -# test_ospf_topo2.py +# test_ospf_unnumbered.py # # Copyright (c) 2019 by # Cumulus Networks, Inc @@ -23,7 +23,7 @@ # """ -test_ospf_topo2.py: Test the OSPF unnumbered. +test_ospf_unnumbered.py: Test the OSPF unnumbered. """ import os diff --git a/tests/topotests/zebra_nht_resolution/r1/sharpd.conf b/tests/topotests/zebra_nht_resolution/r1/sharpd.conf new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/topotests/zebra_nht_resolution/r1/sharpd.conf diff --git a/tests/topotests/zebra_nht_resolution/r1/zebra.conf b/tests/topotests/zebra_nht_resolution/r1/zebra.conf new file mode 100644 index 0000000000..6c35c5c4b1 --- /dev/null +++ b/tests/topotests/zebra_nht_resolution/r1/zebra.conf @@ -0,0 +1,5 @@ +hostname r1 +! +interface r1-eth0 + ip address 192.168.120.1/24 +! diff --git a/tests/topotests/zebra_nht_resolution/test_verify_nh_resolution.py b/tests/topotests/zebra_nht_resolution/test_verify_nh_resolution.py new file mode 100644 index 0000000000..9a8f7cc1f7 --- /dev/null +++ b/tests/topotests/zebra_nht_resolution/test_verify_nh_resolution.py @@ -0,0 +1,166 @@ +#!/usr/bin/env python + +# +# Copyright (c) 2022 by VMware, Inc. ("VMware") +# Used Copyright (c) 2018 by Network Device Education Foundation, +# Inc. ("NetDEF") in this file. +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +Test is indended for validating zebra NH resolution logic +""" + +import os +import sys +import pytest + +from lib.common_config import ( + start_topology, + verify_rib, + verify_ip_nht, + step, + create_static_routes, +) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, "../")) + +pytestmark = [pytest.mark.sharpd] + +#GLOBAL VARIABLES +NH1 = "2.2.2.32" + +def build_topo(tgen): + tgen.add_router("r1") + + switch = tgen.add_switch("sw1") + switch.add_link(tgen.gears["r1"]) + +def setup_module(mod): + tgen = Topogen(build_topo, mod.__name__) + tgen.start_topology() + router_list = tgen.routers() + for rname, router in tgen.routers().items(): + router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))) + router.load_config( + TopoRouter.RD_SHARP, os.path.join(CWD, "{}/sharpd.conf".format(rname)) + ) + tgen.start_router() + +def teardown_module(_mod): + tgen = get_topogen() + tgen.stop_topology() + +def test_verify_zebra_nh_resolution(request): + tgen = get_topogen() + tc_name = request.node.name + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + logger.info("Starting Zebra NH resolution testcase") + r1 = tgen.gears["r1"] + + step("Configure static route") + input_dict_1 = { + "r1": { + "static_routes": [ + {"network": "2.2.2.0/24", "next_hop": "r1-eth0"} + ] + } + } + + result = create_static_routes(tgen, input_dict_1) + assert result is True, "Testcase {} : Failed \n Error: {}".format( + tc_name, result + ) + + step("Verify static routes in RIB of R1") + input_dict_2 = { + "r1": { + "static_routes": [ + {"network": "2.2.2.0/24"} + ] + } + } + + dut = "r1" + result = verify_rib(tgen, "ipv4", dut, input_dict_2) + assert result is True, "Testcase {} :Failed \n Error: {}".format( + tc_name, result) + + step("Set the connected flag on the NH tracking entry") + r1.vtysh_cmd("sharp watch nexthop 2.2.2.32 connected") + + step("Verify that NH 2.2.2.32 gets resolved over static route") + input_dict_nh = { + "r1": { + NH1: { + "Address": "2.2.2.0/24", + "resolvedVia": "static", + "nexthops": {"nexthop1": {"Interfcae": "r1-eth0"}}, + } + } + } + result = verify_ip_nht(tgen, input_dict_nh) + assert result is True, "Testcase {} : Failed \n" + "Error: Nexthop is missing in RIB".format( + tc_name, result) + + step("Add a .32/32 route with the NH as itself") + r1.vtysh_cmd("sharp install routes 2.2.2.32 nexthop 2.2.2.32 1") + + step("Verify that the installation of .32/32 has no effect on the NHT") + input_dict_nh = { + "r1": { + NH1: { + "Address": "2.2.2.0/24", + "resolvedVia": "static", + "nexthops": {"nexthop1": {"Interface": "r1-eth0"}}, + } + } + } + result = verify_ip_nht(tgen, input_dict_nh) + assert result is True, "Testcase {} : Failed \n" + "Error: Nexthop became unresolved".format( + tc_name, result) + + step("Add a .31/32 route with the NH as 2.2.2.32" + "to verify the NH Resolution behaviour") + r1.vtysh_cmd("sharp install routes 2.2.2.31 nexthop 2.2.2.32 1") + + step("Verify that NH 2.2.2.2/32 doesn't become unresolved") + input_dict_nh = { + "r1": { + NH1: { + "Address": "2.2.2.0/24", + "resolvedVia": "static", + "nexthops": {"nexthop1": {"Interface": "r1-eth0"}}, + } + } + } + result = verify_ip_nht(tgen, input_dict_nh) + assert result is True, "Testcase {} : Failed \n" + "Error: Nexthop became unresolved".format( + tc_name, result) + +if __name__ == "__main__": + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tools/etc/frr/support_bundle_commands.conf b/tools/etc/frr/support_bundle_commands.conf index e223eb2743..46e0625d8c 100644 --- a/tools/etc/frr/support_bundle_commands.conf +++ b/tools/etc/frr/support_bundle_commands.conf @@ -78,6 +78,7 @@ show debugging hashtable show running-config show thread cpu show thread poll +show thread timers show daemons show version CMD_LIST_END diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index f91803337d..dae1e4894e 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -681,8 +681,8 @@ struct vrrp_vrouter *vrrp_lookup(const struct interface *ifp, uint8_t vrid) /* Forward decls */ static void vrrp_change_state(struct vrrp_router *r, int to); -static int vrrp_adver_timer_expire(struct thread *thread); -static int vrrp_master_down_timer_expire(struct thread *thread); +static void vrrp_adver_timer_expire(struct thread *thread); +static void vrrp_master_down_timer_expire(struct thread *thread); /* * Finds the first connected address of the appropriate family on a VRRP @@ -983,7 +983,7 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src, /* * Read and process next IPvX datagram. */ -static int vrrp_read(struct thread *thread) +static void vrrp_read(struct thread *thread) { struct vrrp_router *r = thread->arg; @@ -1045,8 +1045,6 @@ done: if (resched) thread_add_read(master, vrrp_read, r, r->sock_rx, &r->t_read); - - return 0; } /* @@ -1480,7 +1478,7 @@ static void vrrp_change_state(struct vrrp_router *r, int to) /* * Called when Adver_Timer expires. */ -static int vrrp_adver_timer_expire(struct thread *thread) +static void vrrp_adver_timer_expire(struct thread *thread) { struct vrrp_router *r = thread->arg; @@ -1503,14 +1501,12 @@ static int vrrp_adver_timer_expire(struct thread *thread) r->vr->vrid, family2str(r->family), vrrp_state_names[r->fsm.state]); } - - return 0; } /* * Called when Master_Down_Timer expires. */ -static int vrrp_master_down_timer_expire(struct thread *thread) +static void vrrp_master_down_timer_expire(struct thread *thread) { struct vrrp_router *r = thread->arg; @@ -1522,8 +1518,6 @@ static int vrrp_master_down_timer_expire(struct thread *thread) r->vr->advertisement_interval * CS2MS, &r->t_adver_timer); vrrp_change_state(r, VRRP_STATE_MASTER); - - return 0; } /* diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index c2b4e779de..d940e03e1c 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -118,7 +118,7 @@ sub scan_file { if ($defun_array[1] =~ m/ipv6/) { $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; } else { - $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; + $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD|VTYSH_FABRICD"; } } elsif ($file =~ /lib\/if_rmap\.c$/) { @@ -143,6 +143,10 @@ sub scan_file { elsif ($fabricd) { $protocol = "VTYSH_FABRICD"; } +# Enable VTYSH_PIM6D once pim6_cmd.c is merged +# elsif ($file =~ /pimd\/pim6_cmd\.c$/) { +# $protocol = "VTYSH_PIM6D"; +# } else { ($protocol) = ($file =~ /^(?:.*\/)?([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); $protocol = "VTYSH_" . uc $protocol; diff --git a/vtysh/subdir.am b/vtysh/subdir.am index 5f7d854948..624361645e 100644 --- a/vtysh/subdir.am +++ b/vtysh/subdir.am @@ -7,6 +7,10 @@ bin_PROGRAMS += vtysh/vtysh man1 += $(MANBUILD)/vtysh.1 endif +clippy_scan += \ + vtysh/vtysh.c \ + # end + vtysh_vtysh_SOURCES = \ vtysh/vtysh_main.c \ vtysh/vtysh.c \ diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 336fe8b30e..f8c6a1fc1d 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -40,6 +40,7 @@ #include "linklist.h" #include "command.h" #include "memory.h" +#include "network.h" #include "filter.h" #include "vtysh/vtysh.h" #include "vtysh/vtysh_daemons.h" @@ -69,8 +70,14 @@ struct vtysh_client { int flag; char path[MAXPATHLEN]; struct vtysh_client *next; + + struct thread *log_reader; + int log_fd; }; +static bool stderr_tty; +static bool stderr_stdout_same; + /* Some utility functions for working on vtysh-specific vty tasks */ static FILE *vty_open_pager(struct vty *vty) @@ -126,26 +133,27 @@ static void vtysh_pager_envdef(bool fallback) /* --- */ struct vtysh_client vtysh_client[] = { - {.fd = -1, .name = "zebra", .flag = VTYSH_ZEBRA, .next = NULL}, - {.fd = -1, .name = "ripd", .flag = VTYSH_RIPD, .next = NULL}, - {.fd = -1, .name = "ripngd", .flag = VTYSH_RIPNGD, .next = NULL}, - {.fd = -1, .name = "ospfd", .flag = VTYSH_OSPFD, .next = NULL}, - {.fd = -1, .name = "ospf6d", .flag = VTYSH_OSPF6D, .next = NULL}, - {.fd = -1, .name = "ldpd", .flag = VTYSH_LDPD, .next = NULL}, - {.fd = -1, .name = "bgpd", .flag = VTYSH_BGPD, .next = NULL}, - {.fd = -1, .name = "isisd", .flag = VTYSH_ISISD, .next = NULL}, - {.fd = -1, .name = "pimd", .flag = VTYSH_PIMD, .next = NULL}, - {.fd = -1, .name = "nhrpd", .flag = VTYSH_NHRPD, .next = NULL}, - {.fd = -1, .name = "eigrpd", .flag = VTYSH_EIGRPD, .next = NULL}, - {.fd = -1, .name = "babeld", .flag = VTYSH_BABELD, .next = NULL}, - {.fd = -1, .name = "sharpd", .flag = VTYSH_SHARPD, .next = NULL}, - {.fd = -1, .name = "fabricd", .flag = VTYSH_FABRICD, .next = NULL}, - {.fd = -1, .name = "watchfrr", .flag = VTYSH_WATCHFRR, .next = NULL}, - {.fd = -1, .name = "pbrd", .flag = VTYSH_PBRD, .next = NULL}, - {.fd = -1, .name = "staticd", .flag = VTYSH_STATICD, .next = NULL}, - {.fd = -1, .name = "bfdd", .flag = VTYSH_BFDD, .next = NULL}, - {.fd = -1, .name = "vrrpd", .flag = VTYSH_VRRPD, .next = NULL}, - {.fd = -1, .name = "pathd", .flag = VTYSH_PATHD, .next = NULL}, + {.name = "zebra", .flag = VTYSH_ZEBRA}, + {.name = "ripd", .flag = VTYSH_RIPD}, + {.name = "ripngd", .flag = VTYSH_RIPNGD}, + {.name = "ospfd", .flag = VTYSH_OSPFD}, + {.name = "ospf6d", .flag = VTYSH_OSPF6D}, + {.name = "ldpd", .flag = VTYSH_LDPD}, + {.name = "bgpd", .flag = VTYSH_BGPD}, + {.name = "isisd", .flag = VTYSH_ISISD}, + {.name = "pimd", .flag = VTYSH_PIMD}, + {.name = "nhrpd", .flag = VTYSH_NHRPD}, + {.name = "eigrpd", .flag = VTYSH_EIGRPD}, + {.name = "babeld", .flag = VTYSH_BABELD}, + {.name = "sharpd", .flag = VTYSH_SHARPD}, + {.name = "fabricd", .flag = VTYSH_FABRICD}, + {.name = "watchfrr", .flag = VTYSH_WATCHFRR}, + {.name = "pbrd", .flag = VTYSH_PBRD}, + {.name = "staticd", .flag = VTYSH_STATICD}, + {.name = "bfdd", .flag = VTYSH_BFDD}, + {.name = "vrrpd", .flag = VTYSH_VRRPD}, + {.name = "pathd", .flag = VTYSH_PATHD}, + {.name = "pim6d", .flag = VTYSH_PIM6D}, }; /* Searches for client by name, returns index */ @@ -181,6 +189,53 @@ static void vclient_close(struct vtysh_client *vclient) } } +static ssize_t vtysh_client_receive(struct vtysh_client *vclient, char *buf, + size_t bufsz, int *pass_fd) +{ + struct iovec iov[1] = { + { + .iov_base = buf, + .iov_len = bufsz, + }, + }; + union { + uint8_t buf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr align; + } u; + struct msghdr mh = { + .msg_iov = iov, + .msg_iovlen = array_size(iov), + .msg_control = u.buf, + .msg_controllen = sizeof(u.buf), + }; + struct cmsghdr *cmh = CMSG_FIRSTHDR(&mh); + ssize_t ret; + + cmh->cmsg_level = SOL_SOCKET; + cmh->cmsg_type = SCM_RIGHTS; + cmh->cmsg_len = CMSG_LEN(sizeof(int)); + memset(CMSG_DATA(cmh), -1, sizeof(int)); + + do { + ret = recvmsg(vclient->fd, &mh, 0); + if (ret >= 0 || (errno != EINTR && errno != EAGAIN)) + break; + } while (true); + + if (cmh->cmsg_len == CMSG_LEN(sizeof(int))) { + int fd; + + memcpy(&fd, CMSG_DATA(cmh), sizeof(int)); + if (fd != -1) { + if (pass_fd) + *pass_fd = fd; + else + close(fd); + } + } + return ret; +} + /* * Send a CLI command to a client and read the response. * @@ -204,7 +259,8 @@ static void vclient_close(struct vtysh_client *vclient) * a status code */ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, - void (*callback)(void *, const char *), void *cbarg) + void (*callback)(void *, const char *), void *cbarg, + int *pass_fd) { int ret; char stackbuf[4096]; @@ -238,8 +294,10 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, bufvalid = buf; do { - ssize_t nread = - read(vclient->fd, bufvalid, buf + bufsz - bufvalid - 1); + ssize_t nread; + + nread = vtysh_client_receive( + vclient, bufvalid, buf + bufsz - bufvalid - 1, pass_fd); if (nread < 0 && (errno == EINTR || errno == EAGAIN)) continue; @@ -381,7 +439,7 @@ static int vtysh_client_run_all(struct vtysh_client *head_client, int correct_instance = 0, wrong_instance = 0; for (client = head_client; client; client = client->next) { - rc = vtysh_client_run(client, line, callback, cbarg); + rc = vtysh_client_run(client, line, callback, cbarg, NULL); if (rc == CMD_NOT_MY_INSTANCE) { wrong_instance++; continue; @@ -1578,6 +1636,8 @@ static int vtysh_end(void) return CMD_SUCCESS; } +#include "vtysh/vtysh_clippy.c" + DEFUNSH(VTYSH_REALLYALL, vtysh_end_all, vtysh_end_all_cmd, "end", "End current mode and change to enable mode\n") { @@ -2714,6 +2774,16 @@ static int show_one_daemon(struct vty *vty, struct cmd_token **argv, int argc, return ret; } +DEFUN (vtysh_show_thread_timer, + vtysh_show_thread_timer_cmd, + "show thread timers", + SHOW_STR + "Thread information\n" + "Show all timers and how long they have in the system\n") +{ + return show_per_daemon(vty, argv, argc, "Thread timers for %s:\n"); +} + DEFUN (vtysh_show_poll, vtysh_show_poll_cmd, "show thread poll", @@ -3460,6 +3530,283 @@ DEFUN (vtysh_show_daemons, return CMD_SUCCESS; } +struct visual_prio { + /* 4 characters for nice alignment */ + const char *label; + + int c256_background; + int c256_formatarg; +}; + +/* clang-format off */ +struct visual_prio visual_prios[] = { + [LOG_EMERG] = { + .label = "\e[31;1mEMRG", + .c256_background = 53, + .c256_formatarg = 225, + }, + [LOG_ALERT] = { + .label = "\e[31;1mALRT", + .c256_background = 53, + .c256_formatarg = 225, + }, + [LOG_CRIT] = { + .label = "\e[31;1mCRIT", + .c256_background = 53, + .c256_formatarg = 225, + }, + [LOG_ERR] = { + .label = "\e[38;5;202mERR!", + .c256_background = 52, + .c256_formatarg = 224, + }, + [LOG_WARNING] = { + .label = "\e[38;5;222mWARN", + .c256_background = 58, + .c256_formatarg = 230, + }, + [LOG_NOTICE] = { + .label = "NTFY", + .c256_background = 234, + .c256_formatarg = 195, + }, + [LOG_INFO] = { + .label = "\e[38;5;192mINFO", + .c256_background = 236, + .c256_formatarg = 195, + }, + [LOG_DEBUG] = { + .label = "\e[38;5;116mDEBG", + .c256_background = 238, + .c256_formatarg = 195, + }, +}; +/* clang-format on */ + +static void vtysh_log_print(struct vtysh_client *vclient, + struct zlog_live_hdr *hdr, const char *text) +{ + size_t textlen = hdr->textlen, textpos = 0; + time_t ts = hdr->ts_sec; + struct visual_prio *vis; + struct tm tm; + char ts_buf[32]; + + if (hdr->prio >= array_size(visual_prios)) + vis = &visual_prios[LOG_CRIT]; + else + vis = &visual_prios[hdr->prio]; + + localtime_r(&ts, &tm); + strftime(ts_buf, sizeof(ts_buf), "%Y-%m-%d %H:%M:%S", &tm); + + if (!stderr_tty) { + const char *label = vis->label + strlen(vis->label) - 4; + + fprintf(stderr, "%s.%03u [%s] %s: %.*s\n", ts_buf, + hdr->ts_nsec / 1000000U, label, vclient->name, + (int)textlen, text); + return; + } + + fprintf(stderr, + "\e[48;5;%dm\e[38;5;247m%s.%03u [%s\e[38;5;247m] \e[38;5;255m%s\e[38;5;247m: \e[38;5;251m", + vis->c256_background, ts_buf, hdr->ts_nsec / 1000000U, + vis->label, vclient->name); + + for (size_t fmtpos = 0; fmtpos < hdr->n_argpos; fmtpos++) { + struct fmt_outpos *fmt = &hdr->argpos[fmtpos]; + + if (fmt->off_start < textpos || fmt->off_end < fmt->off_start || + fmt->off_end > textlen) + continue; + + while (fmt->off_end > fmt->off_start && + text[fmt->off_end - 1] == ' ') + fmt->off_end--; + + fprintf(stderr, "%.*s\e[38;5;%dm%.*s\e[38;5;251m", + (int)(fmt->off_start - textpos), text + textpos, + vis->c256_formatarg, + (int)(fmt->off_end - fmt->off_start), + text + fmt->off_start); + textpos = fmt->off_end; + } + fprintf(stderr, "%.*s\033[K\033[m\n", (int)(textlen - textpos), + text + textpos); +} + +static void vtysh_log_read(struct thread *thread) +{ + struct vtysh_client *vclient = THREAD_ARG(thread); + struct { + struct zlog_live_hdr hdr; + char text[4096]; + } buf; + const char *text; + ssize_t ret; + + thread_add_read(master, vtysh_log_read, vclient, vclient->log_fd, + &vclient->log_reader); + + ret = recv(vclient->log_fd, &buf, sizeof(buf), 0); + + if (ret < 0 && ERRNO_IO_RETRY(errno)) + return; + + if (ret <= 0) { + struct timespec ts; + + buf.text[0] = '\0'; /* coverity */ + + if (ret != 0) + snprintfrr(buf.text, sizeof(buf.text), + "log monitor connection error: %m"); + else + snprintfrr( + buf.text, sizeof(buf.text), + "log monitor connection closed unexpectedly"); + buf.hdr.textlen = strlen(buf.text); + + THREAD_OFF(vclient->log_reader); + close(vclient->log_fd); + vclient->log_fd = -1; + + clock_gettime(CLOCK_REALTIME, &ts); + buf.hdr.ts_sec = ts.tv_sec; + buf.hdr.ts_nsec = ts.tv_nsec; + buf.hdr.prio = LOG_ERR; + buf.hdr.flags = 0; + buf.hdr.arghdrlen = 0; + buf.hdr.n_argpos = 0; + } + + if (stderr_stdout_same) { +#ifdef HAVE_RL_CLEAR_VISIBLE_LINE + rl_clear_visible_line(); +#else + puts("\r"); +#endif + fflush(stdout); + } + + text = buf.text + sizeof(buf.hdr.argpos[0]) * buf.hdr.n_argpos; + vtysh_log_print(vclient, &buf.hdr, text); + + if (stderr_stdout_same) + rl_forced_update_display(); + + return; +} + +#ifdef CLIPPY +/* clippy/clidef can't process the DEFPY below without some value for this */ +#define DAEMONS_LIST "daemon" +#endif + +DEFPY (vtysh_terminal_monitor, + vtysh_terminal_monitor_cmd, + "terminal monitor ["DAEMONS_LIST"]$daemon", + "Set terminal line parameters\n" + "Receive log messages to active VTY session\n" + DAEMONS_STR) +{ + static const char line[] = "terminal monitor\n"; + int ret_all = CMD_SUCCESS, ret, fd; + size_t i, ok = 0; + + for (i = 0; i < array_size(vtysh_client); i++) { + struct vtysh_client *vclient = &vtysh_client[i]; + + if (daemon && strcmp(vclient->name, daemon)) + continue; + + for (; vclient; vclient = vclient->next) { + if (vclient->log_fd != -1) { + vty_out(vty, "%% %s: already monitoring logs\n", + vclient->name); + ok++; + continue; + } + + fd = -1; + ret = vtysh_client_run(vclient, line, NULL, NULL, &fd); + if (fd != -1) { + set_nonblocking(fd); + vclient->log_fd = fd; + thread_add_read(master, vtysh_log_read, vclient, + vclient->log_fd, + &vclient->log_reader); + } + if (ret != CMD_SUCCESS) { + vty_out(vty, "%% failed to enable logs on %s\n", + vclient->name); + ret_all = CMD_WARNING; + } else + ok++; + } + } + + if (!ok && ret_all == CMD_SUCCESS) { + vty_out(vty, + "%% command had no effect, relevant daemons not connected?\n"); + ret_all = CMD_WARNING; + } + return ret_all; +} + +DEFPY (no_vtysh_terminal_monitor, + no_vtysh_terminal_monitor_cmd, + "no terminal monitor ["DAEMONS_LIST"]$daemon", + NO_STR + "Set terminal line parameters\n" + "Receive log messages to active VTY session\n" + DAEMONS_STR) +{ + static const char line[] = "no terminal monitor\n"; + int ret_all = CMD_SUCCESS, ret; + size_t i, ok = 0; + + for (i = 0; i < array_size(vtysh_client); i++) { + struct vtysh_client *vclient = &vtysh_client[i]; + + if (daemon && strcmp(vclient->name, daemon)) + continue; + + for (; vclient; vclient = vclient->next) { + /* run this even if log_fd == -1, in case something + * got desync'd + */ + ret = vtysh_client_run(vclient, line, NULL, NULL, NULL); + if (ret != CMD_SUCCESS) { + vty_out(vty, + "%% failed to disable logs on %s\n", + vclient->name); + ret_all = CMD_WARNING; + } else + ok++; + + /* with this being a datagram socket, we can't expect + * a close notification... + */ + if (vclient->log_fd != -1) { + THREAD_OFF(vclient->log_reader); + + close(vclient->log_fd); + vclient->log_fd = -1; + } + } + } + + if (!ok && ret_all == CMD_SUCCESS) { + vty_out(vty, + "%% command had no effect, relevant daemons not connected?\n"); + ret_all = CMD_WARNING; + } + return ret_all; +} + + /* Execute command in child process. */ static void execute_command(const char *command, int argc, const char *arg1, const char *arg2) @@ -3967,8 +4314,21 @@ void vtysh_uninit(void) void vtysh_init_vty(void) { + struct stat st_out, st_err; + cmd_defer_tree(true); + for (size_t i = 0; i < array_size(vtysh_client); i++) { + vtysh_client[i].fd = -1; + vtysh_client[i].log_fd = -1; + } + + stderr_tty = isatty(STDERR_FILENO); + + if (fstat(STDOUT_FILENO, &st_out) || fstat(STDERR_FILENO, &st_err) || + (st_out.st_dev == st_err.st_dev && st_out.st_ino == st_err.st_ino)) + stderr_stdout_same = true; + /* Make vty structure. */ vty = vty_new(); vty->type = VTY_SHELL; @@ -4462,6 +4822,9 @@ void vtysh_init_vty(void) install_element(VIEW_NODE, &vtysh_terminal_no_length_cmd); install_element(VIEW_NODE, &vtysh_show_daemons_cmd); + install_element(VIEW_NODE, &vtysh_terminal_monitor_cmd); + install_element(VIEW_NODE, &no_vtysh_terminal_monitor_cmd); + install_element(VIEW_NODE, &vtysh_ping_cmd); install_element(VIEW_NODE, &vtysh_ping_ip_cmd); install_element(VIEW_NODE, &vtysh_traceroute_cmd); @@ -4507,6 +4870,7 @@ void vtysh_init_vty(void) install_element(VIEW_NODE, &vtysh_show_work_queues_daemon_cmd); install_element(VIEW_NODE, &vtysh_show_thread_cmd); install_element(VIEW_NODE, &vtysh_show_poll_cmd); + install_element(VIEW_NODE, &vtysh_show_thread_timer_cmd); /* Logging */ install_element(VIEW_NODE, &vtysh_show_logging_cmd); diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 66af248354..6053955be9 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -24,6 +24,10 @@ #include "memory.h" DECLARE_MGROUP(MVTYSH); +struct thread_master; + +extern struct thread_master *master; + #define VTYSH_ZEBRA 0x00001 #define VTYSH_RIPD 0x00002 #define VTYSH_RIPNGD 0x00004 @@ -44,6 +48,7 @@ DECLARE_MGROUP(MVTYSH); #define VTYSH_FABRICD 0x20000 #define VTYSH_VRRPD 0x40000 #define VTYSH_PATHD 0x80000 +#define VTYSH_PIM6D 0x100000 #define VTYSH_WAS_ACTIVE (-2) @@ -52,10 +57,10 @@ DECLARE_MGROUP(MVTYSH); /* watchfrr is not in ALL since library CLI functions should not be * run on it (logging & co. should stay in a fixed/frozen config, and * things like prefix lists are not even initialised) */ -#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_SHARPD|VTYSH_PBRD|VTYSH_STATICD|VTYSH_BFDD|VTYSH_FABRICD|VTYSH_VRRPD|VTYSH_PATHD -#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA -#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_FABRICD -#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_PBRD|VTYSH_FABRICD|VTYSH_VRRPD +#define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_SHARPD|VTYSH_PBRD|VTYSH_STATICD|VTYSH_BFDD|VTYSH_FABRICD|VTYSH_VRRPD|VTYSH_PATHD +#define VTYSH_ACL VTYSH_BFDD|VTYSH_BABELD|VTYSH_BGPD|VTYSH_EIGRPD|VTYSH_ISISD|VTYSH_FABRICD|VTYSH_LDPD|VTYSH_NHRPD|VTYSH_OSPF6D|VTYSH_OSPFD|VTYSH_PBRD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_VRRPD|VTYSH_ZEBRA +#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_EIGRPD|VTYSH_FABRICD +#define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_PIM6D|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_PBRD|VTYSH_FABRICD|VTYSH_VRRPD #define VTYSH_VRF VTYSH_INTERFACE|VTYSH_STATICD #define VTYSH_KEYS VTYSH_RIPD | VTYSH_EIGRPD | VTYSH_OSPF6D /* Daemons who can process nexthop-group configs */ @@ -72,6 +77,7 @@ extern enum vtysh_write_integrated vtysh_write_integrated; extern char frr_config[]; extern char vtydir[]; +extern bool vtysh_loop_exited; void vtysh_init_vty(void); void vtysh_uninit(void); diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index a4f27b61cb..04eb47feeb 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -84,9 +84,6 @@ static sigjmp_buf jmpbuf; /* Flag for avoid recursive siglongjmp() call. */ static int jmpflag = 0; -/* A static variable for holding the line. */ -static char *line_read; - /* Master of threads. */ struct thread_master *master; @@ -208,23 +205,22 @@ struct option longopts[] = { {"timestamp", no_argument, NULL, 't'}, {0}}; -/* Read a string, and return a pointer to it. Returns NULL on EOF. */ -static char *vtysh_rl_gets(void) +bool vtysh_loop_exited; + +static void vtysh_rl_callback(char *line_read) { HIST_ENTRY *last; - /* If the buffer has already been allocated, return the memory - * to the free pool. */ - if (line_read) { - free(line_read); - line_read = NULL; - } - /* Get a line from the user. Change prompt according to node. XXX. */ - line_read = readline(vtysh_prompt()); + rl_callback_handler_remove(); + + if (!line_read) { + vtysh_loop_exited = true; + return; + } /* If the line has any text in it, save it on the history. But only if * last command in history isn't the same one. */ - if (line_read && *line_read) { + if (*line_read) { using_history(); last = previous_history(); if (!last || strcmp(last->line, line_read) != 0) { @@ -233,7 +229,39 @@ static char *vtysh_rl_gets(void) } } - return (line_read); + vtysh_execute(line_read); + + if (!vtysh_loop_exited) + rl_callback_handler_install(vtysh_prompt(), vtysh_rl_callback); +} + +static struct thread *vtysh_rl_read_thread; + +static void vtysh_rl_read(struct thread *thread) +{ + thread_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO, + &vtysh_rl_read_thread); + rl_callback_read_char(); +} + +/* Read a string, and return a pointer to it. Returns NULL on EOF. */ +static void vtysh_rl_run(void) +{ + struct thread thread; + + master = thread_master_create(NULL); + + rl_callback_handler_install(vtysh_prompt(), vtysh_rl_callback); + thread_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO, + &vtysh_rl_read_thread); + + while (!vtysh_loop_exited && thread_fetch(master, &thread)) + thread_call(&thread); + + if (!vtysh_loop_exited) + rl_callback_handler_remove(); + + thread_master_free(master); } static void log_it(const char *line) @@ -458,7 +486,6 @@ int main(int argc, char **argv, char **env) } /* Initialize user input buffer. */ - line_read = NULL; setlinebuf(stdout); /* Signal and others. */ @@ -730,8 +757,7 @@ int main(int argc, char **argv, char **env) jmpflag = 1; /* Main command loop. */ - while (vtysh_rl_gets()) - vtysh_execute(line_read); + vtysh_rl_run(); vtysh_uninit(); diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 0d9734a756..4f50da380c 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -201,7 +201,7 @@ static const struct option longopts[] = { {NULL, 0, NULL, 0}}; static int try_connect(struct daemon *dmn); -static int wakeup_send_echo(struct thread *t_wakeup); +static void wakeup_send_echo(struct thread *t_wakeup); static void try_restart(struct daemon *dmn); static void phase_check(void); static void restart_done(struct daemon *dmn); @@ -350,7 +350,7 @@ static struct timeval *time_elapsed(struct timeval *result, return result; } -static int restart_kill(struct thread *t_kill) +static void restart_kill(struct thread *t_kill) { struct restart_info *restart = THREAD_ARG(t_kill); struct timeval delay; @@ -364,7 +364,6 @@ static int restart_kill(struct thread *t_kill) restart->kills++; thread_add_timer(master, restart_kill, restart, gs.restart_timeout, &restart->t_kill); - return 0; } static struct restart_info *find_child(pid_t child) @@ -546,7 +545,7 @@ static int run_job(struct restart_info *restart, const char *cmdtype, FUZZY(gs.period), &(DMN)->t_wakeup); \ } while (0); -static int wakeup_down(struct thread *t_wakeup) +static void wakeup_down(struct thread *t_wakeup) { struct daemon *dmn = THREAD_ARG(t_wakeup); @@ -555,10 +554,9 @@ static int wakeup_down(struct thread *t_wakeup) SET_WAKEUP_DOWN(dmn); if ((dmn->connect_tries > 1) && (dmn->state != DAEMON_UP)) try_restart(dmn); - return 0; } -static int wakeup_init(struct thread *t_wakeup) +static void wakeup_init(struct thread *t_wakeup) { struct daemon *dmn = THREAD_ARG(t_wakeup); @@ -570,7 +568,6 @@ static int wakeup_init(struct thread *t_wakeup) dmn->state = DAEMON_DOWN; } phase_check(); - return 0; } static void restart_done(struct daemon *dmn) @@ -609,7 +606,7 @@ static void daemon_down(struct daemon *dmn, const char *why) phase_check(); } -static int handle_read(struct thread *t_read) +static void handle_read(struct thread *t_read) { struct daemon *dmn = THREAD_ARG(t_read); static const char resp[sizeof(PING_TOKEN) + 4] = PING_TOKEN "\n"; @@ -624,16 +621,16 @@ static int handle_read(struct thread *t_read) if (ERRNO_IO_RETRY(errno)) { /* Pretend it never happened. */ SET_READ_HANDLER(dmn); - return 0; + return; } snprintf(why, sizeof(why), "unexpected read error: %s", safe_strerror(errno)); daemon_down(dmn, why); - return 0; + return; } if (rc == 0) { daemon_down(dmn, "read returned EOF"); - return 0; + return; } if (!dmn->echo_sent.tv_sec) { char why[sizeof(buf) + 100]; @@ -641,7 +638,7 @@ static int handle_read(struct thread *t_read) "unexpected read returns %d bytes: %.*s", (int)rc, (int)rc, buf); daemon_down(dmn, why); - return 0; + return; } /* We are expecting an echo response: is there any chance that the @@ -653,7 +650,7 @@ static int handle_read(struct thread *t_read) "read returned bad echo response of %d bytes (expecting %u): %.*s", (int)rc, (unsigned int)sizeof(resp), (int)rc, buf); daemon_down(dmn, why); - return 0; + return; } time_elapsed(&delay, &dmn->echo_sent); @@ -677,8 +674,6 @@ static int handle_read(struct thread *t_read) SET_READ_HANDLER(dmn); thread_cancel(&dmn->t_wakeup); SET_WAKEUP_ECHO(dmn); - - return 0; } /* @@ -732,7 +727,7 @@ static void daemon_up(struct daemon *dmn, const char *why) phase_check(); } -static int check_connect(struct thread *t_write) +static void check_connect(struct thread *t_write) { struct daemon *dmn = THREAD_ARG(t_write); int sockerr; @@ -745,7 +740,7 @@ static int check_connect(struct thread *t_write) safe_strerror(errno)); daemon_down(dmn, "getsockopt failed checking connection success"); - return 0; + return; } if ((reslen == sizeof(sockerr)) && sockerr) { char why[100]; @@ -754,14 +749,13 @@ static int check_connect(struct thread *t_write) "getsockopt reports that connection attempt failed: %s", safe_strerror(sockerr)); daemon_down(dmn, why); - return 0; + return; } daemon_up(dmn, "delayed connect succeeded"); - return 0; } -static int wakeup_connect_hanging(struct thread *t_wakeup) +static void wakeup_connect_hanging(struct thread *t_wakeup) { struct daemon *dmn = THREAD_ARG(t_wakeup); char why[100]; @@ -770,7 +764,6 @@ static int wakeup_connect_hanging(struct thread *t_wakeup) snprintf(why, sizeof(why), "connection attempt timed out after %ld seconds", gs.timeout); daemon_down(dmn, why); - return 0; } /* Making connection to protocol daemon. */ @@ -846,14 +839,13 @@ static int try_connect(struct daemon *dmn) return 1; } -static int phase_hanging(struct thread *t_hanging) +static void phase_hanging(struct thread *t_hanging) { gs.t_phase_hanging = NULL; flog_err(EC_WATCHFRR_CONNECTION, "Phase [%s] hanging for %ld seconds, aborting phased restart", phase_str[gs.phase], PHASE_TIMEOUT); gs.phase = PHASE_NONE; - return 0; } static void set_phase(restart_phase_t new_phase) @@ -971,7 +963,7 @@ static void try_restart(struct daemon *dmn) run_job(&gs.restart, "restart", gs.restart_command, 0, 1); } -static int wakeup_unresponsive(struct thread *t_wakeup) +static void wakeup_unresponsive(struct thread *t_wakeup) { struct daemon *dmn = THREAD_ARG(t_wakeup); @@ -984,26 +976,24 @@ static int wakeup_unresponsive(struct thread *t_wakeup) SET_WAKEUP_UNRESPONSIVE(dmn); try_restart(dmn); } - return 0; } -static int wakeup_no_answer(struct thread *t_wakeup) +static void wakeup_no_answer(struct thread *t_wakeup) { struct daemon *dmn = THREAD_ARG(t_wakeup); dmn->t_wakeup = NULL; dmn->state = DAEMON_UNRESPONSIVE; if (dmn->ignore_timeout) - return 0; + return; flog_err(EC_WATCHFRR_CONNECTION, "%s state -> unresponsive : no response yet to ping sent %ld seconds ago", dmn->name, gs.timeout); SET_WAKEUP_UNRESPONSIVE(dmn); try_restart(dmn); - return 0; } -static int wakeup_send_echo(struct thread *t_wakeup) +static void wakeup_send_echo(struct thread *t_wakeup) { static const char echocmd[] = "echo " PING_TOKEN; ssize_t rc; @@ -1022,7 +1012,6 @@ static int wakeup_send_echo(struct thread *t_wakeup) thread_add_timer(master, wakeup_no_answer, dmn, gs.timeout, &dmn->t_wakeup); } - return 0; } bool check_all_up(void) @@ -1099,10 +1088,9 @@ static char *translate_blanks(const char *cmd, const char *blankstr) return res; } -static int startup_timeout(struct thread *t_wakeup) +static void startup_timeout(struct thread *t_wakeup) { daemon_send_ready(1); - return 0; } #ifdef GNU_LINUX diff --git a/zebra/debug_nl.c b/zebra/debug_nl.c index 825497fff3..260ba30b3c 100644 --- a/zebra/debug_nl.c +++ b/zebra/debug_nl.c @@ -20,6 +20,7 @@ #include <sys/socket.h> +#include <linux/netconf.h> #include <linux/netlink.h> #include <linux/nexthop.h> #include <linux/rtnetlink.h> @@ -90,6 +91,11 @@ const char *nlmsg_type2str(uint16_t type) case RTM_GETNEXTHOP: return "GETNEXTHOP"; + case RTM_NEWNETCONF: + return "RTM_NEWNETCONF"; + case RTM_DELNETCONF: + return "RTM_DELNETCONF"; + default: return "UNKNOWN"; } @@ -657,6 +663,37 @@ const char *frh_action2str(uint8_t action) } } +static const char *ncm_rta2str(int type) +{ + switch (type) { + case NETCONFA_UNSPEC: + return "UNSPEC"; + case NETCONFA_IFINDEX: + return "IFINDEX"; + case NETCONFA_FORWARDING: + return "FORWARDING"; + case NETCONFA_RP_FILTER: + return "RP_FILTER"; + case NETCONFA_MC_FORWARDING: + return "MCAST"; + case NETCONFA_PROXY_NEIGH: + return "PROXY_NEIGH"; + case NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN: + return "IGNORE_LINKDOWN"; + case NETCONFA_INPUT: + return "MPLS"; + case NETCONFA_BC_FORWARDING: + return "BCAST"; + default: + return "UNKNOWN"; + } +} + +static void dump_on_off(uint32_t ival, const char *prefix) +{ + zlog_debug("%s%s", prefix, (ival != 0) ? "on" : "off"); +} + static inline void flag_write(int flags, int flag, const char *flagstr, char *buf, size_t buflen) { @@ -1118,6 +1155,7 @@ static void nlnh_dump(struct nhmsg *nhm, size_t msglen) struct nexthop_grp *nhgrp; rta = RTM_NHA(nhm); + next_rta: /* Check the header for valid length and for outbound access. */ if (RTA_OK(rta, msglen) == 0) @@ -1296,6 +1334,52 @@ next_rta: goto next_rta; } +static void nlncm_dump(const struct netconfmsg *ncm, size_t msglen) +{ + const struct rtattr *rta; + size_t plen; + uint32_t ival; + + rta = (void *)((const char *)ncm + + NLMSG_ALIGN(sizeof(struct netconfmsg))); + +next_rta: + /* Check the attr header for valid length. */ + if (RTA_OK(rta, msglen) == 0) + return; + + plen = RTA_PAYLOAD(rta); + + zlog_debug(" rta [len=%d (payload=%zu) type=(%d) %s]", rta->rta_len, + plen, rta->rta_type, ncm_rta2str(rta->rta_type)); + + switch (rta->rta_type) { + case NETCONFA_IFINDEX: + ival = *(uint32_t *)RTA_DATA(rta); + zlog_debug(" %d", (int32_t)ival); + break; + + /* Most attrs are just on/off. */ + case NETCONFA_FORWARDING: + case NETCONFA_RP_FILTER: + case NETCONFA_MC_FORWARDING: + case NETCONFA_PROXY_NEIGH: + case NETCONFA_IGNORE_ROUTES_WITH_LINKDOWN: + case NETCONFA_INPUT: + case NETCONFA_BC_FORWARDING: + ival = *(uint32_t *)RTA_DATA(rta); + dump_on_off(ival, " "); + break; + default: + /* NOTHING: unhandled. */ + break; + } + + /* Get next pointer and start iteration again. */ + rta = RTA_NEXT(rta, msglen); + goto next_rta; +} + void nl_dump(void *msg, size_t msglen) { struct nlmsghdr *nlmsg = msg; @@ -1305,6 +1389,7 @@ void nl_dump(void *msg, size_t msglen) struct ndmsg *ndm; struct rtmsg *rtm; struct nhmsg *nhm; + struct netconfmsg *ncm; struct ifinfomsg *ifi; struct fib_rule_hdr *frh; char fbuf[128]; @@ -1422,6 +1507,14 @@ next_header: nlnh_dump(nhm, nlmsg->nlmsg_len - NLMSG_LENGTH(sizeof(*nhm))); break; + case RTM_NEWNETCONF: + case RTM_DELNETCONF: + ncm = NLMSG_DATA(nlmsg); + zlog_debug(" ncm [family=%s (%d)]", + af_type2str(ncm->ncm_family), ncm->ncm_family); + nlncm_dump(ncm, nlmsg->nlmsg_len - NLMSG_LENGTH(sizeof(*ncm))); + break; + default: break; } diff --git a/zebra/dplane_fpm_nl.c b/zebra/dplane_fpm_nl.c index 3b02128c90..8c8004190b 100644 --- a/zebra/dplane_fpm_nl.c +++ b/zebra/dplane_fpm_nl.c @@ -176,16 +176,16 @@ enum fpm_nl_events { /* * Prototypes. */ -static int fpm_process_event(struct thread *t); +static void fpm_process_event(struct thread *t); static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx); -static int fpm_lsp_send(struct thread *t); -static int fpm_lsp_reset(struct thread *t); -static int fpm_nhg_send(struct thread *t); -static int fpm_nhg_reset(struct thread *t); -static int fpm_rib_send(struct thread *t); -static int fpm_rib_reset(struct thread *t); -static int fpm_rmac_send(struct thread *t); -static int fpm_rmac_reset(struct thread *t); +static void fpm_lsp_send(struct thread *t); +static void fpm_lsp_reset(struct thread *t); +static void fpm_nhg_send(struct thread *t); +static void fpm_nhg_reset(struct thread *t); +static void fpm_rib_send(struct thread *t); +static void fpm_rib_reset(struct thread *t); +static void fpm_rmac_send(struct thread *t); +static void fpm_rmac_reset(struct thread *t); /* * CLI. @@ -419,7 +419,7 @@ static struct cmd_node fpm_node = { /* * FPM functions. */ -static int fpm_connect(struct thread *t); +static void fpm_connect(struct thread *t); static void fpm_reconnect(struct fpm_nl_ctx *fnc) { @@ -458,7 +458,7 @@ static void fpm_reconnect(struct fpm_nl_ctx *fnc) &fnc->t_connect); } -static int fpm_read(struct thread *t) +static void fpm_read(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); ssize_t rv; @@ -471,7 +471,7 @@ static int fpm_read(struct thread *t) /* Schedule next read. */ thread_add_read(fnc->fthread->master, fpm_read, fnc, fnc->socket, &fnc->t_read); - return 0; + return; } if (rv == 0) { atomic_fetch_add_explicit(&fnc->counters.connection_closes, 1, @@ -481,7 +481,7 @@ static int fpm_read(struct thread *t) zlog_debug("%s: connection closed", __func__); FPM_RECONNECT(fnc); - return 0; + return; } if (rv == -1) { atomic_fetch_add_explicit(&fnc->counters.connection_errors, 1, @@ -489,7 +489,7 @@ static int fpm_read(struct thread *t) zlog_warn("%s: connection failure: %s", __func__, strerror(errno)); FPM_RECONNECT(fnc); - return 0; + return; } stream_reset(fnc->ibuf); @@ -499,11 +499,9 @@ static int fpm_read(struct thread *t) thread_add_read(fnc->fthread->master, fpm_read, fnc, fnc->socket, &fnc->t_read); - - return 0; } -static int fpm_write(struct thread *t) +static void fpm_write(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); socklen_t statuslen; @@ -530,7 +528,7 @@ static int fpm_write(struct thread *t) memory_order_relaxed); FPM_RECONNECT(fnc); - return 0; + return; } fnc->connecting = false; @@ -584,7 +582,7 @@ static int fpm_write(struct thread *t) strerror(errno)); FPM_RECONNECT(fnc); - return 0; + return; } /* Account all bytes sent. */ @@ -603,13 +601,11 @@ static int fpm_write(struct thread *t) stream_pulldown(fnc->obuf); thread_add_write(fnc->fthread->master, fpm_write, fnc, fnc->socket, &fnc->t_write); - return 0; + return; } - - return 0; } -static int fpm_connect(struct thread *t) +static void fpm_connect(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); struct sockaddr_in *sin = (struct sockaddr_in *)&fnc->addr; @@ -624,7 +620,7 @@ static int fpm_connect(struct thread *t) strerror(errno)); thread_add_timer(fnc->fthread->master, fpm_connect, fnc, 3, &fnc->t_connect); - return 0; + return; } set_nonblocking(sock); @@ -650,7 +646,7 @@ static int fpm_connect(struct thread *t) strerror(errno)); thread_add_timer(fnc->fthread->master, fpm_connect, fnc, 3, &fnc->t_connect); - return 0; + return; } fnc->connecting = (errno == EINPROGRESS); @@ -670,8 +666,6 @@ static int fpm_connect(struct thread *t) if (!fnc->connecting) thread_add_timer(zrouter.master, fpm_lsp_reset, fnc, 0, &fnc->t_lspreset); - - return 0; } /** @@ -786,6 +780,7 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) nl_buf_len += (size_t)rv; break; + /* Un-handled by FPM at this time. */ case DPLANE_OP_PW_INSTALL: case DPLANE_OP_PW_UNINSTALL: case DPLANE_OP_ADDR_INSTALL: @@ -799,15 +794,27 @@ static int fpm_nl_enqueue(struct fpm_nl_ctx *fnc, struct zebra_dplane_ctx *ctx) case DPLANE_OP_SYS_ROUTE_DELETE: case DPLANE_OP_ROUTE_NOTIFY: case DPLANE_OP_LSP_NOTIFY: + case DPLANE_OP_RULE_ADD: + case DPLANE_OP_RULE_DELETE: + case DPLANE_OP_RULE_UPDATE: + case DPLANE_OP_NEIGH_DISCOVER: + case DPLANE_OP_BR_PORT_UPDATE: + case DPLANE_OP_IPTABLE_ADD: + case DPLANE_OP_IPTABLE_DELETE: + case DPLANE_OP_IPSET_ADD: + case DPLANE_OP_IPSET_DELETE: + case DPLANE_OP_IPSET_ENTRY_ADD: + case DPLANE_OP_IPSET_ENTRY_DELETE: + case DPLANE_OP_NEIGH_IP_INSTALL: + case DPLANE_OP_NEIGH_IP_DELETE: + case DPLANE_OP_NEIGH_TABLE_UPDATE: + case DPLANE_OP_GRE_SET: + case DPLANE_OP_INTF_ADDR_ADD: + case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: case DPLANE_OP_NONE: break; - default: - if (IS_ZEBRA_DEBUG_FPM) - zlog_debug("%s: unhandled data plane message (%d) %s", - __func__, dplane_ctx_get_op(ctx), - dplane_op2str(dplane_ctx_get_op(ctx))); - break; } /* Skip empty enqueues. */ @@ -893,7 +900,7 @@ static int fpm_lsp_send_cb(struct hash_bucket *bucket, void *arg) return HASHWALK_CONTINUE; } -static int fpm_lsp_send(struct thread *t) +static void fpm_lsp_send(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -918,8 +925,6 @@ static int fpm_lsp_send(struct thread *t) thread_add_timer(zrouter.master, fpm_lsp_send, fnc, 0, &fnc->t_lspwalk); } - - return 0; } /* @@ -955,7 +960,7 @@ static int fpm_nhg_send_cb(struct hash_bucket *bucket, void *arg) return HASHWALK_CONTINUE; } -static int fpm_nhg_send(struct thread *t) +static void fpm_nhg_send(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); struct fpm_nhg_arg fna; @@ -979,14 +984,12 @@ static int fpm_nhg_send(struct thread *t) } else /* Otherwise reschedule next hop group again. */ thread_add_timer(zrouter.master, fpm_nhg_send, fnc, 0, &fnc->t_nhgwalk); - - return 0; } /** * Send all RIB installed routes to the connected data plane. */ -static int fpm_rib_send(struct thread *t) +static void fpm_rib_send(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); rib_dest_t *dest; @@ -1020,7 +1023,7 @@ static int fpm_rib_send(struct thread *t) thread_add_timer(zrouter.master, fpm_rib_send, fnc, 1, &fnc->t_ribwalk); - return 0; + return; } /* Mark as sent. */ @@ -1037,8 +1040,6 @@ static int fpm_rib_send(struct thread *t) /* Schedule next event: RMAC reset. */ thread_add_event(zrouter.master, fpm_rmac_reset, fnc, 0, &fnc->t_rmacreset); - - return 0; } /* @@ -1092,7 +1093,7 @@ static void fpm_enqueue_l3vni_table(struct hash_bucket *bucket, void *arg) hash_iterate(zl3vni->rmac_table, fpm_enqueue_rmac_table, zl3vni); } -static int fpm_rmac_send(struct thread *t) +static void fpm_rmac_send(struct thread *t) { struct fpm_rmac_arg fra; @@ -1105,8 +1106,6 @@ static int fpm_rmac_send(struct thread *t) /* RMAC walk completed. */ if (fra.complete) WALK_FINISH(fra.fnc, FNE_RMAC_FINISHED); - - return 0; } /* @@ -1120,7 +1119,7 @@ static void fpm_nhg_reset_cb(struct hash_bucket *bucket, void *arg) UNSET_FLAG(nhe->flags, NEXTHOP_GROUP_FPM); } -static int fpm_nhg_reset(struct thread *t) +static void fpm_nhg_reset(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); @@ -1128,8 +1127,6 @@ static int fpm_nhg_reset(struct thread *t) /* Schedule next step: send next hop groups. */ thread_add_event(zrouter.master, fpm_nhg_send, fnc, 0, &fnc->t_nhgwalk); - - return 0; } /* @@ -1142,7 +1139,7 @@ static void fpm_lsp_reset_cb(struct hash_bucket *bucket, void *arg) UNSET_FLAG(lsp->flags, LSP_FLAG_FPM); } -static int fpm_lsp_reset(struct thread *t) +static void fpm_lsp_reset(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); struct zebra_vrf *zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -1151,14 +1148,12 @@ static int fpm_lsp_reset(struct thread *t) /* Schedule next step: send LSPs */ thread_add_event(zrouter.master, fpm_lsp_send, fnc, 0, &fnc->t_lspwalk); - - return 0; } /** * Resets the RIB FPM flags so we send all routes again. */ -static int fpm_rib_reset(struct thread *t) +static void fpm_rib_reset(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); rib_dest_t *dest; @@ -1180,8 +1175,6 @@ static int fpm_rib_reset(struct thread *t) /* Schedule next step: send RIB routes. */ thread_add_event(zrouter.master, fpm_rib_send, fnc, 0, &fnc->t_ribwalk); - - return 0; } /* @@ -1201,7 +1194,7 @@ static void fpm_unset_l3vni_table(struct hash_bucket *bucket, void *arg) hash_iterate(zl3vni->rmac_table, fpm_unset_rmac_table, zl3vni); } -static int fpm_rmac_reset(struct thread *t) +static void fpm_rmac_reset(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); @@ -1210,11 +1203,9 @@ static int fpm_rmac_reset(struct thread *t) /* Schedule next event: send RMAC entries. */ thread_add_event(zrouter.master, fpm_rmac_send, fnc, 0, &fnc->t_rmacwalk); - - return 0; } -static int fpm_process_queue(struct thread *t) +static void fpm_process_queue(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); struct zebra_dplane_ctx *ctx; @@ -1269,14 +1260,12 @@ static int fpm_process_queue(struct thread *t) */ if (dplane_provider_out_ctx_queue_len(fnc->prov) > 0) dplane_provider_work_ready(); - - return 0; } /** * Handles external (e.g. CLI, data plane or others) events. */ -static int fpm_process_event(struct thread *t) +static void fpm_process_event(struct thread *t) { struct fpm_nl_ctx *fnc = THREAD_ARG(t); int event = THREAD_VAL(t); @@ -1338,8 +1327,6 @@ static int fpm_process_event(struct thread *t) zlog_debug("%s: unhandled event %d", __func__, event); break; } - - return 0; } /* diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 141e4074d5..db8ee3236c 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -74,6 +74,7 @@ #include "zebra/zebra_vxlan.h" #include "zebra/zebra_evpn_mh.h" #include "zebra/zebra_l2.h" +#include "zebra/netconf_netlink.h" extern struct zebra_privs_t zserv_privs; @@ -1001,6 +1002,7 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup) /* Hardware type and address. */ ifp->ll_type = netlink_to_zebra_link_type(ifi->ifi_type); + netlink_interface_update_hw_addr(tb, ifp); if_add_update(ifp); diff --git a/zebra/interface.c b/zebra/interface.c index 2e13cfd55c..fbd2aac005 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -64,7 +64,7 @@ DEFINE_HOOK(zebra_if_config_wr, (struct vty * vty, struct interface *ifp), static void if_down_del_nbr_connected(struct interface *ifp); -static int if_zebra_speed_update(struct thread *thread) +static void if_zebra_speed_update(struct thread *thread) { struct interface *ifp = THREAD_ARG(thread); struct zebra_if *zif = ifp->info; @@ -72,8 +72,6 @@ static int if_zebra_speed_update(struct thread *thread) bool changed = false; int error = 0; - zif->speed_update = NULL; - new_speed = kernel_get_speed(ifp, &error); /* error may indicate vrf not available or @@ -81,7 +79,7 @@ static int if_zebra_speed_update(struct thread *thread) * note that loopback & virtual interfaces can return 0 as speed */ if (error < 0) - return 1; + return; if (new_speed != ifp->speed) { zlog_info("%s: %s old speed: %u new speed: %u", __func__, @@ -92,12 +90,29 @@ static int if_zebra_speed_update(struct thread *thread) } if (changed || new_speed == UINT32_MAX) { - thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 5, - &zif->speed_update); +#define SPEED_UPDATE_SLEEP_TIME 5 +#define SPEED_UPDATE_COUNT_MAX (4 * 60 / SPEED_UPDATE_SLEEP_TIME) + /* + * Some interfaces never actually have an associated speed + * with them ( I am looking at you bridges ). + * So instead of iterating forever, let's give the + * system 4 minutes to try to figure out the speed + * if after that it it's probably never going to become + * useful. + * Since I don't know all the wonderful types of interfaces + * that may come into existence in the future I am going + * to not update the system to keep track of that. This + * is far simpler to just stop trying after 4 minutes + */ + if (new_speed == UINT32_MAX && + zif->speed_update_count == SPEED_UPDATE_COUNT_MAX) + return; + + zif->speed_update_count++; + thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, + SPEED_UPDATE_SLEEP_TIME, &zif->speed_update); thread_ignore_late_timer(zif->speed_update); } - - return 1; } static void zebra_if_node_destroy(route_table_delegate_t *delegate, @@ -198,6 +213,7 @@ static int if_zebra_new_hook(struct interface *ifp) * of seconds and ask again. Hopefully it's all settled * down upon startup. */ + zebra_if->speed_update_count = 0; thread_add_timer(zrouter.master, if_zebra_speed_update, ifp, 15, &zebra_if->speed_update); thread_ignore_late_timer(zebra_if->speed_update); @@ -1320,6 +1336,56 @@ done: dplane_ctx_fini(&ctx); } +/* + * Handle netconf change from a dplane context object; runs in the main + * pthread so it can update zebra data structs. + */ +int zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx) +{ + struct zebra_ns *zns; + struct interface *ifp; + struct zebra_if *zif; + enum dplane_netconf_status_e mpls; + int ret = 0; + + zns = zebra_ns_lookup(dplane_ctx_get_netconf_ns_id(ctx)); + if (zns == NULL) { + ret = -1; + goto done; + } + + ifp = if_lookup_by_index_per_ns(zns, + dplane_ctx_get_netconf_ifindex(ctx)); + if (ifp == NULL) { + ret = -1; + goto done; + } + + zif = ifp->info; + if (zif == NULL) { + ret = -1; + goto done; + } + + mpls = dplane_ctx_get_netconf_mpls(ctx); + + if (mpls == DPLANE_NETCONF_STATUS_ENABLED) + zif->mpls = true; + else if (mpls == DPLANE_NETCONF_STATUS_DISABLED) + zif->mpls = false; + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: if %s, ifindex %d, mpls %s", + __func__, ifp->name, ifp->ifindex, + (zif->mpls ? "ON" : "OFF")); + +done: + /* Free the context */ + dplane_ctx_fini(&ctx); + + return ret; +} + /* Dump if address information to vty. */ static void connected_dump_vty(struct vty *vty, json_object *json, struct connected *connected) @@ -1672,6 +1738,9 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) vty_out(vty, "mtu6 %d ", ifp->mtu6); vty_out(vty, "\n flags: %s\n", if_flag_dump(ifp->flags)); + if (zebra_if->mpls) + vty_out(vty, " MPLS enabled\n"); + /* Hardware address. */ vty_out(vty, " Type: %s\n", if_link_type_str(ifp->ll_type)); if (ifp->hw_addr_len != 0) { @@ -1992,6 +2061,8 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp, json_object_string_add(json_if, "OsDescription", zebra_if->desc); + json_object_boolean_add(json_if, "mplsEnabled", zebra_if->mpls); + if (ifp->ifindex == IFINDEX_INTERNAL) { json_object_boolean_add(json_if, "pseudoInterface", true); return; diff --git a/zebra/interface.h b/zebra/interface.h index 413a67469a..c19e494860 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -329,6 +329,9 @@ struct zebra_if { /* Multicast configuration. */ uint8_t multicast; + /* MPLS status. */ + bool mpls; + /* Router advertise configuration. */ uint8_t rtadv_enable; @@ -409,6 +412,7 @@ struct zebra_if { ifindex_t link_ifindex; struct interface *link; + uint8_t speed_update_count; struct thread *speed_update; /* @@ -520,6 +524,7 @@ extern void zebra_l2_unmap_slave_from_bond(struct zebra_if *zif); extern const char *zebra_protodown_rc_str(enum protodown_reasons protodown_rc, char *pd_buf, uint32_t pd_buf_len); void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx); +int zebra_if_netconf_update_ctx(struct zebra_dplane_ctx *ctx); #ifdef HAVE_PROC_NET_DEV extern void ifstat_update_proc(void); diff --git a/zebra/irdp.h b/zebra/irdp.h index c1ea34f3aa..19f549cc5b 100644 --- a/zebra/irdp.h +++ b/zebra/irdp.h @@ -144,10 +144,10 @@ struct Adv { extern void irdp_if_init(void); extern int irdp_sock_init(void); extern int irdp_config_write(struct vty *, struct interface *); -extern int irdp_send_thread(struct thread *t_advert); +extern void irdp_send_thread(struct thread *t_advert); extern void irdp_advert_off(struct interface *ifp); extern void process_solicit(struct interface *ifp); -extern int irdp_read_raw(struct thread *r); +extern void irdp_read_raw(struct thread *r); extern void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, struct prefix *p, uint32_t ttl); diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index f141b72719..43478c98f1 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -205,7 +205,7 @@ static void irdp_advertisement(struct interface *ifp, struct prefix *p) stream_free(s); } -int irdp_send_thread(struct thread *t_advert) +void irdp_send_thread(struct thread *t_advert) { uint32_t timer, tmp; struct interface *ifp = THREAD_ARG(t_advert); @@ -216,7 +216,7 @@ int irdp_send_thread(struct thread *t_advert) struct connected *ifc; if (!irdp) - return 0; + return; irdp->flags &= ~IF_SOLICIT; @@ -246,7 +246,6 @@ int irdp_send_thread(struct thread *t_advert) irdp->t_advertise = NULL; thread_add_timer(zrouter.master, irdp_send_thread, ifp, timer, &irdp->t_advertise); - return 0; } void irdp_advert_off(struct interface *ifp) diff --git a/zebra/irdp_packet.c b/zebra/irdp_packet.c index 5601b13a92..c27d97ba71 100644 --- a/zebra/irdp_packet.c +++ b/zebra/irdp_packet.c @@ -224,7 +224,7 @@ static int irdp_recvmsg(int sock, uint8_t *buf, int size, int *ifindex) return ret; } -int irdp_read_raw(struct thread *r) +void irdp_read_raw(struct thread *r) { struct interface *ifp; struct zebra_if *zi; @@ -243,22 +243,22 @@ int irdp_read_raw(struct thread *r) ifp = if_lookup_by_index(ifindex, VRF_DEFAULT); if (!ifp) - return ret; + return; zi = ifp->info; if (!zi) - return ret; + return; irdp = zi->irdp; if (!irdp) - return ret; + return; if (!(irdp->flags & IF_ACTIVE)) { if (irdp->flags & IF_DEBUG_MISC) zlog_debug("IRDP: RX ICMP for disabled interface %s", ifp->name); - return 0; + return; } if (irdp->flags & IF_DEBUG_PACKET) { @@ -269,8 +269,6 @@ int irdp_read_raw(struct thread *r) } parse_irdp_packet(buf, ret, ifp); - - return ret; } void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 84c15a2a92..d84b0c1325 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -38,7 +38,6 @@ #include "lib_errors.h" #include "hash.h" -//#include "zebra/zserv.h" #include "zebra/zebra_router.h" #include "zebra/zebra_ns.h" #include "zebra/zebra_vrf.h" @@ -48,6 +47,7 @@ #include "zebra/rt_netlink.h" #include "zebra/if_netlink.h" #include "zebra/rule_netlink.h" +#include "zebra/netconf_netlink.h" #include "zebra/zebra_errors.h" #ifndef SO_RCVBUFFORCE @@ -108,6 +108,8 @@ static const struct message nlmsg_str[] = {{RTM_NEWROUTE, "RTM_NEWROUTE"}, {RTM_NEWNEXTHOP, "RTM_NEWNEXTHOP"}, {RTM_DELNEXTHOP, "RTM_DELNEXTHOP"}, {RTM_GETNEXTHOP, "RTM_GETNEXTHOP"}, + {RTM_NEWNETCONF, "RTM_NEWNETCONF"}, + {RTM_DELNETCONF, "RTM_DELNETCONF"}, {0}}; static const struct message rtproto_str[] = { @@ -153,7 +155,6 @@ static const struct message rttype_str[] = {{RTN_UNSPEC, "none"}, {0}}; extern struct thread_master *master; -extern uint32_t nl_rcvbufsize; extern struct zebra_privs_t zserv_privs; @@ -259,12 +260,11 @@ static int netlink_recvbuf(struct nlsock *nl, uint32_t newsize) /* Try force option (linux >= 2.6.14) and fall back to normal set */ frr_with_privs(&zserv_privs) { ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUFFORCE, - &nl_rcvbufsize, - sizeof(nl_rcvbufsize)); + &rcvbufsize, sizeof(rcvbufsize)); } if (ret < 0) - ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, - &nl_rcvbufsize, sizeof(nl_rcvbufsize)); + ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &rcvbufsize, + sizeof(rcvbufsize)); if (ret < 0) { flog_err_sys(EC_LIB_SOCKET, "Can't set %s receive buffer size: %s", nl->name, @@ -373,6 +373,8 @@ static int netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, /* Messages handled in the dplane thread */ case RTM_NEWADDR: case RTM_DELADDR: + case RTM_NEWNETCONF: + case RTM_DELNETCONF: return 0; default: @@ -407,7 +409,12 @@ static int dplane_netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, case RTM_DELADDR: return netlink_interface_addr_dplane(h, ns_id, startup); - /* TODO */ + case RTM_NEWNETCONF: + case RTM_DELNETCONF: + return netlink_netconf_change(h, ns_id, startup); + + /* TODO -- other messages for the dplane socket and pthread */ + case RTM_NEWLINK: case RTM_DELLINK: @@ -418,7 +425,7 @@ static int dplane_netlink_information_fetch(struct nlmsghdr *h, ns_id_t ns_id, return 0; } -static int kernel_read(struct thread *thread) +static void kernel_read(struct thread *thread) { struct zebra_ns *zns = (struct zebra_ns *)THREAD_ARG(thread); struct zebra_dplane_info dp_info; @@ -431,8 +438,6 @@ static int kernel_read(struct thread *thread) thread_add_read(zrouter.master, kernel_read, zns, zns->netlink.sock, &zns->t_netlink); - - return 0; } /* @@ -458,8 +463,8 @@ int kernel_dplane_read(struct zebra_dplane_info *info) * then the normal course of operations). We are intentionally * allowing some messages from ourselves through * ( I'm looking at you Interface based netlink messages ) - * so that we only had to write one way to handle incoming - * address add/delete changes. + * so that we only have to write one way to handle incoming + * address add/delete and xxxNETCONF changes. */ static void netlink_install_filter(int sock, uint32_t pid, uint32_t dplane_pid) { @@ -475,7 +480,8 @@ static void netlink_install_filter(int sock, uint32_t pid, uint32_t dplane_pid) * if (nlmsg_pid == pid || * nlmsg_pid == dplane_pid) { * if (the incoming nlmsg_type == - * RTM_NEWADDR | RTM_DELADDR) + * RTM_NEWADDR || RTM_DELADDR || RTM_NEWNETCONF || + * RTM_DELNETCONF) * keep this message * else * skip this message @@ -494,7 +500,7 @@ static void netlink_install_filter(int sock, uint32_t pid, uint32_t dplane_pid) /* * 2: Compare to dplane pid */ - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(dplane_pid), 0, 4), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htonl(dplane_pid), 0, 6), /* * 3: Load the nlmsg_type into BPF register */ @@ -503,17 +509,27 @@ static void netlink_install_filter(int sock, uint32_t pid, uint32_t dplane_pid) /* * 4: Compare to RTM_NEWADDR */ - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_NEWADDR), 2, 0), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_NEWADDR), 4, 0), /* * 5: Compare to RTM_DELADDR */ - BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_DELADDR), 1, 0), + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_DELADDR), 3, 0), /* - * 6: This is the end state of we want to skip the + * 6: Compare to RTM_NEWNETCONF + */ + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_NEWNETCONF), 2, + 0), + /* + * 7: Compare to RTM_DELNETCONF + */ + BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, htons(RTM_DELNETCONF), 1, + 0), + /* + * 8: This is the end state of we want to skip the * message */ BPF_STMT(BPF_RET | BPF_K, 0), - /* 7: This is the end state of we want to keep + /* 9: This is the end state of we want to keep * the message */ BPF_STMT(BPF_RET | BPF_K, 0xffff), @@ -1472,6 +1488,7 @@ static enum netlink_msg_status nl_put_msg(struct nl_batch *bth, case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: case DPLANE_OP_NONE: return FRR_NETLINK_ERROR; } @@ -1599,7 +1616,11 @@ void kernel_init(struct zebra_ns *zns) dplane_groups = (RTMGRP_LINK | RTMGRP_IPV4_IFADDR | - RTMGRP_IPV6_IFADDR); + RTMGRP_IPV6_IFADDR | + ((uint32_t) 1 << (RTNLGRP_IPV4_NETCONF - 1)) | + ((uint32_t) 1 << (RTNLGRP_IPV6_NETCONF - 1)) | + ((uint32_t) 1 << (RTNLGRP_MPLS_NETCONF - 1))); + snprintf(zns->netlink.name, sizeof(zns->netlink.name), "netlink-listen (NS %u)", zns->ns_id); @@ -1709,11 +1730,11 @@ void kernel_init(struct zebra_ns *zns) errno); /* Set receive buffer size if it's set from command line */ - if (nl_rcvbufsize) { - netlink_recvbuf(&zns->netlink, nl_rcvbufsize); - netlink_recvbuf(&zns->netlink_cmd, nl_rcvbufsize); - netlink_recvbuf(&zns->netlink_dplane_out, nl_rcvbufsize); - netlink_recvbuf(&zns->netlink_dplane_in, nl_rcvbufsize); + if (rcvbufsize) { + netlink_recvbuf(&zns->netlink, rcvbufsize); + netlink_recvbuf(&zns->netlink_cmd, rcvbufsize); + netlink_recvbuf(&zns->netlink_dplane_out, rcvbufsize); + netlink_recvbuf(&zns->netlink_dplane_in, rcvbufsize); } /* Set filter for inbound sockets, to exclude events we've generated diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index b9228072e5..ce1f17111b 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -1011,6 +1011,8 @@ void rtm_read(struct rt_msghdr *rtm) ifindex_t ifindex = 0; afi_t afi; char fbuf[64]; + int32_t proto = ZEBRA_ROUTE_KERNEL; + uint8_t distance = 0; zebra_flags = 0; @@ -1042,8 +1044,11 @@ void rtm_read(struct rt_msghdr *rtm) if (!(flags & RTF_GATEWAY)) return; - if (flags & RTF_PROTO1) + if (flags & RTF_PROTO1) { SET_FLAG(zebra_flags, ZEBRA_FLAG_SELFROUTE); + proto = ZEBRA_ROUTE_STATIC; + distance = 255; + } memset(&nh, 0, sizeof(nh)); @@ -1111,13 +1116,13 @@ void rtm_read(struct rt_msghdr *rtm) 0, true); if (rtm->rtm_type == RTM_GET || rtm->rtm_type == RTM_ADD || rtm->rtm_type == RTM_CHANGE) - rib_add(afi, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, 0, - zebra_flags, &p, NULL, &nh, 0, RT_TABLE_MAIN, - 0, 0, 0, 0, false); + rib_add(afi, SAFI_UNICAST, VRF_DEFAULT, proto, 0, zebra_flags, + &p, NULL, &nh, 0, RT_TABLE_MAIN, 0, 0, distance, 0, + false); else - rib_delete(afi, SAFI_UNICAST, VRF_DEFAULT, ZEBRA_ROUTE_KERNEL, - 0, zebra_flags, &p, NULL, &nh, 0, RT_TABLE_MAIN, 0, - 0, true); + rib_delete(afi, SAFI_UNICAST, VRF_DEFAULT, proto, 0, + zebra_flags, &p, NULL, &nh, 0, RT_TABLE_MAIN, 0, + distance, true); } /* Interface function for the kernel routing table updates. Support @@ -1292,7 +1297,7 @@ static void rtmsg_debug(struct rt_msghdr *rtm) #endif /* RTAX_MAX */ /* Kernel routing table and interface updates via routing socket. */ -static int kernel_read(struct thread *thread) +static void kernel_read(struct thread *thread) { int sock; int nbytes; @@ -1356,11 +1361,11 @@ static int kernel_read(struct thread *thread) if (errno != EAGAIN && errno != EWOULDBLOCK) flog_err_sys(EC_LIB_SOCKET, "routing socket error: %s", safe_strerror(errno)); - return 0; + return; } if (nbytes == 0) - return 0; + return; thread_add_read(zrouter.master, kernel_read, NULL, sock, NULL); @@ -1377,7 +1382,7 @@ static int kernel_read(struct thread *thread) zlog_debug( "kernel_read: rtm->rtm_msglen %d, nbytes %d, type %d", rtm->rtm_msglen, nbytes, rtm->rtm_type); - return -1; + return; } switch (rtm->rtm_type) { @@ -1403,12 +1408,14 @@ static int kernel_read(struct thread *thread) zlog_debug("Unprocessed RTM_type: %d", rtm->rtm_type); break; } - return 0; } /* Make routing socket. */ static void routing_socket(struct zebra_ns *zns) { + uint32_t default_rcvbuf; + socklen_t optlen; + frr_with_privs(&zserv_privs) { routing_sock = ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id); @@ -1443,6 +1450,23 @@ static void routing_socket(struct zebra_ns *zns) /*if (fcntl (routing_sock, F_SETFL, O_NONBLOCK) < 0) zlog_warn ("Can't set O_NONBLOCK to routing socket");*/ + /* + * Attempt to set a more useful receive buffer size + */ + optlen = sizeof(default_rcvbuf); + if (getsockopt(routing_sock, SOL_SOCKET, SO_RCVBUF, &default_rcvbuf, + &optlen) == -1) + flog_err_sys(EC_LIB_SOCKET, + "routing_sock sockopt SOL_SOCKET SO_RCVBUF"); + else { + for (; rcvbufsize > default_rcvbuf && + setsockopt(routing_sock, SOL_SOCKET, SO_RCVBUF, + &rcvbufsize, sizeof(rcvbufsize)) == -1 && + errno == ENOBUFS; + rcvbufsize /= 2) + ; + } + /* kernel_read needs rewrite. */ thread_add_read(zrouter.master, kernel_read, NULL, routing_sock, NULL); } diff --git a/zebra/main.c b/zebra/main.c index 079751af0a..7ef30d1d49 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -78,10 +78,12 @@ int graceful_restart; bool v6_rr_semantics = false; +/* Receive buffer size for kernel control sockets */ #ifdef HAVE_NETLINK -/* Receive buffer size for netlink socket */ -uint32_t nl_rcvbufsize = 4194304; -#endif /* HAVE_NETLINK */ +uint32_t rcvbufsize = 4194304; +#else +uint32_t rcvbufsize = 128 * 1024; +#endif #define OPTION_V6_RR_SEMANTICS 2000 #define OPTION_ASIC_OFFLOAD 2001 @@ -213,7 +215,7 @@ static void sigint(void) * Final shutdown step for the zebra main thread. This is run after all * async update processing has completed. */ -int zebra_finalize(struct thread *dummy) +void zebra_finalize(struct thread *dummy) { zlog_info("Zebra final shutdown"); @@ -294,9 +296,9 @@ int main(int argc, char **argv) frr_preinit(&zebra_di, argc, argv); frr_opt_add( - "baz:e:rK:" + "baz:e:rK:s:" #ifdef HAVE_NETLINK - "s:n" + "n" #endif , longopts, @@ -308,9 +310,11 @@ int main(int argc, char **argv) " -K, --graceful_restart Graceful restart at the kernel level, timer in seconds for expiration\n" " -A, --asic-offload FRR is interacting with an asic underneath the linux kernel\n" #ifdef HAVE_NETLINK - " -n, --vrfwnetns Use NetNS as VRF backend\n" " -s, --nl-bufsize Set netlink receive buffer size\n" + " -n, --vrfwnetns Use NetNS as VRF backend\n" " --v6-rr-semantics Use v6 RR semantics\n" +#else + " -s, Set kernel socket receive buffer size\n" #endif /* HAVE_NETLINK */ ); @@ -359,10 +363,10 @@ int main(int argc, char **argv) case 'K': graceful_restart = atoi(optarg); break; -#ifdef HAVE_NETLINK case 's': - nl_rcvbufsize = atoi(optarg); + rcvbufsize = atoi(optarg); break; +#ifdef HAVE_NETLINK case 'n': vrf_configure_backend(VRF_BACKEND_NETNS); break; diff --git a/zebra/netconf_netlink.c b/zebra/netconf_netlink.c new file mode 100644 index 0000000000..587f6c749e --- /dev/null +++ b/zebra/netconf_netlink.c @@ -0,0 +1,175 @@ +/* + * netconf_netlink.c - netconf interaction with the kernel using + * netlink + * Copyright (C) 2021 Nvidia, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#include <zebra.h> + +#ifdef HAVE_NETLINK /* Netlink OSes only */ + +#include <ns.h> + +#include "linux/netconf.h" + +#include "zebra/zebra_ns.h" +#include "zebra/zebra_dplane.h" +#include "zebra/kernel_netlink.h" +#include "zebra/netconf_netlink.h" +#include "zebra/debug.h" + +static struct rtattr *netconf_rta(struct netconfmsg *ncm) +{ + return (struct rtattr *)((char *)ncm + + NLMSG_ALIGN(sizeof(struct netconfmsg))); +} + +/* + * Handle netconf update about a single interface: create dplane + * context, and enqueue for processing in the main zebra pthread. + */ +static int netlink_netconf_dplane_update(ns_id_t ns_id, ifindex_t ifindex, + enum dplane_netconf_status_e mpls_on, + enum dplane_netconf_status_e mcast_on) +{ + struct zebra_dplane_ctx *ctx; + + ctx = dplane_ctx_alloc(); + dplane_ctx_set_op(ctx, DPLANE_OP_INTF_NETCONFIG); + dplane_ctx_set_netconf_ns_id(ctx, ns_id); + dplane_ctx_set_netconf_ifindex(ctx, ifindex); + + dplane_ctx_set_netconf_mpls(ctx, mpls_on); + dplane_ctx_set_netconf_mcast(ctx, mcast_on); + + /* Enqueue ctx for main pthread to process */ + dplane_provider_enqueue_to_zebra(ctx); + + return 0; +} + +/* + * Parse and process an incoming netlink netconf update. + */ +int netlink_netconf_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) +{ + struct netconfmsg *ncm; + struct rtattr *tb[NETCONFA_MAX + 1] = {}; + int len; + ifindex_t ifindex; + uint32_t ival; + enum dplane_netconf_status_e mpls_on = DPLANE_NETCONF_STATUS_UNKNOWN; + enum dplane_netconf_status_e mcast_on = DPLANE_NETCONF_STATUS_UNKNOWN; + + if (h->nlmsg_type != RTM_NEWNETCONF && h->nlmsg_type != RTM_DELNETCONF) + return 0; + + len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct netconfmsg)); + if (len < 0) { + zlog_err("%s: Message received from netlink is of a broken size: %d, min %zu", + __func__, h->nlmsg_len, + (size_t)NLMSG_LENGTH(sizeof(struct netconfmsg))); + return -1; + } + + ncm = NLMSG_DATA(h); + + netlink_parse_rtattr(tb, NETCONFA_MAX, netconf_rta(ncm), len); + + if (!tb[NETCONFA_IFINDEX]) { + zlog_err("NETCONF message received from netlink without an ifindex"); + return 0; + } + + ifindex = *(ifindex_t *)RTA_DATA(tb[NETCONFA_IFINDEX]); + + switch (ifindex) { + case NETCONFA_IFINDEX_ALL: + case NETCONFA_IFINDEX_DEFAULT: + /* + * We need the ability to handle netlink messages intended + * for all and default interfaces. I am not 100% sure + * what that is yet, or where we would store it. + */ + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: Ignoring global ifindex %d", + __func__, ifindex); + + return 0; + default: + break; + } + + if (tb[NETCONFA_INPUT]) { + ival = *(uint32_t *)RTA_DATA(tb[NETCONFA_INPUT]); + if (ival != 0) + mpls_on = DPLANE_NETCONF_STATUS_ENABLED; + else + mpls_on = DPLANE_NETCONF_STATUS_DISABLED; + } + + if (tb[NETCONFA_MC_FORWARDING]) { + ival = *(uint32_t *)RTA_DATA(tb[NETCONFA_MC_FORWARDING]); + if (ival != 0) + mcast_on = DPLANE_NETCONF_STATUS_ENABLED; + else + mcast_on = DPLANE_NETCONF_STATUS_DISABLED; + } + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: interface %u is mpls on: %d multicast on: %d", + __func__, ifindex, mpls_on, mcast_on); + + /* Create a dplane context and pass it along for processing */ + netlink_netconf_dplane_update(ns_id, ifindex, mpls_on, mcast_on); + + return 0; +} + +/* + * Request info from the host OS. This only sends the request; any replies + * are processed asynchronously. + */ +int netlink_request_netconf(int sockfd) +{ + struct nlsock *nls; + struct { + struct nlmsghdr n; + struct netconfmsg ncm; + char buf[1024]; + } req = {}; + + nls = kernel_netlink_nlsock_lookup(sockfd); + + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s: nlsock %s", __func__, nls ? nls->name : "NULL"); + + if (nls == NULL) + return -1; + + req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct netconfmsg)); + req.n.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; + req.n.nlmsg_type = RTM_GETNETCONF; + req.ncm.ncm_family = AF_UNSPEC; + + return netlink_request(nls, &req); +} + +#endif /* HAVE_NETLINK */ diff --git a/zebra/netconf_netlink.h b/zebra/netconf_netlink.h new file mode 100644 index 0000000000..3f2e7af768 --- /dev/null +++ b/zebra/netconf_netlink.h @@ -0,0 +1,48 @@ +/* + * netconf_netlink.h - netconf interaction with the kernel using + * netlink + * Copyright (C) 2021 Nvidia, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef __NETCONF_NETLINK_H__ +#define __NETCONF_NETLINK_H__ + +#ifdef HAVE_NETLINK /* Netlink-only module */ + +#include "zebra/zebra_ns.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Parse and handle a NETCONF message. */ +extern int netlink_netconf_change(struct nlmsghdr *h, ns_id_t ns_id, + int startup); +/* Request info from the host OS. */ +int netlink_request_netconf(int sockfd); + + +#ifdef __cplusplus +} +#endif + +#endif /* HAVE_NETLINK */ + +#endif /* NETCONF_NETLINK_H */ diff --git a/zebra/rib.h b/zebra/rib.h index ae1fce727c..c6f3528cec 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -432,7 +432,7 @@ extern struct route_entry *rib_lookup_ipv4(struct prefix_ipv4 *p, extern void rib_update(enum rib_update_event event); extern void rib_update_table(struct route_table *table, enum rib_update_event event, int rtype); -extern int rib_sweep_route(struct thread *t); +extern void rib_sweep_route(struct thread *t); extern void rib_sweep_table(struct route_table *table); extern void rib_close_table(struct route_table *table); extern void rib_init(void); diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 3bbee83d77..2ce5072945 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -471,7 +471,7 @@ no_more_opts: zif->ra_sent++; } -static int rtadv_timer(struct thread *thread) +static void rtadv_timer(struct thread *thread) { struct zebra_vrf *zvrf = THREAD_ARG(thread); struct vrf *vrf; @@ -534,8 +534,6 @@ static int rtadv_timer(struct thread *thread) } } } - - return 0; } static void rtadv_process_solicit(struct interface *ifp) @@ -774,7 +772,7 @@ static void rtadv_process_packet(uint8_t *buf, unsigned int len, return; } -static int rtadv_read(struct thread *thread) +static void rtadv_read(struct thread *thread) { int sock; int len; @@ -797,12 +795,10 @@ static int rtadv_read(struct thread *thread) flog_err_sys(EC_LIB_SOCKET, "RA/RS recv failed, socket %u error %s", sock, safe_strerror(errno)); - return len; + return; } rtadv_process_packet(buf, (unsigned)len, ifindex, hoplimit, &from, zvrf); - - return 0; } static int rtadv_make_socket(ns_id_t ns_id) diff --git a/zebra/subdir.am b/zebra/subdir.am index f0cc6ce71b..77e0898d81 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -69,6 +69,7 @@ zebra_zebra_SOURCES = \ zebra/kernel_socket.c \ zebra/label_manager.c \ zebra/main.c \ + zebra/netconf_netlink.c \ zebra/redistribute.c \ zebra/router-id.c \ zebra/rt_netlink.c \ @@ -148,6 +149,7 @@ noinst_HEADERS += \ zebra/kernel_netlink.h \ zebra/kernel_socket.h \ zebra/label_manager.h \ + zebra/netconf_netlink.h \ zebra/redistribute.h \ zebra/rib.h \ zebra/router-id.h \ diff --git a/zebra/zebra_dplane.c b/zebra/zebra_dplane.c index 9f9270db9a..6de2be3ab8 100644 --- a/zebra/zebra_dplane.c +++ b/zebra/zebra_dplane.c @@ -28,6 +28,7 @@ #include "lib/memory.h" #include "lib/queue.h" #include "lib/zebra.h" +#include "zebra/netconf_netlink.h" #include "zebra/zebra_router.h" #include "zebra/zebra_dplane.h" #include "zebra/zebra_vxlan_private.h" @@ -290,6 +291,19 @@ struct dplane_gre_ctx { unsigned int mtu; struct zebra_l2info_gre info; }; + + +/* + * Network interface configuration info - aligned with netlink's NETCONF + * info. The flags values are public, in the dplane.h file... + */ +struct dplane_netconf_info { + ns_id_t ns_id; + ifindex_t ifindex; + enum dplane_netconf_status_e mpls_val; + enum dplane_netconf_status_e mcast_val; +}; + /* * The context block used to exchange info about route updates across * the boundary between the zebra main context (and pthread) and the @@ -347,6 +361,7 @@ struct zebra_dplane_ctx { } ipset_entry; struct dplane_neigh_table neightable; struct dplane_gre_ctx gre; + struct dplane_netconf_info netconf; } u; /* Namespace info, used especially for netlink kernel communication */ @@ -416,6 +431,9 @@ PREDECL_DLIST(zns_info_list); struct dplane_zns_info { struct zebra_dplane_info info; + /* Request data from the OS */ + struct thread *t_request; + /* Read event */ struct thread *t_read; @@ -539,9 +557,7 @@ DECLARE_DLIST(zns_info_list, struct dplane_zns_info, link); #define DPLANE_PROV_UNLOCK(p) pthread_mutex_unlock(&((p)->dp_mutex)) /* Prototypes */ -static int dplane_thread_loop(struct thread *event); -static void dplane_info_from_zns(struct zebra_dplane_info *ns_info, - struct zebra_ns *zns); +static void dplane_thread_loop(struct thread *event); static enum zebra_dplane_result lsp_update_internal(struct zebra_lsp *lsp, enum dplane_op_e op); static enum zebra_dplane_result pw_update_internal(struct zebra_pw *pw, @@ -769,6 +785,7 @@ static void dplane_ctx_free_internal(struct zebra_dplane_ctx *ctx) } break; case DPLANE_OP_GRE_SET: + case DPLANE_OP_INTF_NETCONFIG: break; } } @@ -1053,6 +1070,9 @@ const char *dplane_op2str(enum dplane_op_e op) case DPLANE_OP_INTF_ADDR_DEL: return "INTF_ADDR_DEL"; + + case DPLANE_OP_INTF_NETCONFIG: + return "INTF_NETCONFIG"; } return ret; @@ -2239,6 +2259,10 @@ uint32_t dplane_intf_extra_get_status(const struct dplane_intf_extra *ptr) return ptr->status; } +/* + * End of interface extra info accessors + */ + uint8_t dplane_ctx_neightable_get_family(const struct zebra_dplane_ctx *ctx) { DPLANE_CTX_VALID(ctx); @@ -2270,9 +2294,66 @@ dplane_ctx_neightable_get_mcast_probes(const struct zebra_dplane_ctx *ctx) return ctx->u.neightable.mcast_probes; } -/* - * End of interface extra info accessors - */ +ifindex_t dplane_ctx_get_netconf_ifindex(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.ifindex; +} + +ns_id_t dplane_ctx_get_netconf_ns_id(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.ns_id; +} + +void dplane_ctx_set_netconf_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t ifindex) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.ifindex = ifindex; +} + +void dplane_ctx_set_netconf_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t ns_id) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.ns_id = ns_id; +} + +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.mpls_val; +} + +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx *ctx) +{ + DPLANE_CTX_VALID(ctx); + + return ctx->u.netconf.mcast_val; +} + +void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.mpls_val = val; +} + +void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val) +{ + DPLANE_CTX_VALID(ctx); + + ctx->u.netconf.mcast_val = val; +} /* * Retrieve the limit on the number of pending, unprocessed updates. @@ -2306,13 +2387,29 @@ uint32_t dplane_get_in_queue_len(void) } /* + * Internal helper that copies information from a zebra ns object; this is + * called in the zebra main pthread context as part of dplane ctx init. + */ +static void ctx_info_from_zns(struct zebra_dplane_info *ns_info, + struct zebra_ns *zns) +{ + ns_info->ns_id = zns->ns_id; + +#if defined(HAVE_NETLINK) + ns_info->is_cmd = true; + ns_info->sock = zns->netlink_dplane_out.sock; + ns_info->seq = zns->netlink_dplane_out.seq; +#endif /* NETLINK */ +} + +/* * Common dataplane context init with zebra namespace info. */ static int dplane_ctx_ns_init(struct zebra_dplane_ctx *ctx, struct zebra_ns *zns, bool is_update) { - dplane_info_from_zns(&(ctx->zd_ns_info), zns); + ctx_info_from_zns(&(ctx->zd_ns_info), zns); /* */ ctx->zd_is_update = is_update; @@ -4844,27 +4941,12 @@ bool dplane_provider_is_threaded(const struct zebra_dplane_provider *prov) return (prov->dp_flags & DPLANE_PROV_FLAG_THREADED); } -/* - * Internal helper that copies information from a zebra ns object; this is - * called in the zebra main pthread context as part of dplane ctx init. - */ -static void dplane_info_from_zns(struct zebra_dplane_info *ns_info, - struct zebra_ns *zns) -{ - ns_info->ns_id = zns->ns_id; - -#if defined(HAVE_NETLINK) - ns_info->is_cmd = true; - ns_info->sock = zns->netlink_dplane_out.sock; -#endif /* NETLINK */ -} - #ifdef HAVE_NETLINK /* * Callback when an OS (netlink) incoming event read is ready. This runs * in the dplane pthread. */ -static int dplane_incoming_read(struct thread *event) +static void dplane_incoming_read(struct thread *event) { struct dplane_zns_info *zi = THREAD_ARG(event); @@ -4873,9 +4955,41 @@ static int dplane_incoming_read(struct thread *event) /* Re-start read task */ thread_add_read(zdplane_info.dg_master, dplane_incoming_read, zi, zi->info.sock, &zi->t_read); +} - return 0; +/* + * Callback in the dataplane pthread that requests info from the OS and + * initiates netlink reads. + */ +static void dplane_incoming_request(struct thread *event) +{ + struct dplane_zns_info *zi = THREAD_ARG(event); + + /* Start read task */ + thread_add_read(zdplane_info.dg_master, dplane_incoming_read, zi, + zi->info.sock, &zi->t_read); + + /* Send requests */ + netlink_request_netconf(zi->info.sock); +} + +/* + * Initiate requests for existing info from the OS. This is called by the + * main pthread, but we want all activity on the dplane netlink socket to + * take place on the dplane pthread, so we schedule an event to accomplish + * that. + */ +static void dplane_kernel_info_request(struct dplane_zns_info *zi) +{ + /* If we happen to encounter an enabled zns before the dplane + * pthread is running, we'll initiate this later on. + */ + if (zdplane_info.dg_master) + thread_add_event(zdplane_info.dg_master, + dplane_incoming_request, zi, 0, + &zi->t_request); } + #endif /* HAVE_NETLINK */ /* @@ -4919,11 +5033,10 @@ void zebra_dplane_ns_enable(struct zebra_ns *zns, bool enabled) zi->info.is_cmd = false; zi->info.sock = zns->netlink_dplane_in.sock; - /* Start read task for the dplane pthread. */ - if (zdplane_info.dg_master) - thread_add_read(zdplane_info.dg_master, - dplane_incoming_read, zi, zi->info.sock, - &zi->t_read); + /* Initiate requests for existing info from the OS, and + * begin reading from the netlink socket. + */ + dplane_kernel_info_request(zi); #endif } else if (zi) { if (IS_ZEBRA_DEBUG_DPLANE) @@ -4933,9 +5046,14 @@ void zebra_dplane_ns_enable(struct zebra_ns *zns, bool enabled) /* Stop reading, free memory */ zns_info_list_del(&zdplane_info.dg_zns_list, zi); - if (zdplane_info.dg_master) + /* Stop any outstanding tasks */ + if (zdplane_info.dg_master) { + thread_cancel_async(zdplane_info.dg_master, + &zi->t_request, NULL); + thread_cancel_async(zdplane_info.dg_master, &zi->t_read, NULL); + } XFREE(MTYPE_DP_NS, zi); } @@ -5115,6 +5233,14 @@ static void kernel_dplane_log_detail(struct zebra_dplane_ctx *ctx) dplane_ctx_get_ifname(ctx), dplane_ctx_get_intf_addr(ctx)); break; + + case DPLANE_OP_INTF_NETCONFIG: + zlog_debug("%s: ifindex %d, mpls %d, mcast %d", + dplane_op2str(dplane_ctx_get_op(ctx)), + dplane_ctx_get_netconf_ifindex(ctx), + dplane_ctx_get_netconf_mpls(ctx), + dplane_ctx_get_netconf_mcast(ctx)); + break; } } @@ -5260,6 +5386,7 @@ static void kernel_dplane_handle_result(struct zebra_dplane_ctx *ctx) /* TODO -- error counters for incoming events? */ case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: break; case DPLANE_OP_NONE: @@ -5595,7 +5722,7 @@ done: * final zebra shutdown. * This runs in the dplane pthread context. */ -static int dplane_check_shutdown_status(struct thread *event) +static void dplane_check_shutdown_status(struct thread *event) { struct dplane_zns_info *zi; @@ -5606,8 +5733,10 @@ static int dplane_check_shutdown_status(struct thread *event) frr_each_safe (zns_info_list, &zdplane_info.dg_zns_list, zi) { zns_info_list_del(&zdplane_info.dg_zns_list, zi); - if (zdplane_info.dg_master) + if (zdplane_info.dg_master) { thread_cancel(&zi->t_read); + thread_cancel(&zi->t_request); + } XFREE(MTYPE_DP_NS, zi); } @@ -5627,8 +5756,6 @@ static int dplane_check_shutdown_status(struct thread *event) */ thread_add_event(zrouter.master, zebra_finalize, NULL, 0, NULL); } - - return 0; } /* @@ -5662,7 +5789,7 @@ void zebra_dplane_finish(void) * pthread can look for other pending work - such as i/o work on behalf of * providers. */ -static int dplane_thread_loop(struct thread *event) +static void dplane_thread_loop(struct thread *event) { struct dplane_ctx_q work_list; struct dplane_ctx_q error_list; @@ -5682,7 +5809,7 @@ static int dplane_thread_loop(struct thread *event) /* Check for zebra shutdown */ if (!zdplane_info.dg_run) - goto done; + return; /* Dequeue some incoming work from zebra (if any) onto the temporary * working list. @@ -5848,9 +5975,6 @@ static int dplane_thread_loop(struct thread *event) (zdplane_info.dg_results_cb)(&work_list); TAILQ_INIT(&work_list); - -done: - return 0; } /* @@ -5942,11 +6066,12 @@ void zebra_dplane_start(void) thread_add_event(zdplane_info.dg_master, dplane_thread_loop, NULL, 0, &zdplane_info.dg_t_update); - /* Enqueue reads if necessary */ + /* Enqueue requests and reads if necessary */ frr_each (zns_info_list, &zdplane_info.dg_zns_list, zi) { #if defined(HAVE_NETLINK) thread_add_read(zdplane_info.dg_master, dplane_incoming_read, zi, zi->info.sock, &zi->t_read); + dplane_kernel_info_request(zi); #endif } diff --git a/zebra/zebra_dplane.h b/zebra/zebra_dplane.h index a7a5f99e45..29555d5b56 100644 --- a/zebra/zebra_dplane.h +++ b/zebra/zebra_dplane.h @@ -185,6 +185,9 @@ enum dplane_op_e { /* Incoming interface address events */ DPLANE_OP_INTF_ADDR_ADD, DPLANE_OP_INTF_ADDR_DEL, + + /* Incoming interface config events */ + DPLANE_OP_INTF_NETCONFIG, }; /* @@ -222,6 +225,22 @@ enum dplane_op_e { #define DPLANE_BR_PORT_NON_DF (1 << 0) +/* Definitions for the dplane 'netconf' apis, corresponding to the netlink + * NETCONF api. + * Sadly, netlink sends incremental updates, so its messages may contain + * just a single changed attribute, and not necessarily + * a complete snapshot of the attributes. + */ +enum dplane_netconf_status_e { + DPLANE_NETCONF_STATUS_UNKNOWN = 0, + DPLANE_NETCONF_STATUS_ENABLED, + DPLANE_NETCONF_STATUS_DISABLED +}; + +/* Some special ifindex values that may be part of the dplane netconf api. */ +#define DPLANE_NETCONF_IFINDEX_ALL -1 +#define DPLANE_NETCONF_IFINDEX_DEFAULT -2 + /* Enable system route notifications */ void dplane_enable_sys_route_notifs(void); @@ -564,6 +583,21 @@ dplane_ctx_gre_get_mtu(const struct zebra_dplane_ctx *ctx); const struct zebra_l2info_gre * dplane_ctx_gre_get_info(const struct zebra_dplane_ctx *ctx); +/* Interface netconf info */ +ifindex_t dplane_ctx_get_netconf_ifindex(const struct zebra_dplane_ctx *ctx); +ns_id_t dplane_ctx_get_netconf_ns_id(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_netconf_ifindex(struct zebra_dplane_ctx *ctx, + ifindex_t ifindex); +void dplane_ctx_set_netconf_ns_id(struct zebra_dplane_ctx *ctx, ns_id_t ns_id); +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mpls(const struct zebra_dplane_ctx *ctx); +enum dplane_netconf_status_e +dplane_ctx_get_netconf_mcast(const struct zebra_dplane_ctx *ctx); +void dplane_ctx_set_netconf_mpls(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val); +void dplane_ctx_set_netconf_mcast(struct zebra_dplane_ctx *ctx, + enum dplane_netconf_status_e val); + /* Namespace fd info - esp. for netlink communication */ const struct zebra_dplane_info *dplane_ctx_get_ns( const struct zebra_dplane_ctx *ctx); diff --git a/zebra/zebra_evpn.c b/zebra/zebra_evpn.c index 13b9cc2002..21fb5299bc 100644 --- a/zebra/zebra_evpn.c +++ b/zebra/zebra_evpn.c @@ -344,10 +344,10 @@ int zebra_evpn_add_macip_for_intf(struct interface *ifp, for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { struct ipaddr ip; - memset(&ip, 0, sizeof(struct ipaddr)); if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) continue; + memset(&ip, 0, sizeof(struct ipaddr)); if (c->address->family == AF_INET) { ip.ipa_type = IPADDR_V4; memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), diff --git a/zebra/zebra_evpn_mac.c b/zebra/zebra_evpn_mac.c index d3791f3e58..e38766bc6b 100644 --- a/zebra/zebra_evpn_mac.c +++ b/zebra/zebra_evpn_mac.c @@ -383,7 +383,7 @@ static char *zebra_evpn_zebra_mac_flag_dump(struct zebra_mac *mac, char *buf, return buf; } -static int zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) +static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) { struct zebra_vrf *zvrf = NULL; struct zebra_mac *mac = NULL; @@ -396,15 +396,15 @@ static int zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) /* since this is asynchronous we need sanity checks*/ zvrf = vrf_info_lookup(mac->zevpn->vrf_id); if (!zvrf) - return 0; + return; zevpn = zebra_evpn_lookup(mac->zevpn->vni); if (!zevpn) - return 0; + return; mac = zebra_evpn_mac_lookup(zevpn, &mac->macaddr); if (!mac) - return 0; + return; if (IS_ZEBRA_DEBUG_VXLAN) { char mac_buf[MAC_BUF_SIZE]; @@ -445,7 +445,7 @@ static int zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) if (zebra_evpn_mac_send_add_to_client(zevpn->vni, &mac->macaddr, mac->flags, mac->loc_seq, mac->es)) - return -1; + return; /* Process all neighbors associated with this MAC. */ zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0, @@ -457,8 +457,6 @@ static int zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) /* Install the entry. */ zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */); } - - return 0; } static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, @@ -1470,7 +1468,7 @@ void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac *mac, * external neighmgr daemon to probe existing hosts to independently * establish their presence on the ES. */ -static int zebra_evpn_mac_hold_exp_cb(struct thread *t) +static void zebra_evpn_mac_hold_exp_cb(struct thread *t) { struct zebra_mac *mac; bool old_bgp_ready; @@ -1483,7 +1481,7 @@ static int zebra_evpn_mac_hold_exp_cb(struct thread *t) * flag */ if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) - return 0; + return; old_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); old_static = zebra_evpn_mac_is_static(mac); @@ -1514,8 +1512,6 @@ static int zebra_evpn_mac_hold_exp_cb(struct thread *t) if (old_bgp_ready != new_bgp_ready) zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, new_bgp_ready); - - return 0; } static inline void zebra_evpn_mac_start_hold_timer(struct zebra_mac *mac) diff --git a/zebra/zebra_evpn_mh.c b/zebra/zebra_evpn_mh.c index af4629e41c..50eecd31d5 100644 --- a/zebra/zebra_evpn_mh.c +++ b/zebra/zebra_evpn_mh.c @@ -2131,7 +2131,7 @@ static void zebra_evpn_mh_advertise_svi_mac(void) zebra_evpn_acc_vl_adv_svi_mac_all(); } -static int zebra_evpn_es_df_delay_exp_cb(struct thread *t) +static void zebra_evpn_es_df_delay_exp_cb(struct thread *t) { struct zebra_evpn_es *es; @@ -2141,8 +2141,6 @@ static int zebra_evpn_es_df_delay_exp_cb(struct thread *t) zlog_debug("es %s df-delay expired", es->esi_str); zebra_evpn_es_run_df_election(es, __func__); - - return 0; } /* currently there is no global config to turn on MH instead we use @@ -3860,15 +3858,13 @@ void zebra_evpn_mh_uplink_oper_update(struct zebra_if *zif) new_protodown); } -static int zebra_evpn_mh_startup_delay_exp_cb(struct thread *t) +static void zebra_evpn_mh_startup_delay_exp_cb(struct thread *t) { if (IS_ZEBRA_DEBUG_EVPN_MH_ES) zlog_debug("startup-delay expired"); zebra_evpn_mh_update_protodown(ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY, false /* set */); - - return 0; } static void zebra_evpn_mh_startup_delay_timer_start(const char *rc) diff --git a/zebra/zebra_evpn_neigh.c b/zebra/zebra_evpn_neigh.c index c3218d0f9a..f557e66384 100644 --- a/zebra/zebra_evpn_neigh.c +++ b/zebra/zebra_evpn_neigh.c @@ -411,7 +411,7 @@ void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh *n, bool old_n_static, * external neighmgr daemon to probe existing hosts to independently * establish their presence on the ES. */ -static int zebra_evpn_neigh_hold_exp_cb(struct thread *t) +static void zebra_evpn_neigh_hold_exp_cb(struct thread *t) { struct zebra_neigh *n; bool old_bgp_ready; @@ -424,7 +424,7 @@ static int zebra_evpn_neigh_hold_exp_cb(struct thread *t) * flag */ if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) - return 0; + return; old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); old_n_static = zebra_evpn_neigh_is_static(n); @@ -448,8 +448,6 @@ static int zebra_evpn_neigh_hold_exp_cb(struct thread *t) if (old_bgp_ready != new_bgp_ready) zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, new_bgp_ready); - - return 0; } static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh *n) @@ -1092,7 +1090,7 @@ static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf, return 0; } -static int zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) +static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) { struct zebra_vrf *zvrf = NULL; struct zebra_neigh *nbr = NULL; @@ -1103,15 +1101,15 @@ static int zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) /* since this is asynchronous we need sanity checks*/ zvrf = vrf_info_lookup(nbr->zevpn->vrf_id); if (!zvrf) - return 0; + return; zevpn = zebra_evpn_lookup(nbr->zevpn->vni); if (!zevpn) - return 0; + return; nbr = zebra_evpn_neigh_lookup(zevpn, &nbr->ip); if (!nbr) - return 0; + return; if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( @@ -1135,8 +1133,6 @@ static int zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) } else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); } - - return 0; } static void zebra_evpn_dup_addr_detect_for_neigh( diff --git a/zebra/zebra_fpm.c b/zebra/zebra_fpm.c index 43958fdfde..6766c752ad 100644 --- a/zebra/zebra_fpm.c +++ b/zebra/zebra_fpm.c @@ -284,8 +284,8 @@ static struct zfpm_glob *zfpm_g = &zfpm_glob_space; static int zfpm_trigger_update(struct route_node *rn, const char *reason); -static int zfpm_read_cb(struct thread *thread); -static int zfpm_write_cb(struct thread *thread); +static void zfpm_read_cb(struct thread *thread); +static void zfpm_write_cb(struct thread *thread); static void zfpm_set_state(enum zfpm_state state, const char *reason); static void zfpm_start_connect_timer(const char *reason); @@ -518,7 +518,7 @@ static inline void zfpm_connect_off(void) * Callback for actions to be taken when the connection to the FPM * comes up. */ -static int zfpm_conn_up_thread_cb(struct thread *thread) +static void zfpm_conn_up_thread_cb(struct thread *thread) { struct route_node *rnode; struct zfpm_rnodes_iter *iter; @@ -559,14 +559,13 @@ static int zfpm_conn_up_thread_cb(struct thread *thread) zfpm_rnodes_iter_pause(iter); thread_add_timer_msec(zfpm_g->master, zfpm_conn_up_thread_cb, NULL, 0, &zfpm_g->t_conn_up); - return 0; + return; } zfpm_g->stats.t_conn_up_finishes++; done: zfpm_rnodes_iter_cleanup(iter); - return 0; } /* @@ -635,7 +634,7 @@ static void zfpm_connect_check(void) * Callback that is invoked to clean up state after the TCP connection * to the FPM goes down. */ -static int zfpm_conn_down_thread_cb(struct thread *thread) +static void zfpm_conn_down_thread_cb(struct thread *thread) { struct route_node *rnode; struct zfpm_rnodes_iter *iter; @@ -686,7 +685,7 @@ static int zfpm_conn_down_thread_cb(struct thread *thread) zfpm_g->t_conn_down = NULL; thread_add_timer_msec(zfpm_g->master, zfpm_conn_down_thread_cb, NULL, 0, &zfpm_g->t_conn_down); - return 0; + return; } zfpm_g->stats.t_conn_down_finishes++; @@ -696,7 +695,6 @@ static int zfpm_conn_down_thread_cb(struct thread *thread) * Start the process of connecting to the FPM again. */ zfpm_start_connect_timer("cleanup complete"); - return 0; } /* @@ -740,7 +738,7 @@ static void zfpm_connection_down(const char *detail) /* * zfpm_read_cb */ -static int zfpm_read_cb(struct thread *thread) +static void zfpm_read_cb(struct thread *thread) { size_t already; struct stream *ibuf; @@ -754,7 +752,7 @@ static int zfpm_read_cb(struct thread *thread) */ if (zfpm_g->state == ZFPM_STATE_CONNECTING) { zfpm_connect_check(); - return 0; + return; } assert(zfpm_g->state == ZFPM_STATE_ESTABLISHED); @@ -778,7 +776,7 @@ static int zfpm_read_cb(struct thread *thread) zfpm_connection_down(buffer); } else zfpm_connection_down("closed socket in read"); - return 0; + return; } if (nbyte != (ssize_t)(FPM_MSG_HDR_LEN - already)) @@ -793,7 +791,7 @@ static int zfpm_read_cb(struct thread *thread) if (!fpm_msg_hdr_ok(hdr)) { zfpm_connection_down("invalid message header"); - return 0; + return; } msg_len = fpm_msg_len(hdr); @@ -816,7 +814,7 @@ static int zfpm_read_cb(struct thread *thread) zfpm_connection_down(buffer); } else zfpm_connection_down("failed to read message"); - return 0; + return; } if (nbyte != (ssize_t)(msg_len - already)) @@ -830,7 +828,6 @@ static int zfpm_read_cb(struct thread *thread) done: zfpm_read_on(); - return 0; } static bool zfpm_updates_pending(void) @@ -1171,7 +1168,7 @@ static void zfpm_build_updates(void) /* * zfpm_write_cb */ -static int zfpm_write_cb(struct thread *thread) +static void zfpm_write_cb(struct thread *thread) { struct stream *s; int num_writes; @@ -1183,7 +1180,7 @@ static int zfpm_write_cb(struct thread *thread) */ if (zfpm_g->state == ZFPM_STATE_CONNECTING) { zfpm_connect_check(); - return 0; + return; } assert(zfpm_g->state == ZFPM_STATE_ESTABLISHED); @@ -1217,7 +1214,7 @@ static int zfpm_write_cb(struct thread *thread) break; zfpm_connection_down("failed to write to socket"); - return 0; + return; } if (bytes_written != bytes_to_write) { @@ -1248,14 +1245,12 @@ static int zfpm_write_cb(struct thread *thread) if (zfpm_writes_pending()) zfpm_write_on(); - - return 0; } /* * zfpm_connect_cb */ -static int zfpm_connect_cb(struct thread *t) +static void zfpm_connect_cb(struct thread *t) { int sock, ret; struct sockaddr_in serv; @@ -1267,7 +1262,7 @@ static int zfpm_connect_cb(struct thread *t) zlog_err("Failed to create socket for connect(): %s", strerror(errno)); zfpm_g->stats.connect_no_sock++; - return 0; + return; } set_nonblocking(sock); @@ -1295,7 +1290,7 @@ static int zfpm_connect_cb(struct thread *t) if (ret >= 0) { zfpm_g->sock = sock; zfpm_connection_up("connect succeeded"); - return 1; + return; } if (errno == EINPROGRESS) { @@ -1304,7 +1299,7 @@ static int zfpm_connect_cb(struct thread *t) zfpm_write_on(); zfpm_set_state(ZFPM_STATE_CONNECTING, "async connect in progress"); - return 0; + return; } zlog_info("can't connect to FPM %d: %s", sock, safe_strerror(errno)); @@ -1314,7 +1309,6 @@ static int zfpm_connect_cb(struct thread *t) * Restart timer for retrying connection. */ zfpm_start_connect_timer("connect() failed"); - return 0; } /* @@ -1663,7 +1657,7 @@ static void zfpm_iterate_rmac_table(struct hash_bucket *bucket, void *args) /* * struct zfpm_statsimer_cb */ -static int zfpm_stats_timer_cb(struct thread *t) +static void zfpm_stats_timer_cb(struct thread *t) { zfpm_g->t_stats = NULL; @@ -1685,8 +1679,6 @@ static int zfpm_stats_timer_cb(struct thread *t) zfpm_stats_reset(&zfpm_g->stats); zfpm_start_stats_timer(); - - return 0; } /* diff --git a/zebra/zebra_gr.c b/zebra/zebra_gr.c index b153ac1d81..56d0df569c 100644 --- a/zebra/zebra_gr.c +++ b/zebra/zebra_gr.c @@ -51,7 +51,7 @@ * Forward declaration. */ static struct zserv *zebra_gr_find_stale_client(struct zserv *client); -static int32_t zebra_gr_route_stale_delete_timer_expiry(struct thread *thread); +static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread); static int32_t zebra_gr_delete_stale_routes(struct client_gr_info *info); static void zebra_gr_process_client_stale_routes(struct zserv *client, vrf_id_t vrf_id); @@ -444,7 +444,7 @@ void zread_client_capabilities(ZAPI_HANDLER_ARGS) * Delete all the stale routes that have not been refreshed * post restart. */ -static int32_t zebra_gr_route_stale_delete_timer_expiry(struct thread *thread) +static void zebra_gr_route_stale_delete_timer_expiry(struct thread *thread) { struct client_gr_info *info; int32_t cnt = 0; @@ -478,7 +478,6 @@ static int32_t zebra_gr_route_stale_delete_timer_expiry(struct thread *thread) info->current_afi = 0; zebra_gr_delete_stale_client(info); } - return 0; } diff --git a/zebra/zebra_mlag.c b/zebra/zebra_mlag.c index 40a2c94e2a..2042f94038 100644 --- a/zebra/zebra_mlag.c +++ b/zebra/zebra_mlag.c @@ -52,8 +52,8 @@ uint8_t mlag_rd_buffer[ZEBRA_MLAG_BUF_LIMIT]; static bool test_mlag_in_progress; static int zebra_mlag_signal_write_thread(void); -static int zebra_mlag_terminate_pthread(struct thread *event); -static int zebra_mlag_post_data_from_main_thread(struct thread *thread); +static void zebra_mlag_terminate_pthread(struct thread *event); +static void zebra_mlag_post_data_from_main_thread(struct thread *thread); static void zebra_mlag_publish_process_state(struct zserv *client, zebra_message_types_t msg_type); @@ -148,7 +148,7 @@ void zebra_mlag_process_mlag_data(uint8_t *data, uint32_t len) * This thread reads the clients data from the Global queue and encodes with * protobuf and pass on to the MLAG socket. */ -static int zebra_mlag_client_msg_handler(struct thread *event) +static void zebra_mlag_client_msg_handler(struct thread *event) { struct stream *s; uint32_t wr_count = 0; @@ -209,7 +209,6 @@ static int zebra_mlag_client_msg_handler(struct thread *event) */ if (wr_count >= ZEBRA_MLAG_POST_LIMIT) zebra_mlag_signal_write_thread(); - return 0; } /* @@ -309,7 +308,7 @@ static void zebra_mlag_publish_process_state(struct zserv *client, * main thread, because for that access was needed for clients list. * so instead of forcing the locks, messages will be posted from main thread. */ -static int zebra_mlag_post_data_from_main_thread(struct thread *thread) +static void zebra_mlag_post_data_from_main_thread(struct thread *thread) { struct stream *s = THREAD_ARG(thread); struct stream *zebra_s = NULL; @@ -319,7 +318,7 @@ static int zebra_mlag_post_data_from_main_thread(struct thread *thread) uint32_t msg_len = 0; if (!s) - return -1; + return; STREAM_GETL(s, msg_type); if (IS_ZEBRA_DEBUG_MLAG) @@ -356,12 +355,11 @@ static int zebra_mlag_post_data_from_main_thread(struct thread *thread) } stream_free(s); - return 0; + return; stream_failure: stream_free(s); if (zebra_s) stream_free(zebra_s); - return 0; } /* @@ -394,7 +392,7 @@ static void zebra_mlag_spawn_pthread(void) * all clients are un-registered for MLAG Updates, terminate the * MLAG write thread */ -static int zebra_mlag_terminate_pthread(struct thread *event) +static void zebra_mlag_terminate_pthread(struct thread *event) { if (IS_ZEBRA_DEBUG_MLAG) zlog_debug("Zebra MLAG write thread terminate called"); @@ -403,7 +401,7 @@ static int zebra_mlag_terminate_pthread(struct thread *event) if (IS_ZEBRA_DEBUG_MLAG) zlog_debug( "Zebra MLAG: still some clients are interested"); - return 0; + return; } frr_pthread_stop(zrouter.mlag_info.zebra_pth_mlag, NULL); @@ -419,7 +417,6 @@ static int zebra_mlag_terminate_pthread(struct thread *event) * Send Notification to clean private data */ hook_call(zebra_mlag_private_cleanup_data); - return 0; } /* diff --git a/zebra/zebra_mlag_private.c b/zebra/zebra_mlag_private.c index b1bba831d2..50a290b9e8 100644 --- a/zebra/zebra_mlag_private.c +++ b/zebra/zebra_mlag_private.c @@ -48,8 +48,8 @@ static struct thread_master *zmlag_master; static int mlag_socket; -static int zebra_mlag_connect(struct thread *thread); -static int zebra_mlag_read(struct thread *thread); +static void zebra_mlag_connect(struct thread *thread); +static void zebra_mlag_read(struct thread *thread); /* * Write the data to MLAGD @@ -72,7 +72,7 @@ static void zebra_mlag_sched_read(void) &zrouter.mlag_info.t_read); } -static int zebra_mlag_read(struct thread *thread) +static void zebra_mlag_read(struct thread *thread) { static uint32_t mlag_rd_buf_offset; uint32_t *msglen; @@ -98,13 +98,13 @@ static int zebra_mlag_read(struct thread *thread) mlag_socket); close(mlag_socket); zebra_mlag_handle_process_state(MLAG_DOWN); - return -1; + return; } mlag_rd_buf_offset += data_len; if (data_len != (ssize_t)(ZEBRA_MLAG_LEN_SIZE - curr_len)) { /* Try again later */ zebra_mlag_sched_read(); - return 0; + return; } curr_len = ZEBRA_MLAG_LEN_SIZE; } @@ -136,13 +136,13 @@ static int zebra_mlag_read(struct thread *thread) mlag_socket); close(mlag_socket); zebra_mlag_handle_process_state(MLAG_DOWN); - return -1; + return; } mlag_rd_buf_offset += data_len; if (data_len != (ssize_t)(tot_len - curr_len)) { /* Try again later */ zebra_mlag_sched_read(); - return 0; + return; } } @@ -162,10 +162,9 @@ static int zebra_mlag_read(struct thread *thread) zebra_mlag_reset_read_buffer(); mlag_rd_buf_offset = 0; zebra_mlag_sched_read(); - return 0; } -static int zebra_mlag_connect(struct thread *thread) +static void zebra_mlag_connect(struct thread *thread) { struct sockaddr_un svr = {0}; @@ -178,7 +177,7 @@ static int zebra_mlag_connect(struct thread *thread) mlag_socket = socket(svr.sun_family, SOCK_STREAM, 0); if (mlag_socket < 0) - return -1; + return; if (connect(mlag_socket, (struct sockaddr *)&svr, sizeof(svr)) == -1) { if (IS_ZEBRA_DEBUG_MLAG) @@ -189,7 +188,7 @@ static int zebra_mlag_connect(struct thread *thread) zrouter.mlag_info.timer_running = true; thread_add_timer(zmlag_master, zebra_mlag_connect, NULL, 10, &zrouter.mlag_info.t_read); - return 0; + return; } set_nonblocking(mlag_socket); @@ -204,7 +203,6 @@ static int zebra_mlag_connect(struct thread *thread) * Connection is established with MLAGD, post to clients */ zebra_mlag_handle_process_state(MLAG_UP); - return 0; } /* diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 8cc7724f05..7cb1906895 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -61,11 +61,11 @@ struct zebra_netns_info { unsigned int retries; }; -static int zebra_ns_ready_read(struct thread *t); +static void zebra_ns_ready_read(struct thread *t); static void zebra_ns_notify_create_context_from_entry_name(const char *name); static int zebra_ns_continue_read(struct zebra_netns_info *zns_info, int stop_retry); -static int zebra_ns_notify_read(struct thread *t); +static void zebra_ns_notify_read(struct thread *t); static struct vrf *vrf_handler_create(struct vty *vty, const char *vrfname) { @@ -231,17 +231,17 @@ static bool zebra_ns_notify_is_default_netns(const char *name) return false; } -static int zebra_ns_ready_read(struct thread *t) +static void zebra_ns_ready_read(struct thread *t) { struct zebra_netns_info *zns_info = THREAD_ARG(t); const char *netnspath; int err, stop_retry = 0; if (!zns_info) - return 0; + return; if (!zns_info->netnspath) { XFREE(MTYPE_NETNS_MISC, zns_info); - return 0; + return; } netnspath = zns_info->netnspath; if (--zns_info->retries == 0) @@ -249,34 +249,40 @@ static int zebra_ns_ready_read(struct thread *t) frr_with_privs(&zserv_privs) { err = ns_switch_to_netns(netnspath); } - if (err < 0) - return zebra_ns_continue_read(zns_info, stop_retry); + if (err < 0) { + zebra_ns_continue_read(zns_info, stop_retry); + return; + } /* go back to default ns */ frr_with_privs(&zserv_privs) { err = ns_switchback_to_initial(); } - if (err < 0) - return zebra_ns_continue_read(zns_info, stop_retry); + if (err < 0) { + zebra_ns_continue_read(zns_info, stop_retry); + return; + } /* check default name is not already set */ if (strmatch(VRF_DEFAULT_NAME, basename(netnspath))) { zlog_warn("NS notify : NS %s is already default VRF.Cancel VRF Creation", basename(netnspath)); - return zebra_ns_continue_read(zns_info, 1); + zebra_ns_continue_read(zns_info, 1); + return; } if (zebra_ns_notify_is_default_netns(basename(netnspath))) { zlog_warn( "NS notify : NS %s is default VRF. Ignore VRF creation", basename(netnspath)); - return zebra_ns_continue_read(zns_info, 1); + zebra_ns_continue_read(zns_info, 1); + return; } /* success : close fd and create zns context */ zebra_ns_notify_create_context_from_entry_name(basename(netnspath)); - return zebra_ns_continue_read(zns_info, 1); + zebra_ns_continue_read(zns_info, 1); } -static int zebra_ns_notify_read(struct thread *t) +static void zebra_ns_notify_read(struct thread *t) { int fd_monitor = THREAD_FD(t); struct inotify_event *event; @@ -290,7 +296,7 @@ static int zebra_ns_notify_read(struct thread *t) flog_err_sys(EC_ZEBRA_NS_NOTIFY_READ, "NS notify read: failed to read (%s)", safe_strerror(errno)); - return 0; + return; } for (event = (struct inotify_event *)buf; (char *)event < &buf[len]; event = (struct inotify_event *)((char *)event + sizeof(*event) @@ -329,7 +335,6 @@ static int zebra_ns_notify_read(struct thread *t) thread_add_timer_msec(zrouter.master, zebra_ns_ready_read, (void *)netnsinfo, 0, NULL); } - return 0; } void zebra_ns_notify_parse(void) diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index c1b104aec7..e1d28e1534 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -2475,7 +2475,7 @@ skip_check: memset(&nexthop->rmap_src.ipv6, 0, sizeof(union g_addr)); - zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id); + zvrf = zebra_vrf_lookup_by_id(re->vrf_id); if (!zvrf) { if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug(" %s: zvrf is NULL", __func__); @@ -2989,6 +2989,7 @@ void zebra_nhg_dplane_result(struct zebra_dplane_ctx *ctx) case DPLANE_OP_GRE_SET: case DPLANE_OP_INTF_ADDR_ADD: case DPLANE_OP_INTF_ADDR_DEL: + case DPLANE_OP_INTF_NETCONFIG: break; } diff --git a/zebra/zebra_opaque.c b/zebra/zebra_opaque.c index 244f16302b..0a98194acb 100644 --- a/zebra/zebra_opaque.c +++ b/zebra/zebra_opaque.c @@ -106,7 +106,7 @@ static const char LOG_NAME[] = "Zebra Opaque"; /* Prototypes */ /* Main event loop, processing incoming message queue */ -static int process_messages(struct thread *event); +static void process_messages(struct thread *event); static int handle_opq_registration(const struct zmsghdr *hdr, struct stream *msg); static int handle_opq_unregistration(const struct zmsghdr *hdr, @@ -270,7 +270,7 @@ uint32_t zebra_opaque_enqueue_batch(struct stream_fifo *batch) /* * Pthread event loop, process the incoming message queue. */ -static int process_messages(struct thread *event) +static void process_messages(struct thread *event) { struct stream_fifo fifo; struct stream *msg; @@ -335,8 +335,6 @@ done: /* This will also free any leftover messages, in the shutdown case */ stream_fifo_deinit(&fifo); - - return 0; } /* diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 32edb78c7d..68e5c391cf 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -100,7 +100,7 @@ static ptm_lib_handle_t *ptm_hdl; struct zebra_ptm_cb ptm_cb; static int zebra_ptm_socket_init(void); -int zebra_ptm_sock_read(struct thread *); +void zebra_ptm_sock_read(struct thread *thread); static void zebra_ptm_install_commands(void); static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt); void zebra_bfd_peer_replay_req(void); @@ -168,12 +168,12 @@ void zebra_ptm_finish(void) close(ptm_cb.ptm_sock); } -static int zebra_ptm_flush_messages(struct thread *thread) +static void zebra_ptm_flush_messages(struct thread *thread) { ptm_cb.t_write = NULL; if (ptm_cb.ptm_sock == -1) - return -1; + return; errno = 0; @@ -187,7 +187,7 @@ static int zebra_ptm_flush_messages(struct thread *thread) ptm_cb.t_timer = NULL; thread_add_timer(zrouter.master, zebra_ptm_connect, NULL, ptm_cb.reconnect_time, &ptm_cb.t_timer); - return -1; + return; case BUFFER_PENDING: ptm_cb.t_write = NULL; thread_add_write(zrouter.master, zebra_ptm_flush_messages, NULL, @@ -196,8 +196,6 @@ static int zebra_ptm_flush_messages(struct thread *thread) case BUFFER_EMPTY: break; } - - return 0; } static int zebra_ptm_send_message(char *data, int size) @@ -226,7 +224,7 @@ static int zebra_ptm_send_message(char *data, int size) return 0; } -int zebra_ptm_connect(struct thread *t) +void zebra_ptm_connect(struct thread *t) { int init = 0; @@ -255,8 +253,6 @@ int zebra_ptm_connect(struct thread *t) } else if (ptm_cb.reconnect_time >= ZEBRA_PTM_RECONNECT_TIME_MAX) { ptm_cb.reconnect_time = ZEBRA_PTM_RECONNECT_TIME_INITIAL; } - - return (errno); } DEFUN (zebra_ptm_enable, @@ -649,7 +645,7 @@ static int zebra_ptm_handle_msg_cb(void *arg, void *in_ctxt) } } -int zebra_ptm_sock_read(struct thread *thread) +void zebra_ptm_sock_read(struct thread *thread) { int sock; int rc; @@ -658,7 +654,7 @@ int zebra_ptm_sock_read(struct thread *thread) sock = THREAD_FD(thread); if (sock == -1) - return -1; + return; /* PTM communicates in CSV format */ do { @@ -679,14 +675,12 @@ int zebra_ptm_sock_read(struct thread *thread) thread_add_timer(zrouter.master, zebra_ptm_connect, NULL, ptm_cb.reconnect_time, &ptm_cb.t_timer); - return -1; + return; } ptm_cb.t_read = NULL; thread_add_read(zrouter.master, zebra_ptm_sock_read, NULL, ptm_cb.ptm_sock, &ptm_cb.t_read); - - return 0; } /* BFD peer/dst register/update */ diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h index 88c9bccb44..f8e843cc73 100644 --- a/zebra/zebra_ptm.h +++ b/zebra/zebra_ptm.h @@ -74,7 +74,7 @@ struct zebra_ptm_cb { void zebra_ptm_init(void); void zebra_ptm_finish(void); -int zebra_ptm_connect(struct thread *t); +void zebra_ptm_connect(struct thread *t); void zebra_ptm_write(struct vty *vty); int zebra_ptm_get_enable_state(void); diff --git a/zebra/zebra_pw.c b/zebra/zebra_pw.c index 57276974c3..7d1153f21f 100644 --- a/zebra/zebra_pw.c +++ b/zebra/zebra_pw.c @@ -47,7 +47,7 @@ DEFINE_HOOK(pw_uninstall, (struct zebra_pw * pw), (pw)); static int zebra_pw_enabled(struct zebra_pw *); static void zebra_pw_install(struct zebra_pw *); static void zebra_pw_uninstall(struct zebra_pw *); -static int zebra_pw_install_retry(struct thread *); +static void zebra_pw_install_retry(struct thread *thread); static int zebra_pw_check_reachability(const struct zebra_pw *); static void zebra_pw_update_status(struct zebra_pw *, int); @@ -226,14 +226,12 @@ void zebra_pw_install_failure(struct zebra_pw *pw, int pwstatus) zebra_pw_update_status(pw, pwstatus); } -static int zebra_pw_install_retry(struct thread *thread) +static void zebra_pw_install_retry(struct thread *thread) { struct zebra_pw *pw = THREAD_ARG(thread); pw->install_retry_timer = NULL; zebra_pw_install(pw); - - return 0; } static void zebra_pw_update_status(struct zebra_pw *pw, int status) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index eb9b80fcef..e376d4b2af 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -116,6 +116,7 @@ static const struct { [ZEBRA_ROUTE_OPENFABRIC] = {ZEBRA_ROUTE_OPENFABRIC, 115, 5}, [ZEBRA_ROUTE_VRRP] = {ZEBRA_ROUTE_VRRP, 255, 7}, [ZEBRA_ROUTE_SRTE] = {ZEBRA_ROUTE_SRTE, 255, 7}, + [ZEBRA_ROUTE_ALL] = {ZEBRA_ROUTE_ALL, 255, 7}, /* Any new route type added to zebra, should be mirrored here */ /* no entry/default: 150 */ @@ -3948,7 +3949,7 @@ static void rib_update_ctx_fini(struct rib_update_ctx **ctx) XFREE(MTYPE_RIB_UPDATE_CTX, *ctx); } -static int rib_update_handler(struct thread *thread) +static void rib_update_handler(struct thread *thread) { struct rib_update_ctx *ctx; @@ -3960,8 +3961,6 @@ static int rib_update_handler(struct thread *thread) rib_update_handle_vrf(ctx->vrf_id, ctx->event, ZEBRA_ROUTE_ALL); rib_update_ctx_fini(&ctx); - - return 0; } /* @@ -4055,7 +4054,7 @@ void rib_sweep_table(struct route_table *table) } /* Sweep all RIB tables. */ -int rib_sweep_route(struct thread *t) +void rib_sweep_route(struct thread *t) { struct vrf *vrf; struct zebra_vrf *zvrf; @@ -4070,8 +4069,6 @@ int rib_sweep_route(struct thread *t) zebra_router_sweep_route(); zebra_router_sweep_nhgs(); - - return 0; } /* Remove specific by protocol routes from 'table'. */ @@ -4181,7 +4178,7 @@ done: * Handle results from the dataplane system. Dequeue update context * structs, dispatch to appropriate internal handlers. */ -static int rib_process_dplane_results(struct thread *thread) +static void rib_process_dplane_results(struct thread *thread) { struct zebra_dplane_ctx *ctx; struct dplane_ctx_q ctxlist; @@ -4324,6 +4321,10 @@ static int rib_process_dplane_results(struct thread *thread) zebra_if_addr_update_ctx(ctx); break; + case DPLANE_OP_INTF_NETCONFIG: + zebra_if_netconf_update_ctx(ctx); + break; + /* Some op codes not handled here */ case DPLANE_OP_ADDR_INSTALL: case DPLANE_OP_ADDR_UNINSTALL: @@ -4349,8 +4350,6 @@ static int rib_process_dplane_results(struct thread *thread) } } while (1); - - return 0; } /* @@ -4388,9 +4387,8 @@ static void check_route_info(void) * ZEBRA_ROUTE_ALL is also ignored. */ for (int i = 0; i < len; i++) { - if (i == ZEBRA_ROUTE_SYSTEM || i == ZEBRA_ROUTE_ALL) - continue; - assert(route_info[i].key); + assert(route_info[i].key >= ZEBRA_ROUTE_SYSTEM && + route_info[i].key < ZEBRA_ROUTE_MAX); assert(route_info[i].meta_q_map < MQ_SIZE); } } diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index f5faaab71b..8ca25359be 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -637,15 +637,11 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi, if (re) { *prn = rn; return re; - } - - if (!CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED)) + } else { + /* Resolve the nexthop recursively by finding matching + * route with lower prefix length + */ rn = rn->parent; - else { - if (IS_ZEBRA_DEBUG_NHT_DETAILED) - zlog_debug( - " Nexthop must be connected, cannot recurse up"); - return NULL; } } diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 908c13f3df..e99cb76119 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1638,7 +1638,7 @@ static void zebra_route_map_process_update_cb(char *rmap_name) zebra_nht_rm_update(rmap_name); } -static int zebra_route_map_update_timer(struct thread *thread) +static void zebra_route_map_update_timer(struct thread *thread) { if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("Event driven route-map update triggered"); @@ -1655,7 +1655,6 @@ static int zebra_route_map_update_timer(struct thread *thread) * 1) VRF Aware <sigh> * 2) Route-map aware */ - return 0; } static void zebra_route_map_set_delay_timer(uint32_t value) diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h index dafe925c26..63a61d5293 100644 --- a/zebra/zebra_router.h +++ b/zebra/zebra_router.h @@ -216,6 +216,7 @@ struct zebra_router { #define GRACEFUL_RESTART_TIME 60 extern struct zebra_router zrouter; +extern uint32_t rcvbufsize; extern void zebra_router_init(bool asic_offload, bool notify_on_ack); extern void zebra_router_cleanup(void); diff --git a/zebra/zebra_script.c b/zebra/zebra_script.c index 0e19376abe..4087749fd7 100644 --- a/zebra/zebra_script.c +++ b/zebra/zebra_script.c @@ -412,6 +412,8 @@ void lua_pushzebra_dplane_ctx(lua_State *L, const struct zebra_dplane_ctx *ctx) lua_setfield(L, -2, "mtu"); } lua_setfield(L, -2, "gre"); + + case DPLANE_OP_INTF_NETCONFIG: /*NYI*/ case DPLANE_OP_NONE: break; } /* Dispatch by op code */ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 1d9ed4ddd9..bb16232118 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -3425,7 +3425,7 @@ DEFUN (show_evpn_mac_vni_mac, vni = strtoul(argv[4]->arg, NULL, 10); if (!prefix_str2mac(argv[6]->arg, &mac)) { - vty_out(vty, "%% Malformed MAC address"); + vty_out(vty, "%% Malformed MAC address\n"); return CMD_WARNING; } zvrf = zebra_vrf_get_evpn(); diff --git a/zebra/zserv.c b/zebra/zserv.c index f3f69661c4..630c76c989 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -216,7 +216,7 @@ static void zserv_client_fail(struct zserv *client) * allows us to expose information about input and output queues to the user in * terms of number of packets rather than size of data. */ -static int zserv_write(struct thread *thread) +static void zserv_write(struct thread *thread) { struct zserv *client = THREAD_ARG(thread); struct stream *msg; @@ -232,7 +232,7 @@ static int zserv_write(struct thread *thread) (uint32_t)monotime(NULL), memory_order_relaxed); zserv_client_event(client, ZSERV_CLIENT_WRITE); - return 0; + return; case BUFFER_EMPTY: break; } @@ -268,7 +268,7 @@ static int zserv_write(struct thread *thread) (uint32_t)monotime(NULL), memory_order_relaxed); zserv_client_event(client, ZSERV_CLIENT_WRITE); - return 0; + return; case BUFFER_EMPTY: break; } @@ -279,14 +279,13 @@ static int zserv_write(struct thread *thread) atomic_store_explicit(&client->last_write_time, (uint32_t)monotime(NULL), memory_order_relaxed); - return 0; + return; zwrite_fail: flog_warn(EC_ZEBRA_CLIENT_WRITE_FAILED, "%s: could not write to %s [fd = %d], closing.", __func__, zebra_route_string(client->proto), client->sock); zserv_client_fail(client); - return 0; } /* @@ -311,7 +310,7 @@ zwrite_fail: * * Any failure in any of these actions is handled by terminating the client. */ -static int zserv_read(struct thread *thread) +static void zserv_read(struct thread *thread) { struct zserv *client = THREAD_ARG(thread); int sock; @@ -453,12 +452,11 @@ static int zserv_read(struct thread *thread) stream_fifo_free(cache); - return 0; + return; zread_fail: stream_fifo_free(cache); zserv_client_fail(client); - return -1; } static void zserv_client_event(struct zserv *client, @@ -495,7 +493,7 @@ static void zserv_client_event(struct zserv *client, * rely on the read thread to handle queuing this task enough times to process * everything on the input queue. */ -static int zserv_process_messages(struct thread *thread) +static void zserv_process_messages(struct thread *thread) { struct zserv *client = THREAD_ARG(thread); struct stream *msg; @@ -529,8 +527,6 @@ static int zserv_process_messages(struct thread *thread) /* Reschedule ourselves if necessary */ if (need_resched) zserv_event(client, ZSERV_PROCESS_MESSAGES); - - return 0; } int zserv_send_message(struct zserv *client, struct stream *msg) @@ -714,12 +710,11 @@ void zserv_close_client(struct zserv *client) * already have been closed and the thread will most likely have died, but its * resources still need to be cleaned up. */ -static int zserv_handle_client_fail(struct thread *thread) +static void zserv_handle_client_fail(struct thread *thread) { struct zserv *client = THREAD_ARG(thread); zserv_close_client(client); - return 0; } /* @@ -853,7 +848,7 @@ void zserv_release_client(struct zserv *client) /* * Accept socket connection. */ -static int zserv_accept(struct thread *thread) +static void zserv_accept(struct thread *thread) { int accept_sock; int client_sock; @@ -871,7 +866,7 @@ static int zserv_accept(struct thread *thread) if (client_sock < 0) { flog_err_sys(EC_LIB_SOCKET, "Can't accept zebra socket: %s", safe_strerror(errno)); - return -1; + return; } /* Make client socket non-blocking. */ @@ -879,8 +874,6 @@ static int zserv_accept(struct thread *thread) /* Create new zebra client. */ zserv_client_create(client_sock); - - return 0; } void zserv_close(void) diff --git a/zebra/zserv.h b/zebra/zserv.h index 203670ac1d..7a5be001be 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -379,7 +379,7 @@ void zserv_log_message(const char *errmsg, struct stream *msg, struct zmsghdr *hdr); /* TODO */ -__attribute__((__noreturn__)) int zebra_finalize(struct thread *event); +__attribute__((__noreturn__)) void zebra_finalize(struct thread *event); /* * Graceful restart functions. |
