diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/frr_pthread.c | 30 | ||||
| -rw-r--r-- | lib/frr_pthread.h | 9 | ||||
| -rw-r--r-- | lib/lib_errors.c | 8 | ||||
| -rw-r--r-- | lib/northbound.c | 11 | ||||
| -rw-r--r-- | lib/northbound_cli.c | 2 | ||||
| -rw-r--r-- | lib/prefix.c | 20 | ||||
| -rw-r--r-- | lib/prefix.h | 32 | ||||
| -rw-r--r-- | lib/table.c | 2 | ||||
| -rw-r--r-- | lib/thread.c | 7 | ||||
| -rw-r--r-- | lib/zclient.c | 68 | ||||
| -rw-r--r-- | lib/zclient.h | 7 |
11 files changed, 107 insertions, 89 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index a0223730b8..d5a2007c4d 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -84,6 +84,8 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); if (os_name) snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); + else + snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", name); /* initialize startup synchronization primitives */ fpt->running_cond_mtx = XCALLOC( MTYPE_PTHREAD_PRIM, sizeof(pthread_mutex_t)); @@ -115,36 +117,19 @@ void frr_pthread_destroy(struct frr_pthread *fpt) XFREE(MTYPE_FRR_PTHREAD, fpt); } -int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, - const char *os_name) +int frr_pthread_set_name(struct frr_pthread *fpt) { int ret = 0; - if (name) { - pthread_mutex_lock(&fpt->mtx); - { - if (fpt->name) - XFREE(MTYPE_FRR_PTHREAD, fpt->name); - fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); - } - pthread_mutex_unlock(&fpt->mtx); - thread_master_set_name(fpt->master, name); - } - - if (os_name) { - pthread_mutex_lock(&fpt->mtx); - snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); - pthread_mutex_unlock(&fpt->mtx); #ifdef HAVE_PTHREAD_SETNAME_NP # ifdef GNU_LINUX - ret = pthread_setname_np(fpt->thread, fpt->os_name); + ret = pthread_setname_np(fpt->thread, fpt->os_name); # else /* NetBSD */ - ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL); + ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL); # endif #elif defined(HAVE_PTHREAD_SET_NAME_NP) - pthread_set_name_np(fpt->thread, fpt->os_name); + pthread_set_name_np(fpt->thread, fpt->os_name); #endif - } return ret; } @@ -273,8 +258,7 @@ static void *fpt_run(void *arg) fpt->master->handle_signals = false; - if (fpt->os_name[0]) - frr_pthread_set_name(fpt, NULL, fpt->os_name); + frr_pthread_set_name(fpt); frr_pthread_notify_running(fpt); diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h index b9e60511d5..e6b3f031b3 100644 --- a/lib/frr_pthread.h +++ b/lib/frr_pthread.h @@ -133,16 +133,13 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, const char *name, const char *os_name); /* - * Changes the name of the frr_pthread. + * Changes the name of the frr_pthread as reported by the operating + * system. * * @param fpt - the frr_pthread to operate on - * @param name - Human-readable name - * @param os_name - 16 characters thread name , including the null - * terminator ('\0') to set in os. * @return - on success returns 0 otherwise nonzero error number. */ -int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, - const char *os_name); +int frr_pthread_set_name(struct frr_pthread *fpt); /* * Destroys an frr_pthread. diff --git a/lib/lib_errors.c b/lib/lib_errors.c index 7e428f135c..5f6c25b770 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -102,7 +102,7 @@ static struct log_ref ferr_lib_warn[] = { .code = EC_LIB_NB_CB_UNNEEDED, .title = "Unneeded northbound callback", .description = "The northbound subsystem, during initialization, has detected a callback that doesn't need to be implemented", - .suggestion = "Check if the installed FRR YANG modules are in sync with the FRR binaries", + .suggestion = "This is a bug; please report it" }, { .code = EC_LIB_NB_CB_CONFIG_VALIDATE, @@ -270,19 +270,19 @@ static struct log_ref ferr_lib_err[] = { .code = EC_LIB_NB_CB_MISSING, .title = "Missing northbound callback", .description = "The northbound subsystem, during initialization, has detected a missing callback for one node of the loaded YANG modules", - .suggestion = "Check if the installed FRR YANG modules are in sync with the FRR binaries", + .suggestion = "This is a bug; please report it" }, { .code = EC_LIB_NB_CB_INVALID_PRIO, .title = "Norhtbound callback has an invalid priority", .description = "The northbound subsystem, during initialization, has detected a callback whose priority is invalid", - .suggestion = "Check if the installed FRR YANG modules are in sync with the FRR binaries", + .suggestion = "This is a bug; please report it" }, { .code = EC_LIB_NB_CBS_VALIDATION, .title = "Failure to validate the northbound callbacks", .description = "The northbound subsystem, during initialization, has detected one or more errors while loading the northbound callbacks", - .suggestion = "Check if the installed FRR YANG modules are in sync with the FRR binaries", + .suggestion = "This is a bug; please report it" }, { .code = EC_LIB_LIBYANG, diff --git a/lib/northbound.c b/lib/northbound.c index a7f9c8620e..6fe612d72a 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -719,7 +719,6 @@ static int nb_configuration_callback(const enum nb_event event, const struct lyd_node *dnode = change->cb.dnode; union nb_resource *resource; int ret = NB_ERR; - enum lib_log_refs ref; if (debug_northbound) { const char *value = "(none)"; @@ -753,6 +752,8 @@ static int nb_configuration_callback(const enum nb_event event, } if (ret != NB_OK) { + enum lib_log_refs ref = 0; + switch (event) { case NB_EV_VALIDATE: ref = EC_LIB_NB_CB_CONFIG_VALIDATE; @@ -1277,8 +1278,12 @@ int nb_oper_data_iterate(const char *xpath, struct yang_translator *translator, n++; } list_keys.num = n; - assert(list_keys.num - == ((struct lys_node_list *)dn->schema)->keys_size); + if (list_keys.num + != ((struct lys_node_list *)dn->schema)->keys_size) { + list_delete(&list_dnodes); + yang_dnode_free(dnode); + return NB_ERR_NOT_FOUND; + } /* Find the list entry pointer. */ nn = dn->schema->priv; diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index 2b024ace93..33035de31b 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -261,7 +261,7 @@ static int nb_cli_confirmed_commit_timeout(struct thread *thread) static int nb_cli_commit(struct vty *vty, bool force, unsigned int confirmed_timeout, char *comment) { - uint32_t transaction_id; + uint32_t transaction_id = 0; int ret; /* Check if there's a pending confirmed commit. */ diff --git a/lib/prefix.c b/lib/prefix.c index 858f860ee8..0203301562 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -451,7 +451,7 @@ int is_zero_mac(struct ethaddr *mac) return 1; } -unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen) +unsigned int prefix_bit(const uint8_t *prefix, const uint16_t prefixlen) { unsigned int offset = prefixlen / 8; unsigned int shift = 7 - (prefixlen % 8); @@ -459,7 +459,7 @@ unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen) return (prefix[offset] >> shift) & 1; } -unsigned int prefix6_bit(const struct in6_addr *prefix, const uint8_t prefixlen) +unsigned int prefix6_bit(const struct in6_addr *prefix, const uint16_t prefixlen) { return prefix_bit((const uint8_t *)&prefix->s6_addr, prefixlen); } @@ -966,18 +966,16 @@ void masklen2ip(const int masklen, struct in_addr *netmask) } /* Convert IP address's netmask into integer. We assume netmask is - sequential one. Argument netmask should be network byte order. */ + * sequential one. Argument netmask should be network byte order. */ uint8_t ip_masklen(struct in_addr netmask) { uint32_t tmp = ~ntohl(netmask.s_addr); - if (tmp) - /* clz: count leading zeroes. sadly, the behaviour of this - * builtin - * is undefined for a 0 argument, even though most CPUs give 32 - */ - return __builtin_clz(tmp); - else - return 32; + + /* + * clz: count leading zeroes. sadly, the behaviour of this builtin is + * undefined for a 0 argument, even though most CPUs give 32 + */ + return tmp ? __builtin_clz(tmp) : 32; } /* Apply mask to IPv4 prefix (network byte order). */ diff --git a/lib/prefix.h b/lib/prefix.h index 4247569137..aaffb1e0c5 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -151,7 +151,7 @@ struct flowspec_prefix { /* FRR generic prefix structure. */ struct prefix { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; union { uint8_t prefix; struct in_addr prefix4; @@ -162,6 +162,7 @@ struct prefix { } lp; struct ethaddr prefix_eth; /* AF_ETHERNET */ uint8_t val[16]; + uint32_t val32[4]; uintptr_t ptr; struct evpn_addr prefix_evpn; /* AF_EVPN */ struct flowspec_prefix prefix_flowspec; /* AF_FLOWSPEC */ @@ -171,20 +172,20 @@ struct prefix { /* IPv4 prefix structure. */ struct prefix_ipv4 { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct in_addr prefix __attribute__((aligned(8))); }; /* IPv6 prefix structure. */ struct prefix_ipv6 { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct in6_addr prefix __attribute__((aligned(8))); }; struct prefix_ls { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct in_addr id __attribute__((aligned(8))); struct in_addr adv_router; }; @@ -192,21 +193,21 @@ struct prefix_ls { /* Prefix for routing distinguisher. */ struct prefix_rd { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; uint8_t val[8] __attribute__((aligned(8))); }; /* Prefix for ethernet. */ struct prefix_eth { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */ }; /* EVPN prefix structure. */ struct prefix_evpn { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct evpn_addr prefix __attribute__((aligned(8))); }; @@ -252,20 +253,20 @@ static inline int is_evpn_prefix_ipaddr_v6(const struct prefix_evpn *evp) /* Prefix for a generic pointer */ struct prefix_ptr { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; uintptr_t prefix __attribute__((aligned(8))); }; /* Prefix for a Flowspec entry */ struct prefix_fs { uint8_t family; - uint8_t prefixlen; /* unused */ + uint16_t prefixlen; /* unused */ struct flowspec_prefix prefix __attribute__((aligned(8))); }; struct prefix_sg { uint8_t family; - uint8_t prefixlen; + uint16_t prefixlen; struct in_addr src __attribute__((aligned(8))); struct in_addr grp; }; @@ -296,15 +297,16 @@ union prefixconstptr { #endif /* INET_ADDRSTRLEN */ #ifndef INET6_ADDRSTRLEN +/* dead:beef:dead:beef:dead:beef:dead:beef + \0 */ #define INET6_ADDRSTRLEN 46 #endif /* INET6_ADDRSTRLEN */ #ifndef INET6_BUFSIZ -#define INET6_BUFSIZ 51 +#define INET6_BUFSIZ 53 #endif /* INET6_BUFSIZ */ -/* Maximum prefix string length (IPv6) */ -#define PREFIX_STRLEN 51 +/* Maximum string length of the result of prefix2str */ +#define PREFIX_STRLEN 80 /* Max bit/byte length of IPv4 address. */ #define IPV4_MAX_BYTELEN 4 @@ -367,9 +369,9 @@ extern const char *safi2str(safi_t safi); extern const char *afi2str(afi_t afi); /* Check bit of the prefix. */ -extern unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen); +extern unsigned int prefix_bit(const uint8_t *prefix, const uint16_t prefixlen); extern unsigned int prefix6_bit(const struct in6_addr *prefix, - const uint8_t prefixlen); + const uint16_t prefixlen); extern struct prefix *prefix_new(void); extern void prefix_free(struct prefix *); diff --git a/lib/table.c b/lib/table.c index 0026b7692b..edba7f1932 100644 --- a/lib/table.c +++ b/lib/table.c @@ -283,7 +283,7 @@ struct route_node *route_node_get(struct route_table *const table, struct route_node *node; struct route_node *match; struct route_node *inserted; - uint8_t prefixlen = p->prefixlen; + uint16_t prefixlen = p->prefixlen; const uint8_t *prefix = &p->u.prefix; apply_mask((struct prefix *)p); diff --git a/lib/thread.c b/lib/thread.c index 44c9e2b2f1..867ca2dc60 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1572,8 +1572,13 @@ void thread_set_yield_time(struct thread *thread, unsigned long yield_time) void thread_getrusage(RUSAGE_T *r) { +#if defined RUSAGE_THREAD +#define FRR_RUSAGE RUSAGE_THREAD +#else +#define FRR_RUSAGE RUSAGE_SELF +#endif monotime(&r->real); - getrusage(RUSAGE_SELF, &(r->cpu)); + getrusage(FRR_RUSAGE, &(r->cpu)); } /* diff --git a/lib/zclient.c b/lib/zclient.c index 1c40750db0..cc936d47d7 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -173,10 +173,10 @@ void zclient_stop(struct zclient *zclient) redist_del_instance( &zclient->mi_redist[afi][zclient->redist_default], zclient->instance); - } - vrf_bitmap_free(zclient->default_information); - zclient->default_information = VRF_BITMAP_NULL; + vrf_bitmap_free(zclient->default_information[afi]); + zclient->default_information[afi] = VRF_BITMAP_NULL; + } } void zclient_reset(struct zclient *zclient) @@ -447,7 +447,7 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) } /* Resend all redistribute request. */ - for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && vrf_bitmap_check(zclient->redist[afi][i], @@ -456,10 +456,13 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) zclient, afi, i, 0, vrf_id); - /* If default information is needed. */ - if (vrf_bitmap_check(zclient->default_information, VRF_DEFAULT)) - zebra_message_send(zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD, - vrf_id); + /* If default information is needed. */ + if (vrf_bitmap_check(zclient->default_information[afi], + VRF_DEFAULT)) + zebra_redistribute_default_send( + ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient, afi, + vrf_id); + } } /* Send unregister requests to zebra daemon for the information in a VRF. */ @@ -512,7 +515,7 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) } /* Flush all redistribute request. */ - for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (afi = AFI_IP; afi < AFI_MAX; afi++) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) if (i != zclient->redist_default && vrf_bitmap_check(zclient->redist[afi][i], @@ -521,10 +524,13 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, i, 0, vrf_id); - /* If default information is needed. */ - if (vrf_bitmap_check(zclient->default_information, VRF_DEFAULT)) - zebra_message_send(zclient, ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, - vrf_id); + /* If default information is needed. */ + if (vrf_bitmap_check(zclient->default_information[afi], + VRF_DEFAULT)) + zebra_redistribute_default_send( + ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient, afi, + vrf_id); + } } /* Send request to zebra daemon to start or stop RA. */ @@ -620,12 +626,13 @@ void zclient_init(struct zclient *zclient, int redist_default, zclient->redist_default = redist_default; zclient->instance = instance; /* Pending: make afi(s) an arg. */ - for (afi = AFI_IP; afi < AFI_MAX; afi++) + for (afi = AFI_IP; afi < AFI_MAX; afi++) { redist_add_instance(&zclient->mi_redist[afi][redist_default], instance); - /* Set default-information redistribute to zero. */ - zclient->default_information = vrf_bitmap_init(); + /* Set default-information redistribute to zero. */ + zclient->default_information[afi] = vrf_bitmap_init(); + } if (zclient_debug) zlog_debug("zclient_start is called"); @@ -1280,6 +1287,22 @@ int zebra_redistribute_send(int command, struct zclient *zclient, afi_t afi, return zclient_send_message(zclient); } +int zebra_redistribute_default_send(int command, struct zclient *zclient, + afi_t afi, vrf_id_t vrf_id) +{ + struct stream *s; + + s = zclient->obuf; + stream_reset(s); + + zclient_create_header(s, command, vrf_id); + stream_putc(s, afi); + + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + /* Get prefix in ZServ format; family should be filled in on prefix */ static void zclient_stream_get_prefix(struct stream *s, struct prefix *p) { @@ -2709,21 +2732,22 @@ void zclient_redistribute(int command, struct zclient *zclient, afi_t afi, void zclient_redistribute_default(int command, struct zclient *zclient, - vrf_id_t vrf_id) + afi_t afi, vrf_id_t vrf_id) { if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) { - if (vrf_bitmap_check(zclient->default_information, vrf_id)) + if (vrf_bitmap_check(zclient->default_information[afi], vrf_id)) return; - vrf_bitmap_set(zclient->default_information, vrf_id); + vrf_bitmap_set(zclient->default_information[afi], vrf_id); } else { - if (!vrf_bitmap_check(zclient->default_information, vrf_id)) + if (!vrf_bitmap_check(zclient->default_information[afi], + vrf_id)) return; - vrf_bitmap_unset(zclient->default_information, vrf_id); + vrf_bitmap_unset(zclient->default_information[afi], vrf_id); } if (zclient->sock > 0) - zebra_message_send(zclient, command, vrf_id); + zebra_redistribute_default_send(command, zclient, afi, vrf_id); } static void zclient_event(enum event event, struct zclient *zclient) diff --git a/lib/zclient.h b/lib/zclient.h index 831cccfb7e..401d6c400a 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -216,7 +216,7 @@ struct zclient { vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; /* Redistribute defauilt. */ - vrf_bitmap_t default_information; + vrf_bitmap_t default_information[AFI_MAX]; /* Pointer to the callback functions. */ void (*zebra_connected)(struct zclient *); @@ -479,13 +479,16 @@ extern int zebra_redistribute_send(int command, struct zclient *, afi_t, int type, unsigned short instance, vrf_id_t vrf_id); +extern int zebra_redistribute_default_send(int command, struct zclient *zclient, + afi_t afi, vrf_id_t vrf_id); + /* If state has changed, update state and call zebra_redistribute_send. */ extern void zclient_redistribute(int command, struct zclient *, afi_t, int type, unsigned short instance, vrf_id_t vrf_id); /* If state has changed, update state and send the command to zebra. */ extern void zclient_redistribute_default(int command, struct zclient *, - vrf_id_t vrf_id); + afi_t, vrf_id_t vrf_id); /* Send the message in zclient->obuf to the zebra daemon (or enqueue it). Returns 0 for success or -1 on an I/O error. */ |
