diff options
427 files changed, 9613 insertions, 5729 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..6b8710a711 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/Makefile.am b/Makefile.am index 737b1acf64..30150b594b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,8 @@ include common.am AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_srcdir)/lib \ -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/lib AM_CFLAGS = $(WERROR) -DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE) +VERSION_TYPE := $(shell if echo $(VERSION) | grep -q '^[0-9\.]*$$'; then echo RELEASE ; else echo DEV ; fi) +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE) -DVERSION_TYPE_$(VERSION_TYPE) LIBCAP = @LIBCAP@ EXTRA_DIST = diff --git a/babeld/kernel.c b/babeld/kernel.c index 8b1b80665c..7e78b6dec7 100644 --- a/babeld/kernel.c +++ b/babeld/kernel.c @@ -210,7 +210,7 @@ if_eui64(int ifindex, unsigned char *eui) return -1; } - u_char len = (u_char) ifp->hw_addr_len; + uint8_t len = (uint8_t)ifp->hw_addr_len; char *tmp = (void*) ifp->hw_addr; if (len == 8) { diff --git a/bgpd/Makefile.am b/bgpd/Makefile.am index 5e08f82774..61d46dfcb9 100644 --- a/bgpd/Makefile.am +++ b/bgpd/Makefile.am @@ -86,7 +86,8 @@ libbgp_a_SOURCES = \ bgp_nht.c bgp_updgrp.c bgp_updgrp_packet.c bgp_updgrp_adv.c bgp_bfd.c \ bgp_encap_tlv.c $(BGP_VNC_RFAPI_SRC) bgp_attr_evpn.c \ bgp_evpn.c bgp_evpn_vty.c bgp_vpn.c bgp_label.c bgp_rd.c \ - bgp_keepalives.c bgp_io.c + bgp_keepalives.c bgp_io.c bgp_flowspec.c bgp_flowspec_util.c \ + bgp_flowspec_vty.c noinst_HEADERS = \ bgp_memory.h \ @@ -99,7 +100,7 @@ noinst_HEADERS = \ bgp_updgrp.h bgp_bfd.h bgp_encap_tlv.h bgp_encap_types.h \ $(BGP_VNC_RFAPI_HD) bgp_attr_evpn.h bgp_evpn.h bgp_evpn_vty.h \ bgp_vpn.h bgp_label.h bgp_rd.h bgp_evpn_private.h bgp_keepalives.h \ - bgp_io.h + bgp_io.h bgp_flowspec.h bgp_flowspec_private.h bgp_flowspec_util.h bgpd_SOURCES = bgp_main.c bgpd_LDADD = libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ @LIBM@ diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index 29b6ca6bfa..94413117c1 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -146,7 +146,7 @@ void bgp_advertise_unintern(struct hash *hash, struct bgp_advertise_attr *baa) } int bgp_adj_out_lookup(struct peer *peer, struct bgp_node *rn, - u_int32_t addpath_tx_id) + uint32_t addpath_tx_id) { struct bgp_adj_out *adj; struct peer_af *paf; @@ -179,7 +179,7 @@ int bgp_adj_out_lookup(struct peer *peer, struct bgp_node *rn, void bgp_adj_in_set(struct bgp_node *rn, struct peer *peer, struct attr *attr, - u_int32_t addpath_id) + uint32_t addpath_id) { struct bgp_adj_in *adj; @@ -209,7 +209,7 @@ void bgp_adj_in_remove(struct bgp_node *rn, struct bgp_adj_in *bai) } int bgp_adj_in_unset(struct bgp_node *rn, struct peer *peer, - u_int32_t addpath_id) + uint32_t addpath_id) { struct bgp_adj_in *adj; struct bgp_adj_in *adj_next; diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h index 3fdc6d8d23..920cca6301 100644 --- a/bgpd/bgp_advertise.h +++ b/bgpd/bgp_advertise.h @@ -29,7 +29,7 @@ struct update_subgroup; struct bgp_advertise_fifo { struct bgp_advertise *next; struct bgp_advertise *prev; - u_int32_t count; + uint32_t count; }; /* BGP advertise attribute. */ @@ -80,7 +80,7 @@ struct bgp_adj_out { /* Prefix information. */ struct bgp_node *rn; - u_int32_t addpath_tx_id; + uint32_t addpath_tx_id; /* Advertised attribute. */ struct attr *attr; @@ -102,7 +102,7 @@ struct bgp_adj_in { struct attr *attr; /* Addpath identifier */ - u_int32_t addpath_rx_id; + uint32_t addpath_rx_id; }; /* BGP advertisement list. */ @@ -168,10 +168,10 @@ struct bgp_synchronize { : (F)->next) /* Prototypes. */ -extern int bgp_adj_out_lookup(struct peer *, struct bgp_node *, u_int32_t); +extern int bgp_adj_out_lookup(struct peer *, struct bgp_node *, uint32_t); extern void bgp_adj_in_set(struct bgp_node *, struct peer *, struct attr *, - u_int32_t); -extern int bgp_adj_in_unset(struct bgp_node *, struct peer *, u_int32_t); + uint32_t); +extern int bgp_adj_in_unset(struct bgp_node *, struct peer *, uint32_t); extern void bgp_adj_in_remove(struct bgp_node *, struct bgp_adj_in *); extern void bgp_sync_init(struct peer *); diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index c3bbb71687..e02617691f 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -80,8 +80,8 @@ * NOT the internal representation! */ struct assegment_header { - u_char type; - u_char length; + uint8_t type; + uint8_t length; }; /* Hash for aspath. This is the top level structure of AS path. */ @@ -109,7 +109,7 @@ const char *aspath_segment_type_str[] = {"as-invalid", "as-set", "as-sequence", * the caller should immediately assign data to the segment, as the segment * otherwise is not generally valid */ -static struct assegment *assegment_new(u_char type, u_short length) +static struct assegment *assegment_new(uint8_t type, unsigned short length) { struct assegment *new; @@ -345,7 +345,7 @@ void aspath_unintern(struct aspath **aspath) /* Return the start or end delimiters for a particular Segment type */ #define AS_SEG_START 0 #define AS_SEG_END 1 -static char aspath_delimiter_char(u_char type, u_char which) +static char aspath_delimiter_char(uint8_t type, uint8_t which) { int i; struct { @@ -864,7 +864,7 @@ static void assegment_data_put(struct stream *s, as_t *as, int num, } } -static size_t assegment_header_put(struct stream *s, u_char type, int length) +static size_t assegment_header_put(struct stream *s, uint8_t type, int length) { size_t lenp; assert(length <= AS_SEGMENT_MAX); @@ -962,7 +962,7 @@ size_t aspath_put(struct stream *s, struct aspath *as, int use32bit) * We have no way to manage the storage, so we use a static stream * wrapper around aspath_put. */ -u_char *aspath_snmp_pathseg(struct aspath *as, size_t *varlen) +uint8_t *aspath_snmp_pathseg(struct aspath *as, size_t *varlen) { #define SNMP_PATHSEG_MAX 1024 @@ -1541,7 +1541,7 @@ struct aspath *aspath_filter_exclude(struct aspath *source, /* Add specified AS to the leftmost of aspath. */ static struct aspath *aspath_add_asns(struct aspath *aspath, as_t asno, - u_char type, unsigned num) + uint8_t type, unsigned num) { struct assegment *assegment = aspath->segments; unsigned i; @@ -1872,7 +1872,7 @@ enum as_token { /* Return next token and point for string parse. */ static const char *aspath_gettoken(const char *buf, enum as_token *token, - u_long *asno) + unsigned long *asno) { const char *p = buf; @@ -1937,8 +1937,8 @@ static const char *aspath_gettoken(const char *buf, enum as_token *token, struct aspath *aspath_str2aspath(const char *str) { enum as_token token = as_token_unknown; - u_short as_type; - u_long asno = 0; + unsigned short as_type; + unsigned long asno = 0; struct aspath *aspath; int needtype; diff --git a/bgpd/bgp_aspath.h b/bgpd/bgp_aspath.h index 0c065cc936..1acc2f67a6 100644 --- a/bgpd/bgp_aspath.h +++ b/bgpd/bgp_aspath.h @@ -51,8 +51,8 @@ struct assegment { struct assegment *next; as_t *as; - u_short length; - u_char type; + unsigned short length; + uint8_t type; }; /* AS path may be include some AsSegments. */ @@ -127,6 +127,6 @@ extern struct aspath *aspath_reconcile_as4(struct aspath *, struct aspath *); extern unsigned int aspath_has_as4(struct aspath *); /* For SNMP BGP4PATHATTRASPATHSEGMENT, might be useful for debug */ -extern u_char *aspath_snmp_pathseg(struct aspath *, size_t *); +extern uint8_t *aspath_snmp_pathseg(struct aspath *, size_t *); #endif /* _QUAGGA_BGP_ASPATH_H */ diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index c3a1105995..ef839dba6a 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -52,6 +52,7 @@ #endif #include "bgp_encap_types.h" #include "bgp_evpn.h" +#include "bgp_flowspec_private.h" /* Attribute strings for logging. */ static const struct message attr_str[] = { @@ -693,7 +694,7 @@ struct attr *bgp_attr_intern(struct attr *attr) } /* Make network statement's attribute. */ -struct attr *bgp_attr_default_set(struct attr *attr, u_char origin) +struct attr *bgp_attr_default_set(struct attr *attr, uint8_t origin) { memset(attr, 0, sizeof(struct attr)); @@ -712,10 +713,10 @@ struct attr *bgp_attr_default_set(struct attr *attr, u_char origin) } /* Create the attributes for an aggregate */ -struct attr *bgp_attr_aggregate_intern(struct bgp *bgp, u_char origin, +struct attr *bgp_attr_aggregate_intern(struct bgp *bgp, uint8_t origin, struct aspath *aspath, struct community *community, int as_set, - u_char atomic_aggregate) + uint8_t atomic_aggregate) { struct attr attr; struct attr *new; @@ -737,7 +738,7 @@ struct attr *bgp_attr_aggregate_intern(struct bgp *bgp, u_char origin, attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); if (community) { - u_int32_t gshut = COMMUNITY_GSHUT; + uint32_t gshut = COMMUNITY_GSHUT; /* If we are not shutting down ourselves and we are * aggregating a route that contains the GSHUT community we @@ -901,16 +902,16 @@ void bgp_attr_flush(struct attr *attr) * introduced by the sending neighbour. */ static bgp_attr_parse_ret_t -bgp_attr_malformed(struct bgp_attr_parser_args *args, u_char subcode, +bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode, bgp_size_t length) { struct peer *const peer = args->peer; - const u_int8_t flags = args->flags; + const uint8_t flags = args->flags; /* startp and length must be special-cased, as whether or not to * send the attribute data with the NOTIFY depends on the error, * the caller therefore signals this with the seperate length argument */ - u_char *notify_datap = (length > 0 ? args->startp : NULL); + uint8_t *notify_datap = (length > 0 ? args->startp : NULL); /* Only relax error handling for eBGP peers */ if (peer->sort != BGP_PEER_EBGP) { @@ -976,12 +977,12 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, u_char subcode, non-transitive" attribute. */ static void bgp_attr_flags_diagnose(struct bgp_attr_parser_args *args, - u_int8_t desired_flags /* how RFC says it must be */ - ) + uint8_t desired_flags /* how RFC says it must be */ +) { - u_char seen = 0, i; - u_char real_flags = args->flags; - const u_int8_t attr_code = args->type; + uint8_t seen = 0, i; + uint8_t real_flags = args->flags; + const uint8_t attr_code = args->type; desired_flags &= ~BGP_ATTR_FLAG_EXTLEN; real_flags &= ~BGP_ATTR_FLAG_EXTLEN; @@ -1008,41 +1009,36 @@ bgp_attr_flags_diagnose(struct bgp_attr_parser_args *args, /* Required flags for attributes. EXTLEN will be masked off when testing, * as will PARTIAL for optional+transitive attributes. */ -const u_int8_t attr_flags_values[] = { - [BGP_ATTR_ORIGIN] = BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_AS_PATH] = BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_NEXT_HOP] = BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_MULTI_EXIT_DISC] = BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_LOCAL_PREF] = BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_ATOMIC_AGGREGATE] = BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_AGGREGATOR] = - BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_COMMUNITIES] = - BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_ORIGINATOR_ID] = BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_CLUSTER_LIST] = BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_MP_REACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_MP_UNREACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL, - [BGP_ATTR_EXT_COMMUNITIES] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_AS4_PATH] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_AS4_AGGREGATOR] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_PMSI_TUNNEL] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_LARGE_COMMUNITIES] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, - [BGP_ATTR_PREFIX_SID] = - BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, +const uint8_t attr_flags_values[] = { + [BGP_ATTR_ORIGIN] = BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_AS_PATH] = BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_NEXT_HOP] = BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_MULTI_EXIT_DISC] = BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_LOCAL_PREF] = BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_ATOMIC_AGGREGATE] = BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_AGGREGATOR] = BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_COMMUNITIES] = BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_ORIGINATOR_ID] = BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_CLUSTER_LIST] = BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_MP_REACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_MP_UNREACH_NLRI] = BGP_ATTR_FLAG_OPTIONAL, + [BGP_ATTR_EXT_COMMUNITIES] = + BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_AS4_PATH] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_AS4_AGGREGATOR] = + BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_PMSI_TUNNEL] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_LARGE_COMMUNITIES] = + BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_PREFIX_SID] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, }; static const size_t attr_flags_values_max = array_size(attr_flags_values) - 1; static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) { - u_int8_t mask = BGP_ATTR_FLAG_EXTLEN; - const u_int8_t flags = args->flags; - const u_int8_t attr_code = args->type; + uint8_t mask = BGP_ATTR_FLAG_EXTLEN; + const uint8_t flags = args->flags; + const uint8_t attr_code = args->type; /* there may be attributes we don't know about */ if (attr_code > attr_flags_values_max) @@ -1531,7 +1527,7 @@ bgp_attr_community(struct bgp_attr_parser_args *args) } attr->community = - community_parse((u_int32_t *)stream_pnt(peer->curr), length); + 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); @@ -1652,6 +1648,13 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, /* Nexthop length check. */ switch (attr->mp_nexthop_len) { + case 0: + if (safi != SAFI_FLOWSPEC) { + zlog_info("%s: (%s) Wrong multiprotocol next hop length: %d", + __func__, peer->host, attr->mp_nexthop_len); + return BGP_ATTR_PARSE_ERROR_NOTIFYPLS; + } + break; case BGP_ATTR_NHLEN_VPNV4: stream_getl(s); /* RD high */ stream_getl(s); /* RD low */ @@ -1723,7 +1726,7 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, } { - u_char val; + uint8_t val; if ((val = stream_getc(s))) zlog_warn( "%s sent non-zero value, %u, for defunct SNPA-length field", @@ -1768,7 +1771,7 @@ int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, afi_t afi; iana_safi_t pkt_safi; safi_t safi; - u_int16_t withdraw_len; + uint16_t withdraw_len; struct peer *const peer = args->peer; struct attr *const attr = args->attr; const bgp_size_t length = args->length; @@ -1827,7 +1830,7 @@ bgp_attr_large_community(struct bgp_attr_parser_args *args) } attr->lcommunity = - lcommunity_parse((u_int8_t *)stream_pnt(peer->curr), length); + lcommunity_parse((uint8_t *)stream_pnt(peer->curr), length); /* XXX: fix ecommunity_parse to use stream API */ stream_forward_getp(peer->curr, length); @@ -1847,7 +1850,7 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args) struct peer *const peer = args->peer; struct attr *const attr = args->attr; const bgp_size_t length = args->length; - u_char sticky = 0; + uint8_t sticky = 0; if (length == 0) { attr->ecommunity = NULL; @@ -1856,7 +1859,7 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args) } attr->ecommunity = - ecommunity_parse((u_int8_t *)stream_pnt(peer->curr), length); + ecommunity_parse((uint8_t *)stream_pnt(peer->curr), length); /* XXX: fix ecommunity_parse to use stream API */ stream_forward_getp(peer->curr, length); @@ -1883,8 +1886,8 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args) static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ bgp_size_t length, /* IN: attr's length field */ struct attr *attr, /* IN: caller already allocated */ - u_char flag, /* IN: attr's flags field */ - u_char *startp) + uint8_t flag, /* IN: attr's flags field */ + uint8_t *startp) { bgp_size_t total; uint16_t tunneltype = 0; @@ -2017,10 +2020,10 @@ bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, struct attr *const attr = args->attr; int type; int length; - u_int32_t label_index; + uint32_t label_index; struct in6_addr ipv6_sid; - u_int32_t srgb_base; - u_int32_t srgb_range; + uint32_t srgb_base; + uint32_t srgb_range; int srgb_count; attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); @@ -2116,7 +2119,7 @@ bgp_attr_pmsi_tunnel(struct bgp_attr_parser_args *args) struct peer *const peer = args->peer; struct attr *const attr = args->attr; const bgp_size_t length = args->length; - u_int8_t tnl_type; + uint8_t tnl_type; /* Verify that the receiver is expecting "ingress replication" as we * can only support that. @@ -2159,9 +2162,9 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args) struct transit *transit; struct peer *const peer = args->peer; struct attr *const attr = args->attr; - u_char *const startp = args->startp; - const u_char type = args->type; - const u_char flag = args->flags; + uint8_t *const startp = args->startp; + const uint8_t type = args->type; + const uint8_t flag = args->flags; const bgp_size_t length = args->length; if (bgp_debug_update(peer, NULL, NULL, 1)) @@ -2213,7 +2216,7 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args) /* Well-known attribute check. */ static int bgp_attr_check(struct peer *peer, struct attr *attr) { - u_char type = 0; + uint8_t type = 0; /* BGP Graceful-Restart End-of-RIB for IPv4 unicast is signaled as an * empty UPDATE. */ @@ -2264,12 +2267,12 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, struct bgp_nlri *mp_withdraw) { int ret; - u_char flag = 0; - u_char type = 0; + uint8_t flag = 0; + uint8_t type = 0; bgp_size_t length; - u_char *startp, *endp; - u_char *attr_endp; - u_char seen[BGP_ATTR_BITMAP_SIZE]; + uint8_t *startp, *endp; + uint8_t *attr_endp; + uint8_t seen[BGP_ATTR_BITMAP_SIZE]; /* we need the as4_path only until we have synthesized the as_path with * it */ /* same goes for as4_aggregator */ @@ -2674,6 +2677,8 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, stream_putc(s, 4); stream_put(s, &attr->mp_nexthop_global_in, 4); break; + case SAFI_FLOWSPEC: + stream_putc(s, 0); /* no nexthop for flowspec */ default: break; } @@ -2724,14 +2729,17 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, stream_put(s, &attr->mp_nexthop_global, IPV6_MAX_BYTELEN); break; + case SAFI_FLOWSPEC: + stream_putc(s, 0); /* no nexthop for flowspec */ default: break; } break; default: - zlog_err( - "Bad nexthop when sening to %s, AFI %u SAFI %u nhlen %d", - peer->host, afi, safi, attr->mp_nexthop_len); + if (safi != SAFI_FLOWSPEC) + zlog_err( + "Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d", + peer->host, afi, safi, attr->mp_nexthop_len); break; } @@ -2742,8 +2750,8 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, struct prefix *p, struct prefix_rd *prd, - mpls_label_t *label, u_int32_t num_labels, - int addpath_encode, u_int32_t addpath_tx_id, + mpls_label_t *label, uint32_t num_labels, + int addpath_encode, uint32_t addpath_tx_id, struct attr *attr) { if (safi == SAFI_MPLS_VPN) { @@ -2761,6 +2769,14 @@ void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, } else if (safi == SAFI_LABELED_UNICAST) { /* Prefix write with label. */ stream_put_labeled_prefix(s, p, label); + } else if (safi == SAFI_FLOWSPEC) { + if (PSIZE (p->prefixlen)+2 < FLOWSPEC_NLRI_SIZELIMIT) + stream_putc(s, PSIZE (p->prefixlen)+2); + else + stream_putw(s, (PSIZE (p->prefixlen)+2)|(0xf<<12)); + stream_putc(s, 2);/* Filter type */ + stream_putc(s, p->prefixlen);/* Prefix length */ + stream_put(s, &p->u.prefix, PSIZE (p->prefixlen)); } else stream_put_prefix_addpath(s, p, addpath_encode, addpath_tx_id); } @@ -2886,8 +2902,8 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, struct bpacket_attr_vec_arr *vecarr, struct prefix *p, afi_t afi, safi_t safi, struct peer *from, struct prefix_rd *prd, - mpls_label_t *label, u_int32_t num_labels, - int addpath_encode, u_int32_t addpath_tx_id) + mpls_label_t *label, uint32_t num_labels, + int addpath_encode, uint32_t addpath_tx_id) { size_t cp; size_t aspath_sizep; @@ -3072,7 +3088,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, */ send_as4_aggregator = 1; } else - stream_putw(s, (u_int16_t)attr->aggregator_as); + stream_putw(s, (uint16_t)attr->aggregator_as); } stream_put_ipv4(s, attr->aggregator_addr.s_addr); } @@ -3179,7 +3195,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, stream_put(s, attr->ecommunity->val, attr->ecommunity->size * 8); } else { - u_int8_t *pnt; + uint8_t *pnt; int tbit; int ecom_tr_size = 0; int i; @@ -3233,7 +3249,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* Label index attribute. */ if (safi == SAFI_LABELED_UNICAST) { if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) { - u_int32_t label_index; + uint32_t label_index; label_index = attr->label_index; @@ -3350,11 +3366,11 @@ size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, safi_t safi) void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p, afi_t afi, safi_t safi, struct prefix_rd *prd, - mpls_label_t *label, u_int32_t num_labels, - int addpath_encode, u_int32_t addpath_tx_id, + mpls_label_t *label, uint32_t num_labels, + int addpath_encode, uint32_t addpath_tx_id, struct attr *attr) { - u_char wlabel[3] = {0x80, 0x00, 0x00}; + uint8_t wlabel[3] = {0x80, 0x00, 0x00}; if (safi == SAFI_LABELED_UNICAST) { label = (mpls_label_t *)wlabel; @@ -3404,7 +3420,7 @@ void bgp_dump_routes_attr(struct stream *s, struct attr *attr, size_t aspath_lenp; struct aspath *aspath; int addpath_encode = 0; - u_int32_t addpath_tx_id = 0; + uint32_t addpath_tx_id = 0; /* Remember current pointer. */ cp = stream_get_endp(s); diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 5403f32543..758db4a447 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -126,19 +126,19 @@ struct attr { /* Apart from in6_addr, the remaining static attributes */ struct in_addr nexthop; - u_int32_t med; - u_int32_t local_pref; + uint32_t med; + uint32_t local_pref; ifindex_t nh_ifindex; /* Path origin attribute */ - u_char origin; + uint8_t origin; /* PMSI tunnel type (RFC 6514). */ enum pta_type pmsi_tnl_type; /* has the route-map changed any attribute? Used on the peer outbound side. */ - u_int32_t rmap_change_flags; + uint32_t rmap_change_flags; /* Multi-Protocol Nexthop, AFI IPv6 */ struct in6_addr mp_nexthop_global; @@ -165,28 +165,28 @@ struct attr { struct in_addr originator_id; /* Local weight, not actually an attribute */ - u_int32_t weight; + uint32_t weight; /* Aggregator ASN */ as_t aggregator_as; /* MP Nexthop length */ - u_char mp_nexthop_len; + uint8_t mp_nexthop_len; /* MP Nexthop preference */ - u_char mp_nexthop_prefer_global; + uint8_t mp_nexthop_prefer_global; /* Static MAC for EVPN */ - u_char sticky; + uint8_t sticky; /* Flag for default gateway extended community in EVPN */ - u_char default_gw; + uint8_t default_gw; /* route tag */ route_tag_t tag; /* Label index */ - u_int32_t label_index; + uint32_t label_index; /* MPLS label */ mpls_label_t label; @@ -201,7 +201,7 @@ struct attr { struct overlay_index evpn_overlay; /* EVPN MAC Mobility sequence number, if any. */ - u_int32_t mm_seqnum; + uint32_t mm_seqnum; /* EVPN local router-mac */ struct ethaddr rmac; @@ -227,7 +227,7 @@ struct cluster_list { struct transit { unsigned long refcnt; int length; - u_char *val; + uint8_t *val; }; /* "(void) 0" will generate a compiler error. this is a safety check to @@ -265,18 +265,17 @@ extern struct attr *bgp_attr_intern(struct attr *attr); extern void bgp_attr_unintern_sub(struct attr *); extern void bgp_attr_unintern(struct attr **); extern void bgp_attr_flush(struct attr *); -extern struct attr *bgp_attr_default_set(struct attr *attr, u_char); -extern struct attr *bgp_attr_aggregate_intern(struct bgp *, u_char, +extern struct attr *bgp_attr_default_set(struct attr *attr, uint8_t); +extern struct attr *bgp_attr_aggregate_intern(struct bgp *, uint8_t, struct aspath *, struct community *, int as_set, - u_char); + uint8_t); extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *, struct stream *, struct attr *, struct bpacket_attr_vec_arr *vecarr, struct prefix *, afi_t, safi_t, struct peer *, struct prefix_rd *, - mpls_label_t *, u_int32_t, int, - u_int32_t); + mpls_label_t *, uint32_t, int, uint32_t); extern void bgp_dump_routes_attr(struct stream *, struct attr *, struct prefix *); extern int attrhash_cmp(const void *, const void *); @@ -298,9 +297,9 @@ struct bgp_attr_parser_args { bgp_size_t length; /* attribute data length; */ bgp_size_t total; /* total length, inc header */ struct attr *attr; - u_int8_t type; - u_int8_t flags; - u_char *startp; + uint8_t type; + uint8_t flags; + uint8_t *startp; }; extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, struct bgp_nlri *); @@ -324,9 +323,9 @@ extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, struct attr *attr); extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, struct prefix *p, struct prefix_rd *prd, - mpls_label_t *label, u_int32_t num_labels, - int addpath_encode, - u_int32_t addpath_tx_id, struct attr *); + mpls_label_t *label, uint32_t num_labels, + int addpath_encode, uint32_t addpath_tx_id, + struct attr *); extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi, struct prefix *p); extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep); @@ -336,12 +335,11 @@ extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, extern void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p, afi_t afi, safi_t safi, struct prefix_rd *prd, mpls_label_t *, - u_int32_t, int, u_int32_t, - struct attr *); + uint32_t, int, uint32_t, struct attr *); extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt); -static inline int bgp_rmap_nhop_changed(u_int32_t out_rmap_flags, - u_int32_t in_rmap_flags) +static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags, + uint32_t in_rmap_flags) { return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) @@ -356,7 +354,7 @@ static inline int bgp_rmap_nhop_changed(u_int32_t out_rmap_flags, : 0); } -static inline u_int32_t mac_mobility_seqnum(struct attr *attr) +static inline uint32_t mac_mobility_seqnum(struct attr *attr) { return (attr) ? attr->mm_seqnum : 0; } diff --git a/bgpd/bgp_attr_evpn.c b/bgpd/bgp_attr_evpn.c index 8d5eff9a6f..d2a61b93fe 100644 --- a/bgpd/bgp_attr_evpn.c +++ b/bgpd/bgp_attr_evpn.c @@ -78,7 +78,7 @@ int str2esi(const char *str, struct eth_segment_id *id) char *esi2str(struct eth_segment_id *id) { char *ptr; - u_char *val; + uint8_t *val; if (!id) return NULL; @@ -117,9 +117,9 @@ void bgp_attr_rmac(struct attr *attr, struct ethaddr *rmac) /* If there is a router mac extended community, set RMAC in attr */ for (i = 0; i < ecom->size; i++) { - u_char *pnt = NULL; - u_char type = 0; - u_char sub_type = 0; + uint8_t *pnt = NULL; + uint8_t type = 0; + uint8_t sub_type = 0; pnt = (ecom->val + (i * ECOMMUNITY_SIZE)); type = *pnt++; @@ -148,8 +148,8 @@ uint8_t bgp_attr_default_gw(struct attr *attr) /* If there is a default gw extendd community return true otherwise * return 0 */ for (i = 0; i < ecom->size; i++) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; pnt = (ecom->val + (i * ECOMMUNITY_SIZE)); type = *pnt++; @@ -167,11 +167,11 @@ uint8_t bgp_attr_default_gw(struct attr *attr) * Fetch and return the sequence number from MAC Mobility extended * community, if present, else 0. */ -u_int32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, u_char *sticky) +uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, uint8_t *sticky) { struct ecommunity *ecom; int i; - u_char flags = 0; + uint8_t flags = 0; ecom = attr->ecommunity; if (!ecom || !ecom->size) @@ -184,9 +184,9 @@ u_int32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, u_char *sticky) * one. */ for (i = 0; i < ecom->size; i++) { - u_char *pnt; - u_char type, sub_type; - u_int32_t seq_num; + uint8_t *pnt; + uint8_t type, sub_type; + uint32_t seq_num; pnt = (ecom->val + (i * ECOMMUNITY_SIZE)); type = *pnt++; @@ -233,12 +233,12 @@ extern int bgp_build_evpn_prefix(int evpn_type, uint32_t eth_tag, SET_IPADDR_V4(&p_evpn_p->ip); memcpy(&p_evpn_p->ip.ipaddr_v4, &src->u.prefix4, sizeof(struct in_addr)); - dst->prefixlen = (u_char)PREFIX_LEN_ROUTE_TYPE_5_IPV4; + dst->prefixlen = (uint8_t)PREFIX_LEN_ROUTE_TYPE_5_IPV4; } else { SET_IPADDR_V6(&p_evpn_p->ip); memcpy(&p_evpn_p->ip.ipaddr_v6, &src->u.prefix6, sizeof(struct in6_addr)); - dst->prefixlen = (u_char)PREFIX_LEN_ROUTE_TYPE_5_IPV6; + dst->prefixlen = (uint8_t)PREFIX_LEN_ROUTE_TYPE_5_IPV6; } } else return -1; diff --git a/bgpd/bgp_attr_evpn.h b/bgpd/bgp_attr_evpn.h index a211da8d2f..cb1c131ef7 100644 --- a/bgpd/bgp_attr_evpn.h +++ b/bgpd/bgp_attr_evpn.h @@ -34,11 +34,11 @@ #define MAX_ET 0xffffffff -u_long eth_tag_id; +unsigned long eth_tag_id; struct attr; struct eth_segment_id { - u_char val[ESI_LEN]; + uint8_t val[ESI_LEN]; }; union gw_addr { @@ -60,8 +60,8 @@ extern void bgp_add_routermac_ecom(struct attr *attr, extern int bgp_build_evpn_prefix(int type, uint32_t eth_tag, struct prefix *dst); extern void bgp_attr_rmac(struct attr *attr, struct ethaddr *rmac); -extern u_int32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, - u_char *sticky); +extern uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, + uint8_t *sticky); extern uint8_t bgp_attr_default_gw(struct attr *attr); #endif /* _QUAGGA_BGP_ATTR_EVPN_H */ diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 91b6929ff9..c7d6249870 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -383,8 +383,8 @@ static int bgp_bfd_dest_update(int command, struct zclient *zclient, /* * bgp_bfd_peer_param_set - Set the configured BFD paramter values for peer. */ -static int bgp_bfd_peer_param_set(struct peer *peer, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, +static int bgp_bfd_peer_param_set(struct peer *peer, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults) { struct peer_group *group; @@ -526,7 +526,7 @@ void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr) /* * bgp_bfd_show_info - Show the peer BFD information. */ -void bgp_bfd_show_info(struct vty *vty, struct peer *peer, u_char use_json, +void bgp_bfd_show_info(struct vty *vty, struct peer *peer, uint8_t use_json, json_object *json_neigh) { bfd_show_info(vty, (struct bfd_info *)peer->bfd_info, @@ -571,9 +571,9 @@ DEFUN (neighbor_bfd_param, int idx_number_2 = 4; int idx_number_3 = 5; struct peer *peer; - u_int32_t rx_val; - u_int32_t tx_val; - u_int8_t dm_val; + uint32_t rx_val; + uint32_t tx_val; + uint8_t dm_val; int ret; peer = peer_and_group_lookup_vty(vty, argv[idx_peer]->arg); diff --git a/bgpd/bgp_bfd.h b/bgpd/bgp_bfd.h index 72d86596bf..a3cfca9c0d 100644 --- a/bgpd/bgp_bfd.h +++ b/bgpd/bgp_bfd.h @@ -35,7 +35,7 @@ extern void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr); extern void bgp_bfd_show_info(struct vty *vty, struct peer *peer, - u_char use_json, json_object *json_neigh); + uint8_t use_json, json_object *json_neigh); extern int bgp_bfd_is_peer_multihop(struct peer *peer); diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index 4faebb538e..bf2607f2e7 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -68,12 +68,12 @@ enum MRT_MSG_TYPES { MSG_TABLE_DUMP /* routing table dump */ }; -static int attr_parse(struct stream *s, u_int16_t len) +static int attr_parse(struct stream *s, uint16_t len) { - u_int flag; - u_int type; - u_int16_t length; - u_int16_t lim; + unsigned int flag; + unsigned int type; + uint16_t length; + uint16_t lim; lim = s->getp + len; @@ -94,7 +94,7 @@ static int attr_parse(struct stream *s, u_int16_t len) switch (type) { case BGP_ATTR_ORIGIN: { - u_char origin; + uint8_t origin; origin = stream_getc(s); printf("ORIGIN: %d\n", origin); } break; @@ -134,7 +134,7 @@ int main(int argc, char **argv) int family; struct in_addr sip; struct in_addr dip; - u_int16_t viewno, seq_num; + uint16_t viewno, seq_num; struct prefix_ipv4 p; s = stream_new(10000); @@ -230,10 +230,10 @@ int main(int argc, char **argv) /* printf ("now read %d\n", len); */ if (type == MSG_TABLE_DUMP) { - u_char status; + uint8_t status; time_t originated; struct in_addr peer; - u_int16_t attrlen; + uint16_t attrlen; viewno = stream_getw(s); seq_num = stream_getw(s); diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 72b1098ede..8f38f5765f 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -334,13 +334,13 @@ community_list_entry_lookup(struct community_list *list, const void *arg, static char *community_str_get(struct community *com, int i) { int len; - u_int32_t comval; - u_int16_t as; - u_int16_t val; + uint32_t comval; + uint16_t as; + uint16_t val; char *str; char *pnt; - memcpy(&comval, com_nthval(com, i), sizeof(u_int32_t)); + memcpy(&comval, com_nthval(com, i), sizeof(uint32_t)); comval = ntohl(comval); switch (comval) { @@ -451,11 +451,11 @@ static int community_regexp_match(struct community *com, regex_t *reg) static char *lcommunity_str_get(struct lcommunity *lcom, int i) { struct lcommunity_val lcomval; - u_int32_t globaladmin; - u_int32_t localdata1; - u_int32_t localdata2; + uint32_t globaladmin; + uint32_t localdata1; + uint32_t localdata2; char *str; - u_char *ptr; + uint8_t *ptr; char *pnt; ptr = lcom->val + (i * LCOMMUNITY_SIZE); @@ -465,7 +465,7 @@ static char *lcommunity_str_get(struct lcommunity *lcom, int i) /* Allocate memory. 48 bytes taken off bgp_lcommunity.c */ str = pnt = XMALLOC(MTYPE_LCOMMUNITY_STR, 48); - ptr = (u_char *)lcomval.val; + ptr = (uint8_t *)lcomval.val; ptr = ptr_get_be32(ptr, &globaladmin); ptr = ptr_get_be32(ptr, &localdata1); ptr = ptr_get_be32(ptr, &localdata2); @@ -549,7 +549,7 @@ static struct community * community_regexp_delete (struct community *com, regex_t * reg) { int i; - u_int32_t comval; + uint32_t comval; /* Maximum is "65535:65535" + '\0'. */ char c[12]; const char *str; @@ -560,7 +560,7 @@ community_regexp_delete (struct community *com, regex_t * reg) i = 0; while (i < com->size) { - memcpy (&comval, com_nthval (com, i), sizeof (u_int32_t)); + memcpy (&comval, com_nthval (com, i), sizeof (uint32_t)); comval = ntohl (comval); switch (comval) @@ -694,8 +694,8 @@ struct community *community_list_match_delete(struct community *com, struct community_list *list) { struct community_entry *entry; - u_int32_t val; - u_int32_t com_index_to_delete[com->size]; + uint32_t val; + uint32_t com_index_to_delete[com->size]; int delete_index = 0; int i; @@ -895,8 +895,8 @@ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, struct community_list *list) { struct community_entry *entry; - u_int32_t com_index_to_delete[lcom->size]; - u_char *ptr; + uint32_t com_index_to_delete[lcom->size]; + uint8_t *ptr; int delete_index = 0; int i; diff --git a/bgpd/bgp_clist.h b/bgpd/bgp_clist.h index c21654f399..0dbde2a453 100644 --- a/bgpd/bgp_clist.h +++ b/bgpd/bgp_clist.h @@ -68,13 +68,13 @@ struct community_entry { struct community_entry *prev; /* Permit or deny. */ - u_char direct; + uint8_t direct; /* Standard or expanded. */ - u_char style; + uint8_t style; /* Any match. */ - u_char any; + uint8_t any; /* Community structure. */ union { diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index b78edcb2ff..10ce1486a9 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -55,7 +55,7 @@ void community_free(struct community *com) } /* Add one community value to the community. */ -static void community_add_val(struct community *com, u_int32_t val) +static void community_add_val(struct community *com, uint32_t val) { com->size++; if (com->val) @@ -65,11 +65,11 @@ static void community_add_val(struct community *com, u_int32_t val) com->val = XMALLOC(MTYPE_COMMUNITY_VAL, com_length(com)); val = htonl(val); - memcpy(com_lastval(com), &val, sizeof(u_int32_t)); + memcpy(com_lastval(com), &val, sizeof(uint32_t)); } /* Delete one community. */ -void community_del_val(struct community *com, u_int32_t *val) +void community_del_val(struct community *com, uint32_t *val) { int i = 0; int c = 0; @@ -78,7 +78,7 @@ void community_del_val(struct community *com, u_int32_t *val) return; while (i < com->size) { - if (memcmp(com->val + i, val, sizeof(u_int32_t)) == 0) { + if (memcmp(com->val + i, val, sizeof(uint32_t)) == 0) { c = com->size - i - 1; if (c > 0) @@ -117,11 +117,11 @@ struct community *community_delete(struct community *com1, /* Callback function from qsort(). */ static int community_compare(const void *a1, const void *a2) { - u_int32_t v1; - u_int32_t v2; + uint32_t v1; + uint32_t v2; - memcpy(&v1, a1, sizeof(u_int32_t)); - memcpy(&v2, a2, sizeof(u_int32_t)); + memcpy(&v1, a1, sizeof(uint32_t)); + memcpy(&v2, a2, sizeof(uint32_t)); v1 = ntohl(v1); v2 = ntohl(v2); @@ -132,28 +132,28 @@ static int community_compare(const void *a1, const void *a2) return 0; } -int community_include(struct community *com, u_int32_t val) +int community_include(struct community *com, uint32_t val) { int i; val = htonl(val); for (i = 0; i < com->size; i++) - if (memcmp(&val, com_nthval(com, i), sizeof(u_int32_t)) == 0) + if (memcmp(&val, com_nthval(com, i), sizeof(uint32_t)) == 0) return 1; return 0; } -u_int32_t community_val_get(struct community *com, int i) +uint32_t community_val_get(struct community *com, int i) { - u_char *p; - u_int32_t val; + uint8_t *p; + uint32_t val; - p = (u_char *)com->val; + p = (uint8_t *)com->val; p += (i * 4); - memcpy(&val, p, sizeof(u_int32_t)); + memcpy(&val, p, sizeof(uint32_t)); return ntohl(val); } @@ -163,7 +163,7 @@ struct community *community_uniq_sort(struct community *com) { int i; struct community *new; - u_int32_t val; + uint32_t val; if (!com) return NULL; @@ -178,7 +178,7 @@ struct community *community_uniq_sort(struct community *com) community_add_val(new, val); } - qsort(new->val, new->size, sizeof(u_int32_t), community_compare); + qsort(new->val, new->size, sizeof(uint32_t), community_compare); return new; } @@ -201,9 +201,9 @@ static void set_community_string(struct community *com, bool make_json) char *pnt; int len; int first; - u_int32_t comval; - u_int16_t as; - u_int16_t val; + uint32_t comval; + uint16_t as; + uint16_t val; json_object *json_community_list = NULL; json_object *json_string = NULL; @@ -234,7 +234,7 @@ static void set_community_string(struct community *com, bool make_json) len = 0; for (i = 0; i < com->size; i++) { - memcpy(&comval, com_nthval(com, i), sizeof(u_int32_t)); + memcpy(&comval, com_nthval(com, i), sizeof(uint32_t)); comval = ntohl(comval); switch (comval) { @@ -265,7 +265,7 @@ static void set_community_string(struct community *com, bool make_json) /* Fill in string. */ for (i = 0; i < com->size; i++) { - memcpy(&comval, com_nthval(com, i), sizeof(u_int32_t)); + memcpy(&comval, com_nthval(com, i), sizeof(uint32_t)); comval = ntohl(comval); if (first) @@ -391,7 +391,7 @@ void community_unintern(struct community **com) } /* Create new community attribute. */ -struct community *community_parse(u_int32_t *pnt, u_short length) +struct community *community_parse(uint32_t *pnt, unsigned short length) { struct community tmp; struct community *new; @@ -441,7 +441,7 @@ char *community_str(struct community *com, bool make_json) hash package.*/ unsigned int community_hash_make(struct community *com) { - u_int32_t *pnt = (u_int32_t *)com->val; + uint32_t *pnt = (uint32_t *)com->val; return jhash2(pnt, com->size, 0x43ea96c1); } @@ -462,8 +462,7 @@ int community_match(const struct community *com1, const struct community *com2) /* Every community on com2 needs to be on com1 for this to match */ while (i < com1->size && j < com2->size) { - if (memcmp(com1->val + i, com2->val + j, sizeof(u_int32_t)) - == 0) + if (memcmp(com1->val + i, com2->val + j, sizeof(uint32_t)) == 0) j++; i++; } @@ -518,7 +517,7 @@ enum community_token { /* Get next community token from string. */ static const char * -community_gettoken(const char *buf, enum community_token *token, u_int32_t *val) +community_gettoken(const char *buf, enum community_token *token, uint32_t *val) { const char *p = buf; @@ -573,8 +572,8 @@ community_gettoken(const char *buf, enum community_token *token, u_int32_t *val) if (isdigit((int)*p)) { int separator = 0; int digit = 0; - u_int32_t community_low = 0; - u_int32_t community_high = 0; + uint32_t community_low = 0; + uint32_t community_high = 0; while (isdigit((int)*p) || *p == ':') { if (*p == ':') { @@ -624,7 +623,7 @@ struct community *community_str2com(const char *str) { struct community *com = NULL; struct community *com_sort = NULL; - u_int32_t val = 0; + uint32_t val = 0; enum community_token token = community_token_unknown; do { diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h index 5016f132f2..c180bea465 100644 --- a/bgpd/bgp_community.h +++ b/bgpd/bgp_community.h @@ -32,7 +32,7 @@ struct community { int size; /* Communities value. */ - u_int32_t *val; + uint32_t *val; /* Communities as a json object */ json_object *json; @@ -60,7 +60,7 @@ extern void community_init(void); extern void community_finish(void); extern void community_free(struct community *); extern struct community *community_uniq_sort(struct community *); -extern struct community *community_parse(u_int32_t *, u_short); +extern struct community *community_parse(uint32_t *, unsigned short); extern struct community *community_intern(struct community *); extern void community_unintern(struct community **); extern char *community_str(struct community *, bool make_json); @@ -73,10 +73,10 @@ extern struct community *community_merge(struct community *, extern struct community *community_delete(struct community *, struct community *); extern struct community *community_dup(struct community *); -extern int community_include(struct community *, u_int32_t); -extern void community_del_val(struct community *, u_int32_t *); +extern int community_include(struct community *, uint32_t); +extern void community_del_val(struct community *, uint32_t *); extern unsigned long community_count(void); extern struct hash *community_hash(void); -extern u_int32_t community_val_get(struct community *com, int i); +extern uint32_t community_val_get(struct community *com, int i); #endif /* _QUAGGA_BGP_COMMUNITY_H */ diff --git a/bgpd/bgp_damp.c b/bgpd/bgp_damp.c index e2f97bf4fe..1ed557e074 100644 --- a/bgpd/bgp_damp.c +++ b/bgpd/bgp_damp.c @@ -523,7 +523,7 @@ void bgp_config_write_damp(struct vty *vty) } static const char *bgp_get_reuse_time(unsigned int penalty, char *buf, - size_t len, u_char use_json, + size_t len, uint8_t use_json, json_object *json) { time_t reuse_time = 0; @@ -641,7 +641,7 @@ void bgp_damp_info_vty(struct vty *vty, struct bgp_info *binfo, } const char *bgp_damp_reuse_time_vty(struct vty *vty, struct bgp_info *binfo, - char *timebuf, size_t len, u_char use_json, + char *timebuf, size_t len, uint8_t use_json, json_object *json) { struct bgp_damp_info *bdi; diff --git a/bgpd/bgp_damp.h b/bgpd/bgp_damp.h index 1139ef8394..d3b0ae42aa 100644 --- a/bgpd/bgp_damp.h +++ b/bgpd/bgp_damp.h @@ -53,7 +53,7 @@ struct bgp_damp_info { int index; /* Last time message type. */ - u_char lastrecord; + uint8_t lastrecord; #define BGP_RECORD_UPDATE 1U #define BGP_RECORD_WITHDRAW 2U @@ -141,7 +141,7 @@ extern void bgp_config_write_damp(struct vty *); extern void bgp_damp_info_vty(struct vty *, struct bgp_info *, json_object *json_path); extern const char *bgp_damp_reuse_time_vty(struct vty *, struct bgp_info *, - char *, size_t, u_char, + char *, size_t, uint8_t, json_object *); extern int bgp_show_dampening_parameters(struct vty *vty, afi_t, safi_t); diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index f867266956..ae4ff5d67e 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -42,6 +42,7 @@ #include "bgpd/bgp_ecommunity.h" #include "bgpd/bgp_label.h" #include "bgpd/bgp_evpn.h" +#include "bgpd/bgp_flowspec.h" unsigned long conf_bgp_debug_as4; unsigned long conf_bgp_debug_neighbor_events; @@ -56,6 +57,7 @@ unsigned long conf_bgp_debug_allow_martians; unsigned long conf_bgp_debug_nht; unsigned long conf_bgp_debug_update_groups; unsigned long conf_bgp_debug_vpn; +unsigned long conf_bgp_debug_flowspec; unsigned long term_bgp_debug_as4; unsigned long term_bgp_debug_neighbor_events; @@ -70,6 +72,7 @@ unsigned long term_bgp_debug_allow_martians; unsigned long term_bgp_debug_nht; unsigned long term_bgp_debug_update_groups; unsigned long term_bgp_debug_vpn; +unsigned long term_bgp_debug_flowspec; struct list *bgp_debug_neighbor_events_peers = NULL; struct list *bgp_debug_keepalive_peers = NULL; @@ -469,13 +472,13 @@ const char *bgp_notify_subcode_str(char code, char subcode) } /* extract notify admin reason if correctly present */ -const char *bgp_notify_admin_message(char *buf, size_t bufsz, u_char *data, +const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data, size_t datalen) { if (!data || datalen < 1) return NULL; - u_char len = data[0]; + uint8_t len = data[0]; if (len > 128 || len > datalen - 1) return NULL; @@ -1688,6 +1691,7 @@ DEFUN (no_debug_bgp, TERM_DEBUG_OFF(vpn, VPN_LEAK_TO_VRF); TERM_DEBUG_OFF(vpn, VPN_LEAK_RMAP_EVENT); TERM_DEBUG_OFF(vpn, VPN_LEAK_LABEL); + TERM_DEBUG_OFF(flowspec, FLOWSPEC); vty_out(vty, "All possible debugging has been turned off\n"); return CMD_SUCCESS; @@ -1758,6 +1762,8 @@ DEFUN_NOSH (show_debugging_bgp, vty_out(vty, " BGP vpn route-map event debugging is on\n"); if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) vty_out(vty, " BGP vpn label event debugging is on\n"); + if (BGP_DEBUG(flowspec, FLOWSPEC)) + vty_out(vty, " BGP flowspec debugging is on\n"); vty_out(vty, "\n"); return CMD_SUCCESS; @@ -1811,6 +1817,8 @@ int bgp_debug_count(void) ret++; if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) ret++; + if (BGP_DEBUG(flowspec, FLOWSPEC)) + ret++; return ret; } @@ -1904,6 +1912,10 @@ static int bgp_config_write_debug(struct vty *vty) vty_out(vty, "debug bgp vpn label\n"); write++; } + if (CONF_BGP_DEBUG(flowspec, FLOWSPEC)) { + vty_out(vty, "debug bgp flowspec\n"); + write++; + } return write; } @@ -2159,8 +2171,8 @@ int bgp_debug_zebra(struct prefix *p) const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi, struct prefix_rd *prd, union prefixconstptr pu, - mpls_label_t *label, u_int32_t num_labels, - int addpath_valid, u_int32_t addpath_id, + mpls_label_t *label, uint32_t num_labels, + int addpath_valid, uint32_t addpath_id, char *str, int size) { char rd_buf[RD_ADDRSTRLEN]; @@ -2192,7 +2204,7 @@ const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi, bgp_evpn_label2str(label, num_labels, tag_buf2, 20); sprintf(tag_buf, " label %s", tag_buf2); } else { - u_int32_t label_value; + uint32_t label_value; label_value = decode_label(label); sprintf(tag_buf, " label %u", label_value); @@ -2204,7 +2216,17 @@ const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi, prefix_rd2str(prd, rd_buf, sizeof(rd_buf)), prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf, pathid_buf, afi2str(afi), safi2str(safi)); - else + else if (safi == SAFI_FLOWSPEC) { + char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX]; + const struct prefix_fs *fs = pu.fs; + + bgp_fs_nlri_get_string((unsigned char *)fs->prefix.ptr, + fs->prefix.prefixlen, + return_string, + NLRI_STRING_FORMAT_DEBUG, NULL); + snprintf(str, size, "FS %s Match{%s}", afi2str(afi), + return_string); + } else snprintf(str, size, "%s%s%s %s %s", prefix2str(pu, pfx_buf, sizeof(pfx_buf)), tag_buf, pathid_buf, afi2str(afi), safi2str(safi)); diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index fe7ca8c46a..a0b179e213 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -73,6 +73,7 @@ extern unsigned long conf_bgp_debug_allow_martians; extern unsigned long conf_bgp_debug_nht; extern unsigned long conf_bgp_debug_update_groups; extern unsigned long conf_bgp_debug_vpn; +extern unsigned long conf_bgp_debug_flowspec; extern unsigned long term_bgp_debug_as4; extern unsigned long term_bgp_debug_neighbor_events; @@ -85,6 +86,7 @@ extern unsigned long term_bgp_debug_allow_martians; extern unsigned long term_bgp_debug_nht; extern unsigned long term_bgp_debug_update_groups; extern unsigned long term_bgp_debug_vpn; +extern unsigned long term_bgp_debug_flowspec; extern struct list *bgp_debug_neighbor_events_peers; extern struct list *bgp_debug_keepalive_peers; @@ -117,6 +119,7 @@ struct bgp_debug_filter { #define BGP_DEBUG_VPN_LEAK_TO_VRF 0x02 #define BGP_DEBUG_VPN_LEAK_RMAP_EVENT 0x04 #define BGP_DEBUG_VPN_LEAK_LABEL 0x08 +#define BGP_DEBUG_FLOWSPEC 0x01 #define BGP_DEBUG_PACKET_SEND 0x01 #define BGP_DEBUG_PACKET_SEND_DETAIL 0x02 @@ -161,9 +164,9 @@ extern int bgp_debug_zebra(struct prefix *p); extern int bgp_debug_count(void); extern const char *bgp_debug_rdpfxpath2str(afi_t, safi_t, struct prefix_rd *, union prefixconstptr, mpls_label_t *, - u_int32_t, int, u_int32_t, char *, + uint32_t, int, uint32_t, char *, int); -const char *bgp_notify_admin_message(char *buf, size_t bufsz, u_char *data, +const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data, size_t datalen); #endif /* _QUAGGA_BGP_DEBUG_H */ diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 4e998b1fd9..d69b1c46f2 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -277,7 +277,7 @@ static void bgp_dump_routes_index_table(struct bgp *bgp) if (sockunion_family(&peer->su) == AF_INET) { stream_put_in_addr(obuf, &peer->su.sin.sin_addr); } else if (sockunion_family(&peer->su) == AF_INET6) { - stream_write(obuf, (u_char *)&peer->su.sin6.sin6_addr, + stream_write(obuf, (uint8_t *)&peer->su.sin6.sin6_addr, IPV6_MAX_BYTELEN); } @@ -329,12 +329,12 @@ static struct bgp_info *bgp_dump_route_node_record(int afi, struct bgp_node *rn, if (afi == AFI_IP) { /* We'll dump only the useful bits (those not 0), but have to * align on 8 bits */ - stream_write(obuf, (u_char *)&rn->p.u.prefix4, + stream_write(obuf, (uint8_t *)&rn->p.u.prefix4, (rn->p.prefixlen + 7) / 8); } else if (afi == AFI_IP6) { /* We'll dump only the useful bits (those not 0), but have to * align on 8 bits */ - stream_write(obuf, (u_char *)&rn->p.u.prefix6, + stream_write(obuf, (uint8_t *)&rn->p.u.prefix6, (rn->p.prefixlen + 7) / 8); } diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index cea1c6baa2..54ec7d392b 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -33,6 +33,13 @@ #include "bgpd/bgp_ecommunity.h" #include "bgpd/bgp_lcommunity.h" #include "bgpd/bgp_aspath.h" +#include "bgpd/bgp_flowspec_private.h" + +/* struct used to dump the rate contained in FS set traffic-rate EC */ +union traffic_rate { + float rate_float; + uint8_t rate_byte[4]; +}; /* Hash of community attribute. */ static struct hash *ecomhash; @@ -68,7 +75,7 @@ static void ecommunity_hash_free(struct ecommunity *ecom) else return 0. */ int ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) { - u_int8_t *p; + uint8_t *p; int ret; int c; @@ -126,7 +133,7 @@ struct ecommunity *ecommunity_uniq_sort(struct ecommunity *ecom) } /* Parse Extended Communites Attribute in BGP packet. */ -struct ecommunity *ecommunity_parse(u_int8_t *pnt, u_short length) +struct ecommunity *ecommunity_parse(uint8_t *pnt, unsigned short length) { struct ecommunity tmp; struct ecommunity *new; @@ -283,8 +290,8 @@ enum ecommunity_token { * Encode BGP extended community from passed values. Supports types * defined in RFC 4360 and well-known sub-types. */ -static int ecommunity_encode(u_char type, u_char sub_type, int trans, as_t as, - struct in_addr ip, u_int32_t val, +static int ecommunity_encode(uint8_t type, uint8_t sub_type, int trans, as_t as, + struct in_addr ip, uint32_t val, struct ecommunity_val *eval) { assert(eval); @@ -338,8 +345,8 @@ static const char *ecommunity_gettoken(const char *str, char *endptr; struct in_addr ip; as_t as = 0; - u_int32_t val = 0; - u_char ecomm_type; + uint32_t val = 0; + uint8_t ecomm_type; char buf[INET_ADDRSTRLEN + 1]; /* Skip white space. */ @@ -547,7 +554,7 @@ struct ecommunity *ecommunity_str2com(const char *str, int type, return ecom; } -static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type, +static int ecommunity_rt_soo_str(char *buf, uint8_t *pnt, int type, int sub_type, int format) { int len = 0; @@ -628,7 +635,7 @@ static int ecommunity_rt_soo_str(char *buf, u_int8_t *pnt, int type, char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) { int i; - u_int8_t *pnt; + uint8_t *pnt; int type = 0; int sub_type = 0; #define ECOMMUNITY_STR_DEFAULT_LEN 27 @@ -661,8 +668,10 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) } /* Space between each value. */ - if (!first) + if (!first) { str_buf[str_pnt++] = ' '; + len++; + } pnt = ecom->val + (i * 8); @@ -712,8 +721,8 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) (uint8_t)rmac.octet[5]); } else if (*pnt == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY) { - u_int32_t seqnum; - u_char flags = *++pnt; + uint32_t seqnum; + uint8_t flags = *++pnt; memcpy(&seqnum, pnt + 2, 4); seqnum = ntohl(seqnum); @@ -727,6 +736,61 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) "MM:%u", seqnum); } else unk_ecom = 1; + } else if (type == ECOMMUNITY_ENCODE_TRANS_EXP) { + sub_type = *pnt++; + + if (sub_type == ECOMMUNITY_TRAFFIC_ACTION) { + char action[64]; + char *ptr = action; + + if (*(pnt+3) == + 1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL) + ptr += snprintf(ptr, sizeof(action), + "terminate (apply)"); + else + ptr += snprintf(ptr, sizeof(action), + "eval stops"); + if (*(pnt+3) == + 1 << FLOWSPEC_TRAFFIC_ACTION_SAMPLE) + snprintf(ptr, sizeof(action) - + (size_t)(ptr-action), + ", sample"); + len = snprintf(str_buf + str_pnt, + str_size - len, + "FS:action %s", action); + } else if (sub_type == ECOMMUNITY_TRAFFIC_RATE) { + union traffic_rate data; + + data.rate_byte[3] = *(pnt+2); + data.rate_byte[2] = *(pnt+3); + data.rate_byte[1] = *(pnt+4); + data.rate_byte[0] = *(pnt+5); + len = sprintf( + str_buf + str_pnt, + "FS:rate %f", data.rate_float); + } else if (sub_type == ECOMMUNITY_REDIRECT_VRF) { + char buf[16]; + + memset(buf, 0, sizeof(buf)); + ecommunity_rt_soo_str(buf, (uint8_t *)pnt, + type & + ~ECOMMUNITY_ENCODE_TRANS_EXP, + ECOMMUNITY_ROUTE_TARGET, + ECOMMUNITY_FORMAT_DISPLAY); + len = snprintf( + str_buf + str_pnt, + str_size - len, + "FS:redirect VRF %s", buf); + } else if (sub_type == ECOMMUNITY_TRAFFIC_MARKING) { + len = sprintf( + str_buf + str_pnt, + "FS:marking %u", *(pnt+5)); + } else if (sub_type == ECOMMUNITY_REDIRECT_IP_NH) { + len = sprintf( + str_buf + str_pnt, + "FS:redirect IP 0x%x", *(pnt+5)); + } else + unk_ecom = 1; } else unk_ecom = 1; @@ -774,7 +838,7 @@ int ecommunity_match(const struct ecommunity *ecom1, extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *ecom, uint8_t type, uint8_t subtype) { - u_int8_t *p; + uint8_t *p; int c; /* If the value already exists in the structure return 0. */ @@ -795,7 +859,7 @@ extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *ecom, extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type, uint8_t subtype) { - u_int8_t *p; + uint8_t *p; int c, found = 0; /* When this is fist value, just add it. */ if (ecom == NULL || ecom->val == NULL) { diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index c967f8bd47..31ff1481ba 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -27,10 +27,19 @@ #define ECOMMUNITY_ENCODE_AS4 0x02 #define ECOMMUNITY_ENCODE_OPAQUE 0x03 #define ECOMMUNITY_ENCODE_EVPN 0x06 +#define ECOMMUNITY_ENCODE_TRANS_EXP 0x80 /* Flow Spec */ +/* RFC7674 */ +#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_2 0x81 +#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82 /* Low-order octet of the Extended Communities type field. */ #define ECOMMUNITY_ROUTE_TARGET 0x02 #define ECOMMUNITY_SITE_ORIGIN 0x03 +#define ECOMMUNITY_TRAFFIC_RATE 0x06 /* Flow Spec */ +#define ECOMMUNITY_TRAFFIC_ACTION 0x07 +#define ECOMMUNITY_REDIRECT_VRF 0x08 +#define ECOMMUNITY_TRAFFIC_MARKING 0x09 +#define ECOMMUNITY_REDIRECT_IP_NH 0x00 /* Low-order octet of the Extended Communities type field for EVPN types */ #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00 @@ -53,7 +62,7 @@ #define ECOMMUNITY_SIZE 8 /* Extended Communities type flag. */ -#define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40 +#define ECOMMUNITY_FLAG_NON_TRANSITIVE 0x40 /* Extended Communities attribute. */ struct ecommunity { @@ -64,7 +73,7 @@ struct ecommunity { int size; /* Extended Communities value. */ - u_int8_t *val; + uint8_t *val; /* Human readable format string. */ char *str; @@ -90,7 +99,7 @@ struct ecommunity_val { /* * Encode BGP Route Target AS:nn. */ -static inline void encode_route_target_as(as_t as, u_int32_t val, +static inline void encode_route_target_as(as_t as, uint32_t val, struct ecommunity_val *eval) { eval->val[0] = ECOMMUNITY_ENCODE_AS; @@ -106,7 +115,7 @@ static inline void encode_route_target_as(as_t as, u_int32_t val, /* * Encode BGP Route Target IP:nn. */ -static inline void encode_route_target_ip(struct in_addr ip, u_int16_t val, +static inline void encode_route_target_ip(struct in_addr ip, uint16_t val, struct ecommunity_val *eval) { eval->val[0] = ECOMMUNITY_ENCODE_IP; @@ -119,7 +128,7 @@ static inline void encode_route_target_ip(struct in_addr ip, u_int16_t val, /* * Encode BGP Route Target AS4:nn. */ -static inline void encode_route_target_as4(as_t as, u_int16_t val, +static inline void encode_route_target_as4(as_t as, uint16_t val, struct ecommunity_val *eval) { eval->val[0] = ECOMMUNITY_ENCODE_AS4; @@ -135,7 +144,7 @@ static inline void encode_route_target_as4(as_t as, u_int16_t val, extern void ecommunity_init(void); extern void ecommunity_finish(void); extern void ecommunity_free(struct ecommunity **); -extern struct ecommunity *ecommunity_parse(u_int8_t *, u_short); +extern struct ecommunity *ecommunity_parse(uint8_t *, unsigned short); extern struct ecommunity *ecommunity_dup(struct ecommunity *); extern struct ecommunity *ecommunity_merge(struct ecommunity *, struct ecommunity *); diff --git a/bgpd/bgp_encap_types.h b/bgpd/bgp_encap_types.h index cf6f70cf5f..8d1bf682ad 100644 --- a/bgpd/bgp_encap_types.h +++ b/bgpd/bgp_encap_types.h @@ -82,7 +82,7 @@ struct bgp_tea_subtlv_color { /* per draft-rosen-idr-tunnel-encaps */ struct bgp_tea_subtlv_remote_endpoint { - u_char family; /* IPv4 or IPv6 */ + uint8_t family; /* IPv4 or IPv6 */ union { struct in_addr v4; struct in6_addr v6; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index c1fc45f070..e5e5f72699 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -335,7 +335,7 @@ static int evpn_route_target_cmp(struct ecommunity *ecom1, static inline void mask_ecom_global_admin(struct ecommunity_val *dst, struct ecommunity_val *src) { - u_char type; + uint8_t type; type = src->val[0]; dst->val[0] = 0; @@ -488,7 +488,7 @@ static void evpn_convert_nexthop_to_ipv6(struct attr *attr) static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, struct prefix_evpn *p, struct in_addr remote_vtep_ip, int add, - u_char flags) + uint8_t flags) { struct stream *s; int ipa_len; @@ -603,7 +603,7 @@ static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf, memset(&ecom_encap, 0, sizeof(ecom_encap)); encode_encap_extcomm(tnl_type, &eval); ecom_encap.size = 1; - ecom_encap.val = (u_int8_t *)eval.val; + ecom_encap.val = (uint8_t *)eval.val; /* Add Encap */ attr->ecommunity = ecommunity_dup(&ecom_encap); @@ -653,7 +653,7 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, bgp_encap_types tnl_type; struct listnode *node, *nnode; struct ecommunity *ecom; - u_int32_t seqnum; + uint32_t seqnum; struct list *vrf_export_rtl = NULL; /* Encap */ @@ -661,7 +661,7 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, memset(&ecom_encap, 0, sizeof(ecom_encap)); encode_encap_extcomm(tnl_type, &eval); ecom_encap.size = 1; - ecom_encap.val = (u_int8_t *)eval.val; + ecom_encap.val = (uint8_t *)eval.val; /* Add Encap */ attr->ecommunity = ecommunity_dup(&ecom_encap); @@ -689,7 +689,7 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, memset(&ecom_sticky, 0, sizeof(ecom_sticky)); encode_mac_mobility_extcomm(1, seqnum, &eval_sticky); ecom_sticky.size = 1; - ecom_sticky.val = (u_int8_t *)eval_sticky.val; + ecom_sticky.val = (uint8_t *)eval_sticky.val; attr->ecommunity = ecommunity_merge(attr->ecommunity, &ecom_sticky); } @@ -720,13 +720,13 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, /* * Add MAC mobility extended community to attribute. */ -static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) +static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr) { struct ecommunity ecom_tmp; struct ecommunity_val eval; - u_int8_t *ecom_val_ptr; + uint8_t *ecom_val_ptr; int i; - u_int8_t *pnt; + uint8_t *pnt; int type = 0; int sub_type = 0; @@ -745,9 +745,8 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) if (type == ECOMMUNITY_ENCODE_EVPN && sub_type == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY) { - ecom_val_ptr = - (u_int8_t *)(attr->ecommunity->val - + (i * 8)); + ecom_val_ptr = (uint8_t *)(attr->ecommunity->val + + (i * 8)); break; } } @@ -761,7 +760,7 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) else { memset(&ecom_tmp, 0, sizeof(ecom_tmp)); ecom_tmp.size = 1; - ecom_tmp.val = (u_int8_t *)eval.val; + ecom_tmp.val = (uint8_t *)eval.val; attr->ecommunity = ecommunity_merge(attr->ecommunity, &ecom_tmp); @@ -771,7 +770,7 @@ static void add_mac_mobility_to_attr(u_int32_t seq_num, struct attr *attr) /* Install EVPN route into zebra. */ static int evpn_zebra_install(struct bgp *bgp, struct bgpevpn *vpn, struct prefix_evpn *p, - struct in_addr remote_vtep_ip, u_char flags) + struct in_addr remote_vtep_ip, uint8_t flags) { int ret; @@ -848,7 +847,7 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn, afi_t afi = AFI_L2VPN; safi_t safi = SAFI_EVPN; int ret = 0; - u_char flags = 0; + uint8_t flags = 0; /* Compute the best path. */ bgp_best_selection(bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new, @@ -1111,15 +1110,15 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct prefix_evpn *evp, static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, afi_t afi, safi_t safi, struct bgp_node *rn, struct attr *attr, int add, int vni_table, - struct bgp_info **ri, u_char flags) + struct bgp_info **ri, uint8_t flags) { struct bgp_info *tmp_ri; struct bgp_info *local_ri, *remote_ri; struct attr *attr_new; mpls_label_t label[BGP_MAX_LABELS]; - u_int32_t num_labels = 1; + uint32_t num_labels = 1; int route_change = 1; - u_char sticky = 0; + uint8_t sticky = 0; struct prefix_evpn *evp; *ri = NULL; @@ -1167,7 +1166,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, * This will ensure that local routes are preferred for g/w macs */ if (remote_ri && !CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW)) { - u_int32_t cur_seqnum; + uint32_t cur_seqnum; /* Add MM extended community to route. */ cur_seqnum = mac_mobility_seqnum(remote_ri->attr); @@ -1260,7 +1259,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, * and schedule for processing. */ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, u_char flags) + struct prefix_evpn *p, uint8_t flags) { struct bgp_node *rn; struct attr attr; @@ -2083,8 +2082,8 @@ static int is_route_matching_for_vrf(struct bgp *bgp_vrf, struct bgp_info *ri) * matches, we're done. */ for (i = 0; i < ecom->size; i++) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; struct ecommunity_val *eval; struct ecommunity_val eval_tmp; struct vrf_irt_node *irt; @@ -2150,8 +2149,8 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn, * matches, we're done. */ for (i = 0; i < ecom->size; i++) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; struct ecommunity_val *eval; struct ecommunity_val eval_tmp; struct irt_node *irt; @@ -2519,8 +2518,8 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi, * the route into matching VNIs/VRFs. */ for (i = 0; i < ecom->size; i++) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; struct ecommunity_val *eval; struct ecommunity_val eval_tmp; struct irt_node *irt; /* import rt for l2vni */ @@ -2806,15 +2805,15 @@ static void withdraw_router_id_vni(struct hash_backet *backet, struct bgp *bgp) * Process received EVPN type-2 route (advertise or withdraw). */ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, - struct attr *attr, u_char *pfx, int psize, - u_int32_t addpath_id) + struct attr *attr, uint8_t *pfx, int psize, + uint32_t addpath_id) { struct prefix_rd prd; struct prefix_evpn p; - u_char ipaddr_len; - u_char macaddr_len; + uint8_t ipaddr_len; + uint8_t macaddr_len; mpls_label_t label[BGP_MAX_LABELS]; /* holds the VNI(s) as in packet */ - u_int32_t num_labels = 0; + uint32_t num_labels = 0; int ret; /* Type-2 route should be either 33, 37 or 49 bytes or an @@ -2915,12 +2914,12 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, * Process received EVPN type-3 route (advertise or withdraw). */ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, - struct attr *attr, u_char *pfx, int psize, - u_int32_t addpath_id) + struct attr *attr, uint8_t *pfx, int psize, + uint32_t addpath_id) { struct prefix_rd prd; struct prefix_evpn p; - u_char ipaddr_len; + uint8_t ipaddr_len; int ret; /* Type-3 route should be either 17 or 29 bytes: RD (8), Eth Tag (4), @@ -2988,14 +2987,14 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, * Process received EVPN type-5 route (advertise or withdraw). */ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi, - struct attr *attr, u_char *pfx, int psize, - u_int32_t addpath_id, int withdraw) + struct attr *attr, uint8_t *pfx, int psize, + uint32_t addpath_id, int withdraw) { struct prefix_rd prd; struct prefix_evpn p; struct bgp_route_evpn evpn; - u_char ippfx_len; - u_int32_t eth_tag; + uint8_t ippfx_len; + uint32_t eth_tag; mpls_label_t label; /* holds the VNI as in the packet */ int ret; @@ -3087,7 +3086,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi, static void evpn_mpattr_encode_type5(struct stream *s, struct prefix *p, struct prefix_rd *prd, mpls_label_t *label, - u_int32_t num_labels, struct attr *attr) + uint32_t num_labels, struct attr *attr) { int len; char temp[16]; @@ -3547,7 +3546,7 @@ int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn) /* * TODO: Hardcoded for a maximum of 2 VNIs right now */ -char *bgp_evpn_label2str(mpls_label_t *label, u_int32_t num_labels, char *buf, +char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, char *buf, int len) { vni_t vni1, vni2; @@ -3596,7 +3595,7 @@ void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json) buf1, sizeof(buf1))); } else { - u_char family; + uint8_t family; family = IS_EVPN_PREFIX_IPADDR_V4(p) ? AF_INET : AF_INET6; @@ -3647,7 +3646,7 @@ char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len) prefix_mac2str(&p->prefix.mac, buf1, sizeof(buf1))); else { - u_char family; + uint8_t family; family = IS_EVPN_PREFIX_IPADDR_V4(p) ? AF_INET : AF_INET6; @@ -3680,8 +3679,8 @@ char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len) */ void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p, struct prefix_rd *prd, mpls_label_t *label, - u_int32_t num_labels, struct attr *attr, - int addpath_encode, u_int32_t addpath_tx_id) + uint32_t num_labels, struct attr *attr, + int addpath_encode, uint32_t addpath_tx_id) { struct prefix_evpn *evp = (struct prefix_evpn *)p; int len, ipa_len = 0; @@ -3740,15 +3739,15 @@ void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p, int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, struct bgp_nlri *packet, int withdraw) { - u_char *pnt; - u_char *lim; + uint8_t *pnt; + uint8_t *lim; afi_t afi; safi_t safi; - u_int32_t addpath_id; + uint32_t addpath_id; int addpath_encoded; int psize = 0; - u_char rtype; - u_char rlen; + uint8_t rtype; + uint8_t rlen; struct prefix p; /* Start processing the NLRI - there may be multiple in the MP_REACH */ @@ -4042,7 +4041,7 @@ struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni, derive_rd_rt_for_vni(bgp, vpn); /* Initialize EVPN route table. */ - vpn->route_table = bgp_table_init(AFI_L2VPN, SAFI_EVPN); + vpn->route_table = bgp_table_init(bgp, AFI_L2VPN, SAFI_EVPN); /* Add to hash */ if (!hash_get(bgp->vnihash, vpn, hash_alloc_intern)) { @@ -4192,7 +4191,7 @@ int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, struct ethaddr *mac, * Handle add of a local MACIP. */ int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac, - struct ipaddr *ip, u_char flags) + struct ipaddr *ip, uint8_t flags) { struct bgpevpn *vpn; struct prefix_evpn p; @@ -4337,6 +4336,7 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id) struct bgp *bgp_vrf = NULL; /* bgp vrf instance */ struct bgp *bgp_def = NULL; /* default bgp instance */ struct listnode *node = NULL; + struct listnode *next = NULL; struct bgpevpn *vpn = NULL; bgp_vrf = bgp_lookup_by_vrf_id(vrf_id); @@ -4387,6 +4387,10 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id) } } + /* If any L2VNIs point to this instance, unlink them. */ + for (ALL_LIST_ELEMENTS(bgp_vrf->l2vnis, node, next, vpn)) + bgpevpn_unlink_from_l3vni(vpn); + /* Delete the instance if it was autocreated */ if (CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_AUTO)) bgp_delete(bgp_vrf); diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h index 7c0d638327..dd8d6e2e8e 100644 --- a/bgpd/bgp_evpn.h +++ b/bgpd/bgp_evpn.h @@ -36,7 +36,7 @@ static inline int is_evpn_enabled(void) static inline void vni2label(vni_t vni, mpls_label_t *label) { - u_char *tag = (u_char *)label; + uint8_t *tag = (uint8_t *)label; tag[0] = (vni >> 16) & 0xFF; tag[1] = (vni >> 8) & 0xFF; @@ -45,12 +45,12 @@ static inline void vni2label(vni_t vni, mpls_label_t *label) static inline vni_t label2vni(mpls_label_t *label) { - u_char *tag = (u_char *)label; + uint8_t *tag = (uint8_t *)label; vni_t vni; - vni = ((u_int32_t)*tag++ << 16); - vni |= (u_int32_t)*tag++ << 8; - vni |= (u_int32_t)(*tag & 0xFF); + vni = ((uint32_t)*tag++ << 16); + vni |= (uint32_t)*tag++ << 8; + vni |= (uint32_t)(*tag & 0xFF); return vni; } @@ -74,6 +74,32 @@ static inline int advertise_type5_routes(struct bgp *bgp_vrf, return 0; } +/* Flag if the route's parent is a EVPN route. */ +static inline int is_route_parent_evpn(struct bgp_info *ri) +{ + struct bgp_info *parent_ri; + struct bgp_table *table; + struct bgp_node *rn; + + /* If not imported (or doesn't have a parent), bail. */ + if (ri->sub_type != BGP_ROUTE_IMPORTED || + !ri->extra || + !ri->extra->parent) + return 0; + + /* See if the parent is of family L2VPN/EVPN */ + parent_ri = (struct bgp_info *)ri->extra->parent; + rn = parent_ri->net; + if (!rn) + return 0; + table = bgp_node_table(rn); + if (table && + table->afi == AFI_L2VPN && + table->safi == SAFI_EVPN) + return 1; + return 0; +} + extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p, struct attr *src_attr, afi_t afi, @@ -86,14 +112,14 @@ extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, safi_t safi); extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf); extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw); -extern char *bgp_evpn_label2str(mpls_label_t *label, u_int32_t num_labels, +extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, char *buf, int len); extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len); extern void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json); extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p, struct prefix_rd *prd, mpls_label_t *label, - u_int32_t num_labels, struct attr *attr, - int addpath_encode, u_int32_t addpath_tx_id); + uint32_t num_labels, struct attr *attr, + int addpath_encode, uint32_t addpath_tx_id); extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, struct bgp_nlri *packet, int withdraw); extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, @@ -105,7 +131,7 @@ extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, struct ethaddr *mac, struct ipaddr *ip); extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac, struct ipaddr *ip, - u_char flags); + uint8_t flags); extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id, struct ethaddr *rmac, struct in_addr originator_ip, int filter); diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index ce279005dc..1eecb9ecf7 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -55,7 +55,7 @@ typedef enum { struct bgpevpn { vni_t vni; vrf_id_t tenant_vrf_id; - u_int32_t flags; + uint32_t flags; #define VNI_FLAG_CFGD 0x1 /* VNI is user configured */ #define VNI_FLAG_LIVE 0x2 /* VNI is "live" */ #define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */ @@ -69,31 +69,31 @@ struct bgpevpn { /* Flag to indicate if we are * advertising the g/w mac ip for * this VNI*/ - u_int8_t advertise_gw_macip; + uint8_t advertise_gw_macip; - /* Flag to indicate if we are - * advertising subnet for this VNI */ - u_int8_t advertise_subnet; + /* Flag to indicate if we are + * advertising subnet for this VNI */ + uint8_t advertise_subnet; - /* Id for deriving the RD - * automatically for this VNI */ - u_int16_t rd_id; + /* Id for deriving the RD + * automatically for this VNI */ + uint16_t rd_id; - /* RD for this VNI. */ - struct prefix_rd prd; + /* RD for this VNI. */ + struct prefix_rd prd; - /* Route type 3 field */ - struct in_addr originator_ip; + /* Route type 3 field */ + struct in_addr originator_ip; - /* Import and Export RTs. */ - struct list *import_rtl; - struct list *export_rtl; + /* Import and Export RTs. */ + struct list *import_rtl; + struct list *export_rtl; - /* Route table for EVPN routes for - * this VNI. */ - struct bgp_table *route_table; + /* Route table for EVPN routes for + * this VNI. */ + struct bgp_table *route_table; - QOBJ_FIELDS + QOBJ_FIELDS }; DECLARE_QOBJ_TYPE(bgpevpn) @@ -254,7 +254,7 @@ static inline void encode_default_gw_extcomm(struct ecommunity_val *eval) eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DEF_GW; } -static inline void encode_mac_mobility_extcomm(int static_mac, u_int32_t seq, +static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq, struct ecommunity_val *eval) { memset(eval, 0, sizeof(*eval)); diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 3d77199bfd..8fd7cb5d14 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -56,8 +56,8 @@ struct vni_walk_ctx { static void display_vrf_import_rt(struct vty *vty, struct vrf_irt_node *irt, json_object *json) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; struct ecommunity_as eas; struct ecommunity_ip eip; struct listnode *node, *nnode; @@ -71,7 +71,7 @@ static void display_vrf_import_rt(struct vty *vty, struct vrf_irt_node *irt, json_vrfs = json_object_new_array(); } - pnt = (u_char *)&irt->rt.val; + pnt = (uint8_t *)&irt->rt.val; type = *pnt++; sub_type = *pnt++; if (sub_type != ECOMMUNITY_ROUTE_TARGET) @@ -164,8 +164,8 @@ static void show_vrf_import_rt_entry(struct hash_backet *backet, void *args[]) static void display_import_rt(struct vty *vty, struct irt_node *irt, json_object *json) { - u_char *pnt; - u_char type, sub_type; + uint8_t *pnt; + uint8_t type, sub_type; struct ecommunity_as eas; struct ecommunity_ip eip; struct listnode *node, *nnode; @@ -181,7 +181,7 @@ static void display_import_rt(struct vty *vty, struct irt_node *irt, /* TODO: This needs to go into a function */ - pnt = (u_char *)&irt->rt.val; + pnt = (uint8_t *)&irt->rt.val; type = *pnt++; sub_type = *pnt++; if (sub_type != ECOMMUNITY_ROUTE_TARGET) @@ -274,10 +274,10 @@ static void bgp_evpn_show_route_rd_header(struct vty *vty, struct bgp_node *rd_rn, json_object *json) { - u_int16_t type; + uint16_t type; struct rd_as rd_as; struct rd_ip rd_ip; - u_char *pnt; + uint8_t *pnt; char rd_str[RD_ADDRSTRLEN]; pnt = rd_rn->p.u.val; @@ -495,7 +495,7 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type, struct bgp_node *rn; struct bgp_info *ri; int header = 1; - u_int32_t prefix_cnt, path_cnt; + uint32_t prefix_cnt, path_cnt; prefix_cnt = path_cnt = 0; @@ -814,7 +814,7 @@ static void show_vni_entry(struct hash_backet *backet, void *args[]) static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, - int option, u_char use_json) + int option, uint8_t use_json) { afi_t afi = AFI_L2VPN; struct bgp *bgp; @@ -930,10 +930,10 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, header = 0; } if (rd_header) { - u_int16_t type; + uint16_t type; struct rd_as rd_as; struct rd_ip rd_ip; - u_char *pnt; + uint8_t *pnt; pnt = rn->p.u.val; @@ -1103,7 +1103,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_routes, union sockunion su; struct peer *peer; int ret; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); argv_find(argv, argc, "A.B.C.D", &idx_ipv4); @@ -1163,7 +1163,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_routes, union sockunion su; struct peer *peer; struct prefix_rd prd; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community); argv_find(argv, argc, "A.B.C.D", &idx_ipv4); @@ -1236,7 +1236,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_all_neighbor_advertised_routes, int ret; struct peer *peer; union sockunion su; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); argv_find(argv, argc, "A.B.C.D", &idx_ipv4); @@ -1294,7 +1294,7 @@ DEFUN(show_ip_bgp_l2vpn_evpn_rd_neighbor_advertised_routes, struct peer *peer; struct prefix_rd prd; union sockunion su; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); argv_find(argv, argc, "ASN:NN_OR_IP-ADDRESS:NN", &idx_ext_community); argv_find(argv, argc, "A.B.C.D", &idx_ipv4); @@ -1807,7 +1807,7 @@ static void evpn_show_import_rts(struct vty *vty, struct bgp *bgp, static void evpn_show_routes_vni_all(struct vty *vty, struct bgp *bgp, struct in_addr vtep_ip, json_object *json) { - u_int32_t num_vnis; + uint32_t num_vnis; struct vni_walk_ctx wctx; num_vnis = hashcount(bgp->vnihash); @@ -1834,7 +1834,7 @@ static void evpn_show_route_vni_multicast(struct vty *vty, struct bgp *bgp, struct prefix_evpn p; struct bgp_node *rn; struct bgp_info *ri; - u_int32_t path_cnt = 0; + uint32_t path_cnt = 0; afi_t afi; safi_t safi; json_object *json_paths = NULL; @@ -1903,7 +1903,7 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp, struct prefix_evpn p; struct bgp_node *rn; struct bgp_info *ri; - u_int32_t path_cnt = 0; + uint32_t path_cnt = 0; afi_t afi; safi_t safi; json_object *json_paths = NULL; @@ -1998,7 +1998,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp, struct bgp_info *ri; afi_t afi; safi_t safi; - u_int32_t path_cnt = 0; + uint32_t path_cnt = 0; json_object *json_paths = NULL; char prefix_str[BUFSIZ]; @@ -2065,7 +2065,7 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp, int rd_header = 1; afi_t afi; safi_t safi; - u_int32_t prefix_cnt, path_cnt; + uint32_t prefix_cnt, path_cnt; char rd_str[RD_ADDRSTRLEN]; json_object *json_rd = NULL; int add_rd_to_json = 0; @@ -2187,7 +2187,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, int rd_header; afi_t afi; safi_t safi; - u_int32_t prefix_cnt, path_cnt; + uint32_t prefix_cnt, path_cnt; afi = AFI_L2VPN; safi = SAFI_EVPN; @@ -2313,7 +2313,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, static void evpn_show_vni(struct vty *vty, struct bgp *bgp, vni_t vni, json_object *json) { - u_char found = 0; + uint8_t found = 0; struct bgpevpn *vpn; vpn = bgp_evpn_lookup_vni(bgp, vni); @@ -2906,10 +2906,10 @@ DEFUN(show_bgp_l2vpn_evpn_vni, struct bgp *bgp_def; vni_t vni; int idx = 0; - u_char uj = 0; + uint8_t uj = 0; json_object *json = NULL; - u_int32_t num_l2vnis = 0; - u_int32_t num_l3vnis = 0; + uint32_t num_l2vnis = 0; + uint32_t num_l3vnis = 0; uint32_t num_vnis = 0; struct listnode *node = NULL; struct bgp *bgp_temp = NULL; @@ -2992,7 +2992,7 @@ DEFUN(show_bgp_l2vpn_evpn_summary, JSON_STR) { int idx_vrf = 0; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); char *vrf = NULL; if (argv_find(argv, argc, "vrf", &idx_vrf)) @@ -3020,7 +3020,7 @@ DEFUN(show_bgp_l2vpn_evpn_route, struct bgp *bgp; int type_idx = 0; int type = 0; - u_char uj = 0; + uint8_t uj = 0; json_object *json = NULL; uj = use_json(argc, argv); @@ -3472,7 +3472,7 @@ DEFUN(show_bgp_l2vpn_evpn_vrf_import_rt, "Show vrf import route target\n" JSON_STR) { - u_char uj = 0; + uint8_t uj = 0; struct bgp *bgp_def = NULL; json_object *json = NULL; @@ -3509,7 +3509,7 @@ DEFUN(show_bgp_l2vpn_evpn_import_rt, JSON_STR) { struct bgp *bgp; - u_char uj = 0; + uint8_t uj = 0; json_object *json = NULL; bgp = bgp_get_default(); @@ -3902,7 +3902,7 @@ DEFUN (show_bgp_vrf_l3vni_info, json_object *json_vnis = NULL; json_object *json_export_rts = NULL; json_object *json_import_rts = NULL; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (uj) { json = json_object_new_object(); diff --git a/bgpd/bgp_flowspec.c b/bgpd/bgp_flowspec.c new file mode 100644 index 0000000000..5db7e37089 --- /dev/null +++ b/bgpd/bgp_flowspec.c @@ -0,0 +1,195 @@ +/* BGP FlowSpec for packet handling + * Portions: + * Copyright (C) 2017 ChinaTelecom SDN Group + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 "math.h" + +#include <zebra.h> +#include "prefix.h" + +#include "bgpd/bgpd.h" +#include "bgpd/bgp_route.h" +#include "bgpd/bgp_flowspec.h" +#include "bgpd/bgp_flowspec_util.h" +#include "bgpd/bgp_flowspec_private.h" +#include "bgpd/bgp_ecommunity.h" +#include "bgpd/bgp_debug.h" + +static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len) +{ + uint32_t offset = 0; + int type; + int ret = 0, error = 0; + + while (offset < len-1) { + type = nlri_content[offset]; + offset++; + switch (type) { + case FLOWSPEC_DEST_PREFIX: + case FLOWSPEC_SRC_PREFIX: + ret = bgp_flowspec_ip_address( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, &error); + break; + case FLOWSPEC_IP_PROTOCOL: + case FLOWSPEC_PORT: + case FLOWSPEC_DEST_PORT: + case FLOWSPEC_SRC_PORT: + case FLOWSPEC_ICMP_TYPE: + case FLOWSPEC_ICMP_CODE: + ret = bgp_flowspec_op_decode(BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, &error); + break; + case FLOWSPEC_TCP_FLAGS: + ret = bgp_flowspec_tcpflags_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, &error); + break; + case FLOWSPEC_PKT_LEN: + case FLOWSPEC_DSCP: + ret = bgp_flowspec_op_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, &error); + break; + case FLOWSPEC_FRAGMENT: + ret = bgp_flowspec_fragment_type_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, &error); + break; + default: + error = -1; + break; + } + offset += ret; + if (error < 0) + break; + } + return error; +} + +int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr, + struct bgp_nlri *packet, int withdraw) +{ + uint8_t *pnt; + uint8_t *lim; + afi_t afi; + safi_t safi; + int psize = 0; + uint8_t rlen; + struct prefix p; + int ret; + void *temp; + + /* Start processing the NLRI - there may be multiple in the MP_REACH */ + pnt = packet->nlri; + lim = pnt + packet->length; + afi = packet->afi; + safi = packet->safi; + + if (afi == AFI_IP6) { + zlog_err("BGP flowspec IPv6 not supported"); + return -1; + } + + if (packet->length >= FLOWSPEC_NLRI_SIZELIMIT) { + zlog_err("BGP flowspec nlri length maximum reached (%u)", + packet->length); + return -1; + } + + for (; pnt < lim; pnt += psize) { + /* Clear prefix structure. */ + memset(&p, 0, sizeof(struct prefix)); + + /* All FlowSpec NLRI begin with length. */ + if (pnt + 1 > lim) + return -1; + + psize = rlen = *pnt++; + + /* When packet overflow occur return immediately. */ + if (pnt + psize > lim) { + zlog_err("Flowspec NLRI length inconsistent ( size %u seen)", + psize); + return -1; + } + if (bgp_fs_nlri_validate(pnt, psize) < 0) { + zlog_err("Bad flowspec format or NLRI options not supported"); + return -1; + } + p.family = AF_FLOWSPEC; + p.prefixlen = 0; + /* Flowspec encoding is in bytes */ + p.u.prefix_flowspec.prefixlen = psize; + temp = XCALLOC(MTYPE_TMP, psize); + memcpy(temp, pnt, psize); + p.u.prefix_flowspec.ptr = (uintptr_t) temp; + + if (BGP_DEBUG(flowspec, FLOWSPEC)) { + char return_string[BGP_FLOWSPEC_NLRI_STRING_MAX]; + char local_string[BGP_FLOWSPEC_NLRI_STRING_MAX]; + char ec_string[BGP_FLOWSPEC_NLRI_STRING_MAX]; + char *s = NULL; + + bgp_fs_nlri_get_string((unsigned char *) + p.u.prefix_flowspec.ptr, + p.u.prefix_flowspec.prefixlen, + return_string, + NLRI_STRING_FORMAT_MIN, NULL); + snprintf(ec_string, BGP_FLOWSPEC_NLRI_STRING_MAX, + "EC{none}"); + if (attr && attr->ecommunity) { + s = ecommunity_ecom2str(attr->ecommunity, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + snprintf(ec_string, + BGP_FLOWSPEC_NLRI_STRING_MAX, + "EC{%s}", + s == NULL ? "none" : s); + } + snprintf(local_string, BGP_FLOWSPEC_NLRI_STRING_MAX, + "FS Rx %s %s %s %s", withdraw ? + "Withdraw":"Update", + afi2str(afi), return_string, + attr != NULL ? ec_string : ""); + zlog_info("%s", local_string); + } + /* Process the route. */ + if (!withdraw) + ret = bgp_update(peer, &p, 0, attr, + afi, safi, + ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, + NULL, NULL, 0, 0, NULL); + else + ret = bgp_withdraw(peer, &p, 0, attr, + afi, safi, + ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, + NULL, NULL, 0, NULL); + if (ret) { + zlog_err("Flowspec NLRI failed to be %s.", + attr ? "added" : "withdrawn"); + return -1; + } + } + return 0; +} diff --git a/bgpd/bgp_flowspec.h b/bgpd/bgp_flowspec.h new file mode 100644 index 0000000000..392b321530 --- /dev/null +++ b/bgpd/bgp_flowspec.h @@ -0,0 +1,50 @@ +/* BGP Flowspec header for packet handling + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 _FRR_BGP_FLOWSPEC_H +#define _FRR_BGP_FLOWSPEC_H + +#define NLRI_STRING_FORMAT_LARGE 0 +#define NLRI_STRING_FORMAT_DEBUG 1 +#define NLRI_STRING_FORMAT_MIN 2 +#define NLRI_STRING_FORMAT_JSON 3 +#define NLRI_STRING_FORMAT_JSON_SIMPLE 4 + +#define BGP_FLOWSPEC_NLRI_STRING_MAX 512 + +extern int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr, + struct bgp_nlri *packet, int withdraw); + +extern void bgp_flowspec_vty_init(void); + +extern int bgp_show_table_flowspec(struct vty *vty, struct bgp *bgp, afi_t afi, + struct bgp_table *table, + enum bgp_show_type type, + void *output_arg, uint8_t use_json, + int is_last, + unsigned long *output_cum, + unsigned long *total_cum); + +extern void bgp_fs_nlri_get_string(unsigned char *nlri_content, size_t len, + char *return_string, int format, + json_object *json_path); + +extern void route_vty_out_flowspec(struct vty *vty, struct prefix *p, + struct bgp_info *binfo, + int display, json_object *json_paths); +#endif /* _FRR_BGP_FLOWSPEC_H */ diff --git a/bgpd/bgp_flowspec_private.h b/bgpd/bgp_flowspec_private.h new file mode 100644 index 0000000000..dede4e03d3 --- /dev/null +++ b/bgpd/bgp_flowspec_private.h @@ -0,0 +1,44 @@ +/* BGP Flowspec header . private structs and defines + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 _FRR_BGP_FLOWSPEC_PRIVATE_H +#define _FRR_BGP_FLOWSPEC_PRIVATE_H + +#define FLOWSPEC_NLRI_SIZELIMIT 240 + +/* Flowspec raffic action bit*/ +#define FLOWSPEC_TRAFFIC_ACTION_TERMINAL 1 +#define FLOWSPEC_TRAFFIC_ACTION_SAMPLE 0 +#define FLOWSPEC_TRAFFIC_ACTION_DISTRIBUTE 1 + +/* Flow Spec Component Types */ +#define NUM_OF_FLOWSPEC_MATCH_TYPES 12 +#define FLOWSPEC_DEST_PREFIX 1 +#define FLOWSPEC_SRC_PREFIX 2 +#define FLOWSPEC_IP_PROTOCOL 3 +#define FLOWSPEC_PORT 4 +#define FLOWSPEC_DEST_PORT 5 +#define FLOWSPEC_SRC_PORT 6 +#define FLOWSPEC_ICMP_TYPE 7 +#define FLOWSPEC_ICMP_CODE 8 +#define FLOWSPEC_TCP_FLAGS 9 +#define FLOWSPEC_PKT_LEN 10 +#define FLOWSPEC_DSCP 11 +#define FLOWSPEC_FRAGMENT 12 + +#endif /* _FRR_BGP_FLOWSPEC_PRIVATE_H */ diff --git a/bgpd/bgp_flowspec_util.c b/bgpd/bgp_flowspec_util.c new file mode 100644 index 0000000000..007b27f17e --- /dev/null +++ b/bgpd/bgp_flowspec_util.c @@ -0,0 +1,458 @@ +/* BGP FlowSpec Utilities + * Portions: + * Copyright (C) 2017 ChinaTelecom SDN Group + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 "prefix.h" + +#include "bgp_table.h" +#include "bgp_flowspec_util.h" +#include "bgp_flowspec_private.h" + +static void hex2bin(uint8_t *hex, int *bin) +{ + int remainder = *hex; + int i = 0; + + while (remainder >= 1 && i < 8) { + bin[7-i] = remainder % 2; + remainder = remainder / 2; + i++; + } + for (; i < 8; i++) + bin[7-i] = 0; +} + +static int hexstr2num(uint8_t *hexstr, int len) +{ + int i = 0; + int num = 0; + + for (i = 0; i < len; i++) + num = hexstr[i] + 16*16*num; + return num; +} + + +/* + * handle the flowspec address src/dst or generic address NLRI + * return number of bytes analysed ( >= 0). + */ +int bgp_flowspec_ip_address(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error) +{ + char *display = (char *)result; /* for return_string */ + struct prefix *prefix = (struct prefix *)result; + uint32_t offset = 0; + struct prefix prefix_local; + int psize; + + *error = 0; + memset(&prefix_local, 0, sizeof(struct prefix)); + /* read the prefix length */ + prefix_local.prefixlen = nlri_ptr[offset]; + psize = PSIZE(prefix_local.prefixlen); + offset++; + /* TODO Flowspec IPv6 Support */ + prefix_local.family = AF_INET; + /* Prefix length check. */ + if (prefix_local.prefixlen > prefix_blen(&prefix_local) * 8) + *error = -1; + /* When packet overflow occur return immediately. */ + if (psize + offset > max_len) + *error = -1; + /* Defensive coding, double-check + * the psize fits in a struct prefix + */ + if (psize > (ssize_t)sizeof(prefix_local.u)) + *error = -1; + memcpy(&prefix_local.u.prefix, &nlri_ptr[offset], psize); + offset += psize; + switch (type) { + case BGP_FLOWSPEC_RETURN_STRING: + prefix2str(&prefix_local, display, + BGP_FLOWSPEC_STRING_DISPLAY_MAX); + break; + case BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE: + PREFIX_COPY_IPV4(prefix, &prefix_local) + break; + case BGP_FLOWSPEC_VALIDATE_ONLY: + default: + break; + } + return offset; +} + +/* + * handle the flowspec operator NLRI + * return number of bytes analysed + * if there is an error, the passed error param is used to give error: + * -1 if decoding error, + * if result is a string, its assumed length + * is BGP_FLOWSPEC_STRING_DISPLAY_MAX + */ +int bgp_flowspec_op_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error) +{ + int op[8]; + int len, value, value_size; + int loop = 0; + char *ptr = (char *)result; /* for return_string */ + uint32_t offset = 0; + int len_string = BGP_FLOWSPEC_STRING_DISPLAY_MAX; + int len_written; + + *error = 0; + do { + hex2bin(&nlri_ptr[offset], op); + offset++; + len = 2*op[2]+op[3]; + value_size = 1 << len; + value = hexstr2num(&nlri_ptr[offset], value_size); + /* can not be < and > at the same time */ + if (op[5] == 1 && op[6] == 1) + *error = -1; + /* if first element, AND bit can not be set */ + if (op[1] == 1 && loop == 0) + *error = -1; + switch (type) { + case BGP_FLOWSPEC_RETURN_STRING: + if (loop) { + len_written = snprintf(ptr, len_string, + ", "); + len_string -= len_written; + ptr += len_written; + } + if (op[5] == 1) { + len_written = snprintf(ptr, len_string, + "<"); + len_string -= len_written; + ptr += len_written; + } + if (op[6] == 1) { + len_written = snprintf(ptr, len_string, + ">"); + len_string -= len_written; + ptr += len_written; + } + if (op[7] == 1) { + len_written = snprintf(ptr, len_string, + "="); + len_string -= len_written; + ptr += len_written; + } + len_written = snprintf(ptr, len_string, + " %d ", value); + len_string -= len_written; + ptr += len_written; + break; + case BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE: + /* TODO : FS OPAQUE */ + break; + case BGP_FLOWSPEC_VALIDATE_ONLY: + default: + /* no action */ + break; + } + offset += value_size; + loop++; + } while (op[0] == 0 && offset < max_len - 1); + if (offset > max_len) + *error = -1; + /* use error parameter to count the number of entries */ + if (*error == 0) + *error = loop; + return offset; +} + + +/* + * handle the flowspec tcpflags field + * return number of bytes analysed + * if there is an error, the passed error param is used to give error: + * -1 if decoding error, + * if result is a string, its assumed length + * is BGP_FLOWSPEC_STRING_DISPLAY_MAX + */ +int bgp_flowspec_tcpflags_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error) +{ + int op[8]; + int len, value_size, loop = 0, value; + char *ptr = (char *)result; /* for return_string */ + uint32_t offset = 0; + int len_string = BGP_FLOWSPEC_STRING_DISPLAY_MAX; + int len_written; + + *error = 0; + do { + hex2bin(&nlri_ptr[offset], op); + /* if first element, AND bit can not be set */ + if (op[1] == 1 && loop == 0) + *error = -1; + offset++; + len = 2 * op[2] + op[3]; + value_size = 1 << len; + value = hexstr2num(&nlri_ptr[offset], value_size); + switch (type) { + case BGP_FLOWSPEC_RETURN_STRING: + if (op[1] == 1 && loop != 0) { + len_written = snprintf(ptr, len_string, + ", and "); + len_string -= len_written; + ptr += len_written; + } else if (op[1] == 0 && loop != 0) { + len_written = snprintf(ptr, len_string, + ", or "); + len_string -= len_written; + ptr += len_written; + } + len_written = snprintf(ptr, len_string, + "tcp flags is "); + len_string -= len_written; + ptr += len_written; + if (op[6] == 1) { + ptr += snprintf(ptr, len_string, + "not "); + len_string -= len_written; + ptr += len_written; + } + if (op[7] == 1) { + ptr += snprintf(ptr, len_string, + "exactly match "); + len_string -= len_written; + ptr += len_written; + } + ptr += snprintf(ptr, len_string, + "%d", value); + len_string -= len_written; + ptr += len_written; + break; + case BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE: + /* TODO : FS OPAQUE */ + break; + case BGP_FLOWSPEC_VALIDATE_ONLY: + default: + /* no action */ + break; + } + offset += value_size; + loop++; + } while (op[0] == 0 && offset < max_len - 1); + if (offset > max_len) + *error = -1; + /* use error parameter to count the number of entries */ + if (*error == 0) + *error = loop; + return offset; +} + +/* + * handle the flowspec fragment type field + * return error (returned values are invalid) or number of bytes analysed + * -1 if error in decoding + * >= 0 : number of bytes analysed (ok). + */ +int bgp_flowspec_fragment_type_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error) +{ + int op[8]; + int len, value, value_size, loop = 0; + char *ptr = (char *)result; /* for return_string */ + uint32_t offset = 0; + int len_string = BGP_FLOWSPEC_STRING_DISPLAY_MAX; + int len_written; + + *error = 0; + do { + hex2bin(&nlri_ptr[offset], op); + offset++; + len = 2 * op[2] + op[3]; + value_size = 1 << len; + value = hexstr2num(&nlri_ptr[offset], value_size); + if (value != 1 && value != 2 && value != 4 && value != 8) + *error = -1; + offset += value_size; + /* TODO : as per RFC5574 : first Fragment bits are Reserved + * does that mean that it is not possible + * to handle multiple occurences ? + * as of today, we only grab the first TCP fragment + */ + if (loop) { + *error = -2; + loop++; + continue; + } + switch (type) { + case BGP_FLOWSPEC_RETURN_STRING: + switch (value) { + case 1: + len_written = snprintf(ptr, len_string, + "dont-fragment"); + len_string -= len_written; + ptr += len_written; + break; + case 2: + len_written = snprintf(ptr, len_string, + "is-fragment"); + len_string -= len_written; + ptr += len_written; + break; + case 4: + len_written = snprintf(ptr, len_string, + "first-fragment"); + len_string -= len_written; + ptr += len_written; + break; + case 8: + len_written = snprintf(ptr, len_string, + "last-fragment"); + len_string -= len_written; + ptr += len_written; + break; + default: + {} + } + break; + case BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE: + /* TODO : FS OPAQUE */ + break; + case BGP_FLOWSPEC_VALIDATE_ONLY: + default: + /* no action */ + break; + } + loop++; + } while (op[0] == 0 && offset < max_len - 1); + if (offset > max_len) + *error = -1; + return offset; +} + + +static bool bgp_flowspec_contains_prefix(struct prefix *pfs, + struct prefix *input, + int prefix_check) +{ + uint32_t offset = 0; + int type; + int ret = 0, error = 0; + uint8_t *nlri_content = (uint8_t *)pfs->u.prefix_flowspec.ptr; + size_t len = pfs->u.prefix_flowspec.prefixlen; + struct prefix compare; + + error = 0; + while (offset < len-1 && error >= 0) { + type = nlri_content[offset]; + offset++; + switch (type) { + case FLOWSPEC_DEST_PREFIX: + case FLOWSPEC_SRC_PREFIX: + memset(&compare, 0, sizeof(struct prefix)); + ret = bgp_flowspec_ip_address( + BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE, + nlri_content+offset, + len - offset, + &compare, &error); + if (ret <= 0) + break; + if (prefix_check && + compare.prefixlen != input->prefixlen) + break; + if (compare.family != input->family) + break; + if ((input->family == AF_INET) && + IPV4_ADDR_SAME(&input->u.prefix4, + &compare.u.prefix4)) + return true; + if ((input->family == AF_INET6) && + IPV6_ADDR_SAME(&input->u.prefix6.s6_addr, + &compare.u.prefix6.s6_addr)) + return true; + break; + case FLOWSPEC_IP_PROTOCOL: + case FLOWSPEC_PORT: + case FLOWSPEC_DEST_PORT: + case FLOWSPEC_SRC_PORT: + case FLOWSPEC_ICMP_TYPE: + case FLOWSPEC_ICMP_CODE: + ret = bgp_flowspec_op_decode(BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content+offset, + len - offset, + NULL, &error); + break; + case FLOWSPEC_TCP_FLAGS: + ret = bgp_flowspec_tcpflags_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content+offset, + len - offset, + NULL, &error); + break; + case FLOWSPEC_PKT_LEN: + case FLOWSPEC_DSCP: + ret = bgp_flowspec_op_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, + &error); + break; + case FLOWSPEC_FRAGMENT: + ret = bgp_flowspec_fragment_type_decode( + BGP_FLOWSPEC_VALIDATE_ONLY, + nlri_content + offset, + len - offset, NULL, + &error); + break; + default: + error = -1; + break; + } + offset += ret; + } + return false; +} + +struct bgp_node *bgp_flowspec_get_match_per_ip(afi_t afi, + struct bgp_table *rib, + struct prefix *match, + int prefix_check) +{ + struct bgp_node *rn; + struct prefix *prefix; + + for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) { + prefix = &rn->p; + + if (prefix->family != AF_FLOWSPEC) + continue; + + if (bgp_flowspec_contains_prefix(prefix, match, prefix_check)) + return rn; + } + return NULL; +} diff --git a/bgpd/bgp_flowspec_util.h b/bgpd/bgp_flowspec_util.h new file mode 100644 index 0000000000..aa21461102 --- /dev/null +++ b/bgpd/bgp_flowspec_util.h @@ -0,0 +1,58 @@ +/* BGP Flowspec header for utilities + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 _FRR_BGP_FLOWSPEC_UTIL_H +#define _FRR_BGP_FLOWSPEC_UTIL_H + +#include "zclient.h" + +#define BGP_FLOWSPEC_STRING_DISPLAY_MAX 512 + +enum bgp_flowspec_util_nlri_t { + BGP_FLOWSPEC_VALIDATE_ONLY = 0, + BGP_FLOWSPEC_RETURN_STRING = 1, + BGP_FLOWSPEC_CONVERT_TO_NON_OPAQUE = 2, + BGP_FLOWSPEC_RETURN_JSON = 3, +}; + + +extern int bgp_flowspec_op_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error); + +extern int bgp_flowspec_ip_address(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error); + +extern int bgp_flowspec_tcpflags_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error); + +extern int bgp_flowspec_fragment_type_decode(enum bgp_flowspec_util_nlri_t type, + uint8_t *nlri_ptr, + uint32_t max_len, + void *result, int *error); + +extern struct bgp_node *bgp_flowspec_get_match_per_ip(afi_t afi, + struct bgp_table *rib, + struct prefix *match, + int prefix_check); +#endif /* _FRR_BGP_FLOWSPEC_UTIL_H */ diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c new file mode 100644 index 0000000000..247da5d183 --- /dev/null +++ b/bgpd/bgp_flowspec_vty.c @@ -0,0 +1,414 @@ +/* BGP FlowSpec VTY + * Copyright (C) 2018 6WIND + * + * FRRouting 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. + * + * FRRouting 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 "command.h" + +#include "bgpd/bgpd.h" +#include "bgpd/bgp_table.h" +#include "bgpd/bgp_attr.h" +#include "bgpd/bgp_ecommunity.h" +#include "bgpd/bgp_vty.h" +#include "bgpd/bgp_route.h" +#include "bgpd/bgp_aspath.h" +#include "bgpd/bgp_flowspec.h" +#include "bgpd/bgp_flowspec_util.h" +#include "bgpd/bgp_flowspec_private.h" +#include "bgpd/bgp_debug.h" + +/* Local Structures and variables declarations + * This code block hosts the struct declared that host the flowspec rules + * as well as some structure used to convert to stringx + */ + +static const struct message bgp_flowspec_display_large[] = { + {FLOWSPEC_DEST_PREFIX, "Destination Address"}, + {FLOWSPEC_SRC_PREFIX, "Source Address"}, + {FLOWSPEC_IP_PROTOCOL, "IP Protocol"}, + {FLOWSPEC_PORT, "Port"}, + {FLOWSPEC_DEST_PORT, "Destination Port"}, + {FLOWSPEC_SRC_PORT, "Source Port"}, + {FLOWSPEC_ICMP_TYPE, "ICMP Type"}, + {FLOWSPEC_ICMP_CODE, "ICMP Code"}, + {FLOWSPEC_TCP_FLAGS, "TCP Flags"}, + {FLOWSPEC_PKT_LEN, "Packet Length"}, + {FLOWSPEC_DSCP, "DSCP field"}, + {FLOWSPEC_FRAGMENT, "Packet Fragment"}, + {0} +}; + +static const struct message bgp_flowspec_display_min[] = { + {FLOWSPEC_DEST_PREFIX, "to"}, + {FLOWSPEC_SRC_PREFIX, "from"}, + {FLOWSPEC_IP_PROTOCOL, "proto"}, + {FLOWSPEC_PORT, "port"}, + {FLOWSPEC_DEST_PORT, "dstp"}, + {FLOWSPEC_SRC_PORT, "srcp"}, + {FLOWSPEC_ICMP_TYPE, "type"}, + {FLOWSPEC_ICMP_CODE, "code"}, + {FLOWSPEC_TCP_FLAGS, "flags"}, + {FLOWSPEC_PKT_LEN, "pktlen"}, + {FLOWSPEC_DSCP, "dscp"}, + {FLOWSPEC_FRAGMENT, "pktfrag"}, + {0} +}; + +#define FS_STRING_UPDATE(count, ptr, format, remaining_len) do { \ + int _len_written; \ + \ + if (((format) == NLRI_STRING_FORMAT_DEBUG) && (count)) {\ + _len_written = snprintf((ptr), (remaining_len), \ + ", "); \ + (remaining_len) -= _len_written; \ + (ptr) += _len_written; \ + } else if (((format) == NLRI_STRING_FORMAT_MIN) \ + && (count)) { \ + _len_written = snprintf((ptr), (remaining_len), \ + " "); \ + (remaining_len) -= _len_written; \ + (ptr) += _len_written; \ + } \ + count++; \ + } while (0) + +/* Parse FLOWSPEC NLRI + * passed return_string string has assumed length + * BGP_FLOWSPEC_STRING_DISPLAY_MAX + */ +void bgp_fs_nlri_get_string(unsigned char *nlri_content, size_t len, + char *return_string, int format, + json_object *json_path) +{ + uint32_t offset = 0; + int type; + int ret = 0, error = 0; + char *ptr = return_string; + char local_string[BGP_FLOWSPEC_STRING_DISPLAY_MAX]; + int count = 0; + char extra[2] = ""; + char pre_extra[2] = ""; + const struct message *bgp_flowspec_display; + enum bgp_flowspec_util_nlri_t type_util; + int len_string = BGP_FLOWSPEC_STRING_DISPLAY_MAX; + int len_written; + + if (format == NLRI_STRING_FORMAT_LARGE) { + snprintf(pre_extra, sizeof(pre_extra), "\t"); + snprintf(extra, sizeof(extra), "\n"); + bgp_flowspec_display = bgp_flowspec_display_large; + } else + bgp_flowspec_display = bgp_flowspec_display_min; + /* if needed. type_util can be set to other values */ + type_util = BGP_FLOWSPEC_RETURN_STRING; + error = 0; + while (offset < len-1 && error >= 0) { + type = nlri_content[offset]; + offset++; + switch (type) { + case FLOWSPEC_DEST_PREFIX: + case FLOWSPEC_SRC_PREFIX: + ret = bgp_flowspec_ip_address( + type_util, + nlri_content+offset, + len - offset, + local_string, &error); + if (ret <= 0) + break; + if (json_path) { + json_object_string_add(json_path, + lookup_msg(bgp_flowspec_display, type, ""), + local_string); + break; + } + FS_STRING_UPDATE(count, ptr, format, len_string); + len_written = snprintf(ptr, len_string, "%s%s %s%s", + pre_extra, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string, extra); + len_string -= len_written; + ptr += len_written; + break; + case FLOWSPEC_IP_PROTOCOL: + case FLOWSPEC_PORT: + case FLOWSPEC_DEST_PORT: + case FLOWSPEC_SRC_PORT: + case FLOWSPEC_ICMP_TYPE: + case FLOWSPEC_ICMP_CODE: + ret = bgp_flowspec_op_decode(type_util, + nlri_content+offset, + len - offset, + local_string, &error); + if (ret <= 0) + break; + if (json_path) { + json_object_string_add(json_path, + lookup_msg(bgp_flowspec_display, type, ""), + local_string); + break; + } + FS_STRING_UPDATE(count, ptr, format, len_string); + len_written = snprintf(ptr, len_string, "%s%s %s%s", + pre_extra, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string, extra); + len_string -= len_written; + ptr += len_written; + break; + case FLOWSPEC_TCP_FLAGS: + ret = bgp_flowspec_tcpflags_decode( + type_util, + nlri_content+offset, + len - offset, + local_string, &error); + if (ret <= 0) + break; + if (json_path) { + json_object_string_add(json_path, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string); + break; + } + FS_STRING_UPDATE(count, ptr, format, len_string); + len_written = snprintf(ptr, len_string, "%s%s %s%s", + pre_extra, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string, extra); + len_string -= len_written; + ptr += len_written; + break; + case FLOWSPEC_PKT_LEN: + case FLOWSPEC_DSCP: + ret = bgp_flowspec_op_decode( + type_util, + nlri_content + offset, + len - offset, local_string, + &error); + if (ret <= 0) + break; + if (json_path) { + json_object_string_add(json_path, + lookup_msg(bgp_flowspec_display, type, ""), + local_string); + break; + } + FS_STRING_UPDATE(count, ptr, format, len_string); + len_written = snprintf(ptr, len_string, "%s%s %s%s", + pre_extra, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string, extra); + len_string -= len_written; + ptr += len_written; + break; + case FLOWSPEC_FRAGMENT: + ret = bgp_flowspec_fragment_type_decode( + type_util, + nlri_content + offset, + len - offset, local_string, + &error); + if (ret <= 0) + break; + if (json_path) { + json_object_string_add(json_path, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string); + break; + } + FS_STRING_UPDATE(count, ptr, format, len_string); + len_written = snprintf(ptr, len_string, "%s%s %s%s", + pre_extra, + lookup_msg(bgp_flowspec_display, + type, ""), + local_string, extra); + len_string -= len_written; + ptr += len_written; + break; + default: + error = -1; + break; + } + offset += ret; + } +} + +void route_vty_out_flowspec(struct vty *vty, struct prefix *p, + struct bgp_info *binfo, + int display, json_object *json_paths) +{ + struct attr *attr; + char return_string[BGP_FLOWSPEC_STRING_DISPLAY_MAX]; + char *s; + json_object *json_nlri_path = NULL; + json_object *json_ecom_path = NULL; + json_object *json_time_path = NULL; + char timebuf[BGP_UPTIME_LEN]; + + /* Print prefix */ + if (p != NULL) { + if (p->family != AF_FLOWSPEC) + return; + if (json_paths) { + if (display == NLRI_STRING_FORMAT_JSON) + json_nlri_path = json_object_new_object(); + else + json_nlri_path = json_paths; + } + if (display == NLRI_STRING_FORMAT_LARGE) + vty_out(vty, "BGP flowspec entry: (flags 0x%x)\n", + binfo->flags); + bgp_fs_nlri_get_string((unsigned char *) + p->u.prefix_flowspec.ptr, + p->u.prefix_flowspec.prefixlen, + return_string, + display, + json_nlri_path); + if (display == NLRI_STRING_FORMAT_LARGE) + vty_out(vty, "%s", return_string); + else if (display == NLRI_STRING_FORMAT_DEBUG) + vty_out(vty, "%s", return_string); + else if (display == NLRI_STRING_FORMAT_MIN) + vty_out(vty, " %-30s", return_string); + else if (json_paths && display == NLRI_STRING_FORMAT_JSON) + json_object_array_add(json_paths, json_nlri_path); + } + if (!binfo) + return; + if (binfo->attr && binfo->attr->ecommunity) { + /* Print attribute */ + attr = binfo->attr; + s = ecommunity_ecom2str(attr->ecommunity, + ECOMMUNITY_FORMAT_ROUTE_MAP, 0); + if (!s) + return; + if (display == NLRI_STRING_FORMAT_LARGE) + vty_out(vty, "\t%s\n", s); + else if (display == NLRI_STRING_FORMAT_MIN) + vty_out(vty, "%s", s); + else if (json_paths) { + json_ecom_path = json_object_new_object(); + json_object_string_add(json_ecom_path, + "ecomlist", s); + if (display == NLRI_STRING_FORMAT_JSON) + json_object_array_add(json_paths, + json_ecom_path); + } + XFREE(MTYPE_ECOMMUNITY_STR, s); + } + peer_uptime(binfo->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL); + if (display == NLRI_STRING_FORMAT_LARGE) + vty_out(vty, "\tup for %8s\n", timebuf); + else if (json_paths) { + json_time_path = json_object_new_object(); + json_object_string_add(json_time_path, + "time", timebuf); + if (display == NLRI_STRING_FORMAT_JSON) + json_object_array_add(json_paths, json_time_path); + } + +} + +int bgp_show_table_flowspec(struct vty *vty, struct bgp *bgp, afi_t afi, + struct bgp_table *table, enum bgp_show_type type, + void *output_arg, uint8_t use_json, + int is_last, unsigned long *output_cum, + unsigned long *total_cum) +{ + struct bgp_info *ri; + struct bgp_node *rn; + unsigned long total_count = 0; + json_object *json_paths = NULL; + int display = NLRI_STRING_FORMAT_LARGE; + + if (type != bgp_show_type_detail) + return CMD_SUCCESS; + + for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { + if (rn->info == NULL) + continue; + if (use_json) { + json_paths = json_object_new_array(); + display = NLRI_STRING_FORMAT_JSON; + } + for (ri = rn->info; ri; ri = ri->next) { + total_count++; + route_vty_out_flowspec(vty, &rn->p, + ri, display, + json_paths); + + } + if (use_json) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext( + json_paths, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json_paths); + json_paths = NULL; + } + } + if (total_count && !use_json) + vty_out(vty, + "\nDisplayed %ld flowspec entries\n", + total_count); + return CMD_SUCCESS; +} + +DEFUN (debug_bgp_flowspec, + debug_bgp_flowspec_cmd, + "debug bgp flowspec", + DEBUG_STR + BGP_STR + "BGP allow flowspec debugging entries\n") +{ + if (vty->node == CONFIG_NODE) + DEBUG_ON(flowspec, FLOWSPEC); + else { + TERM_DEBUG_ON(flowspec, FLOWSPEC); + vty_out(vty, "BGP flowspec debugging is on\n"); + } + return CMD_SUCCESS; +} + +DEFUN (no_debug_bgp_flowspec, + no_debug_bgp_flowspec_cmd, + "no debug bgp flowspec", + NO_STR + DEBUG_STR + BGP_STR + "BGP allow flowspec debugging entries\n") +{ + if (vty->node == CONFIG_NODE) + DEBUG_OFF(flowspec, FLOWSPEC); + else { + TERM_DEBUG_OFF(flowspec, FLOWSPEC); + vty_out(vty, "BGP flowspec debugging is off\n"); + } + return CMD_SUCCESS; +} + +void bgp_flowspec_vty_init(void) +{ + install_element(ENABLE_NODE, &debug_bgp_flowspec_cmd); + install_element(CONFIG_NODE, &debug_bgp_flowspec_cmd); + install_element(ENABLE_NODE, &no_debug_bgp_flowspec_cmd); + install_element(CONFIG_NODE, &no_debug_bgp_flowspec_cmd); +} diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index e4a0a1d404..a11a4f78f7 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -166,8 +166,8 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) zlog_err( "[%s] Dropping pending packet on connection transfer:", peer->host); - u_int16_t type = stream_getc_from(peer->curr, - BGP_MARKER_SIZE + 2); + uint16_t type = stream_getc_from(peer->curr, + BGP_MARKER_SIZE + 2); bgp_dump_packet(peer, type, peer->curr); stream_free(peer->curr); peer->curr = NULL; @@ -763,8 +763,8 @@ int bgp_maxmed_onstartup_active(struct bgp *bgp) void bgp_maxmed_update(struct bgp *bgp) { - u_char maxmed_active; - u_int32_t maxmed_value; + uint8_t maxmed_active; + uint32_t maxmed_value; if (bgp->v_maxmed_admin) { maxmed_active = 1; @@ -1199,7 +1199,8 @@ static int bgp_stop_with_error(struct peer *peer) /* something went wrong, send notify and tear down */ -static int bgp_stop_with_notify(struct peer *peer, u_char code, u_char sub_code) +static int bgp_stop_with_notify(struct peer *peer, uint8_t code, + uint8_t sub_code) { /* Send notify to remote peer */ bgp_notify_send(peer, code, sub_code); @@ -1393,7 +1394,7 @@ int bgp_start(struct peer *peer) else connected = 0; - if (!bgp_find_or_add_nexthop(peer->bgp, + if (!bgp_find_or_add_nexthop(peer->bgp, peer->bgp, family2afi(peer->su.sa.sa_family), NULL, peer, connected)) { #if defined(HAVE_CUMULUS) diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 8621997419..3882ff8b56 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -281,7 +281,7 @@ static int bgp_process_reads(struct thread *thread) */ static uint16_t bgp_write(struct peer *peer) { - u_char type; + uint8_t type; struct stream *s; int num; int update_last_write = 0; diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index 546ed0ed68..ceca644de2 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -48,7 +48,7 @@ int bgp_parse_fec_update(void) struct bgp *bgp; struct bgp_table *table; struct prefix p; - u_int32_t label; + uint32_t label; afi_t afi; safi_t safi; @@ -124,7 +124,7 @@ void bgp_reg_dereg_for_label(struct bgp_node *rn, struct bgp_info *ri, int reg) struct stream *s; struct prefix *p; int command; - u_int16_t flags = 0; + uint16_t flags = 0; size_t flags_pos = 0; /* Check socket. */ @@ -164,13 +164,13 @@ void bgp_reg_dereg_for_label(struct bgp_node *rn, struct bgp_info *ri, int reg) zclient_send_message(zclient); } -static int bgp_nlri_get_labels(struct peer *peer, u_char *pnt, u_char plen, +static int bgp_nlri_get_labels(struct peer *peer, uint8_t *pnt, uint8_t plen, mpls_label_t *label) { - u_char *data = pnt; - u_char *lim = pnt + plen; - u_char llen = 0; - u_char label_depth = 0; + uint8_t *data = pnt; + uint8_t *lim = pnt + plen; + uint8_t llen = 0; + uint8_t label_depth = 0; for (; data < lim; data += BGP_LABEL_BYTES) { memcpy(label, data, BGP_LABEL_BYTES); @@ -200,17 +200,17 @@ static int bgp_nlri_get_labels(struct peer *peer, u_char *pnt, u_char plen, int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, struct bgp_nlri *packet) { - u_char *pnt; - u_char *lim; + uint8_t *pnt; + uint8_t *lim; struct prefix p; int psize = 0; int prefixlen; afi_t afi; safi_t safi; int addpath_encoded; - u_int32_t addpath_id; + uint32_t addpath_id; mpls_label_t label = MPLS_INVALID_LABEL; - u_char llen; + uint8_t llen; pnt = packet->nlri; lim = pnt + packet->length; diff --git a/bgpd/bgp_label.h b/bgpd/bgp_label.h index 0b5eaa7124..01bf8b372b 100644 --- a/bgpd/bgp_label.h +++ b/bgpd/bgp_label.h @@ -51,7 +51,7 @@ static inline int bgp_labeled_safi(safi_t safi) static inline int bgp_is_withdraw_label(mpls_label_t *label) { - u_char *pkt = (u_char *)label; + uint8_t *pkt = (uint8_t *)label; /* The check on pkt[2] for 0x00 or 0x02 is in case bgp_set_valid_label() * was called on the withdraw label */ @@ -63,7 +63,7 @@ static inline int bgp_is_withdraw_label(mpls_label_t *label) static inline int bgp_is_valid_label(mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; if (!t) return 0; return (t[2] & 0x02); @@ -71,14 +71,14 @@ static inline int bgp_is_valid_label(mpls_label_t *label) static inline void bgp_set_valid_label(mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; if (t) t[2] |= 0x02; } static inline void bgp_unset_valid_label(mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; if (t) t[2] &= ~0x02; } @@ -95,17 +95,17 @@ static inline void bgp_unregister_for_label(struct bgp_node *rn) } /* Label stream to value */ -static inline u_int32_t label_pton(mpls_label_t *label) +static inline uint32_t label_pton(mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; return ((((unsigned int)t[0]) << 12) | (((unsigned int)t[1]) << 4) | ((unsigned int)((t[2] & 0xF0) >> 4))); } /* Encode label values */ -static inline void label_ntop(u_int32_t l, int bos, mpls_label_t *label) +static inline void label_ntop(uint32_t l, int bos, mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; t[0] = ((l & 0x000FF000) >> 12); t[1] = ((l & 0x00000FF0) >> 4); t[2] = ((l & 0x0000000F) << 4); @@ -114,9 +114,9 @@ static inline void label_ntop(u_int32_t l, int bos, mpls_label_t *label) } /* Return BOS value of label stream */ -static inline u_char label_bos(mpls_label_t *label) +static inline uint8_t label_bos(mpls_label_t *label) { - u_char *t = (u_char *)label; + uint8_t *t = (uint8_t *)label; return (t[2] & 0x01); }; diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index 36980b7c24..09b3a8718a 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -66,7 +66,7 @@ static void lcommunity_hash_free(struct lcommunity *lcom) static int lcommunity_add_val(struct lcommunity *lcom, struct lcommunity_val *lval) { - u_int8_t *p; + uint8_t *p; int ret; int c; @@ -124,7 +124,7 @@ struct lcommunity *lcommunity_uniq_sort(struct lcommunity *lcom) } /* Parse Large Communites Attribute in BGP packet. */ -struct lcommunity *lcommunity_parse(u_int8_t *pnt, u_short length) +struct lcommunity *lcommunity_parse(uint8_t *pnt, unsigned short length) { struct lcommunity tmp; struct lcommunity *new; @@ -291,9 +291,9 @@ static const char *lcommunity_gettoken(const char *str, if (isdigit((int)*p)) { int separator = 0; int digit = 0; - u_int32_t globaladmin = 0; - u_int32_t localdata1 = 0; - u_int32_t localdata2 = 0; + uint32_t globaladmin = 0; + uint32_t localdata1 = 0; + uint32_t localdata2 = 0; while (isdigit((int)*p) || *p == ':') { if (*p == ':') { @@ -375,10 +375,10 @@ struct lcommunity *lcommunity_str2com(const char *str) return lcom; } -int lcommunity_include(struct lcommunity *lcom, u_char *ptr) +int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr) { int i; - u_char *lcom_ptr; + uint8_t *lcom_ptr; for (i = 0; i < lcom->size; i++) { lcom_ptr = lcom->val + (i * LCOMMUNITY_SIZE); @@ -394,14 +394,14 @@ int lcommunity_include(struct lcommunity *lcom, u_char *ptr) char *lcommunity_lcom2str(struct lcommunity *lcom, int format) { int i; - u_int8_t *pnt; + uint8_t *pnt; #define LCOMMUNITY_STR_DEFAULT_LEN 40 int str_size; int str_pnt; char *str_buf; int len = 0; int first = 1; - u_int32_t globaladmin, localdata1, localdata2; + uint32_t globaladmin, localdata1, localdata2; if (lcom->size == 0) { str_buf = XMALLOC(MTYPE_LCOMMUNITY_STR, 1); @@ -472,7 +472,7 @@ int lcommunity_match(const struct lcommunity *lcom1, } /* Delete one lcommunity. */ -void lcommunity_del_val(struct lcommunity *lcom, u_char *ptr) +void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr) { int i = 0; int c = 0; diff --git a/bgpd/bgp_lcommunity.h b/bgpd/bgp_lcommunity.h index 7576d7a980..78841accf3 100644 --- a/bgpd/bgp_lcommunity.h +++ b/bgpd/bgp_lcommunity.h @@ -38,7 +38,7 @@ struct lcommunity { int size; /* Large Communities value. */ - u_int8_t *val; + uint8_t *val; /* Human readable format string. */ char *str; @@ -54,7 +54,7 @@ struct lcommunity_val { extern void lcommunity_init(void); extern void lcommunity_finish(void); extern void lcommunity_free(struct lcommunity **); -extern struct lcommunity *lcommunity_parse(u_int8_t *, u_short); +extern struct lcommunity *lcommunity_parse(uint8_t *, unsigned short); extern struct lcommunity *lcommunity_dup(struct lcommunity *); extern struct lcommunity *lcommunity_merge(struct lcommunity *, struct lcommunity *); @@ -69,6 +69,6 @@ extern char *lcommunity_lcom2str(struct lcommunity *, int); extern int lcommunity_match(const struct lcommunity *, const struct lcommunity *); extern char *lcommunity_str(struct lcommunity *); -extern int lcommunity_include(struct lcommunity *lcom, u_char *ptr); -extern void lcommunity_del_val(struct lcommunity *lcom, u_char *ptr); +extern int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr); +extern void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr); #endif /* _QUAGGA_BGP_LCOMMUNITY_H */ diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index bf60f9c118..5158717b5d 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -337,7 +337,7 @@ int main(int argc, char **argv) frr_preinit(&bgpd_di, argc, argv); frr_opt_add( "p:l:rSne:", longopts, - " -p, --bgp_port Set bgp protocol's port number\n" + " -p, --bgp_port Set BGP listen port number (0 means do not listen).\n" " -l, --listenon Listen on specified address (implies -n)\n" " -r, --retain When program terminates, retain added route by bgpd.\n" " -n, --no_kernel Do not install route to kernel.\n" @@ -356,7 +356,7 @@ int main(int argc, char **argv) break; case 'p': tmp_port = atoi(optarg); - if (tmp_port <= 0 || tmp_port > 0xffff) + if (tmp_port < 0 || tmp_port > 0xffff) bgp_port = BGP_PORT_DEFAULT; else bgp_port = tmp_port; @@ -395,6 +395,8 @@ int main(int argc, char **argv) /* BGP master init. */ bgp_master_init(frr_init()); bm->port = bgp_port; + if (bgp_port == 0) + bgp_option_set(BGP_OPT_NO_LISTEN); bm->address = bgp_address; if (no_fib_flag) bgp_option_set(BGP_OPT_NO_FIB); diff --git a/bgpd/bgp_memory.c b/bgpd/bgp_memory.c index 64543ff019..4669fad3b7 100644 --- a/bgpd/bgp_memory.c +++ b/bgpd/bgp_memory.c @@ -119,3 +119,10 @@ DEFINE_MTYPE(BGPD, BGP_EVPN, "BGP EVPN Information") DEFINE_MTYPE(BGPD, BGP_EVPN_IMPORT_RT, "BGP EVPN Import RT") DEFINE_MTYPE(BGPD, BGP_EVPN_VRF_IMPORT_RT, "BGP EVPN VRF Import RT") DEFINE_MTYPE(BGPD, BGP_EVPN_MACIP, "BGP EVPN MAC IP") + +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC, "BGP flowspec") +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC_RULE, "BGP flowspec rule") +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC_RULE_STR, "BGP flowspec rule str") +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC_COMPILED, "BGP flowspec compiled") +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC_NAME, "BGP flowspec name") +DEFINE_MTYPE(BGPD, BGP_FLOWSPEC_INDEX, "BGP flowspec index") diff --git a/bgpd/bgp_memory.h b/bgpd/bgp_memory.h index fae98329c6..6fa3040a19 100644 --- a/bgpd/bgp_memory.h +++ b/bgpd/bgp_memory.h @@ -115,4 +115,12 @@ DECLARE_MTYPE(BGP_EVPN) DECLARE_MTYPE(BGP_EVPN_IMPORT_RT) DECLARE_MTYPE(BGP_EVPN_VRF_IMPORT_RT) DECLARE_MTYPE(BGP_EVPN_MACIP) + +DECLARE_MTYPE(BGP_FLOWSPEC) +DECLARE_MTYPE(BGP_FLOWSPEC_RULE) +DECLARE_MTYPE(BGP_FLOWSPEC_RULE_STR) +DECLARE_MTYPE(BGP_FLOWSPEC_COMPILED) +DECLARE_MTYPE(BGP_FLOWSPEC_NAME) +DECLARE_MTYPE(BGP_FLOWSPEC_INDEX) + #endif /* _QUAGGA_BGP_MEMORY_H */ diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 667be50842..e33f3d3477 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -46,7 +46,7 @@ * Record maximum-paths configuration for BGP instance */ int bgp_maximum_paths_set(struct bgp *bgp, afi_t afi, safi_t safi, int peertype, - u_int16_t maxpaths, u_int16_t options) + uint16_t maxpaths, uint16_t options) { if (!bgp || (afi >= AFI_MAX) || (safi >= SAFI_MAX)) return -1; @@ -370,7 +370,7 @@ struct bgp_info *bgp_info_mpath_first(struct bgp_info *binfo) * * Given the bestpath bgp_info, return the number of multipath entries */ -u_int32_t bgp_info_mpath_count(struct bgp_info *binfo) +uint32_t bgp_info_mpath_count(struct bgp_info *binfo) { if (!binfo->mpath) return 0; @@ -382,7 +382,7 @@ u_int32_t bgp_info_mpath_count(struct bgp_info *binfo) * * Sets the count of multipaths into bestpath's mpath element */ -static void bgp_info_mpath_count_set(struct bgp_info *binfo, u_int32_t count) +static void bgp_info_mpath_count_set(struct bgp_info *binfo, uint32_t count) { struct bgp_info_mpath *mpath; if (!count && !binfo->mpath) @@ -432,7 +432,7 @@ void bgp_info_mpath_update(struct bgp_node *rn, struct bgp_info *new_best, struct bgp_info *old_best, struct list *mp_list, struct bgp_maxpaths_cfg *mpath_cfg) { - u_int16_t maxpaths, mpath_count, old_mpath_count; + uint16_t maxpaths, mpath_count, old_mpath_count; struct listnode *mp_node, *mp_next_node; struct bgp_info *cur_mpath, *new_mpath, *next_mpath, *prev_mpath; int mpath_changed, debug; @@ -677,7 +677,7 @@ void bgp_info_mpath_aggregate_update(struct bgp_info *new_best, struct aspath *aspath; struct aspath *asmerge; struct attr *new_attr, *old_attr; - u_char origin; + uint8_t origin; struct community *community, *commerge; struct ecommunity *ecomm, *ecommerge; struct lcommunity *lcomm, *lcommerge; diff --git a/bgpd/bgp_mpath.h b/bgpd/bgp_mpath.h index 48af14eb79..1fa11d3d0e 100644 --- a/bgpd/bgp_mpath.h +++ b/bgpd/bgp_mpath.h @@ -36,15 +36,15 @@ struct bgp_info_mpath { struct bgp_info *mp_info; /* When attached to best path, the number of selected multipaths */ - u_int32_t mp_count; + uint32_t mp_count; /* Aggregated attribute for advertising multipath route */ struct attr *mp_attr; }; /* Functions to support maximum-paths configuration */ -extern int bgp_maximum_paths_set(struct bgp *, afi_t, safi_t, int, u_int16_t, - u_int16_t); +extern int bgp_maximum_paths_set(struct bgp *, afi_t, safi_t, int, uint16_t, + uint16_t); extern int bgp_maximum_paths_unset(struct bgp *, afi_t, safi_t, int); /* Functions used by bgp_best_selection to record current @@ -70,7 +70,7 @@ extern struct bgp_info *bgp_info_mpath_first(struct bgp_info *); extern struct bgp_info *bgp_info_mpath_next(struct bgp_info *); /* Accessors for multipath information */ -extern u_int32_t bgp_info_mpath_count(struct bgp_info *); +extern uint32_t bgp_info_mpath_count(struct bgp_info *); extern struct attr *bgp_info_mpath_attr(struct bgp_info *); #endif /* _QUAGGA_BGP_MPATH_H */ diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 9f740db325..06d82f654d 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -44,6 +44,7 @@ #include "bgpd/bgp_ecommunity.h" #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_nexthop.h" +#include "bgpd/bgp_nht.h" #if ENABLE_BGP_VNC #include "bgpd/rfapi/rfapi_backend.h" @@ -70,20 +71,20 @@ extern int argv_find_and_parse_vpnvx(struct cmd_token **argv, int argc, return ret; } -u_int32_t decode_label(mpls_label_t *label_pnt) +uint32_t decode_label(mpls_label_t *label_pnt) { - u_int32_t l; - u_char *pnt = (u_char *)label_pnt; + uint32_t l; + uint8_t *pnt = (uint8_t *)label_pnt; - l = ((u_int32_t)*pnt++ << 12); - l |= (u_int32_t)*pnt++ << 4; - l |= (u_int32_t)((*pnt & 0xf0) >> 4); + l = ((uint32_t)*pnt++ << 12); + l |= (uint32_t)*pnt++ << 4; + l |= (uint32_t)((*pnt & 0xf0) >> 4); return l; } void encode_label(mpls_label_t label, mpls_label_t *label_pnt) { - u_char *pnt = (u_char *)label_pnt; + uint8_t *pnt = (uint8_t *)label_pnt; if (pnt == NULL) return; *pnt++ = (label >> 12) & 0xff; @@ -94,12 +95,12 @@ void encode_label(mpls_label_t label, mpls_label_t *label_pnt) int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, struct bgp_nlri *packet) { - u_char *pnt; - u_char *lim; + uint8_t *pnt; + uint8_t *lim; struct prefix p; int psize = 0; int prefixlen; - u_int16_t type; + uint16_t type; struct rd_as rd_as; struct rd_ip rd_ip; struct prefix_rd prd; @@ -107,7 +108,7 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, afi_t afi; safi_t safi; int addpath_encoded; - u_int32_t addpath_id; + uint32_t addpath_id; /* Make prefix_rd */ prd.family = AF_UNSPEC; @@ -256,19 +257,14 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi) { mpls_label_t label = MPLS_LABEL_NONE; - const char *name = "default"; int debug = BGP_DEBUG(vpn, VPN_LEAK_LABEL); - if (debug && (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT)) { - name = bgp->name; - } - if (bgp->vrf_id == VRF_UNKNOWN) { if (debug) { zlog_debug( "%s: vrf %s: afi %s: vrf_id not set, " "can't set zebra vrf label", - __func__, name, afi2str(afi)); + __func__, bgp->name_pretty, afi2str(afi)); } return; } @@ -279,7 +275,8 @@ void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi) if (debug) { zlog_debug("%s: vrf %s: afi %s: setting label %d for vrf id %d", - __func__, name, afi2str(afi), label, bgp->vrf_id); + __func__, bgp->name_pretty, afi2str(afi), label, + bgp->vrf_id); } zclient_send_vrf_label(zclient, bgp->vrf_id, afi, label, ZEBRA_LSP_BGP); @@ -306,7 +303,7 @@ void vpn_leak_zebra_vrf_label_withdraw(struct bgp *bgp, afi_t afi) if (debug) { zlog_debug("%s: deleting label for vrf %s (id=%d)", __func__, - (bgp->name ? bgp->name : "default"), bgp->vrf_id); + bgp->name_pretty, bgp->vrf_id); } zclient_send_vrf_label(zclient, bgp->vrf_id, afi, label, ZEBRA_LSP_BGP); @@ -338,22 +335,31 @@ static int ecom_intersect(struct ecommunity *e1, struct ecommunity *e2) * returns pointer to new bgp_info upon success */ static struct bgp_info * -leak_update(struct bgp *bgp, /* destination bgp instance */ - struct bgp_node *bn, struct attr *new_attr, /* already interned */ - afi_t afi, safi_t safi, struct bgp_info *source_bi, u_char type, - u_char sub_type, mpls_label_t *label, int num_labels, void *parent, - struct bgp *bgp_orig, struct prefix *nexthop_orig, int debug) +leak_update( + struct bgp *bgp, /* destination bgp instance */ + struct bgp_node *bn, + struct attr *new_attr, /* already interned */ + afi_t afi, + safi_t safi, + struct bgp_info *source_bi, + mpls_label_t *label, + int num_labels, + void *parent, + struct bgp *bgp_orig, + struct prefix *nexthop_orig, + int nexthop_self_flag, + int debug) { struct prefix *p = &bn->p; struct bgp_info *bi; struct bgp_info *new; char buf_prefix[PREFIX_STRLEN]; - const char *pDestInstanceName = "default"; if (debug) { prefix2str(&bn->p, buf_prefix, sizeof(buf_prefix)); - if (bgp->name) - pDestInstanceName = bgp->name; + zlog_debug("%s: entry: leak-to=%s, p=%s, type=%d, sub_type=%d", + __func__, bgp->name_pretty, buf_prefix, + source_bi->type, source_bi->sub_type); } /* @@ -372,7 +378,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ if (debug) zlog_debug( "%s: ->%s: %s: Found route, no change", - __func__, pDestInstanceName, + __func__, bgp->name_pretty, buf_prefix); return NULL; } @@ -389,6 +395,35 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ bi->attr = new_attr; bi->uptime = bgp_clock(); + if (nexthop_self_flag) + bgp_info_set_flag(bn, bi, BGP_INFO_ANNC_NH_SELF); + + struct bgp *bgp_nexthop = bgp; + int nh_valid; + + if (bi->extra && bi->extra->bgp_orig) + bgp_nexthop = bi->extra->bgp_orig; + + /* No nexthop tracking for redistributed routes */ + if (source_bi->sub_type == BGP_ROUTE_REDISTRIBUTE) + nh_valid = 1; + else + /* + * TBD do we need to do anything about the + * 'connected' parameter? + */ + nh_valid = bgp_find_or_add_nexthop( + bgp, bgp_nexthop, + afi, bi, NULL, 0); + + if (debug) + zlog_debug("%s: nexthop is %svalid (in vrf %s)", + __func__, (nh_valid ? "" : "not "), + bgp_nexthop->name_pretty); + + if (nh_valid) + bgp_info_set_flag(bn, bi, BGP_INFO_VALID); + /* Process change. */ bgp_aggregate_increment(bgp, p, bi, afi, safi); bgp_process(bgp, bn, afi, safi); @@ -396,13 +431,16 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ if (debug) zlog_debug("%s: ->%s: %s Found route, changed attr", - __func__, pDestInstanceName, buf_prefix); + __func__, bgp->name_pretty, buf_prefix); return NULL; } - new = info_make(type, sub_type, 0, bgp->peer_self, new_attr, bn); - SET_FLAG(new->flags, BGP_INFO_VALID); + new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, 0, + bgp->peer_self, new_attr, bn); + + if (nexthop_self_flag) + bgp_info_set_flag(bn, new, BGP_INFO_ANNC_NH_SELF); bgp_info_extra_get(new); if (label) { @@ -428,6 +466,37 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ if (nexthop_orig) new->extra->nexthop_orig = *nexthop_orig; + /* + * nexthop tracking for unicast routes + */ + struct bgp *bgp_nexthop = bgp; + int nh_valid; + + if (new->extra && new->extra->bgp_orig) + bgp_nexthop = new->extra->bgp_orig; + + /* + * No nexthop tracking for redistributed routes because + * their originating protocols will do the tracking and + * withdraw those routes if the nexthops become unreachable + */ + if (source_bi->sub_type == BGP_ROUTE_REDISTRIBUTE) + nh_valid = 1; + else + /* + * TBD do we need to do anything about the + * 'connected' parameter? + */ + nh_valid = bgp_find_or_add_nexthop(bgp, bgp_nexthop, + afi, new, NULL, 0); + + if (debug) + zlog_debug("%s: nexthop is %svalid (in vrf %s)", + __func__, (nh_valid ? "" : "not "), + bgp_nexthop->name_pretty); + if (nh_valid) + bgp_info_set_flag(bn, new, BGP_INFO_VALID); + bgp_aggregate_increment(bgp, p, new, afi, safi); bgp_info_add(bn, new); @@ -436,7 +505,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ if (debug) zlog_debug("%s: ->%s: %s: Added new route", __func__, - pDestInstanceName, buf_prefix); + bgp->name_pretty, buf_prefix); return new; } @@ -456,6 +525,10 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ mpls_label_t label; struct bgp_node *bn; const char *debugmsg; + int nexthop_self_flag = 0; + + if (debug) + zlog_debug("%s: from vrf %s", __func__, bgp_vrf->name_pretty); if (debug && info_vrf->attr->ecommunity) { char *s = ecommunity_ecom2str(info_vrf->attr->ecommunity, @@ -506,7 +579,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ if (debug) zlog_debug( "%s: vrf %s route map \"%s\" says DENY, returning", - __func__, bgp_vrf->name, + __func__, bgp_vrf->name_pretty, bgp_vrf->vpn_policy[afi] .rmap[BGP_VPN_POLICY_DIR_TOVPN] ->name); @@ -580,23 +653,14 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ assert(0); } } else { - switch (afi) { - case AFI_IP: - default: - /* Clear ipv4 */ - static_attr.mp_nexthop_global_in.s_addr = 0; + if (afi == AFI_IP) { + /* For ipv4, copy to multiprotocol nexthop field */ + static_attr.mp_nexthop_global_in = static_attr.nexthop; static_attr.mp_nexthop_len = 4; - static_attr.nexthop.s_addr = 0; /* self */ - static_attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); - break; - - case AFI_IP6: - /* Clear ipv6 */ - memset(&static_attr.mp_nexthop_global, 0, - sizeof(static_attr.mp_nexthop_global)); - static_attr.mp_nexthop_len = 16; /* bytes */ - break; + /* XXX Leave static_attr.nexthop intact for NHT */ + static_attr.flag &= ~ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); } + nexthop_self_flag = 1; } label_val = bgp_vrf->vpn_policy[afi].tovpn_label; @@ -632,8 +696,8 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ struct bgp_info *new_info; new_info = leak_update(bgp_vpn, bn, new_attr, afi, safi, info_vrf, - ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, &label, 1, - info_vrf, bgp_vrf, NULL, debug); + &label, 1, info_vrf, bgp_vrf, NULL, + nexthop_self_flag, debug); /* * Routes actually installed in the vpn RIB must also be @@ -659,6 +723,15 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */ struct bgp_info *bi; struct bgp_node *bn; const char *debugmsg; + char buf_prefix[PREFIX_STRLEN]; + + if (debug) { + prefix2str(p, buf_prefix, sizeof(buf_prefix)); + zlog_debug( + "%s: entry: leak-from=%s, p=%s, type=%d, sub_type=%d", + __func__, bgp_vrf->name_pretty, buf_prefix, + info_vrf->type, info_vrf->sub_type); + } if (info_vrf->type != ZEBRA_ROUTE_BGP) { if (debug) @@ -785,7 +858,7 @@ void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, /* to */ if (debug) zlog_debug("%s: entry, afi=%d, vrf=%s", __func__, afi, - bgp_vrf->name); + bgp_vrf->name_pretty); for (bn = bgp_table_top(bgp_vrf->rib[afi][SAFI_UNICAST]); bn; bn = bgp_route_next(bn)) { @@ -818,6 +891,7 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ struct prefix nexthop_orig; mpls_label_t *pLabels = NULL; int num_labels = 0; + int nexthop_self_flag = 1; int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF); @@ -836,7 +910,8 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ } if (debug) - zlog_debug("%s: updating to vrf %s", __func__, bgp_vrf->name); + zlog_debug("%s: updating to vrf %s", __func__, + bgp_vrf->name_pretty); bgp_attr_dup(&static_attr, info_vpn->attr); /* shallow copy */ @@ -858,20 +933,13 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ /* save */ nexthop_orig.u.prefix4 = info_vpn->attr->mp_nexthop_global_in; nexthop_orig.prefixlen = 32; - - static_attr.nexthop.s_addr = 0; /* self */ static_attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); - break; case AF_INET6: /* save */ nexthop_orig.u.prefix6 = info_vpn->attr->mp_nexthop_global; nexthop_orig.prefixlen = 128; - - memset(&static_attr.mp_nexthop_global, 0, - sizeof(static_attr.mp_nexthop_global)); /* clear */ - static_attr.mp_nexthop_len = 16; /* bytes */ break; } @@ -894,12 +962,18 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ if (debug) zlog_debug( "%s: vrf %s vpn-policy route map \"%s\" says DENY, returning", - __func__, bgp_vrf->name, + __func__, bgp_vrf->name_pretty, bgp_vrf->vpn_policy[afi] .rmap[BGP_VPN_POLICY_DIR_FROMVPN] ->name); return; } + /* + * if route-map changed nexthop, don't nexthop-self on output + */ + if (!CHECK_FLAG(static_attr.rmap_change_flags, + BATTR_RMAP_NEXTHOP_UNCHANGED)) + nexthop_self_flag = 0; } new_attr = bgp_attr_intern(&static_attr); @@ -923,10 +997,10 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ num_labels); } - leak_update(bgp_vrf, bn, new_attr, afi, safi, info_vpn, ZEBRA_ROUTE_BGP, - BGP_ROUTE_IMPORTED, pLabels, num_labels, - info_vpn, /* parent */ - bgp_vpn, &nexthop_orig, debug); + leak_update(bgp_vrf, bn, new_attr, afi, safi, info_vpn, + pLabels, num_labels, + info_vpn, /* parent */ + bgp_vpn, &nexthop_orig, nexthop_self_flag, debug); } void vpn_leak_to_vrf_update(struct bgp *bgp_vpn, /* from */ @@ -961,9 +1035,17 @@ void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */ struct bgp_node *bn; struct bgp_info *bi; const char *debugmsg; + char buf_prefix[PREFIX_STRLEN]; int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF); + if (debug) { + prefix2str(&info_vpn->net->p, buf_prefix, sizeof(buf_prefix)); + zlog_debug("%s: entry: p=%s, type=%d, sub_type=%d", + __func__, buf_prefix, + info_vpn->type, info_vpn->sub_type); + } + if (debug) zlog_debug("%s: start (info_vpn=%p)", __func__, info_vpn); @@ -1004,7 +1086,7 @@ void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */ if (debug) zlog_debug("%s: withdrawing from vrf %s", __func__, - bgp->name); + bgp->name_pretty); bn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); for (bi = (bn ? bn->info : NULL); bi; bi = bi->next) { @@ -1307,7 +1389,7 @@ DEFUN (no_vpnv6_network, int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, int tags, - u_char use_json) + uint8_t use_json) { struct bgp *bgp; struct bgp_table *table; @@ -1485,7 +1567,7 @@ DEFUN (show_ip_bgp_vpn_all_neighbor_routes, union sockunion su; struct peer *peer; int ret; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); afi_t afi; int idx = 0; @@ -1549,7 +1631,7 @@ DEFUN (show_ip_bgp_vpn_rd_neighbor_routes, union sockunion su; struct peer *peer; struct prefix_rd prd; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); afi_t afi; int idx = 0; @@ -1627,7 +1709,7 @@ DEFUN (show_ip_bgp_vpn_all_neighbor_advertised_routes, int ret; struct peer *peer; union sockunion su; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); afi_t afi; int idx = 0; @@ -1689,7 +1771,7 @@ DEFUN (show_ip_bgp_vpn_rd_neighbor_advertised_routes, struct peer *peer; struct prefix_rd prd; union sockunion su; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); afi_t afi; int idx = 0; @@ -1774,3 +1856,22 @@ void bgp_mplsvpn_init(void) &show_ip_bgp_vpn_rd_neighbor_advertised_routes_cmd); #endif /* KEEP_OLD_VPN_COMMANDS */ } + +vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey) +{ + struct listnode *mnode, *mnnode; + struct bgp *bgp; + + for (ALL_LIST_ELEMENTS(bm->bgp, mnode, mnnode, bgp)) { + struct ecommunity *ec; + + if (bgp->inst_type != BGP_INSTANCE_TYPE_VRF) + continue; + + ec = bgp->vpn_policy[AFI_IP].import_redirect_rtlist; + + if (ecom_intersect(ec, eckey)) + return bgp->vrf_id; + } + return VRF_UNKNOWN; +} diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index d35568b838..64303325ee 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -43,14 +43,14 @@ extern void bgp_mplsvpn_init(void); extern int bgp_nlri_parse_vpn(struct peer *, struct attr *, struct bgp_nlri *); -extern u_int32_t decode_label(mpls_label_t *); +extern uint32_t decode_label(mpls_label_t *); extern void encode_label(mpls_label_t, mpls_label_t *); extern int argv_find_and_parse_vpnvx(struct cmd_token **argv, int argc, int *index, afi_t *afi); extern int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, - int tags, u_char use_json); + int tags, uint8_t use_json); extern void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, struct bgp *bgp_vrf, struct bgp_info *info_vrf); @@ -176,4 +176,6 @@ static inline void vpn_leak_postchange(vpn_policy_direction_t direction, extern void vpn_policy_routemap_event(const char *rmap_name); +extern vrf_id_t get_first_vrf_for_redirect_with_rt(struct ecommunity *eckey); + #endif /* _QUAGGA_BGP_MPLSVPN_H */ diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 79463ee142..3700778c73 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -632,10 +632,11 @@ void bgp_scan_init(struct bgp *bgp) for (afi = AFI_IP; afi < AFI_MAX; afi++) { bgp->nexthop_cache_table[afi] = - bgp_table_init(afi, SAFI_UNICAST); - bgp->connected_table[afi] = bgp_table_init(afi, SAFI_UNICAST); + bgp_table_init(bgp, afi, SAFI_UNICAST); + bgp->connected_table[afi] = bgp_table_init(bgp, afi, + SAFI_UNICAST); bgp->import_check_table[afi] = - bgp_table_init(afi, SAFI_UNICAST); + bgp_table_init(bgp, afi, SAFI_UNICAST); } } diff --git a/bgpd/bgp_nexthop.h b/bgpd/bgp_nexthop.h index 2c5b2ab118..519f092762 100644 --- a/bgpd/bgp_nexthop.h +++ b/bgpd/bgp_nexthop.h @@ -38,13 +38,13 @@ /* BGP nexthop cache value structure. */ struct bgp_nexthop_cache { /* IGP route's metric. */ - u_int32_t metric; + uint32_t metric; /* Nexthop number and nexthop linked list.*/ - u_char nexthop_num; + uint8_t nexthop_num; struct nexthop *nexthop; time_t last_update; - u_int16_t flags; + uint16_t flags; #define BGP_NEXTHOP_VALID (1 << 0) #define BGP_NEXTHOP_REGISTERED (1 << 1) @@ -52,8 +52,9 @@ struct bgp_nexthop_cache { #define BGP_NEXTHOP_PEER_NOTIFIED (1 << 3) #define BGP_STATIC_ROUTE (1 << 4) #define BGP_STATIC_ROUTE_EXACT_MATCH (1 << 5) +#define BGP_NEXTHOP_LABELED_VALID (1 << 6) - u_int16_t change_flags; + uint16_t change_flags; #define BGP_NEXTHOP_CHANGED (1 << 0) #define BGP_NEXTHOP_METRIC_CHANGED (1 << 1) diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 54c0f85cb3..8b6ff3fa22 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -59,6 +59,12 @@ static int bgp_isvalid_nexthop(struct bgp_nexthop_cache *bnc) || (bnc && CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID))); } +static int bgp_isvalid_labeled_nexthop(struct bgp_nexthop_cache *bnc) +{ + return (bgp_zebra_num_connects() == 0 + || (bnc && CHECK_FLAG(bnc->flags, BGP_NEXTHOP_LABELED_VALID))); +} + int bgp_find_nexthop(struct bgp_info *path, int connected) { struct bgp_nexthop_cache *bnc = path->nexthop; @@ -132,7 +138,12 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) bgp_unlink_nexthop_check(bnc); } -int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t afi, struct bgp_info *ri, +/* + * A route and its nexthop might belong to different VRFs. Therefore, + * we need both the bgp_route and bgp_nexthop pointers. + */ +int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, + afi_t afi, struct bgp_info *ri, struct peer *peer, int connected) { struct bgp_node *rn; @@ -175,15 +186,15 @@ int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t afi, struct bgp_info *ri, return 0; if (is_bgp_static_route) - rn = bgp_node_get(bgp->import_check_table[afi], &p); + rn = bgp_node_get(bgp_nexthop->import_check_table[afi], &p); else - rn = bgp_node_get(bgp->nexthop_cache_table[afi], &p); + rn = bgp_node_get(bgp_nexthop->nexthop_cache_table[afi], &p); if (!rn->info) { bnc = bnc_new(); rn->info = bnc; bnc->node = rn; - bnc->bgp = bgp; + bnc->bgp = bgp_nexthop; bgp_lock_node(rn); if (BGP_DEBUG(nht, NHT)) { char buf[PREFIX2STR_BUFFER]; @@ -199,12 +210,12 @@ int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t afi, struct bgp_info *ri, SET_FLAG(bnc->flags, BGP_STATIC_ROUTE); /* If we're toggling the type, re-register */ - if ((bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) + if ((bgp_flag_check(bgp_route, BGP_FLAG_IMPORT_CHECK)) && !CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)) { SET_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH); UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); - } else if ((!bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK)) + } else if ((!bgp_flag_check(bgp_route, BGP_FLAG_IMPORT_CHECK)) && CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH)) { UNSET_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH); @@ -235,7 +246,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t afi, struct bgp_info *ri, UNSET_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED); UNSET_FLAG(bnc->flags, BGP_NEXTHOP_VALID); } - if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) { + if (bgp_route->inst_type == BGP_INSTANCE_TYPE_VIEW) { bnc->flags |= BGP_NEXTHOP_REGISTERED; bnc->flags |= BGP_NEXTHOP_VALID; } else if (!CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED)) @@ -261,7 +272,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t afi, struct bgp_info *ri, * ability to detect nexthops. So when we have a view * just tell everyone the nexthop is valid */ - if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) + if (bgp_route->inst_type == BGP_INSTANCE_TYPE_VIEW) return 1; else return (bgp_isvalid_nexthop(bnc)); @@ -396,14 +407,27 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) bnc->metric = nhr.metric; bnc->nexthop_num = nhr.nexthop_num; + bnc->flags &= ~BGP_NEXTHOP_LABELED_VALID; /* check below */ + for (i = 0; i < nhr.nexthop_num; i++) { + int num_labels = 0; + nexthop = nexthop_from_zapi_nexthop(&nhr.nexthops[i]); + /* There is at least one label-switched path */ + if (nexthop->nh_label && + nexthop->nh_label->num_labels) { + + bnc->flags |= BGP_NEXTHOP_LABELED_VALID; + num_labels = nexthop->nh_label->num_labels; + } + if (BGP_DEBUG(nht, NHT)) { char buf[NEXTHOP_STRLEN]; zlog_debug( - " nhop via %s", - nexthop2str(nexthop, buf, sizeof(buf))); + " nhop via %s (%d labels)", + nexthop2str(nexthop, buf, sizeof(buf)), + num_labels); } if (nhlist_tail) { @@ -422,7 +446,8 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) continue; for (oldnh = bnc->nexthop; oldnh; oldnh = oldnh->next) - if (nexthop_same_no_recurse(oldnh, nexthop)) + if (nexthop_same_no_recurse(oldnh, nexthop) && + nexthop_labels_match(oldnh, nexthop)) break; if (!oldnh) @@ -552,6 +577,15 @@ static void sendmsg_zebra_rnh(struct bgp_nexthop_cache *bnc, int command) || CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH))) exact_match = true; + if (BGP_DEBUG(zebra, ZEBRA)) { + char buf[PREFIX2STR_BUFFER]; + + prefix2str(p, buf, PREFIX2STR_BUFFER); + zlog_debug("%s: sending cmd %s for %s (vrf %s)", + __func__, zserv_command_string(command), buf, + bnc->bgp->name); + } + ret = zclient_send_rnh(zclient, command, p, exact_match, bnc->bgp->vrf_id); /* TBD: handle the failure */ @@ -618,11 +652,11 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) { struct bgp_node *rn; struct bgp_info *path; - struct bgp *bgp = bnc->bgp; int afi; struct peer *peer = (struct peer *)bnc->nht_info; struct bgp_table *table; safi_t safi; + struct bgp *bgp_path; if (BGP_DEBUG(nht, NHT)) { char buf[PREFIX2STR_BUFFER]; @@ -635,7 +669,8 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) LIST_FOREACH (path, &(bnc->paths), nh_thread) { if (!(path->type == ZEBRA_ROUTE_BGP && ((path->sub_type == BGP_ROUTE_NORMAL) - || (path->sub_type == BGP_ROUTE_STATIC)))) + || (path->sub_type == BGP_ROUTE_STATIC) + || (path->sub_type == BGP_ROUTE_IMPORTED)))) continue; rn = path->net; @@ -644,19 +679,55 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) table = bgp_node_table(rn); safi = table->safi; - /* Path becomes valid/invalid depending on whether the nexthop + /* + * handle routes from other VRFs (they can have a + * nexthop in THIS VRF). bgp_path is the bgp instance + * that owns the route referencing this nexthop. + */ + bgp_path = table->bgp; + + /* + * Path becomes valid/invalid depending on whether the nexthop * reachable/unreachable. + * + * In case of unicast routes that were imported from vpn + * and that have labels, they are valid only if there are + * nexthops with labels */ + + int bnc_is_valid_nexthop = 0; + + if (safi == SAFI_UNICAST && + path->sub_type == BGP_ROUTE_IMPORTED && + path->extra && + path->extra->num_labels) { + + bnc_is_valid_nexthop = + bgp_isvalid_labeled_nexthop(bnc) ? 1 : 0; + } else { + bnc_is_valid_nexthop = + bgp_isvalid_nexthop(bnc) ? 1 : 0; + } + + if (BGP_DEBUG(nht, NHT)) { + char buf[PREFIX_STRLEN]; + + prefix2str(&rn->p, buf, PREFIX_STRLEN); + zlog_debug("%s: prefix %s (vrf %s) %svalid", + __func__, buf, bgp_path->name, + (bnc_is_valid_nexthop ? "" : "not ")); + } + if ((CHECK_FLAG(path->flags, BGP_INFO_VALID) ? 1 : 0) - != (bgp_isvalid_nexthop(bnc) ? 1 : 0)) { + != bnc_is_valid_nexthop) { if (CHECK_FLAG(path->flags, BGP_INFO_VALID)) { - bgp_aggregate_decrement(bgp, &rn->p, path, afi, - safi); + bgp_aggregate_decrement(bgp_path, &rn->p, + path, afi, safi); bgp_info_unset_flag(rn, path, BGP_INFO_VALID); } else { bgp_info_set_flag(rn, path, BGP_INFO_VALID); - bgp_aggregate_increment(bgp, &rn->p, path, afi, - safi); + bgp_aggregate_increment(bgp_path, &rn->p, + path, afi, safi); } } @@ -671,7 +742,7 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) || CHECK_FLAG(bnc->change_flags, BGP_NEXTHOP_CHANGED)) SET_FLAG(path->flags, BGP_INFO_IGP_CHANGED); - bgp_process(bgp, rn, afi, safi); + bgp_process(bgp_path, rn, afi, safi); } if (peer && !CHECK_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED)) { diff --git a/bgpd/bgp_nht.h b/bgpd/bgp_nht.h index 4b297f410c..a821a42c20 100644 --- a/bgpd/bgp_nht.h +++ b/bgpd/bgp_nht.h @@ -39,14 +39,16 @@ extern int bgp_find_nexthop(struct bgp_info *p, int connected); * object. If not found, create a new object and register with ZEBRA for * nexthop notification. * ARGUMENTS: - * bgp - BGP instance + * bgp_route - BGP instance of route + * bgp_nexthop - BGP instance of nexthop * a - afi: AFI_IP or AF_IP6 * p - path for which the nexthop object is being looked up * peer - The BGP peer associated with this NHT * connected - True if NH MUST be a connected route */ -extern int bgp_find_or_add_nexthop(struct bgp *bgp, afi_t a, struct bgp_info *p, - struct peer *peer, int connected); +extern int bgp_find_or_add_nexthop(struct bgp *bgp_route, + struct bgp *bgp_nexthop, afi_t a, struct bgp_info *p, + struct peer *peer, int connected); /** * bgp_unlink_nexthop() - Unlink the nexthop object from the path structure. diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 77fb61fbb8..aa98f8a557 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -51,8 +51,8 @@ Next, if we send capability to the peer we want to set my capabilty inforation at each peer. */ -void bgp_capability_vty_out(struct vty *vty, struct peer *peer, u_char use_json, - json_object *json_neigh) +void bgp_capability_vty_out(struct vty *vty, struct peer *peer, + uint8_t use_json, json_object *json_neigh) { char *pnt; char *end; @@ -146,6 +146,12 @@ void bgp_capability_vty_out(struct vty *vty, struct peer *peer, u_char use_json, "capabilityErrorMultiProtocolSafi", "EVPN"); break; + case SAFI_FLOWSPEC: + json_object_string_add( + json_cap, + "capabilityErrorMultiProtocolSafi", + "flowspec"); + break; default: json_object_int_add( json_cap, @@ -187,6 +193,9 @@ void bgp_capability_vty_out(struct vty *vty, struct peer *peer, u_char use_json, case SAFI_ENCAP: vty_out(vty, "SAFI ENCAP"); break; + case SAFI_FLOWSPEC: + vty_out(vty, "SAFI FLOWSPEC"); + break; case SAFI_EVPN: vty_out(vty, "SAFI EVPN"); break; @@ -271,8 +280,8 @@ static int bgp_capability_mp(struct peer *peer, struct capability_header *hdr) } static void bgp_capability_orf_not_support(struct peer *peer, iana_afi_t afi, - iana_safi_t safi, u_char type, - u_char mode) + iana_safi_t safi, uint8_t type, + uint8_t mode) { if (bgp_debug_neighbor_events(peer)) zlog_debug( @@ -295,15 +304,15 @@ static int bgp_capability_orf_entry(struct peer *peer, { struct stream *s = BGP_INPUT(peer); struct capability_mp_data mpc; - u_char num; + uint8_t num; iana_afi_t pkt_afi; afi_t afi; iana_safi_t pkt_safi; safi_t safi; - u_char type; - u_char mode; - u_int16_t sm_cap = 0; /* capability send-mode receive */ - u_int16_t rm_cap = 0; /* capability receive-mode receive */ + uint8_t type; + uint8_t mode; + uint16_t sm_cap = 0; /* capability send-mode receive */ + uint16_t rm_cap = 0; /* capability receive-mode receive */ int i; /* ORF Entry header */ @@ -433,7 +442,7 @@ static int bgp_capability_restart(struct peer *peer, struct capability_header *caphdr) { struct stream *s = BGP_INPUT(peer); - u_int16_t restart_flag_time; + uint16_t restart_flag_time; size_t end = stream_get_getp(s) + caphdr->length; /* Verify length is a multiple of 4 */ @@ -468,7 +477,7 @@ static int bgp_capability_restart(struct peer *peer, safi_t safi; iana_afi_t pkt_afi = stream_getw(s); iana_safi_t pkt_safi = stream_getc(s); - u_char flag = stream_getc(s); + uint8_t flag = stream_getc(s); /* Convert AFI, SAFI to internal values, check. */ if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, &safi)) { @@ -545,7 +554,7 @@ static int bgp_capability_addpath(struct peer *peer, safi_t safi; iana_afi_t pkt_afi = stream_getw(s); iana_safi_t pkt_safi = stream_getc(s); - u_char send_receive = stream_getc(s); + uint8_t send_receive = stream_getc(s); if (bgp_debug_neighbor_events(peer)) zlog_debug( @@ -659,7 +668,7 @@ static int bgp_capability_hostname(struct peer *peer, struct stream *s = BGP_INPUT(peer); char str[BGP_MAX_HOSTNAME + 1]; size_t end = stream_get_getp(s) + hdr->length; - u_char len; + uint8_t len; SET_FLAG(peer->cap, PEER_CAP_HOSTNAME_RCV); @@ -788,7 +797,7 @@ static const size_t cap_modsizes[] = { * capabilities were encountered. */ static int bgp_capability_parse(struct peer *peer, size_t length, - int *mp_capability, u_char **error) + int *mp_capability, uint8_t **error) { int ret; struct stream *s = BGP_INPUT(peer); @@ -798,7 +807,7 @@ static int bgp_capability_parse(struct peer *peer, size_t length, while (stream_get_getp(s) < end) { size_t start; - u_char *sp = stream_pnt(s); + uint8_t *sp = stream_pnt(s); struct capability_header caphdr; ret = 0; @@ -991,7 +1000,7 @@ static int strict_capability_same(struct peer *peer) /* peek into option, stores ASN to *as4 if the AS4 capability was found. * Returns 0 if no as4 found, as4cap value otherwise. */ -as_t peek_for_as4_capability(struct peer *peer, u_char length) +as_t peek_for_as4_capability(struct peer *peer, uint8_t length) { struct stream *s = BGP_INPUT(peer); size_t orig_getp = stream_get_getp(s); @@ -1007,8 +1016,8 @@ as_t peek_for_as4_capability(struct peer *peer, u_char length) * correctly formatted options. */ while (stream_get_getp(s) < end) { - u_char opt_type; - u_char opt_length; + uint8_t opt_type; + uint8_t opt_length; /* Check the length. */ if (stream_get_getp(s) + 2 > end) @@ -1064,11 +1073,11 @@ end: * * @param[out] mp_capability @see bgp_capability_parse() for semantics. */ -int bgp_open_option_parse(struct peer *peer, u_char length, int *mp_capability) +int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability) { int ret = 0; - u_char *error; - u_char error_data[BGP_MAX_PACKET_SIZE]; + uint8_t *error; + uint8_t error_data[BGP_MAX_PACKET_SIZE]; struct stream *s = BGP_INPUT(peer); size_t end = stream_get_getp(s) + length; @@ -1079,8 +1088,8 @@ int bgp_open_option_parse(struct peer *peer, u_char length, int *mp_capability) peer->host, length); while (stream_get_getp(s) < end) { - u_char opt_type; - u_char opt_length; + uint8_t opt_type; + uint8_t opt_length; /* Must have at least an OPEN option header */ if (STREAM_READABLE(s) < 2) { @@ -1166,11 +1175,13 @@ int bgp_open_option_parse(struct peer *peer, u_char length, int *mp_capability) && !peer->afc_nego[AFI_IP][SAFI_LABELED_UNICAST] && !peer->afc_nego[AFI_IP][SAFI_MPLS_VPN] && !peer->afc_nego[AFI_IP][SAFI_ENCAP] + && !peer->afc_nego[AFI_IP][SAFI_FLOWSPEC] && !peer->afc_nego[AFI_IP6][SAFI_UNICAST] && !peer->afc_nego[AFI_IP6][SAFI_MULTICAST] && !peer->afc_nego[AFI_IP6][SAFI_LABELED_UNICAST] && !peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN] && !peer->afc_nego[AFI_IP6][SAFI_ENCAP] + && !peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] && !peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) { zlog_err( "%s [Error] Configured AFI/SAFIs do not " @@ -1192,10 +1203,10 @@ int bgp_open_option_parse(struct peer *peer, u_char length, int *mp_capability) } static void bgp_open_capability_orf(struct stream *s, struct peer *peer, - afi_t afi, safi_t safi, u_char code) + afi_t afi, safi_t safi, uint8_t code) { - u_char cap_len; - u_char orf_len; + uint8_t cap_len; + uint8_t orf_len; unsigned long capp; unsigned long orfp; unsigned long numberp; @@ -1262,15 +1273,15 @@ static void bgp_open_capability_orf(struct stream *s, struct peer *peer, /* Fill in capability open option to the packet. */ void bgp_open_capability(struct stream *s, struct peer *peer) { - u_char len; + uint8_t len; unsigned long cp, capp, rcapp; iana_afi_t pkt_afi; afi_t afi; safi_t safi; iana_safi_t pkt_safi; as_t local_as; - u_int32_t restart_time; - u_char afi_safi_count = 0; + uint32_t restart_time; + uint8_t afi_safi_count = 0; int adv_addpath_tx = 0; /* Remember current pointer for Opt Parm Len. */ diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h index 83b79a589a..c92fd9b0a7 100644 --- a/bgpd/bgp_open.h +++ b/bgpd/bgp_open.h @@ -23,14 +23,14 @@ /* Standard header for capability TLV */ struct capability_header { - u_char code; - u_char length; + uint8_t code; + uint8_t length; }; /* Generic MP capability data */ struct capability_mp_data { uint16_t afi; /* iana_afi_t */ - u_char reserved; + uint8_t reserved; uint8_t safi; /* iana_safi_t */ }; @@ -41,11 +41,11 @@ struct capability_as4 { struct graceful_restart_af { afi_t afi; safi_t safi; - u_char flag; + uint8_t flag; }; struct capability_gr { - u_int16_t restart_flag_time; + uint16_t restart_flag_time; struct graceful_restart_af gr[]; }; @@ -93,10 +93,10 @@ struct capability_gr { #define RESTART_R_BIT 0x8000 #define RESTART_F_BIT 0x80 -extern int bgp_open_option_parse(struct peer *, u_char, int *); +extern int bgp_open_option_parse(struct peer *, uint8_t, int *); extern void bgp_open_capability(struct stream *, struct peer *); -extern void bgp_capability_vty_out(struct vty *, struct peer *, u_char, +extern void bgp_capability_vty_out(struct vty *, struct peer *, uint8_t, json_object *); -extern as_t peek_for_as4_capability(struct peer *, u_char); +extern as_t peek_for_as4_capability(struct peer *, uint8_t); #endif /* _QUAGGA_BGP_OPEN_H */ diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index d17c334419..f0b30f0186 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -59,6 +59,7 @@ #include "bgpd/bgp_label.h" #include "bgpd/bgp_io.h" #include "bgpd/bgp_keepalives.h" +#include "bgpd/bgp_flowspec.h" /** * Sets marker and type fields for a BGP message. @@ -67,7 +68,7 @@ * @param type the packet type * @return the size of the stream */ -int bgp_packet_set_marker(struct stream *s, u_char type) +int bgp_packet_set_marker(struct stream *s, uint8_t type) { int i; @@ -302,6 +303,8 @@ int bgp_nlri_parse(struct peer *peer, struct attr *attr, packet); case SAFI_EVPN: return bgp_nlri_parse_evpn(peer, attr, packet, mp_withdraw); + case SAFI_FLOWSPEC: + return bgp_nlri_parse_flowspec(peer, attr, packet, mp_withdraw); } return -1; } @@ -497,7 +500,7 @@ void bgp_keepalive_send(struct peer *peer) void bgp_open_send(struct peer *peer) { struct stream *s; - u_int16_t send_holdtime; + uint16_t send_holdtime; as_t local_as; if (PEER_OR_GROUP_TIMER_SET(peer)) @@ -518,9 +521,8 @@ void bgp_open_send(struct peer *peer) /* Set open packet values. */ stream_putc(s, BGP_VERSION_4); /* BGP version */ - stream_putw(s, - (local_as <= BGP_AS_MAX) ? (u_int16_t)local_as - : BGP_AS_TRANS); + stream_putw(s, (local_as <= BGP_AS_MAX) ? (uint16_t)local_as + : BGP_AS_TRANS); stream_putw(s, send_holdtime); /* Hold Time */ stream_put_in_addr(s, &peer->local_id); /* BGP Identifier */ @@ -560,7 +562,7 @@ void bgp_open_send(struct peer *peer) static int bgp_write_notify(struct peer *peer) { int ret, val; - u_char type; + uint8_t type; struct stream *s; /* There should be at least one packet. */ @@ -643,8 +645,8 @@ static int bgp_write_notify(struct peer *peer) * @param data Data portion * @param datalen length of data portion */ -void bgp_notify_send_with_data(struct peer *peer, u_char code, u_char sub_code, - u_char *data, size_t datalen) +void bgp_notify_send_with_data(struct peer *peer, uint8_t code, + uint8_t sub_code, uint8_t *data, size_t datalen) { struct stream *s; int length; @@ -753,7 +755,7 @@ void bgp_notify_send_with_data(struct peer *peer, u_char code, u_char sub_code, * @param code BGP error code * @param sub_code BGP error subcode */ -void bgp_notify_send(struct peer *peer, u_char code, u_char sub_code) +void bgp_notify_send(struct peer *peer, uint8_t code, uint8_t sub_code) { bgp_notify_send_with_data(peer, code, sub_code, NULL, 0); } @@ -769,7 +771,8 @@ void bgp_notify_send(struct peer *peer, u_char code, u_char sub_code) * @param remove Whether to remove ORF for specified AFI/SAFI */ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, - u_char orf_type, u_char when_to_refresh, int remove) + uint8_t orf_type, uint8_t when_to_refresh, + int remove) { struct stream *s; struct bgp_filter *filter; @@ -800,7 +803,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, if (orf_type == ORF_TYPE_PREFIX || orf_type == ORF_TYPE_PREFIX_OLD) if (remove || filter->plist[FILTER_IN].plist) { - u_int16_t orf_len; + uint16_t orf_len; unsigned long orfp; orf_refresh = 1; @@ -1033,24 +1036,24 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id) static int bgp_open_receive(struct peer *peer, bgp_size_t size) { int ret; - u_char version; - u_char optlen; - u_int16_t holdtime; - u_int16_t send_holdtime; + uint8_t version; + uint8_t optlen; + uint16_t holdtime; + uint16_t send_holdtime; as_t remote_as; as_t as4 = 0; struct in_addr remote_id; int mp_capability; - u_int8_t notify_data_remote_as[2]; - u_int8_t notify_data_remote_as4[4]; - u_int8_t notify_data_remote_id[4]; - u_int16_t *holdtime_ptr; + uint8_t notify_data_remote_as[2]; + uint8_t notify_data_remote_as4[4]; + uint8_t notify_data_remote_id[4]; + uint16_t *holdtime_ptr; /* Parse open packet. */ version = stream_getc(peer->curr); memcpy(notify_data_remote_as, stream_pnt(peer->curr), 2); remote_as = stream_getw(peer->curr); - holdtime_ptr = (u_int16_t *)stream_pnt(peer->curr); + holdtime_ptr = (uint16_t *)stream_pnt(peer->curr); holdtime = stream_getw(peer->curr); memcpy(notify_data_remote_id, stream_pnt(peer->curr), 4); remote_id.s_addr = stream_get_ipv4(peer->curr); @@ -1158,7 +1161,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) /* Peer BGP version check. */ if (version != BGP_VERSION_4) { - u_int16_t maxver = htons(BGP_VERSION_4); + uint16_t maxver = htons(BGP_VERSION_4); /* XXX this reply may not be correct if version < 4 XXX */ if (bgp_debug_neighbor_events(peer)) zlog_debug( @@ -1167,7 +1170,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) /* Data must be in network byte order here */ bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNSUP_VERSION, - (u_int8_t *)&maxver, 2); + (uint8_t *)&maxver, 2); return BGP_Stop; } @@ -1225,7 +1228,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) if (holdtime < 3 && holdtime != 0) { bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_UNACEP_HOLDTIME, - (u_char *)holdtime_ptr, 2); + (uint8_t *)holdtime_ptr, 2); return BGP_Stop; } @@ -1275,6 +1278,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) peer->afc[AFI_IP][SAFI_MULTICAST]; peer->afc_nego[AFI_IP][SAFI_LABELED_UNICAST] = peer->afc[AFI_IP][SAFI_LABELED_UNICAST]; + peer->afc_nego[AFI_IP][SAFI_FLOWSPEC] = + peer->afc[AFI_IP][SAFI_FLOWSPEC]; peer->afc_nego[AFI_IP6][SAFI_UNICAST] = peer->afc[AFI_IP6][SAFI_UNICAST]; peer->afc_nego[AFI_IP6][SAFI_MULTICAST] = @@ -1283,6 +1288,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) peer->afc[AFI_IP6][SAFI_LABELED_UNICAST]; peer->afc_nego[AFI_L2VPN][SAFI_EVPN] = peer->afc[AFI_L2VPN][SAFI_EVPN]; + peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] = + peer->afc[AFI_IP6][SAFI_FLOWSPEC]; } /* When collision is detected and this peer is closed. Retrun @@ -1367,7 +1374,7 @@ static int bgp_keepalive_receive(struct peer *peer, bgp_size_t size) static int bgp_update_receive(struct peer *peer, bgp_size_t size) { int ret, nlri_ret; - u_char *end; + uint8_t *end; struct stream *s; struct attr attr; bgp_size_t attribute_len; @@ -1680,7 +1687,7 @@ static int bgp_notify_receive(struct peer *peer, bgp_size_t size) stream_getc(peer->curr)); strcpy(bgp_notify.data, c); } - bgp_notify.raw_data = (u_char *)peer->notify.data; + bgp_notify.raw_data = (uint8_t *)peer->notify.data; } bgp_notify_print(peer, &bgp_notify, "received"); @@ -1764,10 +1771,10 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) } if (size != BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE) { - u_char *end; - u_char when_to_refresh; - u_char orf_type; - u_int16_t orf_len; + uint8_t *end; + uint8_t when_to_refresh; + uint8_t orf_type; + uint16_t orf_len; if (size - (BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE) < 5) { @@ -1792,8 +1799,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) uint8_t *p_pnt = stream_pnt(s); uint8_t *p_end = stream_pnt(s) + orf_len; struct orf_prefix orfp; - u_char common = 0; - u_int32_t seq; + uint8_t common = 0; + uint32_t seq; int psize; char name[BUFSIZ]; int ret = CMD_SUCCESS; @@ -1839,12 +1846,12 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) name); break; } - ok = ((u_int32_t)(p_end - p_pnt) - >= sizeof(u_int32_t)); + ok = ((uint32_t)(p_end - p_pnt) + >= sizeof(uint32_t)); if (ok) { memcpy(&seq, p_pnt, - sizeof(u_int32_t)); - p_pnt += sizeof(u_int32_t); + sizeof(uint32_t)); + p_pnt += sizeof(uint32_t); orfp.seq = ntohl(seq); } else p_pnt = p_end; @@ -1988,13 +1995,13 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) * @param size size of the packet * @return as in summary */ -static int bgp_capability_msg_parse(struct peer *peer, u_char *pnt, +static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt, bgp_size_t length) { - u_char *end; + uint8_t *end; struct capability_mp_data mpc; struct capability_header *hdr; - u_char action; + uint8_t action; iana_afi_t pkt_afi; afi_t afi; iana_safi_t pkt_safi; @@ -2106,7 +2113,7 @@ static int bgp_capability_msg_parse(struct peer *peer, u_char *pnt, */ int bgp_capability_receive(struct peer *peer, bgp_size_t size) { - u_char *pnt; + uint8_t *pnt; /* Fetch pointer. */ pnt = stream_pnt(peer->curr); @@ -2171,7 +2178,7 @@ int bgp_process_packet(struct thread *thread) unsigned int processed = 0; while (processed < rpkt_quanta_old) { - u_char type = 0; + uint8_t type = 0; bgp_size_t size; char notify_data_length[2]; diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h index 008f2b814b..06a190585b 100644 --- a/bgpd/bgp_packet.h +++ b/bgpd/bgp_packet.h @@ -39,11 +39,11 @@ /* Packet send and receive function prototypes. */ extern void bgp_keepalive_send(struct peer *); extern void bgp_open_send(struct peer *); -extern void bgp_notify_send(struct peer *, u_int8_t, u_int8_t); -extern void bgp_notify_send_with_data(struct peer *, u_int8_t, u_int8_t, - u_int8_t *, size_t); -extern void bgp_route_refresh_send(struct peer *, afi_t, safi_t, u_char, u_char, - int); +extern void bgp_notify_send(struct peer *, uint8_t, uint8_t); +extern void bgp_notify_send_with_data(struct peer *, uint8_t, uint8_t, + uint8_t *, size_t); +extern void bgp_route_refresh_send(struct peer *, afi_t, safi_t, uint8_t, + uint8_t, int); extern void bgp_capability_send(struct peer *, afi_t, safi_t, int, int); extern void bgp_default_update_send(struct peer *, struct attr *, afi_t, safi_t, struct peer *); @@ -58,7 +58,7 @@ extern void bgp_update_restarted_peers(struct peer *); extern void bgp_update_implicit_eors(struct peer *); extern void bgp_check_update_delay(struct bgp *); -extern int bgp_packet_set_marker(struct stream *s, u_char type); +extern int bgp_packet_set_marker(struct stream *s, uint8_t type); extern int bgp_packet_set_size(struct stream *s); extern int bgp_generate_updgrp_packets(struct thread *); diff --git a/bgpd/bgp_rd.c b/bgpd/bgp_rd.c index ae1ec7b845..64e083d1ef 100644 --- a/bgpd/bgp_rd.c +++ b/bgpd/bgp_rd.c @@ -36,57 +36,57 @@ #include "bgpd/rfapi/rfapi_backend.h" #endif -u_int16_t decode_rd_type(u_char *pnt) +uint16_t decode_rd_type(uint8_t *pnt) { - u_int16_t v; + uint16_t v; - v = ((u_int16_t)*pnt++ << 8); + v = ((uint16_t)*pnt++ << 8); #if ENABLE_BGP_VNC /* * VNC L2 stores LHI in lower byte, so omit it */ if (v != RD_TYPE_VNC_ETH) - v |= (u_int16_t)*pnt; + v |= (uint16_t)*pnt; #else /* duplicate code for clarity */ - v |= (u_int16_t)*pnt; + v |= (uint16_t)*pnt; #endif return v; } -void encode_rd_type(u_int16_t v, u_char *pnt) +void encode_rd_type(uint16_t v, uint8_t *pnt) { - *((u_int16_t *)pnt) = htons(v); + *((uint16_t *)pnt) = htons(v); } /* type == RD_TYPE_AS */ -void decode_rd_as(u_char *pnt, struct rd_as *rd_as) +void decode_rd_as(uint8_t *pnt, struct rd_as *rd_as) { - rd_as->as = (u_int16_t)*pnt++ << 8; - rd_as->as |= (u_int16_t)*pnt++; + rd_as->as = (uint16_t)*pnt++ << 8; + rd_as->as |= (uint16_t)*pnt++; ptr_get_be32(pnt, &rd_as->val); } /* type == RD_TYPE_AS4 */ -void decode_rd_as4(u_char *pnt, struct rd_as *rd_as) +void decode_rd_as4(uint8_t *pnt, struct rd_as *rd_as) { pnt = ptr_get_be32(pnt, &rd_as->as); - rd_as->val = ((u_int16_t)*pnt++ << 8); - rd_as->val |= (u_int16_t)*pnt; + rd_as->val = ((uint16_t)*pnt++ << 8); + rd_as->val |= (uint16_t)*pnt; } /* type == RD_TYPE_IP */ -void decode_rd_ip(u_char *pnt, struct rd_ip *rd_ip) +void decode_rd_ip(uint8_t *pnt, struct rd_ip *rd_ip) { memcpy(&rd_ip->ip, pnt, 4); pnt += 4; - rd_ip->val = ((u_int16_t)*pnt++ << 8); - rd_ip->val |= (u_int16_t)*pnt; + rd_ip->val = ((uint16_t)*pnt++ << 8); + rd_ip->val |= (uint16_t)*pnt; } #if ENABLE_BGP_VNC /* type == RD_TYPE_VNC_ETH */ -void decode_rd_vnc_eth(u_char *pnt, struct rd_vnc_eth *rd_vnc_eth) +void decode_rd_vnc_eth(uint8_t *pnt, struct rd_vnc_eth *rd_vnc_eth) { rd_vnc_eth->type = RD_TYPE_VNC_ETH; rd_vnc_eth->local_nve_id = pnt[1]; @@ -161,8 +161,8 @@ out: char *prefix_rd2str(struct prefix_rd *prd, char *buf, size_t size) { - u_char *pnt; - u_int16_t type; + uint8_t *pnt; + uint16_t type; struct rd_as rd_as; struct rd_ip rd_ip; diff --git a/bgpd/bgp_rd.h b/bgpd/bgp_rd.h index cbc449ed45..a8ea83a4a7 100644 --- a/bgpd/bgp_rd.h +++ b/bgpd/bgp_rd.h @@ -35,33 +35,33 @@ #define RD_ADDRSTRLEN 28 struct rd_as { - u_int16_t type; + uint16_t type; as_t as; - u_int32_t val; + uint32_t val; }; struct rd_ip { - u_int16_t type; + uint16_t type; struct in_addr ip; - u_int16_t val; + uint16_t val; }; #if ENABLE_BGP_VNC struct rd_vnc_eth { - u_int16_t type; + uint16_t type; uint8_t local_nve_id; struct ethaddr macaddr; }; #endif -extern u_int16_t decode_rd_type(u_char *pnt); -extern void encode_rd_type(u_int16_t, u_char *); +extern uint16_t decode_rd_type(uint8_t *pnt); +extern void encode_rd_type(uint16_t, uint8_t *); -extern void decode_rd_as(u_char *pnt, struct rd_as *rd_as); -extern void decode_rd_as4(u_char *pnt, struct rd_as *rd_as); -extern void decode_rd_ip(u_char *pnt, struct rd_ip *rd_ip); +extern void decode_rd_as(uint8_t *pnt, struct rd_as *rd_as); +extern void decode_rd_as4(uint8_t *pnt, struct rd_as *rd_as); +extern void decode_rd_ip(uint8_t *pnt, struct rd_ip *rd_ip); #if ENABLE_BGP_VNC -extern void decode_rd_vnc_eth(u_char *pnt, struct rd_vnc_eth *rd_vnc_eth); +extern void decode_rd_vnc_eth(uint8_t *pnt, struct rd_vnc_eth *rd_vnc_eth); #endif extern int str2prefix_rd(const char *, struct prefix_rd *); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index e0c54e0845..944ae5b5dc 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -73,6 +73,8 @@ #include "bgpd/bgp_encap_tlv.h" #include "bgpd/bgp_evpn.h" #include "bgpd/bgp_evpn_vty.h" +#include "bgpd/bgp_flowspec.h" +#include "bgpd/bgp_flowspec_util.h" #ifndef VTYSH_EXTRACT_PL #include "bgpd/bgp_route_clippy.c" @@ -113,7 +115,7 @@ struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, prn = bgp_node_get(table, (struct prefix *)prd); if (prn->info == NULL) - prn->info = bgp_table_init(afi, safi); + prn->info = bgp_table_init(table->bgp, afi, safi); else bgp_unlock_node(prn); table = prn->info; @@ -337,7 +339,7 @@ static int bgp_label_index_differs(struct bgp_info *ri1, struct bgp_info *ri2) /* Set/unset bgp_info flags, adjusting any other state as needed. * This is here primarily to keep prefix-count in check. */ -void bgp_info_set_flag(struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) +void bgp_info_set_flag(struct bgp_node *rn, struct bgp_info *ri, uint32_t flag) { SET_FLAG(ri->flags, flag); @@ -351,7 +353,7 @@ void bgp_info_set_flag(struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag) } void bgp_info_unset_flag(struct bgp_node *rn, struct bgp_info *ri, - u_int32_t flag) + uint32_t flag) { UNSET_FLAG(ri->flags, flag); @@ -366,7 +368,7 @@ void bgp_info_unset_flag(struct bgp_node *rn, struct bgp_info *ri, /* Get MED value. If MED value is missing and "bgp bestpath missing-as-worst" is specified, treat it as the worst value. */ -static u_int32_t bgp_med_value(struct attr *attr, struct bgp *bgp) +static uint32_t bgp_med_value(struct attr *attr, struct bgp *bgp) { if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) return attr->med; @@ -397,12 +399,12 @@ static int bgp_info_cmp(struct bgp *bgp, struct bgp_info *new, struct attr *newattr, *existattr; bgp_peer_sort_t new_sort; bgp_peer_sort_t exist_sort; - u_int32_t new_pref; - u_int32_t exist_pref; - u_int32_t new_med; - u_int32_t exist_med; - u_int32_t new_weight; - u_int32_t exist_weight; + uint32_t new_pref; + uint32_t exist_pref; + uint32_t new_med; + uint32_t exist_med; + uint32_t new_weight; + uint32_t exist_weight; uint32_t newm, existm; struct in_addr new_id; struct in_addr exist_id; @@ -413,8 +415,8 @@ static int bgp_info_cmp(struct bgp *bgp, struct bgp_info *new, int ret = 0; char new_buf[PATH_ADDPATH_STR_BUFFER]; char exist_buf[PATH_ADDPATH_STR_BUFFER]; - u_int32_t new_mm_seq; - u_int32_t exist_mm_seq; + uint32_t new_mm_seq; + uint32_t exist_mm_seq; *paths_eq = 0; @@ -567,7 +569,7 @@ static int bgp_info_cmp(struct bgp *bgp, struct bgp_info *new, } if (!(exist->sub_type == BGP_ROUTE_NORMAL || - new->sub_type == BGP_ROUTE_IMPORTED)) { + exist->sub_type == BGP_ROUTE_IMPORTED)) { if (debug) zlog_debug( "%s: %s loses to %s due to preferred BGP_ROUTE type", @@ -1181,7 +1183,7 @@ static int bgp_output_modifier(struct peer *peer, struct prefix *p, struct bgp_info info; route_map_result_t ret; struct route_map *rmap = NULL; - u_char rmap_type; + uint8_t rmap_type; /* * So if we get to this point and have no rmap_name @@ -1323,10 +1325,12 @@ void bgp_attr_add_gshut_community(struct attr *attr) } -static void subgroup_announce_reset_nhop(u_char family, struct attr *attr) +static void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr) { - if (family == AF_INET) + if (family == AF_INET) { attr->nexthop.s_addr = 0; + attr->mp_nexthop_global_in.s_addr = 0; + } if (family == AF_INET6) memset(&attr->mp_nexthop_global, 0, IPV6_MAX_BYTELEN); } @@ -1749,7 +1753,22 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_info *ri, ? AF_INET6 : p->family), attr); + } else if (CHECK_FLAG(ri->flags, BGP_INFO_ANNC_NH_SELF)) { + /* + * This flag is used for leaked vpn-vrf routes + */ + int family = p->family; + + if (peer_cap_enhe(peer, afi, safi)) + family = AF_INET6; + + if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) + zlog_debug( + "%s: BGP_INFO_ANNC_NH_SELF, family=%s", + __func__, family2str(family)); + subgroup_announce_reset_nhop(family, attr); } + /* If IPv6/MP and nexthop does not have any override and happens * to * be a link-local address, reset it so that we don't pass along @@ -1992,7 +2011,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, int subgroup_process_announce_selected(struct update_subgroup *subgrp, struct bgp_info *selected, struct bgp_node *rn, - u_int32_t addpath_tx_id) + uint32_t addpath_tx_id) { struct prefix *p; struct peer *onlypeer; @@ -2521,7 +2540,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, pkt_afi = afi_int2iana(afi); pkt_safi = safi_int2iana(safi); { - u_int8_t ndata[7]; + uint8_t ndata[7]; ndata[0] = (pkt_afi >> 8); ndata[1] = pkt_afi; @@ -2644,7 +2663,7 @@ static void bgp_rib_withdraw(struct bgp_node *rn, struct bgp_info *ri, bgp_rib_remove(rn, ri, peer, afi, safi); } -struct bgp_info *info_make(int type, int sub_type, u_short instance, +struct bgp_info *info_make(int type, int sub_type, unsigned short instance, struct peer *peer, struct attr *attr, struct bgp_node *rn) { @@ -2772,10 +2791,10 @@ static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, return ret; } -int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, +int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, - u_int32_t num_labels, int soft_reconfig, + uint32_t num_labels, int soft_reconfig, struct bgp_route_evpn *evpn) { int ret; @@ -3159,8 +3178,13 @@ int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, else connected = 0; - if (bgp_find_or_add_nexthop(bgp, afi, ri, NULL, - connected) + struct bgp *bgp_nexthop = bgp; + + if (ri->extra && ri->extra->bgp_orig) + bgp_nexthop = ri->extra->bgp_orig; + + if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, afi, + ri, NULL, connected) || CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) bgp_info_set_flag(rn, ri, BGP_INFO_VALID); else { @@ -3287,7 +3311,7 @@ int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, else connected = 0; - if (bgp_find_or_add_nexthop(bgp, afi, new, NULL, connected) + if (bgp_find_or_add_nexthop(bgp, bgp, afi, new, NULL, connected) || CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD)) bgp_info_set_flag(rn, new, BGP_INFO_VALID); else { @@ -3424,10 +3448,10 @@ filtered: return 0; } -int bgp_withdraw(struct peer *peer, struct prefix *p, u_int32_t addpath_id, +int bgp_withdraw(struct peer *peer, struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, - u_int32_t num_labels, struct bgp_route_evpn *evpn) + uint32_t num_labels, struct bgp_route_evpn *evpn) { struct bgp *bgp; char pfx_buf[BGP_PRD_PATH_STRLEN]; @@ -3629,7 +3653,7 @@ static void bgp_soft_reconfig_table(struct peer *peer, afi_t afi, safi_t safi, continue; struct bgp_info *ri = rn->info; - u_int32_t num_labels = 0; + uint32_t num_labels = 0; mpls_label_t *label_pnt = NULL; if (ri && ri->extra) @@ -3714,12 +3738,14 @@ static wq_item_status bgp_clear_route_node(struct work_queue *wq, void *data) /* Handle withdraw for VRF route-leaking and L3VPN */ if (SAFI_UNICAST == safi && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF || - bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, ri); + } if (SAFI_MPLS_VPN == safi && - bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) + bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { vpn_leak_to_vrf_withdraw(bgp, ri); + } bgp_rib_remove(rn, ri, peer, afi, safi); } @@ -4087,15 +4113,15 @@ static int bgp_addpath_encode_rx(struct peer *peer, afi_t afi, safi_t safi) int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, struct bgp_nlri *packet) { - u_char *pnt; - u_char *lim; + uint8_t *pnt; + uint8_t *lim; struct prefix p; int psize; int ret; afi_t afi; safi_t safi; int addpath_encoded; - u_int32_t addpath_id; + uint32_t addpath_id; pnt = packet->nlri; lim = pnt + packet->length; @@ -4370,8 +4396,14 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK) && (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) { - if (bgp_find_or_add_nexthop(bgp, afi, ri, NULL, - 0)) + + struct bgp *bgp_nexthop = bgp; + + if (ri->extra && ri->extra->bgp_orig) + bgp_nexthop = ri->extra->bgp_orig; + + if (bgp_find_or_add_nexthop(bgp, bgp_nexthop, + afi, ri, NULL, 0)) bgp_info_set_flag(rn, ri, BGP_INFO_VALID); else { @@ -4422,7 +4454,7 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, /* Nexthop reachability check. */ if (bgp_flag_check(bgp, BGP_FLAG_IMPORT_CHECK) && (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)) { - if (bgp_find_or_add_nexthop(bgp, afi, new, NULL, 0)) + if (bgp_find_or_add_nexthop(bgp, bgp, afi, new, NULL, 0)) bgp_info_set_flag(rn, new, BGP_INFO_VALID); else { if (BGP_DEBUG(nht, NHT)) { @@ -4548,7 +4580,7 @@ static void bgp_static_update_safi(struct bgp *bgp, struct prefix *p, #if ENABLE_BGP_VNC mpls_label_t label = 0; #endif - u_int32_t num_labels = 0; + uint32_t num_labels = 0; union gw_addr add; assert(bgp_static); @@ -4713,14 +4745,14 @@ static void bgp_static_update_safi(struct bgp *bgp, struct prefix *p, route should be installed as valid. */ static int bgp_static_set(struct vty *vty, const char *negate, const char *ip_str, afi_t afi, safi_t safi, - const char *rmap, int backdoor, u_int32_t label_index) + const char *rmap, int backdoor, uint32_t label_index) { VTY_DECLVAR_CONTEXT(bgp, bgp); int ret; struct prefix p; struct bgp_static *bgp_static; struct bgp_node *rn; - u_char need_update = 0; + uint8_t need_update = 0; /* Convert IP prefix string to struct prefix. */ ret = str2prefix(ip_str, &p); @@ -5070,7 +5102,7 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, } prn = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); if (prn->info == NULL) - prn->info = bgp_table_init(afi, safi); + prn->info = bgp_table_init(bgp, afi, safi); else bgp_unlock_node(prn); table = prn->info; @@ -5168,7 +5200,7 @@ int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty, prn = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); if (prn->info == NULL) - prn->info = bgp_table_init(afi, safi); + prn->info = bgp_table_init(bgp, afi, safi); else bgp_unlock_node(prn); table = prn->info; @@ -5329,10 +5361,10 @@ DEFPY(ipv6_bgp_network, */ struct bgp_aggregate { /* Summary-only flag. */ - u_char summary_only; + uint8_t summary_only; /* AS set generation. */ - u_char as_set; + uint8_t as_set; /* Route-map for aggregated route. */ struct route_map *map; @@ -5363,20 +5395,20 @@ static void bgp_aggregate_route(struct bgp *bgp, struct prefix *p, struct bgp_table *table; struct bgp_node *top; struct bgp_node *rn; - u_char origin; + uint8_t origin; struct aspath *aspath = NULL; struct aspath *asmerge = NULL; struct community *community = NULL; struct community *commerge = NULL; #if defined(AGGREGATE_NEXTHOP_CHECK) struct in_addr nexthop; - u_int32_t med = 0; + uint32_t med = 0; #endif struct bgp_info *ri; struct bgp_info *new; int first = 1; unsigned long match = 0; - u_char atomic_aggregate = 0; + uint8_t atomic_aggregate = 0; /* Record adding route's nexthop and med. */ if (rinew) { @@ -5551,7 +5583,8 @@ void bgp_aggregate_increment(struct bgp *bgp, struct prefix *p, /* MPLS-VPN aggregation is not yet supported. */ if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) - || (safi == SAFI_EVPN)) + || (safi == SAFI_EVPN) + || (safi == SAFI_FLOWSPEC)) return; table = bgp->aggregate[afi][safi]; @@ -5589,7 +5622,8 @@ void bgp_aggregate_decrement(struct bgp *bgp, struct prefix *p, /* MPLS-VPN aggregation is not yet supported. */ if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) - || (safi == SAFI_EVPN)) + || (safi == SAFI_EVPN) + || (safi == SAFI_FLOWSPEC)) return; table = bgp->aggregate[afi][safi]; @@ -5624,12 +5658,12 @@ static void bgp_aggregate_add(struct bgp *bgp, struct prefix *p, afi_t afi, struct bgp_info *new; struct bgp_info *ri; unsigned long match; - u_char origin = BGP_ORIGIN_IGP; + uint8_t origin = BGP_ORIGIN_IGP; struct aspath *aspath = NULL; struct aspath *asmerge = NULL; struct community *community = NULL; struct community *commerge = NULL; - u_char atomic_aggregate = 0; + uint8_t atomic_aggregate = 0; table = bgp->rib[afi][safi]; @@ -5817,6 +5851,9 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, struct bgp_node *rn; struct bgp_aggregate *aggregate; + if (safi == SAFI_FLOWSPEC) + return CMD_WARNING_CONFIG_FAILED; + /* Convert string to prefix structure. */ ret = str2prefix(prefix_str, &p); if (!ret) { @@ -5852,7 +5889,7 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, } static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, - safi_t safi, u_char summary_only, u_char as_set) + safi_t safi, uint8_t summary_only, uint8_t as_set) { VTY_DECLVAR_CONTEXT(bgp, bgp); int ret; @@ -5860,6 +5897,9 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, struct bgp_node *rn; struct bgp_aggregate *aggregate; + if (safi == SAFI_FLOWSPEC) + return CMD_WARNING_CONFIG_FAILED; + /* Convert string to prefix structure. */ ret = str2prefix(prefix_str, &p); if (!ret) { @@ -6039,7 +6079,8 @@ DEFUN (no_ipv6_aggregate_address, void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, const union g_addr *nexthop, ifindex_t ifindex, enum nexthop_types_t nhtype, uint32_t metric, - u_char type, u_short instance, route_tag_t tag) + uint8_t type, unsigned short instance, + route_tag_t tag) { struct bgp_info *new; struct bgp_info *bi; @@ -6196,8 +6237,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, aspath_unintern(&attr.aspath); } -void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, u_char type, - u_short instance) +void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, uint8_t type, + unsigned short instance) { afi_t afi; struct bgp_node *rn; @@ -6232,7 +6273,7 @@ void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, u_char type, /* Withdraw specified route type's route. */ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type, - u_short instance) + unsigned short instance) { struct bgp_node *rn; struct bgp_info *ri; @@ -6266,7 +6307,7 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty, json_object *json) { int len = 0; - u_int32_t destination; + uint32_t destination; char buf[BUFSIZ]; if (p->family == AF_INET) { @@ -6307,6 +6348,11 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty, prefix2str(p, buf, PREFIX_STRLEN); len = vty_out(vty, "%s", buf); #endif + } else if (p->family == AF_FLOWSPEC) { + route_vty_out_flowspec(vty, p, NULL, + json ? + NLRI_STRING_FORMAT_JSON_SIMPLE : + NLRI_STRING_FORMAT_MIN, json); } else { if (!json) len = vty_out( @@ -6498,9 +6544,10 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, "used"); } else vty_out(vty, "%-16s", inet_ntoa(attr->nexthop)); - } + } else if (safi == SAFI_FLOWSPEC) { + /* already done */ /* IPv4 Next Hop */ - else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) { + } else if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(attr)) { if (json_paths) { json_nexthop_global = json_object_new_object(); @@ -6694,7 +6741,7 @@ void route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, /* called from terminal list command */ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, - safi_t safi, u_char use_json, json_object *json_ar) + safi_t safi, uint8_t use_json, json_object *json_ar) { json_object *json_status = NULL; json_object *json_net = NULL; @@ -7019,7 +7066,7 @@ void route_vty_out_overlay(struct vty *vty, struct prefix *p, /* dampening route */ static void damp_route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, int display, safi_t safi, - u_char use_json, json_object *json) + uint8_t use_json, json_object *json) { struct attr *attr; int len; @@ -7082,7 +7129,7 @@ static void damp_route_vty_out(struct vty *vty, struct prefix *p, /* flap route */ static void flap_route_vty_out(struct vty *vty, struct prefix *p, struct bgp_info *binfo, int display, safi_t safi, - u_char use_json, json_object *json) + uint8_t use_json, json_object *json) { struct attr *attr; struct bgp_damp_info *bdi; @@ -8072,7 +8119,7 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp, static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, struct bgp_table *table, enum bgp_show_type type, - void *output_arg, u_char use_json, char *rd, + void *output_arg, uint8_t use_json, char *rd, int is_last, unsigned long *output_cum, unsigned long *total_cum, unsigned long *json_header_depth) @@ -8180,7 +8227,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, continue; } if (type == bgp_show_type_cidr_only) { - u_int32_t destination; + uint32_t destination; destination = ntohl(rn->p.u.prefix4.s_addr); if (IN_CLASSC(destination) @@ -8357,7 +8404,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, struct bgp_table *table, struct prefix_rd *prd_match, enum bgp_show_type type, void *output_arg, - u_char use_json) + uint8_t use_json) { struct bgp_node *rn, *next; unsigned long output_cum = 0; @@ -8397,7 +8444,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, return CMD_SUCCESS; } static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, - enum bgp_show_type type, void *output_arg, u_char use_json) + enum bgp_show_type type, void *output_arg, uint8_t use_json) { struct bgp_table *table; unsigned long json_header_depth = 0; @@ -8420,6 +8467,12 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, return bgp_show_table_rd(vty, bgp, safi, table, NULL, type, output_arg, use_json); } + + if (safi == SAFI_FLOWSPEC && type == bgp_show_type_detail) { + return bgp_show_table_flowspec(vty, bgp, afi, table, type, + output_arg, use_json, + 1, NULL, NULL); + } /* labeled-unicast routes live in the unicast table */ else if (safi == SAFI_LABELED_UNICAST) safi = SAFI_UNICAST; @@ -8429,7 +8482,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, } static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi, - safi_t safi, u_char use_json) + safi_t safi, uint8_t use_json) { struct listnode *node, *nnode; struct bgp *bgp; @@ -8629,7 +8682,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, struct bgp_table *rib, const char *ip_str, afi_t afi, safi_t safi, struct prefix_rd *prd, int prefix_check, - enum bgp_path_type pathtype, u_char use_json) + enum bgp_path_type pathtype, + uint8_t use_json) { int ret; int header; @@ -8701,6 +8755,18 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, bgp_unlock_node(rm); } + } else if (safi == SAFI_FLOWSPEC) { + rn = bgp_flowspec_get_match_per_ip(afi, rib, + &match, prefix_check); + if (rn != NULL) { + route_vty_out_flowspec(vty, &rn->p, + rn->info, use_json ? + NLRI_STRING_FORMAT_JSON : + NLRI_STRING_FORMAT_LARGE, + json_paths); + display++; + bgp_unlock_node(rn); + } } else { header = 1; @@ -8759,7 +8825,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str, afi_t afi, safi_t safi, struct prefix_rd *prd, int prefix_check, enum bgp_path_type pathtype, - u_char use_json) + uint8_t use_json) { if (!bgp) { bgp = bgp_get_default(); @@ -8783,7 +8849,7 @@ static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str, static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc, struct cmd_token **argv, afi_t afi, safi_t safi, - u_char uj) + uint8_t uj) { struct lcommunity *lcom; struct buffer *b; @@ -8820,7 +8886,7 @@ static int bgp_show_lcommunity(struct vty *vty, struct bgp *bgp, int argc, static int bgp_show_lcommunity_list(struct vty *vty, struct bgp *bgp, const char *lcom, afi_t afi, safi_t safi, - u_char uj) + uint8_t uj) { struct community_list *list; @@ -9126,7 +9192,7 @@ DEFUN (show_ip_bgp_route, char *prefix = NULL; struct bgp *bgp = NULL; enum bgp_path_type path_type; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 0; @@ -9363,7 +9429,7 @@ static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp, } static struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp, - const char *ip_str, u_char use_json) + const char *ip_str, uint8_t use_json) { int ret; struct peer *peer; @@ -9762,7 +9828,7 @@ static int bgp_peer_count_walker(struct thread *t) } static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi, - safi_t safi, u_char use_json) + safi_t safi, uint8_t use_json) { struct peer_pcounts pcounts = {.peer = peer}; unsigned int i; @@ -9908,7 +9974,7 @@ DEFUN (show_ip_bgp_vpn_neighbor_prefix_counts, { int idx_peer = 6; struct peer *peer; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); peer = peer_lookup_in_view(vty, NULL, argv[idx_peer]->arg, uj); if (!peer) @@ -9981,7 +10047,7 @@ DEFUN (show_ip_bgp_l2vpn_evpn_all_route_prefix, static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in, const char *rmap_name, - u_char use_json, json_object *json) + uint8_t use_json, json_object *json) { struct bgp_table *table; struct bgp_adj_in *ain; @@ -10205,7 +10271,7 @@ static void show_adj_route(struct vty *vty, struct peer *peer, afi_t afi, static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in, const char *rmap_name, - u_char use_json) + uint8_t use_json) { json_object *json = NULL; @@ -10347,7 +10413,7 @@ DEFUN (show_ip_bgp_neighbor_received_prefix_filter, argv_find(argv, argc, "neighbors", &idx); peerstr = argv[++idx]->arg; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); ret = str2sockunion(peerstr, &su); if (ret < 0) { @@ -10391,7 +10457,7 @@ DEFUN (show_ip_bgp_neighbor_received_prefix_filter, static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, - enum bgp_show_type type, u_char use_json) + enum bgp_show_type type, uint8_t use_json) { /* labeled-unicast routes live in the unicast table */ if (safi == SAFI_LABELED_UNICAST) @@ -10415,6 +10481,32 @@ static int bgp_show_neighbor_route(struct vty *vty, struct peer *peer, return bgp_show(vty, peer->bgp, afi, safi, type, &peer->su, use_json); } +DEFUN (show_ip_bgp_flowspec_routes_detailed, + show_ip_bgp_flowspec_routes_detailed_cmd, + "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" flowspec] detail [json]", + SHOW_STR + IP_STR + BGP_STR + BGP_INSTANCE_HELP_STR + BGP_AFI_HELP_STR + "SAFI Flowspec\n" + "Detailed information on flowspec entries\n" + JSON_STR) +{ + afi_t afi = AFI_IP; + safi_t safi = SAFI_UNICAST; + struct bgp *bgp = NULL; + int idx = 0; + + bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, + &bgp); + if (!idx) + return CMD_WARNING; + + return bgp_show(vty, bgp, afi, safi, + bgp_show_type_detail, NULL, use_json(argc, argv)); +} + DEFUN (show_ip_bgp_neighbor_routes, show_ip_bgp_neighbor_routes_cmd, "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_WITH_LABEL_CMD_STR"]] " @@ -10476,7 +10568,7 @@ struct bgp_table *bgp_distance_table[AFI_MAX][SAFI_MAX]; struct bgp_distance { /* Distance value for the IP source prefix. */ - u_char distance; + uint8_t distance; /* Name of the access-list to be matched. */ char *access_list; @@ -10532,7 +10624,7 @@ static int bgp_distance_set(struct vty *vty, const char *distance_str, afi_t afi; safi_t safi; struct prefix p; - u_char distance; + uint8_t distance; struct bgp_node *rn; struct bgp_distance *bdistance; @@ -10619,8 +10711,8 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, } /* Apply BGP information to distance method. */ -u_char bgp_distance_apply(struct prefix *p, struct bgp_info *rinfo, afi_t afi, - safi_t safi, struct bgp *bgp) +uint8_t bgp_distance_apply(struct prefix *p, struct bgp_info *rinfo, afi_t afi, + safi_t safi, struct bgp *bgp) { struct bgp_node *rn; struct prefix q; @@ -11197,7 +11289,7 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi, /* "network" configuration display. */ if (bgp_option_check(BGP_OPT_CONFIG_CISCO) && afi == AFI_IP) { - u_int32_t destination; + uint32_t destination; struct in_addr netmask; destination = ntohl(p->u.prefix4.s_addr); @@ -11306,7 +11398,7 @@ void bgp_route_init(void) /* Init BGP distance table. */ FOREACH_AFI_SAFI (afi, safi) - bgp_distance_table[afi][safi] = bgp_table_init(afi, safi); + bgp_distance_table[afi][safi] = bgp_table_init(NULL, afi, safi); /* IPv4 BGP commands. */ install_element(BGP_NODE, &bgp_table_map_cmd); @@ -11429,6 +11521,10 @@ void bgp_route_init(void) /* Large Communities */ install_element(VIEW_NODE, &show_ip_bgp_large_community_list_cmd); install_element(VIEW_NODE, &show_ip_bgp_large_community_cmd); + + /* show bgp ipv4 flowspec detailed */ + install_element(VIEW_NODE, &show_ip_bgp_flowspec_routes_detailed_cmd); + } void bgp_route_finish(void) diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 748c4f9110..1e788b00f1 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -48,7 +48,8 @@ enum bgp_show_type { bgp_show_type_flap_statistics, bgp_show_type_flap_neighbor, bgp_show_type_dampend_paths, - bgp_show_type_damp_neighbor + bgp_show_type_damp_neighbor, + bgp_show_type_detail, }; @@ -76,11 +77,11 @@ struct bgp_info_extra { int suppress; /* Nexthop reachability check. */ - u_int32_t igpmetric; + uint32_t igpmetric; /* MPLS label(s) - VNI(s) for EVPN-VxLAN */ mpls_label_t label[BGP_MAX_LABELS]; - u_int32_t num_labels; + uint32_t num_labels; #if ENABLE_BGP_VNC union { @@ -97,7 +98,7 @@ struct bgp_info_extra { void *hme; /* encap monitor, if this is a VPN route */ struct prefix_rd rd; /* import: route's route-distinguisher */ - u_char un_family; /* family of cached un address, 0 if + uint8_t un_family; /* family of cached un address, 0 if unset */ union { struct in_addr addr4; @@ -174,7 +175,7 @@ struct bgp_info { int lock; /* BGP information status. */ - u_int16_t flags; + uint16_t flags; #define BGP_INFO_IGP_CHANGED (1 << 0) #define BGP_INFO_DAMPED (1 << 1) #define BGP_INFO_HISTORY (1 << 2) @@ -189,13 +190,14 @@ struct bgp_info { #define BGP_INFO_MULTIPATH (1 << 11) #define BGP_INFO_MULTIPATH_CHG (1 << 12) #define BGP_INFO_RIB_ATTR_CHG (1 << 13) +#define BGP_INFO_ANNC_NH_SELF (1 << 14) /* BGP route type. This can be static, RIP, OSPF, BGP etc. */ - u_char type; + uint8_t type; /* When above type is BGP. This sub type specify BGP sub type information. */ - u_char sub_type; + uint8_t sub_type; #define BGP_ROUTE_NORMAL 0 #define BGP_ROUTE_STATIC 1 #define BGP_ROUTE_AGGREGATE 2 @@ -205,11 +207,11 @@ struct bgp_info { #endif #define BGP_ROUTE_IMPORTED 5 /* from another bgp instance/safi */ - u_short instance; + unsigned short instance; /* Addpath identifiers */ - u_int32_t addpath_rx_id; - u_int32_t addpath_tx_id; + uint32_t addpath_rx_id; + uint32_t addpath_tx_id; }; /* Structure used in BGP path selection */ @@ -224,20 +226,20 @@ struct bgp_static { int backdoor; /* Label index configuration; applies to LU prefixes. */ - u_int32_t label_index; + uint32_t label_index; #define BGP_INVALID_LABEL_INDEX 0xFFFFFFFF /* Import check status. */ - u_char valid; + uint8_t valid; /* IGP metric. */ - u_int32_t igpmetric; + uint32_t igpmetric; /* IGP nexthop. */ struct in_addr igpnexthop; /* Atomic set reference count (ie cause of pathlimit) */ - u_int32_t atomic; + uint32_t atomic; /* BGP redistribute route-map. */ struct { @@ -348,9 +350,8 @@ extern void bgp_info_add(struct bgp_node *rn, struct bgp_info *ri); extern void bgp_info_reap(struct bgp_node *rn, struct bgp_info *ri); extern void bgp_info_delete(struct bgp_node *rn, struct bgp_info *ri); extern struct bgp_info_extra *bgp_info_extra_get(struct bgp_info *); -extern void bgp_info_set_flag(struct bgp_node *, struct bgp_info *, u_int32_t); -extern void bgp_info_unset_flag(struct bgp_node *, struct bgp_info *, - u_int32_t); +extern void bgp_info_set_flag(struct bgp_node *, struct bgp_info *, uint32_t); +extern void bgp_info_unset_flag(struct bgp_node *, struct bgp_info *, uint32_t); extern void bgp_info_path_with_addpath_rx_str(struct bgp_info *ri, char *buf); extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *); @@ -360,11 +361,11 @@ extern int bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int); extern void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, const union g_addr *nexthop, ifindex_t ifindex, enum nexthop_types_t nhtype, uint32_t metric, - u_char type, u_short instance, + uint8_t type, unsigned short instance, route_tag_t tag); -extern void bgp_redistribute_delete(struct bgp *, struct prefix *, u_char, - u_short); -extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, u_short); +extern void bgp_redistribute_delete(struct bgp *, struct prefix *, uint8_t, + unsigned short); +extern void bgp_redistribute_withdraw(struct bgp *, afi_t, int, unsigned short); extern void bgp_static_add(struct bgp *); extern void bgp_static_delete(struct bgp *); @@ -384,13 +385,12 @@ extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *, const char *, const char *, const char *); /* this is primarily for MPLS-VPN */ -extern int bgp_update(struct peer *, struct prefix *, u_int32_t, struct attr *, +extern int bgp_update(struct peer *, struct prefix *, uint32_t, struct attr *, afi_t, safi_t, int, int, struct prefix_rd *, - mpls_label_t *, u_int32_t, int, struct bgp_route_evpn *); -extern int bgp_withdraw(struct peer *, struct prefix *, u_int32_t, - struct attr *, afi_t, safi_t, int, int, - struct prefix_rd *, mpls_label_t *, u_int32_t, - struct bgp_route_evpn *); + mpls_label_t *, uint32_t, int, struct bgp_route_evpn *); +extern int bgp_withdraw(struct peer *, struct prefix *, uint32_t, struct attr *, + afi_t, safi_t, int, int, struct prefix_rd *, + mpls_label_t *, uint32_t, struct bgp_route_evpn *); /* for bgp_nexthop and bgp_damp */ extern void bgp_process(struct bgp *, struct bgp_node *, afi_t, safi_t); @@ -411,22 +411,22 @@ extern void bgp_aggregate_increment(struct bgp *, struct prefix *, extern void bgp_aggregate_decrement(struct bgp *, struct prefix *, struct bgp_info *, afi_t, safi_t); -extern u_char bgp_distance_apply(struct prefix *, struct bgp_info *, afi_t, - safi_t, struct bgp *); +extern uint8_t bgp_distance_apply(struct prefix *, struct bgp_info *, afi_t, + safi_t, struct bgp *); extern afi_t bgp_node_afi(struct vty *); extern safi_t bgp_node_safi(struct vty *); -extern struct bgp_info *info_make(int type, int sub_type, u_short instance, - struct peer *peer, struct attr *attr, - struct bgp_node *rn); +extern struct bgp_info *info_make(int type, int sub_type, + unsigned short instance, struct peer *peer, + struct attr *attr, struct bgp_node *rn); extern void route_vty_out(struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *); extern void route_vty_out_tag(struct vty *, struct prefix *, struct bgp_info *, int, safi_t, json_object *); extern void route_vty_out_tmp(struct vty *, struct prefix *, struct attr *, - safi_t, u_char, json_object *); + safi_t, uint8_t, json_object *); extern void route_vty_out_overlay(struct vty *vty, struct prefix *p, struct bgp_info *binfo, int display, json_object *json); @@ -434,7 +434,7 @@ extern void route_vty_out_overlay(struct vty *vty, struct prefix *p, extern int subgroup_process_announce_selected(struct update_subgroup *subgrp, struct bgp_info *selected, struct bgp_node *rn, - u_int32_t addpath_tx_id); + uint32_t addpath_tx_id); extern int subgroup_announce_check(struct bgp_node *rn, struct bgp_info *ri, struct update_subgroup *subgrp, @@ -474,5 +474,5 @@ extern void route_vty_out_detail(struct vty *vty, struct bgp *bgp, extern int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, struct bgp_table *table, struct prefix_rd *prd, enum bgp_show_type type, void *output_arg, - u_char use_json); + uint8_t use_json); #endif /* _QUAGGA_BGP_ROUTE_H */ diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 5a265b6c9c..4cc889286e 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -122,12 +122,12 @@ o Local extensions #define RMAP_VALUE_SUB 2 struct rmap_value { - u_int8_t action; - u_int8_t variable; - u_int32_t value; + uint8_t action; + uint8_t variable; + uint32_t value; }; -static int route_value_match(struct rmap_value *rv, u_int32_t value) +static int route_value_match(struct rmap_value *rv, uint32_t value) { if (rv->variable == 0 && value == rv->value) return RMAP_MATCH; @@ -135,10 +135,10 @@ static int route_value_match(struct rmap_value *rv, u_int32_t value) return RMAP_NOMATCH; } -static u_int32_t route_value_adjust(struct rmap_value *rv, u_int32_t current, - struct peer *peer) +static uint32_t route_value_adjust(struct rmap_value *rv, uint32_t current, + struct peer *peer) { - u_int32_t value; + uint32_t value; switch (rv->variable) { case 1: @@ -165,7 +165,7 @@ static u_int32_t route_value_adjust(struct rmap_value *rv, u_int32_t current, static void *route_value_compile(const char *arg) { - u_int8_t action = RMAP_VALUE_SET, var = 0; + uint8_t action = RMAP_VALUE_SET, var = 0; unsigned long larg = 0; char *endptr = NULL; struct rmap_value *rv; @@ -723,10 +723,10 @@ static route_map_result_t route_match_evpn_route_type(void *rule, route_map_object_t type, void *object) { - u_char route_type = 0; + uint8_t route_type = 0; if (type == RMAP_BGP) { - route_type = *((u_char *)rule); + route_type = *((uint8_t *)rule); if (route_type == prefix->u.prefix_evpn.route_type) return RMAP_MATCH; @@ -738,9 +738,9 @@ static route_map_result_t route_match_evpn_route_type(void *rule, /* Route map `route-type' match statement. */ static void *route_match_evpn_route_type_compile(const char *arg) { - u_char *route_type = NULL; + uint8_t *route_type = NULL; - route_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_char)); + route_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); if (strncmp(arg, "ma", 2) == 0) *route_type = BGP_EVPN_MAC_IP_ROUTE; @@ -771,7 +771,7 @@ static route_map_result_t route_match_local_pref(void *rule, route_map_object_t type, void *object) { - u_int32_t *local_pref; + uint32_t *local_pref; struct bgp_info *bgp_info; if (type == RMAP_BGP) { @@ -790,7 +790,7 @@ static route_map_result_t route_match_local_pref(void *rule, `arg' is local-pref value */ static void *route_match_local_pref_compile(const char *arg) { - u_int32_t *local_pref; + uint32_t *local_pref; char *endptr = NULL; unsigned long tmpval; @@ -803,7 +803,7 @@ static void *route_match_local_pref_compile(const char *arg) if (*endptr != '\0' || errno || tmpval > UINT32_MAX) return NULL; - local_pref = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + local_pref = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); if (!local_pref) return local_pref; @@ -1073,7 +1073,7 @@ static route_map_result_t route_match_origin(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_char *origin; + uint8_t *origin; struct bgp_info *bgp_info; if (type == RMAP_BGP) { @@ -1089,9 +1089,9 @@ static route_map_result_t route_match_origin(void *rule, struct prefix *prefix, static void *route_match_origin_compile(const char *arg) { - u_char *origin; + uint8_t *origin; - origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_char)); + origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); if (strcmp(arg, "igp") == 0) *origin = 0; @@ -1362,7 +1362,7 @@ static route_map_result_t route_set_local_pref(void *rule, { struct rmap_value *rv; struct bgp_info *bgp_info; - u_int32_t locpref = 0; + uint32_t locpref = 0; if (type == RMAP_BGP) { /* Fetch routemap's rule information. */ @@ -1424,7 +1424,7 @@ static route_map_result_t route_set_metric(void *rule, struct prefix *prefix, { struct rmap_value *rv; struct bgp_info *bgp_info; - u_int32_t med = 0; + uint32_t med = 0; if (type == RMAP_BGP) { /* Fetch routemap's rule information. */ @@ -2035,7 +2035,7 @@ static route_map_result_t route_set_origin(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_char *origin; + uint8_t *origin; struct bgp_info *bgp_info; if (type == RMAP_BGP) { @@ -2051,9 +2051,9 @@ static route_map_result_t route_set_origin(void *rule, struct prefix *prefix, /* Compile function for origin set. */ static void *route_set_origin_compile(const char *arg) { - u_char *origin; + uint8_t *origin; - origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_char)); + origin = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); if (strcmp(arg, "igp") == 0) *origin = 0; @@ -2205,7 +2205,7 @@ static route_map_result_t route_set_label_index(void *rule, { struct rmap_value *rv; struct bgp_info *bgp_info; - u_int32_t label_index; + uint32_t label_index; if (type == RMAP_BGP) { /* Fetch routemap's rule information. */ diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 7c9a134b0f..75ba1609d0 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -179,7 +179,7 @@ static void *route_match_compile(const char *arg) { int *rpki_status; - rpki_status = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_char)); + rpki_status = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint8_t)); if (strcmp(arg, "valid") == 0) *rpki_status = RPKI_VALID; diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index 90ffa9da34..2c7e4e0435 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -125,19 +125,19 @@ static oid bgp_trap_oid[] = {BGP4MIB, 0}; static struct in_addr bgp_empty_addr = {.s_addr = 0}; /* Hook functions. */ -static u_char *bgpVersion(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); -static u_char *bgpLocalAs(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); -static u_char *bgpPeerTable(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); -static u_char *bgpRcvdPathAttrTable(struct variable *, oid[], size_t *, int, - size_t *, WriteMethod **); -static u_char *bgpIdentifier(struct variable *, oid[], size_t *, int, size_t *, +static uint8_t *bgpVersion(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *bgpLocalAs(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *bgpPeerTable(struct variable *, oid[], size_t *, int, size_t *, WriteMethod **); -static u_char *bgp4PathAttrTable(struct variable *, oid[], size_t *, int, - size_t *, WriteMethod **); -/* static u_char *bgpTraps (); */ +static uint8_t *bgpRcvdPathAttrTable(struct variable *, oid[], size_t *, int, + size_t *, WriteMethod **); +static uint8_t *bgpIdentifier(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *bgp4PathAttrTable(struct variable *, oid[], size_t *, int, + size_t *, WriteMethod **); +/* static uint8_t *bgpTraps (); */ static struct variable bgp_variables[] = { /* BGP version. */ @@ -315,11 +315,11 @@ static struct variable bgp_variables[] = { }; -static u_char *bgpVersion(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgpVersion(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { - static u_char version; + static uint8_t version; if (smux_header_generic(v, name, length, exact, var_len, write_method) == MATCH_FAILED) @@ -330,12 +330,12 @@ static u_char *bgpVersion(struct variable *v, oid name[], size_t *length, /* Return octet string length 1. */ *var_len = 1; - return (u_char *)&version; + return (uint8_t *)&version; } -static u_char *bgpLocalAs(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgpLocalAs(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct bgp *bgp; @@ -443,9 +443,9 @@ static struct peer *bgpPeerTable_lookup(struct variable *v, oid name[], } /* BGP write methods. */ -static int write_bgpPeerTable(int action, u_char *var_val, u_char var_val_type, - size_t var_val_len, u_char *statP, oid *name, - size_t length) +static int write_bgpPeerTable(int action, uint8_t *var_val, + uint8_t var_val_type, size_t var_val_len, + uint8_t *statP, oid *name, size_t length) { struct in_addr addr; struct peer *peer; @@ -506,9 +506,9 @@ static int write_bgpPeerTable(int action, u_char *var_val, u_char var_val_type, return SNMP_ERR_NOERROR; } -static u_char *bgpPeerTable(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgpPeerTable(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { static struct in_addr addr; struct peer *peer; @@ -588,11 +588,11 @@ static u_char *bgpPeerTable(struct variable *v, oid name[], size_t *length, return SNMP_INTEGER(PEER_TOTAL_TX(peer)); break; case BGPPEERLASTERROR: { - static u_char lasterror[2]; + static uint8_t lasterror[2]; lasterror[0] = peer->notify.code; lasterror[1] = peer->notify.subcode; *var_len = 2; - return (u_char *)&lasterror; + return (uint8_t *)&lasterror; } break; case BGPPEERFSMESTABLISHEDTRANSITIONS: return SNMP_INTEGER(peer->established); @@ -644,9 +644,9 @@ static u_char *bgpPeerTable(struct variable *v, oid name[], size_t *length, return NULL; } -static u_char *bgpIdentifier(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgpIdentifier(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct bgp *bgp; @@ -661,9 +661,9 @@ static u_char *bgpIdentifier(struct variable *v, oid name[], size_t *length, return SNMP_IPADDRESS(bgp->router_id); } -static u_char *bgpRcvdPathAttrTable(struct variable *v, oid name[], - size_t *length, int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgpRcvdPathAttrTable(struct variable *v, oid name[], + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { /* Received Path Attribute Table. This table contains, one entry per path to a network, path attributes received from all peers @@ -805,9 +805,9 @@ static struct bgp_info *bgp4PathAttrLookup(struct variable *v, oid name[], return NULL; } -static u_char *bgp4PathAttrTable(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[], + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { struct bgp *bgp; struct bgp_info *binfo; diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c index 261ab9f76d..613b924d0d 100644 --- a/bgpd/bgp_table.c +++ b/bgpd/bgp_table.c @@ -90,7 +90,7 @@ route_table_delegate_t bgp_table_delegate = {.create_node = bgp_node_create, /* * bgp_table_init */ -struct bgp_table *bgp_table_init(afi_t afi, safi_t safi) +struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t afi, safi_t safi) { struct bgp_table *rt; @@ -103,6 +103,11 @@ struct bgp_table *bgp_table_init(afi_t afi, safi_t safi) */ rt->route_table->info = rt; + /* + * pointer to bgp instance allows working back from bgp_info to bgp + */ + rt->bgp = bgp; + bgp_table_lock(rt); rt->afi = afi; rt->safi = safi; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index a4f3b604c2..388c247227 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -26,6 +26,9 @@ #include "queue.h" struct bgp_table { + /* table belongs to this instance */ + struct bgp *bgp; + /* afi/safi of this table */ afi_t afi; safi_t safi; @@ -58,7 +61,7 @@ struct bgp_node { mpls_label_t local_label; uint64_t version; - u_char flags; + uint8_t flags; #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) #define BGP_NODE_USER_CLEAR (1 << 1) #define BGP_NODE_LABEL_CHANGED (1 << 2) @@ -75,7 +78,7 @@ typedef struct bgp_table_iter_t_ { route_table_iter_t rt_iter; } bgp_table_iter_t; -extern struct bgp_table *bgp_table_init(afi_t, safi_t); +extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t); extern void bgp_table_lock(struct bgp_table *); extern void bgp_table_unlock(struct bgp_table *); extern void bgp_table_finish(struct bgp_table **); diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 233fe5d14e..c1cbca6dcf 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -77,7 +77,7 @@ typedef enum { BGP_ATTR_VEC_NH = 0, BGP_ATTR_VEC_MAX } bpacket_attr_vec_type; typedef struct { - u_int32_t flags; + uint32_t flags; unsigned long offset; } bpacket_attr_vec; @@ -139,19 +139,19 @@ struct update_group { uint64_t id; time_t uptime; - u_int32_t join_events; - u_int32_t prune_events; - u_int32_t merge_events; - u_int32_t updgrp_switch_events; - u_int32_t peer_refreshes_combined; - u_int32_t adj_count; - u_int32_t split_events; - u_int32_t merge_checks_triggered; + uint32_t join_events; + uint32_t prune_events; + uint32_t merge_events; + uint32_t updgrp_switch_events; + uint32_t peer_refreshes_combined; + uint32_t adj_count; + uint32_t split_events; + uint32_t merge_checks_triggered; - u_int32_t subgrps_created; - u_int32_t subgrps_deleted; + uint32_t subgrps_created; + uint32_t subgrps_deleted; - u_int32_t num_dbg_en_peers; + uint32_t num_dbg_en_peers; }; /* @@ -214,7 +214,7 @@ struct update_subgroup { struct hash *hash; struct thread *t_coalesce; - u_int32_t v_coalesce; + uint32_t v_coalesce; struct thread *t_merge_check; @@ -236,25 +236,25 @@ struct update_subgroup { uint64_t subgroup_id; } split_from; - u_int32_t join_events; - u_int32_t prune_events; + uint32_t join_events; + uint32_t prune_events; /* * This is bumped up when another subgroup merges into this one. */ - u_int32_t merge_events; - u_int32_t updgrp_switch_events; - u_int32_t peer_refreshes_combined; - u_int32_t adj_count; - u_int32_t split_events; - u_int32_t merge_checks_triggered; + uint32_t merge_events; + uint32_t updgrp_switch_events; + uint32_t peer_refreshes_combined; + uint32_t adj_count; + uint32_t split_events; + uint32_t merge_checks_triggered; uint64_t id; - u_int16_t sflags; + uint16_t sflags; /* Subgroup flags, see below */ - u_int16_t flags; + uint16_t flags; }; /* @@ -302,7 +302,7 @@ struct updwalk_context { int policy_route_update; updgrp_walkcb cb; void *context; - u_int8_t flags; + uint8_t flags; #define UPDWALK_FLAGS_ADVQUEUE (1 << 0) #define UPDWALK_FLAGS_ADVERTISED (1 << 1) @@ -449,7 +449,7 @@ extern void update_group_announce_rrclients(struct bgp *bgp); extern void peer_af_announce_route(struct peer_af *paf, int combine); extern struct bgp_adj_out *bgp_adj_out_alloc(struct update_subgroup *subgrp, struct bgp_node *rn, - u_int32_t addpath_tx_id); + uint32_t addpath_tx_id); extern void bgp_adj_out_remove_subgroup(struct bgp_node *rn, struct bgp_adj_out *adj, struct update_subgroup *subgrp); @@ -458,7 +458,7 @@ extern void bgp_adj_out_set_subgroup(struct bgp_node *rn, struct attr *attr, struct bgp_info *binfo); extern void bgp_adj_out_unset_subgroup(struct bgp_node *rn, struct update_subgroup *subgrp, - char withdraw, u_int32_t addpath_tx_id); + char withdraw, uint32_t addpath_tx_id); void subgroup_announce_table(struct update_subgroup *subgrp, struct bgp_table *table); extern void subgroup_trigger_write(struct update_subgroup *subgrp); diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index e66e5a540b..d555006571 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -57,7 +57,7 @@ static inline struct bgp_adj_out *adj_lookup(struct bgp_node *rn, struct update_subgroup *subgrp, - u_int32_t addpath_tx_id) + uint32_t addpath_tx_id) { struct bgp_adj_out *adj; struct peer *peer; @@ -207,7 +207,7 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg) } static void subgrp_show_adjq_vty(struct update_subgroup *subgrp, - struct vty *vty, u_int8_t flags) + struct vty *vty, uint8_t flags) { struct bgp_table *table; struct bgp_adj_out *adj; @@ -280,7 +280,7 @@ static int updgrp_show_adj_walkcb(struct update_group *updgrp, void *arg) } static void updgrp_show_adj(struct bgp *bgp, afi_t afi, safi_t safi, - struct vty *vty, uint64_t id, u_int8_t flags) + struct vty *vty, uint64_t id, uint8_t flags) { struct updwalk_context ctx; memset(&ctx, 0, sizeof(ctx)); @@ -370,7 +370,7 @@ static int update_group_announce_rrc_walkcb(struct update_group *updgrp, */ struct bgp_adj_out *bgp_adj_out_alloc(struct update_subgroup *subgrp, struct bgp_node *rn, - u_int32_t addpath_tx_id) + uint32_t addpath_tx_id) { struct bgp_adj_out *adj; @@ -487,7 +487,7 @@ void bgp_adj_out_set_subgroup(struct bgp_node *rn, */ void bgp_adj_out_unset_subgroup(struct bgp_node *rn, struct update_subgroup *subgrp, char withdraw, - u_int32_t addpath_tx_id) + uint32_t addpath_tx_id) { struct bgp_adj_out *adj; struct bgp_advertise *adv; diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 1d50cb1ca1..8ba7902a5f 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -396,7 +396,7 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, vec = &pkt->arr.entries[BGP_ATTR_VEC_NH]; if (CHECK_FLAG(vec->flags, BPKT_ATTRVEC_FLAGS_UPDATED)) { - u_int8_t nhlen; + uint8_t nhlen; afi_t nhafi = AFI_MAX; /* NH AFI is based on nhlen! */ int route_map_sets_nh; nhlen = stream_getc_from(s, vec->offset); @@ -699,10 +699,10 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) int num_pfx = 0; int addpath_encode = 0; int addpath_overhead = 0; - u_int32_t addpath_tx_id = 0; + uint32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; mpls_label_t label = MPLS_INVALID_LABEL, *label_pnt = NULL; - u_int32_t num_labels = 0; + uint32_t num_labels = 0; if (!subgrp) return NULL; @@ -937,7 +937,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) size_t mp_start = 0; size_t attrlen_pos = 0; size_t mplen_pos = 0; - u_char first_time = 1; + uint8_t first_time = 1; afi_t afi; safi_t safi; int space_remaining = 0; @@ -945,7 +945,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) int num_pfx = 0; int addpath_encode = 0; int addpath_overhead = 0; - u_int32_t addpath_tx_id = 0; + uint32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index 4661e195a2..80bd2cd799 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -32,7 +32,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, struct prefix_rd *prd, afi_t afi, safi_t safi, - u_char use_json) + uint8_t use_json) { struct bgp *bgp; struct bgp_table *table; @@ -124,14 +124,14 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, } if (rd_header) { - u_int16_t type; + uint16_t type; struct rd_as rd_as; struct rd_ip rd_ip = {0}; #if ENABLE_BGP_VNC struct rd_vnc_eth rd_vnc_eth = { 0}; #endif - u_char *pnt; + uint8_t *pnt; pnt = rn->p.u.val; diff --git a/bgpd/bgp_vpn.h b/bgpd/bgp_vpn.h index d2a2cb4a5e..98b4d9f180 100644 --- a/bgpd/bgp_vpn.h +++ b/bgpd/bgp_vpn.h @@ -25,6 +25,6 @@ extern int show_adj_route_vpn(struct vty *vty, struct peer *peer, struct prefix_rd *prd, afi_t afi, safi_t safi, - u_char use_json); + uint8_t use_json); #endif /* _QUAGGA_BGP_VPN_H */ diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index ad6f1a5588..3e577317ad 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -80,6 +80,8 @@ static enum node_type bgp_node_type(afi_t afi, safi_t safi) case SAFI_MPLS_VPN: return BGP_VPNV4_NODE; break; + case SAFI_FLOWSPEC: + return BGP_FLOWSPECV4_NODE; default: /* not expected */ return BGP_IPV4_NODE; @@ -100,6 +102,8 @@ static enum node_type bgp_node_type(afi_t afi, safi_t safi) case SAFI_MPLS_VPN: return BGP_VPNV6_NODE; break; + case SAFI_FLOWSPEC: + return BGP_FLOWSPECV6_NODE; default: /* not expected */ return BGP_IPV4_NODE; @@ -128,6 +132,7 @@ afi_t bgp_node_afi(struct vty *vty) case BGP_IPV6M_NODE: case BGP_IPV6L_NODE: case BGP_VPNV6_NODE: + case BGP_FLOWSPECV6_NODE: afi = AFI_IP6; break; case BGP_EVPN_NODE: @@ -161,6 +166,10 @@ safi_t bgp_node_safi(struct vty *vty) case BGP_IPV6L_NODE: safi = SAFI_LABELED_UNICAST; break; + case BGP_FLOWSPECV4_NODE: + case BGP_FLOWSPECV6_NODE: + safi = SAFI_FLOWSPEC; + break; default: safi = SAFI_UNICAST; break; @@ -214,6 +223,8 @@ safi_t bgp_vty_safi_from_str(const char *safi_str) safi = SAFI_MPLS_VPN; else if (strmatch(safi_str, "labeled-unicast")) safi = SAFI_LABELED_UNICAST; + else if (strmatch(safi_str, "flowspec")) + safi = SAFI_FLOWSPEC; return safi; } @@ -237,6 +248,10 @@ int argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, ret = 1; if (safi) *safi = SAFI_MPLS_VPN; + } else if (argv_find(argv, argc, "flowspec", index)) { + ret = 1; + if (safi) + *safi = SAFI_FLOWSPEC; } return ret; } @@ -1111,11 +1126,11 @@ DEFUN (no_bgp_confederation_peers, * @set: 1 for setting values, 0 for removing the max-paths config. */ static int bgp_maxpaths_config_vty(struct vty *vty, int peer_type, - const char *mpaths, u_int16_t options, + const char *mpaths, uint16_t options, int set) { VTY_DECLVAR_CONTEXT(bgp, bgp); - u_int16_t maxpaths = 0; + uint16_t maxpaths = 0; int ret; afi_t afi; safi_t safi; @@ -1257,8 +1272,8 @@ static int bgp_update_delay_config_vty(struct vty *vty, const char *delay, const char *wait) { VTY_DECLVAR_CONTEXT(bgp, bgp); - u_int16_t update_delay; - u_int16_t establish_wait; + uint16_t update_delay; + uint16_t establish_wait; update_delay = strtoul(delay, NULL, 10); @@ -1779,7 +1794,7 @@ DEFUN (bgp_graceful_restart_stalepath_time, { VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; - u_int32_t stalepath; + uint32_t stalepath; stalepath = strtoul(argv[idx_number]->arg, NULL, 10); bgp->stalepath_time = stalepath; @@ -1796,7 +1811,7 @@ DEFUN (bgp_graceful_restart_restart_time, { VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; - u_int32_t restart; + uint32_t restart; restart = strtoul(argv[idx_number]->arg, NULL, 10); bgp->restart_time = restart; @@ -2292,7 +2307,7 @@ DEFUN (bgp_default_local_preference, { VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; - u_int32_t local_pref; + uint32_t local_pref; local_pref = strtoul(argv[idx_number]->arg, NULL, 10); @@ -2329,7 +2344,7 @@ DEFUN (bgp_default_subgroup_pkt_queue_max, { VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_number = 3; - u_int32_t max_size; + uint32_t max_size; max_size = strtoul(argv[idx_number]->arg, NULL, 10); @@ -3404,7 +3419,7 @@ ALIAS_HIDDEN(no_neighbor_set_peer_group, no_neighbor_set_peer_group_hidden_cmd, "Peer-group name\n") static int peer_flag_modify_vty(struct vty *vty, const char *ip_str, - u_int16_t flag, int set) + uint16_t flag, int set) { int ret; struct peer *peer; @@ -3436,14 +3451,13 @@ static int peer_flag_modify_vty(struct vty *vty, const char *ip_str, return bgp_vty_return(vty, ret); } -static int peer_flag_set_vty(struct vty *vty, const char *ip_str, - u_int16_t flag) +static int peer_flag_set_vty(struct vty *vty, const char *ip_str, uint16_t flag) { return peer_flag_modify_vty(vty, ip_str, flag, 1); } static int peer_flag_unset_vty(struct vty *vty, const char *ip_str, - u_int16_t flag) + uint16_t flag) { return peer_flag_modify_vty(vty, ip_str, flag, 0); } @@ -3608,7 +3622,7 @@ DEFUN (no_neighbor_capability_enhe, } static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str, - afi_t afi, safi_t safi, u_int32_t flag, + afi_t afi, safi_t safi, uint32_t flag, int set) { int ret; @@ -3627,13 +3641,13 @@ static int peer_af_flag_modify_vty(struct vty *vty, const char *peer_str, } static int peer_af_flag_set_vty(struct vty *vty, const char *peer_str, - afi_t afi, safi_t safi, u_int32_t flag) + afi_t afi, safi_t safi, uint32_t flag) { return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 1); } static int peer_af_flag_unset_vty(struct vty *vty, const char *peer_str, - afi_t afi, safi_t safi, u_int32_t flag) + afi_t afi, safi_t safi, uint32_t flag) { return peer_af_flag_modify_vty(vty, peer_str, afi, safi, flag, 0); } @@ -3653,7 +3667,7 @@ DEFUN (neighbor_capability_orf_prefix, { int idx_peer = 1; int idx_send_recv = 5; - u_int16_t flag = 0; + uint16_t flag = 0; if (strmatch(argv[idx_send_recv]->text, "send")) flag = PEER_FLAG_ORF_PREFIX_SM; @@ -3697,7 +3711,7 @@ DEFUN (no_neighbor_capability_orf_prefix, { int idx_peer = 2; int idx_send_recv = 6; - u_int16_t flag = 0; + uint16_t flag = 0; if (strmatch(argv[idx_send_recv]->text, "send")) flag = PEER_FLAG_ORF_PREFIX_SM; @@ -4072,7 +4086,7 @@ DEFUN (neighbor_send_community_type, "Send Large Community attributes\n") { int idx = 0; - u_int32_t flag = 0; + uint32_t flag = 0; char *peer = argv[1]->arg; @@ -4338,7 +4352,7 @@ DEFUN (neighbor_attr_unchanged, int idx = 0; char *peer_str = argv[1]->arg; struct peer *peer; - u_int16_t flags = 0; + uint16_t flags = 0; afi_t afi = bgp_node_afi(vty); safi_t safi = bgp_node_safi(vty); @@ -4408,7 +4422,7 @@ DEFUN (no_neighbor_attr_unchanged, { int idx = 0; char *peer = argv[2]->arg; - u_int16_t flags = 0; + uint16_t flags = 0; if (argv_find(argv, argc, "as-path", &idx)) SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED); @@ -4747,7 +4761,7 @@ static int peer_port_vty(struct vty *vty, const char *ip_str, int afi, const char *port_str) { struct peer *peer; - u_int16_t port; + uint16_t port; struct servent *sp; peer = peer_lookup_vty(vty, ip_str); @@ -4924,8 +4938,8 @@ static int peer_timers_set_vty(struct vty *vty, const char *ip_str, { int ret; struct peer *peer; - u_int32_t keepalive; - u_int32_t holdtime; + uint32_t keepalive; + uint32_t holdtime; peer = peer_and_group_lookup_vty(vty, ip_str); if (!peer) @@ -4990,7 +5004,7 @@ static int peer_timers_connect_set_vty(struct vty *vty, const char *ip_str, { int ret; struct peer *peer; - u_int32_t connect; + uint32_t connect; peer = peer_and_group_lookup_vty(vty, ip_str); if (!peer) @@ -5052,7 +5066,7 @@ static int peer_advertise_interval_vty(struct vty *vty, const char *ip_str, { int ret; struct peer *peer; - u_int32_t routeadv = 0; + uint32_t routeadv = 0; peer = peer_and_group_lookup_vty(vty, ip_str); if (!peer) @@ -5107,7 +5121,7 @@ DEFUN (bgp_set_route_map_delay_timer, "0 disables the timer, no route updates happen when route-maps change\n") { int idx_number = 3; - u_int32_t rmap_delay_timer; + uint32_t rmap_delay_timer; if (argv[idx_number]->arg) { rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10); @@ -5658,9 +5672,9 @@ static int peer_maximum_prefix_set_vty(struct vty *vty, const char *ip_str, { int ret; struct peer *peer; - u_int32_t max; - u_char threshold; - u_int16_t restart; + uint32_t max; + uint8_t threshold; + uint16_t restart; peer = peer_and_group_lookup_vty(vty, ip_str); if (!peer) @@ -6588,12 +6602,69 @@ DEFPY (bgp_imexport_vpn, return CMD_SUCCESS; } +DEFPY (af_routetarget_import, + af_routetarget_import_cmd, + "[no] <rt|route-target> redirect import RTLIST...", + NO_STR + "Specify route target list\n" + "Specify route target list\n" + "Flow-spec redirect type route target\n" + "Import routes to this address-family\n" + "Space separated route target list (A.B.C.D:MN|EF:OPQR|GHJK:MN)\n") +{ + VTY_DECLVAR_CONTEXT(bgp, bgp); + int ret; + struct ecommunity *ecom = NULL; + int doafi[AFI_MAX] = {0}; + afi_t afi; + int idx = 0; + int yes = 1; + + if (argv_find(argv, argc, "no", &idx)) + yes = 0; + + ret = vpn_policy_getafi(vty, doafi); + if (ret != CMD_SUCCESS) + return ret; + if (yes) { + if (!argv_find(argv, argc, "RTLIST", &idx)) { + vty_out(vty, "%% Missing RTLIST\n"); + return CMD_WARNING_CONFIG_FAILED; + } + ret = set_ecom_list(vty, argc - idx, argv + idx, &ecom); + if (ret != CMD_SUCCESS) + return ret; + } + for (afi = 0; afi < AFI_MAX; ++afi) { + if (!doafi[afi]) + continue; + if (yes) { + if (bgp->vpn_policy[afi].import_redirect_rtlist) + ecommunity_free( + &bgp->vpn_policy[afi] + .import_redirect_rtlist); + bgp->vpn_policy[afi].import_redirect_rtlist = + ecommunity_dup(ecom); + } else { + if (bgp->vpn_policy[afi].import_redirect_rtlist) + ecommunity_free( + &bgp->vpn_policy[afi] + .import_redirect_rtlist); + bgp->vpn_policy[afi].import_redirect_rtlist = NULL; + } + } + if (ecom) + ecommunity_free(&ecom); + + return CMD_SUCCESS; +} + DEFUN_NOSH (address_family_ipv4_safi, - address_family_ipv4_safi_cmd, - "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast>]", - "Enter Address Family command mode\n" - "Address Family\n" - BGP_SAFI_WITH_LABEL_HELP_STR) + address_family_ipv4_safi_cmd, + "address-family ipv4 [<unicast|multicast|vpn|labeled-unicast|flowspec>]", + "Enter Address Family command mode\n" + "Address Family\n" + BGP_SAFI_WITH_LABEL_HELP_STR) { if (argc == 3) { @@ -6614,11 +6685,11 @@ DEFUN_NOSH (address_family_ipv4_safi, } DEFUN_NOSH (address_family_ipv6_safi, - address_family_ipv6_safi_cmd, - "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast>]", - "Enter Address Family command mode\n" - "Address Family\n" - BGP_SAFI_WITH_LABEL_HELP_STR) + address_family_ipv6_safi_cmd, + "address-family ipv6 [<unicast|multicast|vpn|labeled-unicast|flowspec>]", + "Enter Address Family command mode\n" + "Address Family\n" + BGP_SAFI_WITH_LABEL_HELP_STR) { if (argc == 3) { VTY_DECLVAR_CONTEXT(bgp, bgp); @@ -6682,7 +6753,9 @@ DEFUN_NOSH (exit_address_family, || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6M_NODE || vty->node == BGP_IPV6L_NODE || vty->node == BGP_VPNV6_NODE - || vty->node == BGP_EVPN_NODE) + || vty->node == BGP_EVPN_NODE + || vty->node == BGP_FLOWSPECV4_NODE + || vty->node == BGP_FLOWSPECV6_NODE) vty->node = BGP_NODE; return CMD_SUCCESS; } @@ -6969,7 +7042,7 @@ DEFUN (show_bgp_vrfs, struct list *inst = bm->bgp; struct listnode *node; struct bgp *bgp; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); json_object *json = NULL; json_object *json_vrfs = NULL; int count = 0; @@ -7290,7 +7363,7 @@ static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json) /* Show BGP peer's summary information. */ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, - u_char use_json, json_object *json) + uint8_t use_json, json_object *json) { struct peer *peer; struct listnode *node, *nnode; @@ -7705,7 +7778,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, } static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, - int safi, u_char use_json, + int safi, uint8_t use_json, json_object *json) { int is_first = 1; @@ -7767,7 +7840,7 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, } static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, - safi_t safi, u_char use_json) + safi_t safi, uint8_t use_json) { struct listnode *node, *nnode; struct bgp *bgp; @@ -7804,7 +7877,7 @@ static void bgp_show_all_instances_summary_vty(struct vty *vty, afi_t afi, } int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, - safi_t safi, u_char use_json) + safi_t safi, uint8_t use_json) { struct bgp *bgp; @@ -7887,6 +7960,8 @@ const char *afi_safi_print(afi_t afi, safi_t safi) return "IPv4 VPN"; else if (afi == AFI_IP && safi == SAFI_ENCAP) return "IPv4 Encap"; + else if (afi == AFI_IP && safi == SAFI_FLOWSPEC) + return "IPv4 Flowspec"; else if (afi == AFI_IP6 && safi == SAFI_UNICAST) return "IPv6 Unicast"; else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) @@ -7897,6 +7972,8 @@ const char *afi_safi_print(afi_t afi, safi_t safi) return "IPv6 VPN"; else if (afi == AFI_IP6 && safi == SAFI_ENCAP) return "IPv6 Encap"; + else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC) + return "IPv6 Flowspec"; else if (afi == AFI_L2VPN && safi == SAFI_EVPN) return "L2VPN EVPN"; else @@ -7921,6 +7998,8 @@ const char *afi_safi_json(afi_t afi, safi_t safi) return "ipv4Vpn"; else if (afi == AFI_IP && safi == SAFI_ENCAP) return "ipv4Encap"; + else if (afi == AFI_IP && safi == SAFI_FLOWSPEC) + return "ipv4Flowspec"; else if (afi == AFI_IP6 && safi == SAFI_UNICAST) return "ipv6Unicast"; else if (afi == AFI_IP6 && safi == SAFI_MULTICAST) @@ -7931,6 +8010,8 @@ const char *afi_safi_json(afi_t afi, safi_t safi) return "ipv6Vpn"; else if (afi == AFI_IP6 && safi == SAFI_ENCAP) return "ipv6Encap"; + else if (afi == AFI_IP6 && safi == SAFI_FLOWSPEC) + return "ipv6Flowspec"; else if (afi == AFI_L2VPN && safi == SAFI_EVPN) return "l2VpnEvpn"; else @@ -7942,9 +8023,9 @@ enum show_type { show_all, show_peer }; static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p, afi_t afi, safi_t safi, - u_int16_t adv_smcap, u_int16_t adv_rmcap, - u_int16_t rcv_smcap, u_int16_t rcv_rmcap, - u_char use_json, json_object *json_pref) + uint16_t adv_smcap, uint16_t adv_rmcap, + uint16_t rcv_smcap, uint16_t rcv_rmcap, + uint8_t use_json, json_object *json_pref) { /* Send-Mode */ if (CHECK_FLAG(p->af_cap[afi][safi], adv_smcap) @@ -8004,7 +8085,7 @@ static void bgp_show_peer_afi_orf_cap(struct vty *vty, struct peer *p, } static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, - safi_t safi, u_char use_json, + safi_t safi, uint8_t use_json, json_object *json_neigh) { struct bgp_filter *filter; @@ -8579,7 +8660,7 @@ static void bgp_show_peer_afi(struct vty *vty, struct peer *p, afi_t afi, } } -static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, +static void bgp_show_peer(struct vty *vty, struct peer *p, uint8_t use_json, json_object *json) { struct bgp *bgp; @@ -8590,8 +8671,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, const char *code_str; afi_t afi; safi_t safi; - u_int16_t i; - u_char *msg; + uint16_t i; + uint8_t *msg; json_object *json_neigh = NULL; time_t epoch_tbuf; @@ -8784,7 +8865,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, uptime -= p->uptime; epoch_tbuf = time(NULL) - uptime; -#if CONFDATE > 20200101 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20200101 CPP_NOTICE( "bgpTimerUp should be deprecated and can be removed now"); #endif @@ -8945,8 +9026,12 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, || p->afc_recv[AFI_IP6][SAFI_MPLS_VPN] || p->afc_adv[AFI_IP6][SAFI_ENCAP] || p->afc_recv[AFI_IP6][SAFI_ENCAP] + || p->afc_adv[AFI_IP6][SAFI_FLOWSPEC] + || p->afc_recv[AFI_IP6][SAFI_FLOWSPEC] || p->afc_adv[AFI_IP][SAFI_ENCAP] || p->afc_recv[AFI_IP][SAFI_ENCAP] + || p->afc_adv[AFI_IP][SAFI_FLOWSPEC] + || p->afc_recv[AFI_IP][SAFI_FLOWSPEC] || p->afc_adv[AFI_IP][SAFI_MPLS_VPN] || p->afc_recv[AFI_IP][SAFI_MPLS_VPN]) { if (use_json) { @@ -10026,7 +10111,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, msg_str = bgp_notify_admin_message( msgbuf, sizeof(msgbuf), - (u_char *)p->notify.data, + (uint8_t *)p->notify.data, p->notify.length); if (msg_str) json_object_string_add( @@ -10062,7 +10147,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, msg_str = bgp_notify_admin_message( msgbuf, sizeof(msgbuf), - (u_char *)p->notify.data, + (uint8_t *)p->notify.data, p->notify.length); if (msg_str) vty_out(vty, @@ -10316,7 +10401,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json, static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, enum show_type type, union sockunion *su, - const char *conf_if, u_char use_json, + const char *conf_if, uint8_t use_json, json_object *json) { struct listnode *node, *nnode; @@ -10373,7 +10458,7 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, static void bgp_show_all_instances_neighbors_vty(struct vty *vty, enum show_type type, const char *ip_str, - u_char use_json) + uint8_t use_json) { struct listnode *node, *nnode; struct bgp *bgp; @@ -10440,7 +10525,7 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty, static int bgp_show_neighbor_vty(struct vty *vty, const char *name, enum show_type type, const char *ip_str, - u_char use_json) + uint8_t use_json) { int ret; struct bgp *bgp; @@ -10515,7 +10600,7 @@ DEFUN (show_ip_bgp_neighbors, char *sh_arg = NULL; enum show_type sh_type; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 0; @@ -11027,7 +11112,7 @@ DEFUN (bgp_redistribute_ipv4_metric, int idx_protocol = 1; int idx_number = 3; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); @@ -11064,7 +11149,7 @@ DEFUN (bgp_redistribute_ipv4_rmap_metric, int idx_word = 3; int idx_number = 5; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); @@ -11106,7 +11191,7 @@ DEFUN (bgp_redistribute_ipv4_metric_rmap, int idx_number = 3; int idx_word = 5; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP, argv[idx_protocol]->text); @@ -11144,8 +11229,8 @@ DEFUN (bgp_redistribute_ipv4_ospf, VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_ospf_table = 1; int idx_number = 2; - u_short instance; - u_short protocol; + unsigned short instance; + unsigned short protocol; instance = strtoul(argv[idx_number]->arg, NULL, 10); @@ -11180,7 +11265,7 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap, int idx_number = 2; int idx_word = 4; struct bgp_redist *red; - u_short instance; + unsigned short instance; int protocol; if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) @@ -11218,9 +11303,9 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric, int idx_ospf_table = 1; int idx_number = 2; int idx_number_2 = 4; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; - u_short instance; + unsigned short instance; int protocol; if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) @@ -11263,9 +11348,9 @@ DEFUN (bgp_redistribute_ipv4_ospf_rmap_metric, int idx_number = 2; int idx_word = 4; int idx_number_2 = 6; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; - u_short instance; + unsigned short instance; int protocol; if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) @@ -11312,9 +11397,9 @@ DEFUN (bgp_redistribute_ipv4_ospf_metric_rmap, int idx_number = 2; int idx_number_2 = 4; int idx_word = 6; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; - u_short instance; + unsigned short instance; int protocol; if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) @@ -11360,7 +11445,7 @@ DEFUN (no_bgp_redistribute_ipv4_ospf, VTY_DECLVAR_CONTEXT(bgp, bgp); int idx_ospf_table = 2; int idx_number = 3; - u_short instance; + unsigned short instance; int protocol; if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) @@ -11476,7 +11561,7 @@ DEFUN (bgp_redistribute_ipv6_metric, int idx_protocol = 1; int idx_number = 3; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); @@ -11506,7 +11591,7 @@ DEFUN (bgp_redistribute_ipv6_rmap_metric, int idx_word = 3; int idx_number = 5; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); @@ -11537,7 +11622,7 @@ DEFUN (bgp_redistribute_ipv6_metric_rmap, int idx_number = 3; int idx_word = 5; int type; - u_int32_t metric; + uint32_t metric; struct bgp_redist *red; type = proto_redistnum(AFI_IP6, argv[idx_protocol]->text); @@ -11685,7 +11770,16 @@ void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp, bgp->vpn_policy[afi] .rmap_name[BGP_VPN_POLICY_DIR_TOVPN]); } + if (bgp->vpn_policy[afi].import_redirect_rtlist) { + char *b = ecommunity_ecom2str( + bgp->vpn_policy[afi] + .import_redirect_rtlist, + ECOMMUNITY_FORMAT_ROUTE_MAP, + ECOMMUNITY_ROUTE_TARGET); + vty_out(vty, "%*srt redirect import %s\n", indent, "", b); + XFREE(MTYPE_ECOMMUNITY_STR, b); + } } @@ -11730,6 +11824,12 @@ static struct cmd_node bgp_evpn_node = {BGP_EVPN_NODE, static struct cmd_node bgp_evpn_vni_node = {BGP_EVPN_VNI_NODE, "%s(config-router-af-vni)# ", 1}; +static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE, + "%s(config-router-af)# ", 1}; + +static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE, + "%s(config-router-af-vpnv6)# ", 1}; + static void community_list_vty(void); static void bgp_ac_neighbor(vector comps, struct cmd_token *token) @@ -11790,6 +11890,8 @@ void bgp_vty_init(void) install_node(&bgp_vpnv6_node, NULL); install_node(&bgp_evpn_node, NULL); install_node(&bgp_evpn_vni_node, NULL); + install_node(&bgp_flowspecv4_node, NULL); + install_node(&bgp_flowspecv6_node, NULL); /* Install default VTY commands to new nodes. */ install_default(BGP_NODE); @@ -11801,6 +11903,8 @@ void bgp_vty_init(void) install_default(BGP_IPV6L_NODE); install_default(BGP_VPNV4_NODE); install_default(BGP_VPNV6_NODE); + install_default(BGP_FLOWSPECV4_NODE); + install_default(BGP_FLOWSPECV6_NODE); install_default(BGP_EVPN_NODE); install_default(BGP_EVPN_VNI_NODE); @@ -12033,6 +12137,8 @@ void bgp_vty_init(void) install_element(BGP_IPV6L_NODE, &neighbor_activate_cmd); install_element(BGP_VPNV4_NODE, &neighbor_activate_cmd); install_element(BGP_VPNV6_NODE, &neighbor_activate_cmd); + install_element(BGP_FLOWSPECV4_NODE, &neighbor_activate_cmd); + install_element(BGP_FLOWSPECV6_NODE, &neighbor_activate_cmd); install_element(BGP_EVPN_NODE, &neighbor_activate_cmd); /* "no neighbor activate" commands. */ @@ -12045,6 +12151,8 @@ void bgp_vty_init(void) install_element(BGP_IPV6L_NODE, &no_neighbor_activate_cmd); install_element(BGP_VPNV4_NODE, &no_neighbor_activate_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_activate_cmd); + install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_activate_cmd); + install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_activate_cmd); install_element(BGP_EVPN_NODE, &no_neighbor_activate_cmd); /* "neighbor peer-group" set commands. */ @@ -12056,6 +12164,10 @@ void bgp_vty_init(void) install_element(BGP_IPV6L_NODE, &neighbor_set_peer_group_hidden_cmd); install_element(BGP_VPNV4_NODE, &neighbor_set_peer_group_hidden_cmd); install_element(BGP_VPNV6_NODE, &neighbor_set_peer_group_hidden_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &neighbor_set_peer_group_hidden_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &neighbor_set_peer_group_hidden_cmd); /* "no neighbor peer-group unset" commands. */ install_element(BGP_NODE, &no_neighbor_set_peer_group_cmd); @@ -12066,6 +12178,10 @@ void bgp_vty_init(void) install_element(BGP_IPV6L_NODE, &no_neighbor_set_peer_group_hidden_cmd); install_element(BGP_VPNV4_NODE, &no_neighbor_set_peer_group_hidden_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_set_peer_group_hidden_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &no_neighbor_set_peer_group_hidden_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &no_neighbor_set_peer_group_hidden_cmd); /* "neighbor softreconfiguration inbound" commands.*/ install_element(BGP_NODE, &neighbor_soft_reconfiguration_hidden_cmd); @@ -12086,6 +12202,14 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &no_neighbor_soft_reconfiguration_cmd); install_element(BGP_VPNV6_NODE, &neighbor_soft_reconfiguration_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_soft_reconfiguration_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &neighbor_soft_reconfiguration_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &no_neighbor_soft_reconfiguration_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &neighbor_soft_reconfiguration_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &no_neighbor_soft_reconfiguration_cmd); /* "neighbor attribute-unchanged" commands. */ install_element(BGP_NODE, &neighbor_attr_unchanged_hidden_cmd); @@ -12351,6 +12475,14 @@ void bgp_vty_init(void) install_element(BGP_VPNV6_NODE, &neighbor_route_reflector_client_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_route_reflector_client_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &neighbor_route_reflector_client_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &no_neighbor_route_reflector_client_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &neighbor_route_reflector_client_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &no_neighbor_route_reflector_client_cmd); install_element(BGP_EVPN_NODE, &neighbor_route_reflector_client_cmd); install_element(BGP_EVPN_NODE, &no_neighbor_route_reflector_client_cmd); @@ -12373,6 +12505,12 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &no_neighbor_route_server_client_cmd); install_element(BGP_VPNV6_NODE, &neighbor_route_server_client_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_route_server_client_cmd); + install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_server_client_cmd); + install_element(BGP_FLOWSPECV4_NODE, + &no_neighbor_route_server_client_cmd); + install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_server_client_cmd); + install_element(BGP_FLOWSPECV6_NODE, + &no_neighbor_route_server_client_cmd); /* "neighbor addpath-tx-all-paths" commands.*/ install_element(BGP_NODE, &neighbor_addpath_tx_all_paths_hidden_cmd); @@ -12600,6 +12738,10 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &no_neighbor_prefix_list_cmd); install_element(BGP_VPNV6_NODE, &neighbor_prefix_list_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_prefix_list_cmd); + install_element(BGP_FLOWSPECV4_NODE, &neighbor_prefix_list_cmd); + install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_prefix_list_cmd); + install_element(BGP_FLOWSPECV6_NODE, &neighbor_prefix_list_cmd); + install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_prefix_list_cmd); /* "neighbor filter-list" commands. */ install_element(BGP_NODE, &neighbor_filter_list_hidden_cmd); @@ -12620,6 +12762,10 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &no_neighbor_filter_list_cmd); install_element(BGP_VPNV6_NODE, &neighbor_filter_list_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_filter_list_cmd); + install_element(BGP_FLOWSPECV4_NODE, &neighbor_filter_list_cmd); + install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_filter_list_cmd); + install_element(BGP_FLOWSPECV6_NODE, &neighbor_filter_list_cmd); + install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_filter_list_cmd); /* "neighbor route-map" commands. */ install_element(BGP_NODE, &neighbor_route_map_hidden_cmd); @@ -12640,6 +12786,10 @@ void bgp_vty_init(void) install_element(BGP_VPNV4_NODE, &no_neighbor_route_map_cmd); install_element(BGP_VPNV6_NODE, &neighbor_route_map_cmd); install_element(BGP_VPNV6_NODE, &no_neighbor_route_map_cmd); + install_element(BGP_FLOWSPECV4_NODE, &neighbor_route_map_cmd); + install_element(BGP_FLOWSPECV4_NODE, &no_neighbor_route_map_cmd); + install_element(BGP_FLOWSPECV6_NODE, &neighbor_route_map_cmd); + install_element(BGP_FLOWSPECV6_NODE, &no_neighbor_route_map_cmd); install_element(BGP_EVPN_NODE, &neighbor_route_map_cmd); install_element(BGP_EVPN_NODE, &no_neighbor_route_map_cmd); @@ -12788,6 +12938,8 @@ void bgp_vty_init(void) install_element(BGP_IPV6L_NODE, &exit_address_family_cmd); install_element(BGP_VPNV4_NODE, &exit_address_family_cmd); install_element(BGP_VPNV6_NODE, &exit_address_family_cmd); + install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd); + install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd); install_element(BGP_EVPN_NODE, &exit_address_family_cmd); /* "clear ip bgp commands" */ @@ -12897,6 +13049,9 @@ void bgp_vty_init(void) install_element(BGP_IPV4_NODE, &af_route_map_vpn_imexport_cmd); install_element(BGP_IPV6_NODE, &af_route_map_vpn_imexport_cmd); + install_element(BGP_IPV4_NODE, &af_routetarget_import_cmd); + install_element(BGP_IPV6_NODE, &af_routetarget_import_cmd); + install_element(BGP_IPV4_NODE, &af_no_rd_vpn_export_cmd); install_element(BGP_IPV6_NODE, &af_no_rd_vpn_export_cmd); install_element(BGP_IPV4_NODE, &af_no_label_vpn_export_cmd); diff --git a/bgpd/bgp_vty.h b/bgpd/bgp_vty.h index f77ebb610e..afb85f112b 100644 --- a/bgpd/bgp_vty.h +++ b/bgpd/bgp_vty.h @@ -36,11 +36,12 @@ struct bgp; #define BGP_AFI_SAFI_CMD_STR BGP_AFI_CMD_STR" "BGP_SAFI_CMD_STR #define BGP_AFI_SAFI_HELP_STR BGP_AFI_HELP_STR BGP_SAFI_HELP_STR -#define BGP_SAFI_WITH_LABEL_CMD_STR "<unicast|multicast|vpn|labeled-unicast>" +#define BGP_SAFI_WITH_LABEL_CMD_STR "<unicast|multicast|vpn|labeled-unicast|flowspec>" #define BGP_SAFI_WITH_LABEL_HELP_STR \ "Address Family modifier\n" \ "Address Family modifier\n" \ "Address Family modifier\n" \ + "Address Family modifier\n" \ "Address Family modifier\n" extern void bgp_vty_init(void); @@ -70,7 +71,7 @@ extern int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, int argc, int *idx, afi_t *afi, safi_t *safi, struct bgp **bgp); extern int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi, - safi_t safi, u_char use_json); + safi_t safi, uint8_t use_json); extern void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp, afi_t afi); #endif /* _QUAGGA_BGP_VTY_H */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 1e3b2a4f45..023a866315 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -970,6 +970,64 @@ static int bgp_table_map_apply(struct route_map *map, struct prefix *p, return 0; } +static struct thread *bgp_tm_thread_connect; +static bool bgp_tm_status_connected; + +static int bgp_zebra_tm_connect(struct thread *t) +{ + struct zclient *zclient; + int delay = 10, ret = 0; + + zclient = THREAD_ARG(t); + if (bgp_tm_status_connected && zclient->sock > 0) + delay = 60; + else { + bgp_tm_status_connected = false; + ret = tm_table_manager_connect(zclient); + } + if (ret < 0) { + zlog_warn("Error connecting to table manager!"); + bgp_tm_status_connected = false; + } else { + if (!bgp_tm_status_connected) + zlog_debug("Connecting to table manager. Success"); + bgp_tm_status_connected = true; + } + thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, + &bgp_tm_thread_connect); + return 0; +} + +void bgp_zebra_init_tm_connect(void) +{ + int delay = 1; + + /* if already set, do nothing + */ + if (bgp_tm_thread_connect != NULL) + return; + bgp_tm_status_connected = false; + thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, + &bgp_tm_thread_connect); +} + +int bgp_zebra_get_table_range(uint32_t chunk_size, + uint32_t *start, uint32_t *end) +{ + int ret; + + if (!bgp_tm_status_connected) + return -1; + ret = tm_get_table_chunk(zclient, chunk_size, start, end); + if (ret < 0) { + zlog_err("BGP: Error getting table chunk %u", chunk_size); + return -1; + } + zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]", + chunk_size, *start, *end); + return 0; +} + void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, struct bgp_info *info, struct bgp *bgp, afi_t afi, safi_t safi) @@ -979,16 +1037,17 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, int nh_family; unsigned int valid_nh_count = 0; int has_valid_label = 0; - u_char distance; + uint8_t distance; struct peer *peer; struct bgp_info *mpinfo; - u_int32_t metric; + uint32_t metric; struct attr local_attr; struct bgp_info local_info; struct bgp_info *mpinfo_cp = &local_info; route_tag_t tag; mpls_label_t label; int nh_othervrf = 0; + char buf_prefix[PREFIX_STRLEN]; /* filled in if we are debugging */ /* Don't try to install if we're not connected to Zebra or Zebra doesn't * know of this instance. @@ -999,6 +1058,9 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, if (bgp->main_zebra_update_hold) return; + if (bgp_debug_zebra(p)) + prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix)); + /* * vrf leaking support (will have only one nexthop) */ @@ -1039,11 +1101,8 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, if (info->sub_type == BGP_ROUTE_AGGREGATE) zapi_route_set_blackhole(&api, BLACKHOLE_NULL); - /* If it is an EVPN route mark as such. - * Currently presence of rmac in attr denotes - * this is an EVPN type-2 route - */ - if (info->sub_type == BGP_ROUTE_IMPORTED) + /* If the route's source is EVPN, flag as such. */ + if (is_route_parent_evpn(info)) SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED @@ -1084,9 +1143,6 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, struct in_addr *nexthop; if (bgp_debug_zebra(&api.prefix)) { - char buf_prefix[PREFIX_STRLEN]; - prefix2str(&api.prefix, buf_prefix, - sizeof(buf_prefix)); if (mpinfo->extra) { zlog_debug( "%s: p=%s, bgp_is_valid_label: %d", @@ -1197,12 +1253,17 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, ifindex = mpinfo->peer->nexthop.ifp ->ifindex; } - if (ifindex == 0) - continue; + + if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { + if (ifindex == 0) + continue; + } else + ifindex = 0; api_nh->gate.ipv6 = *nexthop; api_nh->ifindex = ifindex; - api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; + api_nh->type = ifindex ? NEXTHOP_TYPE_IPV6_IFINDEX + : NEXTHOP_TYPE_IPV6; } if (mpinfo->extra @@ -1269,6 +1330,16 @@ void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, } } + if (bgp_debug_zebra(p)) { + int recursion_flag = 0; + + if (CHECK_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION)) + recursion_flag = 1; + + zlog_debug("%s: %s: announcing to zebra (recursion %sset)", + __func__, buf_prefix, + (recursion_flag ? "" : "NOT ")); + } zclient_route_send(valid_nh_count ? ZEBRA_ROUTE_ADD : ZEBRA_ROUTE_DELETE, zclient, &api); @@ -1340,11 +1411,8 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, api.safi = safi; api.prefix = *p; - /* If it is an EVPN route mark as such. - * Currently presence of rmac in attr denotes - * this is an EVPN type-2 route - */ - if (info->sub_type == BGP_ROUTE_IMPORTED) + /* If the route's source is EVPN, flag as such. */ + if (is_route_parent_evpn(info)) SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); if (peer->sort == BGP_PEER_IBGP) { @@ -1367,8 +1435,8 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); } -struct bgp_redist *bgp_redist_lookup(struct bgp *bgp, afi_t afi, u_char type, - u_short instance) +struct bgp_redist *bgp_redist_lookup(struct bgp *bgp, afi_t afi, uint8_t type, + unsigned short instance) { struct list *red_list; struct listnode *node; @@ -1385,8 +1453,8 @@ struct bgp_redist *bgp_redist_lookup(struct bgp *bgp, afi_t afi, u_char type, return NULL; } -struct bgp_redist *bgp_redist_add(struct bgp *bgp, afi_t afi, u_char type, - u_short instance) +struct bgp_redist *bgp_redist_add(struct bgp *bgp, afi_t afi, uint8_t type, + unsigned short instance) { struct list *red_list; struct bgp_redist *red; @@ -1408,8 +1476,8 @@ struct bgp_redist *bgp_redist_add(struct bgp *bgp, afi_t afi, u_char type, return red; } -static void bgp_redist_del(struct bgp *bgp, afi_t afi, u_char type, - u_short instance) +static void bgp_redist_del(struct bgp *bgp, afi_t afi, uint8_t type, + unsigned short instance) { struct bgp_redist *red; @@ -1424,7 +1492,8 @@ static void bgp_redist_del(struct bgp *bgp, afi_t afi, u_char type, } /* Other routes redistribution into BGP. */ -int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, u_short instance) +int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, + unsigned short instance) { /* Return if already redistribute flag is set. */ @@ -1471,7 +1540,7 @@ int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, u_short instance) } int bgp_redistribute_resend(struct bgp *bgp, afi_t afi, int type, - u_short instance) + unsigned short instance) { /* Don't try to send if we're not connected to Zebra or Zebra doesn't * know of this instance. @@ -1509,7 +1578,7 @@ int bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name) /* Redistribute with metric specification. */ int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, - afi_t afi, int type, u_int32_t metric) + afi_t afi, int type, uint32_t metric) { struct bgp_node *rn; struct bgp_info *ri; @@ -1547,7 +1616,7 @@ int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, /* Unset redistribution. */ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, - u_short instance) + unsigned short instance) { struct bgp_redist *red; @@ -1586,7 +1655,7 @@ int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, /* Unset redistribution. */ int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, - u_short instance) + unsigned short instance) { struct bgp_redist *red; @@ -1893,7 +1962,7 @@ static int bgp_zebra_process_local_macip(int command, struct zclient *zclient, int ipa_len; char buf[ETHER_ADDR_STRLEN]; char buf1[INET6_ADDRSTRLEN]; - u_char flags; + uint8_t flags; memset(&ip, 0, sizeof(ip)); s = zclient->ibuf; diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index c30f63039b..7263317b6f 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -24,7 +24,10 @@ #include "vxlan.h" extern void bgp_zebra_init(struct thread_master *master); +extern void bgp_zebra_init_tm_connect(void); extern void bgp_zebra_destroy(void); +extern int bgp_zebra_get_table_range(uint32_t chunk_size, + uint32_t *start, uint32_t *end); extern int bgp_if_update_all(void); extern void bgp_config_write_maxpaths(struct vty *, struct bgp *, afi_t, safi_t); @@ -42,16 +45,17 @@ extern void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer); extern void bgp_zebra_instance_register(struct bgp *); extern void bgp_zebra_instance_deregister(struct bgp *); -extern struct bgp_redist *bgp_redist_lookup(struct bgp *, afi_t, u_char, - u_short); -extern struct bgp_redist *bgp_redist_add(struct bgp *, afi_t, u_char, u_short); -extern int bgp_redistribute_set(struct bgp *, afi_t, int, u_short); -extern int bgp_redistribute_resend(struct bgp *, afi_t, int, u_short); +extern struct bgp_redist *bgp_redist_lookup(struct bgp *, afi_t, uint8_t, + unsigned short); +extern struct bgp_redist *bgp_redist_add(struct bgp *, afi_t, uint8_t, + unsigned short); +extern int bgp_redistribute_set(struct bgp *, afi_t, int, unsigned short); +extern int bgp_redistribute_resend(struct bgp *, afi_t, int, unsigned short); extern int bgp_redistribute_rmap_set(struct bgp_redist *, const char *); extern int bgp_redistribute_metric_set(struct bgp *, struct bgp_redist *, afi_t, - int, u_int32_t); -extern int bgp_redistribute_unset(struct bgp *, afi_t, int, u_short); -extern int bgp_redistribute_unreg(struct bgp *, afi_t, int, u_short); + int, uint32_t); +extern int bgp_redistribute_unset(struct bgp *, afi_t, int, unsigned short); +extern int bgp_redistribute_unreg(struct bgp *, afi_t, int, unsigned short); extern struct interface *if_lookup_by_ipv4(struct in_addr *, vrf_id_t); extern struct interface *if_lookup_by_ipv4_exact(struct in_addr *, vrf_id_t); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index d103584594..c46111e1fb 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -80,6 +80,8 @@ #include "bgpd/bgp_keepalives.h" #include "bgpd/bgp_io.h" #include "bgpd/bgp_ecommunity.h" +#include "bgpd/bgp_flowspec.h" + DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)"); DEFINE_QOBJ_TYPE(bgp_master) @@ -376,7 +378,7 @@ time_t bgp_clock(void) } /* BGP timer configuration. */ -int bgp_timers_set(struct bgp *bgp, u_int32_t keepalive, u_int32_t holdtime) +int bgp_timers_set(struct bgp *bgp, uint32_t keepalive, uint32_t holdtime) { bgp->default_keepalive = (keepalive < holdtime / 3 ? keepalive : holdtime / 3); @@ -589,7 +591,7 @@ int bgp_confederation_peers_remove(struct bgp *bgp, as_t as) } /* Local preference configuration. */ -int bgp_default_local_preference_set(struct bgp *bgp, u_int32_t local_pref) +int bgp_default_local_preference_set(struct bgp *bgp, uint32_t local_pref) { if (!bgp) return -1; @@ -610,8 +612,7 @@ int bgp_default_local_preference_unset(struct bgp *bgp) } /* Local preference configuration. */ -int bgp_default_subgroup_pkt_queue_max_set(struct bgp *bgp, - u_int32_t queue_size) +int bgp_default_subgroup_pkt_queue_max_set(struct bgp *bgp, uint32_t queue_size) { if (!bgp) return -1; @@ -796,15 +797,14 @@ static int peer_hash_same(const void *p1, const void *p2) == CHECK_FLAG(peer2->flags, PEER_FLAG_CONFIG_NODE)); } -int peer_af_flag_check(struct peer *peer, afi_t afi, safi_t safi, - u_int32_t flag) +int peer_af_flag_check(struct peer *peer, afi_t afi, safi_t safi, uint32_t flag) { return CHECK_FLAG(peer->af_flags[afi][safi], flag); } /* Return true if flag is set for the peer but not the peer-group */ static int peergroup_af_flag_check(struct peer *peer, afi_t afi, safi_t safi, - u_int32_t flag) + uint32_t flag) { struct peer *g_peer = NULL; @@ -1302,7 +1302,7 @@ static int bgp_peer_conf_if_to_su_update_v4(struct peer *peer, { struct connected *ifc; struct prefix p; - u_int32_t addr; + uint32_t addr; struct listnode *node; /* If our IPv4 address on the interface is /30 or /31, we can derive the @@ -1628,6 +1628,8 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified) PEER_FLAG_REFLECTOR_CLIENT); UNSET_FLAG(peer->af_flags[AFI_IP][SAFI_ENCAP], PEER_FLAG_REFLECTOR_CLIENT); + UNSET_FLAG(peer->af_flags[AFI_IP][SAFI_FLOWSPEC], + PEER_FLAG_REFLECTOR_CLIENT); UNSET_FLAG(peer->af_flags[AFI_IP6][SAFI_UNICAST], PEER_FLAG_REFLECTOR_CLIENT); UNSET_FLAG(peer->af_flags[AFI_IP6][SAFI_MULTICAST], @@ -1638,6 +1640,8 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified) PEER_FLAG_REFLECTOR_CLIENT); UNSET_FLAG(peer->af_flags[AFI_IP6][SAFI_ENCAP], PEER_FLAG_REFLECTOR_CLIENT); + UNSET_FLAG(peer->af_flags[AFI_IP6][SAFI_FLOWSPEC], + PEER_FLAG_REFLECTOR_CLIENT); UNSET_FLAG(peer->af_flags[AFI_L2VPN][SAFI_EVPN], PEER_FLAG_REFLECTOR_CLIENT); } @@ -1975,6 +1979,10 @@ int peer_activate(struct peer *peer, afi_t afi, safi_t safi) bgp_recalculate_afi_safi_bestpaths(bgp, afi, SAFI_UNICAST); } + if (safi == SAFI_FLOWSPEC) { + /* connect to table manager */ + bgp_zebra_init_tm_connect(); + } return ret; } @@ -2897,9 +2905,9 @@ static struct bgp *bgp_create(as_t *as, const char *name, bgp->group->cmp = (int (*)(void *, void *))peer_group_cmp; FOREACH_AFI_SAFI (afi, safi) { - bgp->route[afi][safi] = bgp_table_init(afi, safi); - bgp->aggregate[afi][safi] = bgp_table_init(afi, safi); - bgp->rib[afi][safi] = bgp_table_init(afi, safi); + bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi); + bgp->aggregate[afi][safi] = bgp_table_init(bgp, afi, safi); + bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi); /* Enable maximum-paths */ bgp_maximum_paths_set(bgp, afi, safi, BGP_PEER_EBGP, @@ -2956,6 +2964,28 @@ static struct bgp *bgp_create(as_t *as, const char *name, bgp->restart_time, &bgp->t_startup); } + /* printable name we can use in debug messages */ + if (inst_type == BGP_INSTANCE_TYPE_DEFAULT) { + bgp->name_pretty = XSTRDUP(MTYPE_BGP, "VRF default"); + } else { + const char *n; + int len; + + if (bgp->name) + n = bgp->name; + else + n = "?"; + + len = 4 + 1 + strlen(n) + 1; /* "view foo\0" */ + + bgp->name_pretty = XCALLOC(MTYPE_BGP, len); + snprintf(bgp->name_pretty, len, "%s %s", + (bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + ? "VRF" + : "VIEW", + n); + } + atomic_store_explicit(&bgp->wpkt_quanta, BGP_WRITE_PACKET_MAX, memory_order_relaxed); atomic_store_explicit(&bgp->rpkt_quanta, BGP_READ_PACKET_MAX, @@ -3272,6 +3302,14 @@ int bgp_delete(struct bgp *bgp) #endif bgp_cleanup_routes(bgp); + for (afi = 0; afi < AFI_MAX; ++afi) { + if (!bgp->vpn_policy[afi].import_redirect_rtlist) + continue; + ecommunity_free( + &bgp->vpn_policy[afi] + .import_redirect_rtlist); + bgp->vpn_policy[afi].import_redirect_rtlist = NULL; + } /* Remove visibility via the master list - there may however still be * routes to be processed still referencing the struct bgp. */ @@ -3342,6 +3380,8 @@ void bgp_free(struct bgp *bgp) if (bgp->name) XFREE(MTYPE_BGP, bgp->name); + if (bgp->name_pretty) + XFREE(MTYPE_BGP, bgp->name_pretty); XFREE(MTYPE_BGP, bgp); } @@ -3631,11 +3671,13 @@ int peer_active(struct peer *peer) if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] || peer->afc[AFI_IP][SAFI_MPLS_VPN] || peer->afc[AFI_IP][SAFI_ENCAP] + || peer->afc[AFI_IP][SAFI_FLOWSPEC] || peer->afc[AFI_IP6][SAFI_UNICAST] || peer->afc[AFI_IP6][SAFI_MULTICAST] || peer->afc[AFI_IP6][SAFI_LABELED_UNICAST] || peer->afc[AFI_IP6][SAFI_MPLS_VPN] || peer->afc[AFI_IP6][SAFI_ENCAP] + || peer->afc[AFI_IP6][SAFI_FLOWSPEC] || peer->afc[AFI_L2VPN][SAFI_EVPN]) return 1; return 0; @@ -3649,11 +3691,13 @@ int peer_active_nego(struct peer *peer) || peer->afc_nego[AFI_IP][SAFI_LABELED_UNICAST] || peer->afc_nego[AFI_IP][SAFI_MPLS_VPN] || peer->afc_nego[AFI_IP][SAFI_ENCAP] + || peer->afc_nego[AFI_IP][SAFI_FLOWSPEC] || peer->afc_nego[AFI_IP6][SAFI_UNICAST] || peer->afc_nego[AFI_IP6][SAFI_MULTICAST] || peer->afc_nego[AFI_IP6][SAFI_LABELED_UNICAST] || peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN] || peer->afc_nego[AFI_IP6][SAFI_ENCAP] + || peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] || peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) return 1; return 0; @@ -3709,16 +3753,16 @@ static void peer_change_action(struct peer *peer, afi_t afi, safi_t safi, struct peer_flag_action { /* Peer's flag. */ - u_int32_t flag; + uint32_t flag; /* This flag can be set for peer-group member. */ - u_char not_for_member; + uint8_t not_for_member; /* Action when the flag is changed. */ enum peer_change_type type; /* Peer down cause */ - u_char peer_down; + uint8_t peer_down; }; static const struct peer_flag_action peer_flag_action_list[] = { @@ -3765,7 +3809,7 @@ static const struct peer_flag_action peer_af_flag_action_list[] = { /* Proper action set. */ static int peer_flag_action_set(const struct peer_flag_action *action_list, int size, struct peer_flag_action *action, - u_int32_t flag) + uint32_t flag) { int i; int found = 0; @@ -3809,7 +3853,7 @@ static int peer_flag_action_set(const struct peer_flag_action *action_list, return found; } -static void peer_flag_modify_action(struct peer *peer, u_int32_t flag) +static void peer_flag_modify_action(struct peer *peer, uint32_t flag) { if (flag == PEER_FLAG_SHUTDOWN) { if (CHECK_FLAG(peer->flags, flag)) { @@ -3840,7 +3884,7 @@ static void peer_flag_modify_action(struct peer *peer, u_int32_t flag) msglen = 128; if (msglen) { - u_char msgbuf[129]; + uint8_t msgbuf[129]; msgbuf[0] = msglen; memcpy(msgbuf + 1, msg, msglen); @@ -3874,7 +3918,7 @@ static void peer_flag_modify_action(struct peer *peer, u_int32_t flag) } /* Change specified peer flag. */ -static int peer_flag_modify(struct peer *peer, u_int32_t flag, int set) +static int peer_flag_modify(struct peer *peer, uint32_t flag, int set) { int found; int size; @@ -3947,18 +3991,18 @@ static int peer_flag_modify(struct peer *peer, u_int32_t flag, int set) return 0; } -int peer_flag_set(struct peer *peer, u_int32_t flag) +int peer_flag_set(struct peer *peer, uint32_t flag) { return peer_flag_modify(peer, flag, 1); } -int peer_flag_unset(struct peer *peer, u_int32_t flag) +int peer_flag_unset(struct peer *peer, uint32_t flag) { return peer_flag_modify(peer, flag, 0); } static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, - u_int32_t flag, int set) + uint32_t flag, int set) { int found; int size; @@ -4114,13 +4158,12 @@ static int peer_af_flag_modify(struct peer *peer, afi_t afi, safi_t safi, return 0; } -int peer_af_flag_set(struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag) +int peer_af_flag_set(struct peer *peer, afi_t afi, safi_t safi, uint32_t flag) { return peer_af_flag_modify(peer, afi, safi, flag, 1); } -int peer_af_flag_unset(struct peer *peer, afi_t afi, safi_t safi, - u_int32_t flag) +int peer_af_flag_unset(struct peer *peer, afi_t afi, safi_t safi, uint32_t flag) { return peer_af_flag_modify(peer, afi, safi, flag, 0); } @@ -4552,7 +4595,7 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) return 0; } -int peer_port_set(struct peer *peer, u_int16_t port) +int peer_port_set(struct peer *peer, uint16_t port) { peer->port = port; return 0; @@ -4591,7 +4634,7 @@ static void peer_on_policy_change(struct peer *peer, afi_t afi, safi_t safi, /* neighbor weight. */ -int peer_weight_set(struct peer *peer, afi_t afi, safi_t safi, u_int16_t weight) +int peer_weight_set(struct peer *peer, afi_t afi, safi_t safi, uint16_t weight) { struct peer_group *group; struct listnode *node, *nnode; @@ -4671,7 +4714,7 @@ int peer_weight_unset(struct peer *peer, afi_t afi, safi_t safi) return 0; } -int peer_timers_set(struct peer *peer, u_int32_t keepalive, u_int32_t holdtime) +int peer_timers_set(struct peer *peer, uint32_t keepalive, uint32_t holdtime) { struct peer_group *group; struct listnode *node, *nnode; @@ -4752,7 +4795,7 @@ int peer_timers_unset(struct peer *peer) return 0; } -int peer_timers_connect_set(struct peer *peer, u_int32_t connect) +int peer_timers_connect_set(struct peer *peer, uint32_t connect) { struct peer_group *group; struct listnode *node, *nnode; @@ -4805,7 +4848,7 @@ int peer_timers_connect_unset(struct peer *peer) return 0; } -int peer_advertise_interval_set(struct peer *peer, u_int32_t routeadv) +int peer_advertise_interval_set(struct peer *peer, uint32_t routeadv) { struct peer_group *group; struct listnode *node, *nnode; @@ -5872,8 +5915,8 @@ int peer_unsuppress_map_unset(struct peer *peer, afi_t afi, safi_t safi) } int peer_maximum_prefix_set(struct peer *peer, afi_t afi, safi_t safi, - u_int32_t max, u_char threshold, int warning, - u_int16_t restart) + uint32_t max, uint8_t threshold, int warning, + uint16_t restart) { struct peer_group *group; struct listnode *node, *nnode; @@ -6217,7 +6260,7 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, || CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_OLD_RCV))) { struct bgp_filter *filter = &peer->filter[afi][safi]; - u_char prefix_type; + uint8_t prefix_type; if (CHECK_FLAG(peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_RCV)) @@ -6271,7 +6314,7 @@ int peer_clear_soft(struct peer *peer, afi_t afi, safi_t safi, } /* Display peer uptime.*/ -char *peer_uptime(time_t uptime2, char *buf, size_t len, u_char use_json, +char *peer_uptime(time_t uptime2, char *buf, size_t len, uint8_t use_json, json_object *json) { time_t uptime1, epoch_tbuf; @@ -6281,7 +6324,7 @@ char *peer_uptime(time_t uptime2, char *buf, size_t len, u_char use_json, if (len < BGP_UPTIME_LEN) { if (!use_json) { zlog_warn("peer_uptime (): buffer shortage %lu", - (u_long)len); + (unsigned long)len); /* XXX: should return status instead of buf... */ snprintf(buf, len, "<error> "); } @@ -7091,6 +7134,8 @@ static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi, vty_frame(vty, "ipv4 vpn"); else if (safi == SAFI_ENCAP) vty_frame(vty, "ipv4 encap"); + else if (safi == SAFI_FLOWSPEC) + vty_frame(vty, "ipv4 flowspec"); } else if (afi == AFI_IP6) { if (safi == SAFI_UNICAST) vty_frame(vty, "ipv6 unicast"); @@ -7102,6 +7147,8 @@ static void bgp_config_write_family(struct vty *vty, struct bgp *bgp, afi_t afi, vty_frame(vty, "ipv6 vpn"); else if (safi == SAFI_ENCAP) vty_frame(vty, "ipv6 encap"); + else if (safi == SAFI_FLOWSPEC) + vty_frame(vty, "ipv6 flowspec"); } else if (afi == AFI_L2VPN) { if (safi == SAFI_EVPN) vty_frame(vty, "l2vpn evpn"); @@ -7428,6 +7475,9 @@ int bgp_config_write(struct vty *vty) /* ENCAPv4 configuration. */ bgp_config_write_family(vty, bgp, AFI_IP, SAFI_ENCAP); + /* FLOWSPEC v4 configuration. */ + bgp_config_write_family(vty, bgp, AFI_IP, SAFI_FLOWSPEC); + /* IPv6 unicast configuration. */ bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_UNICAST); @@ -7444,6 +7494,9 @@ int bgp_config_write(struct vty *vty) /* ENCAPv6 configuration. */ bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_ENCAP); + /* FLOWSPEC v6 configuration. */ + bgp_config_write_family(vty, bgp, AFI_IP6, SAFI_FLOWSPEC); + /* EVPN configuration. */ bgp_config_write_family(vty, bgp, AFI_L2VPN, SAFI_EVPN); @@ -7601,6 +7654,7 @@ void bgp_init(void) rfapi_init(); #endif bgp_ethernetvpn_init(); + bgp_flowspec_vty_init(); /* Access list initialize. */ access_list_init(); diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 79fe8c8c3b..0c5f72662c 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -60,9 +60,9 @@ enum { AS_UNSPECIFIED = 0, }; /* Typedef BGP specific types. */ -typedef u_int32_t as_t; -typedef u_int16_t as16_t; /* we may still encounter 16 Bit asnums */ -typedef u_int16_t bgp_size_t; +typedef uint32_t as_t; +typedef uint16_t as16_t; /* we may still encounter 16 Bit asnums */ +typedef uint16_t bgp_size_t; #define max(a, b) \ ({ \ @@ -84,6 +84,8 @@ enum bgp_af_index { BGP_AF_L2VPN_EVPN, BGP_AF_IPV4_LBL_UNICAST, BGP_AF_IPV6_LBL_UNICAST, + BGP_AF_IPV4_FLOWSPEC, + BGP_AF_IPV6_FLOWSPEC, BGP_AF_MAX }; @@ -112,7 +114,7 @@ struct bgp_master { struct list *listen_sockets; /* BGP port number. */ - u_int16_t port; + uint16_t port; /* Listener address */ char *address; @@ -121,7 +123,7 @@ struct bgp_master { time_t start_time; /* Various BGP global configuration. */ - u_char options; + uint8_t options; #define BGP_OPT_NO_FIB (1 << 0) #define BGP_OPT_MULTIPLE_INSTANCE (1 << 1) #define BGP_OPT_CONFIG_CISCO (1 << 2) @@ -132,7 +134,7 @@ struct bgp_master { /* timer to dampen route map changes */ struct thread *t_rmap_update; /* Handle route map updates */ - u_int32_t rmap_update_timer; /* Route map update timer */ + uint32_t rmap_update_timer; /* Route map update timer */ #define RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */ /* Id space for automatic RD derivation for an EVI/VRF */ @@ -149,11 +151,11 @@ struct bgp_rmap { }; struct bgp_redist { - u_short instance; + unsigned short instance; /* BGP redistribute metric configuration. */ - u_char redist_metric_flag; - u_int32_t redist_metric; + uint8_t redist_metric_flag; + uint32_t redist_metric; /* BGP redistribute route-map. */ struct bgp_rmap rmap; @@ -186,6 +188,7 @@ struct bgp { /* Name of this BGP instance. */ char *name; + char *name_pretty; /* printable "VRF|VIEW name|default" */ /* Type of instance and VRF id. */ enum bgp_instance_type inst_type; @@ -216,23 +219,23 @@ struct bgp { * Global statistics for update groups. */ struct { - u_int32_t join_events; - u_int32_t prune_events; - u_int32_t merge_events; - u_int32_t split_events; - u_int32_t updgrp_switch_events; - u_int32_t peer_refreshes_combined; - u_int32_t adj_count; - u_int32_t merge_checks_triggered; - - u_int32_t updgrps_created; - u_int32_t updgrps_deleted; - u_int32_t subgrps_created; - u_int32_t subgrps_deleted; + uint32_t join_events; + uint32_t prune_events; + uint32_t merge_events; + uint32_t split_events; + uint32_t updgrp_switch_events; + uint32_t peer_refreshes_combined; + uint32_t adj_count; + uint32_t merge_checks_triggered; + + uint32_t updgrps_created; + uint32_t updgrps_deleted; + uint32_t subgrps_created; + uint32_t subgrps_deleted; } update_group_stats; /* BGP configuration. */ - u_int16_t config; + uint16_t config; #define BGP_CONFIG_CLUSTER_ID (1 << 0) #define BGP_CONFIG_CONFEDERATION (1 << 1) @@ -252,45 +255,45 @@ struct bgp { struct thread *t_startup; /* start-up timer on only once at the beginning */ - u_int32_t v_maxmed_onstartup; /* Duration of max-med on start-up */ + uint32_t v_maxmed_onstartup; /* Duration of max-med on start-up */ #define BGP_MAXMED_ONSTARTUP_UNCONFIGURED 0 /* 0 means off, its the default */ - u_int32_t maxmed_onstartup_value; /* Max-med value when active on - start-up */ + uint32_t maxmed_onstartup_value; /* Max-med value when active on + start-up */ struct thread *t_maxmed_onstartup; /* non-null when max-med onstartup is on */ - u_char maxmed_onstartup_over; /* Flag to make it effective only once */ + uint8_t maxmed_onstartup_over; /* Flag to make it effective only once */ - u_char v_maxmed_admin; /* 1/0 if max-med administrative is on/off */ + uint8_t v_maxmed_admin; /* 1/0 if max-med administrative is on/off */ #define BGP_MAXMED_ADMIN_UNCONFIGURED 0 /* Off by default */ - u_int32_t maxmed_admin_value; /* Max-med value when administrative in on - */ + uint32_t maxmed_admin_value; /* Max-med value when administrative in on + */ #define BGP_MAXMED_VALUE_DEFAULT 4294967294 /* Maximum by default */ - u_char maxmed_active; /* 1/0 if max-med is active or not */ - u_int32_t maxmed_value; /* Max-med value when its active */ + uint8_t maxmed_active; /* 1/0 if max-med is active or not */ + uint32_t maxmed_value; /* Max-med value when its active */ /* BGP update delay on startup */ struct thread *t_update_delay; struct thread *t_establish_wait; - u_char update_delay_over; - u_char main_zebra_update_hold; - u_char main_peers_update_hold; - u_int16_t v_update_delay; - u_int16_t v_establish_wait; + uint8_t update_delay_over; + uint8_t main_zebra_update_hold; + uint8_t main_peers_update_hold; + uint16_t v_update_delay; + uint16_t v_establish_wait; char update_delay_begin_time[64]; char update_delay_end_time[64]; char update_delay_zebra_resume_time[64]; char update_delay_peers_resume_time[64]; - u_int32_t established; - u_int32_t restarted_peers; - u_int32_t implicit_eors; - u_int32_t explicit_eors; + uint32_t established; + uint32_t restarted_peers; + uint32_t implicit_eors; + uint32_t explicit_eors; #define BGP_UPDATE_DELAY_DEF 0 #define BGP_UPDATE_DELAY_MIN 0 #define BGP_UPDATE_DELAY_MAX 3600 /* BGP flags. */ - u_int32_t flags; + uint32_t flags; #define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0) #define BGP_FLAG_DETERMINISTIC_MED (1 << 1) #define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2) @@ -315,7 +318,7 @@ struct bgp { #define BGP_FLAG_GRACEFUL_SHUTDOWN (1 << 21) /* BGP Per AF flags */ - u_int16_t af_flags[AFI_MAX][SAFI_MAX]; + uint16_t af_flags[AFI_MAX][SAFI_MAX]; #define BGP_CONFIG_DAMPENING (1 << 0) #define BGP_CONFIG_VRF_TO_MPLSVPN_EXPORT (1 << 1) #define BGP_CONFIG_MPLSVPN_TO_VRF_IMPORT (1 << 2) @@ -357,36 +360,36 @@ struct bgp { struct list *redist[AFI_MAX][ZEBRA_ROUTE_MAX]; /* Allocate MPLS labels */ - u_char allocate_mpls_labels[AFI_MAX][SAFI_MAX]; + uint8_t allocate_mpls_labels[AFI_MAX][SAFI_MAX]; /* timer to re-evaluate neighbor default-originate route-maps */ struct thread *t_rmap_def_originate_eval; #define RMAP_DEFAULT_ORIGINATE_EVAL_TIMER 5 /* BGP distance configuration. */ - u_char distance_ebgp[AFI_MAX][SAFI_MAX]; - u_char distance_ibgp[AFI_MAX][SAFI_MAX]; - u_char distance_local[AFI_MAX][SAFI_MAX]; + uint8_t distance_ebgp[AFI_MAX][SAFI_MAX]; + uint8_t distance_ibgp[AFI_MAX][SAFI_MAX]; + uint8_t distance_local[AFI_MAX][SAFI_MAX]; /* BGP default local-preference. */ - u_int32_t default_local_pref; + uint32_t default_local_pref; /* BGP default subgroup pkt queue max */ - u_int32_t default_subgroup_pkt_queue_max; + uint32_t default_subgroup_pkt_queue_max; /* BGP default timer. */ - u_int32_t default_holdtime; - u_int32_t default_keepalive; + uint32_t default_holdtime; + uint32_t default_keepalive; /* BGP graceful restart */ - u_int32_t restart_time; - u_int32_t stalepath_time; + uint32_t restart_time; + uint32_t stalepath_time; /* Maximum-paths configuration */ struct bgp_maxpaths_cfg { - u_int16_t maxpaths_ebgp; - u_int16_t maxpaths_ibgp; - u_int16_t ibgp_flags; + uint16_t maxpaths_ebgp; + uint16_t maxpaths_ibgp; + uint16_t ibgp_flags; #define BGP_FLAG_IBGP_MULTIPATH_SAME_CLUSTERLEN (1 << 0) } maxpaths[AFI_MAX][SAFI_MAX]; @@ -401,7 +404,7 @@ struct bgp { /* Auto-shutdown new peers */ bool autoshutdown; - u_int32_t addpath_tx_id; + uint32_t addpath_tx_id; int addpath_tx_used[AFI_MAX][SAFI_MAX]; #if ENABLE_BGP_VNC @@ -465,6 +468,7 @@ struct bgp { /* vpn-policy */ struct { struct ecommunity *rtlist[BGP_VPN_POLICY_DIR_MAX]; + struct ecommunity *import_redirect_rtlist; char *rmap_name[BGP_VPN_POLICY_DIR_MAX]; struct route_map *rmap[BGP_VPN_POLICY_DIR_MAX]; @@ -509,11 +513,11 @@ struct peer_group { /* BGP Notify message format. */ struct bgp_notify { - u_char code; - u_char subcode; + uint8_t code; + uint8_t subcode; char *data; bgp_size_t length; - u_char *raw_data; + uint8_t *raw_data; }; /* Next hop self address. */ @@ -535,7 +539,7 @@ struct bgp_nexthop { #define BGP_RD_SIZE 8 struct bgp_rd { - u_char val[BGP_RD_SIZE]; + uint8_t val[BGP_RD_SIZE]; }; #define RMAP_IN 0 @@ -719,13 +723,13 @@ struct peer { struct bgp_nexthop nexthop; /* Nexthop */ /* Peer address family configuration. */ - u_char afc[AFI_MAX][SAFI_MAX]; - u_char afc_nego[AFI_MAX][SAFI_MAX]; - u_char afc_adv[AFI_MAX][SAFI_MAX]; - u_char afc_recv[AFI_MAX][SAFI_MAX]; + uint8_t afc[AFI_MAX][SAFI_MAX]; + uint8_t afc_nego[AFI_MAX][SAFI_MAX]; + uint8_t afc_adv[AFI_MAX][SAFI_MAX]; + uint8_t afc_recv[AFI_MAX][SAFI_MAX]; /* Capability flags (reset in bgp_stop) */ - u_int32_t cap; + uint32_t cap; #define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */ #define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */ #define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */ @@ -745,7 +749,7 @@ struct peer { #define PEER_CAP_HOSTNAME_RCV (1 << 16) /* hostname received */ /* Capability flags (reset in bgp_stop) */ - u_int32_t af_cap[AFI_MAX][SAFI_MAX]; + uint32_t af_cap[AFI_MAX][SAFI_MAX]; #define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */ #define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */ #define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */ @@ -763,7 +767,7 @@ struct peer { #define PEER_CAP_ENHE_AF_NEGO (1 << 14) /* Extended nexthop afi/safi negotiated */ /* Global configuration flags. */ - u_int32_t flags; + uint32_t flags; #define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */ #define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */ #define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */ @@ -785,10 +789,10 @@ struct peer { char *tx_shutdown_message; /* NSF mode (graceful restart) */ - u_char nsf[AFI_MAX][SAFI_MAX]; + uint8_t nsf[AFI_MAX][SAFI_MAX]; /* Per AF configuration flags. */ - u_int32_t af_flags[AFI_MAX][SAFI_MAX]; + uint32_t af_flags[AFI_MAX][SAFI_MAX]; #define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */ #define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */ #define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */ @@ -827,7 +831,7 @@ struct peer { } default_rmap[AFI_MAX][SAFI_MAX]; /* Peer status flags. */ - u_int16_t sflags; + uint16_t sflags; #define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */ #define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */ #define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */ @@ -837,7 +841,7 @@ struct peer { #define PEER_STATUS_NSF_WAIT (1 << 6) /* wait comeback peer */ /* Peer status af flags (reset in bgp_stop) */ - u_int16_t af_sflags[AFI_MAX][SAFI_MAX]; + uint16_t af_sflags[AFI_MAX][SAFI_MAX]; #define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */ #define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */ #define PEER_STATUS_PREFIX_THRESHOLD (1 << 2) /* exceed prefix-threshold */ @@ -846,7 +850,7 @@ struct peer { #define PEER_STATUS_EOR_RECEIVED (1 << 5) /* end-of-rib received from peer */ /* Default attribute value for the peer. */ - u_int32_t config; + uint32_t config; #define PEER_CONFIG_TIMER (1 << 0) /* keepalive & holdtime */ #define PEER_CONFIG_CONNECT (1 << 1) /* connect */ #define PEER_CONFIG_ROUTEADV (1 << 2) /* route advertise */ @@ -933,11 +937,11 @@ struct peer { _Atomic uint32_t dynamic_cap_out; /* Dynamic Capability output count. */ /* BGP state count */ - u_int32_t established; /* Established */ - u_int32_t dropped; /* Dropped */ + uint32_t established; /* Established */ + uint32_t dropped; /* Dropped */ /* Update delay related fields */ - u_char update_delay_over; /* When this is set, BGP is no more waiting + uint8_t update_delay_over; /* When this is set, BGP is no more waiting for EOR */ /* Syncronization list and time. */ @@ -971,8 +975,8 @@ struct peer { /* Max prefix count. */ unsigned long pmax[AFI_MAX][SAFI_MAX]; - u_char pmax_threshold[AFI_MAX][SAFI_MAX]; - u_int16_t pmax_restart[AFI_MAX][SAFI_MAX]; + uint8_t pmax_threshold[AFI_MAX][SAFI_MAX]; + uint16_t pmax_restart[AFI_MAX][SAFI_MAX]; #define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75 /* allowas-in. */ @@ -1010,10 +1014,10 @@ struct peer { #define PEER_DOWN_IF_DOWN 25 /* Interface down */ #define PEER_DOWN_NBR_ADDR_DEL 26 /* Peer address lost */ unsigned long last_reset_cause_size; - u_char last_reset_cause[BGP_MAX_PACKET_SIZE]; + uint8_t last_reset_cause[BGP_MAX_PACKET_SIZE]; /* The kind of route-map Flags.*/ - u_char rmap_type; + uint8_t rmap_type; #define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */ #define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */ #define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */ @@ -1052,7 +1056,7 @@ struct bgp_nlri { uint8_t safi; /* iana_safi_t */ /* Pointer to NLRI byte stream. */ - u_char *nlri; + uint8_t *nlri; /* Length of whole NLRI. */ bgp_size_t length; @@ -1353,7 +1357,7 @@ extern struct peer *peer_create(union sockunion *, const char *, struct bgp *, struct peer_group *); extern struct peer *peer_create_accept(struct bgp *); extern void peer_xfer_config(struct peer *dst, struct peer *src); -extern char *peer_uptime(time_t, char *, size_t, u_char, json_object *); +extern char *peer_uptime(time_t, char *, size_t, uint8_t, json_object *); extern int bgp_config_write(struct vty *); @@ -1394,14 +1398,13 @@ extern int bgp_confederation_peers_check(struct bgp *, as_t); extern int bgp_confederation_peers_add(struct bgp *, as_t); extern int bgp_confederation_peers_remove(struct bgp *, as_t); -extern int bgp_timers_set(struct bgp *, u_int32_t keepalive, - u_int32_t holdtime); +extern int bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime); extern int bgp_timers_unset(struct bgp *); -extern int bgp_default_local_preference_set(struct bgp *, u_int32_t); +extern int bgp_default_local_preference_set(struct bgp *, uint32_t); extern int bgp_default_local_preference_unset(struct bgp *); -extern int bgp_default_subgroup_pkt_queue_max_set(struct bgp *bgp, u_int32_t); +extern int bgp_default_subgroup_pkt_queue_max_set(struct bgp *bgp, uint32_t); extern int bgp_default_subgroup_pkt_queue_max_unset(struct bgp *bgp); extern int bgp_listen_limit_set(struct bgp *, int); @@ -1427,12 +1430,12 @@ extern int peer_group_bind(struct bgp *, union sockunion *, struct peer *, struct peer_group *, as_t *); extern int peer_group_unbind(struct bgp *, struct peer *, struct peer_group *); -extern int peer_flag_set(struct peer *, u_int32_t); -extern int peer_flag_unset(struct peer *, u_int32_t); +extern int peer_flag_set(struct peer *, uint32_t); +extern int peer_flag_unset(struct peer *, uint32_t); -extern int peer_af_flag_set(struct peer *, afi_t, safi_t, u_int32_t); -extern int peer_af_flag_unset(struct peer *, afi_t, safi_t, u_int32_t); -extern int peer_af_flag_check(struct peer *, afi_t, safi_t, u_int32_t); +extern int peer_af_flag_set(struct peer *, afi_t, safi_t, uint32_t); +extern int peer_af_flag_unset(struct peer *, afi_t, safi_t, uint32_t); +extern int peer_af_flag_check(struct peer *, afi_t, safi_t, uint32_t); extern int peer_ebgp_multihop_set(struct peer *, int); extern int peer_ebgp_multihop_unset(struct peer *); @@ -1449,20 +1452,20 @@ extern int peer_default_originate_set(struct peer *, afi_t, safi_t, const char *); extern int peer_default_originate_unset(struct peer *, afi_t, safi_t); -extern int peer_port_set(struct peer *, u_int16_t); +extern int peer_port_set(struct peer *, uint16_t); extern int peer_port_unset(struct peer *); -extern int peer_weight_set(struct peer *, afi_t, safi_t, u_int16_t); +extern int peer_weight_set(struct peer *, afi_t, safi_t, uint16_t); extern int peer_weight_unset(struct peer *, afi_t, safi_t); -extern int peer_timers_set(struct peer *, u_int32_t keepalive, - u_int32_t holdtime); +extern int peer_timers_set(struct peer *, uint32_t keepalive, + uint32_t holdtime); extern int peer_timers_unset(struct peer *); -extern int peer_timers_connect_set(struct peer *, u_int32_t); +extern int peer_timers_connect_set(struct peer *, uint32_t); extern int peer_timers_connect_unset(struct peer *); -extern int peer_advertise_interval_set(struct peer *, u_int32_t); +extern int peer_advertise_interval_set(struct peer *, uint32_t); extern int peer_advertise_interval_unset(struct peer *); extern void peer_interface_set(struct peer *, const char *); @@ -1494,8 +1497,8 @@ extern int peer_password_unset(struct peer *); extern int peer_unsuppress_map_unset(struct peer *, afi_t, safi_t); -extern int peer_maximum_prefix_set(struct peer *, afi_t, safi_t, u_int32_t, - u_char, int, u_int16_t); +extern int peer_maximum_prefix_set(struct peer *, afi_t, safi_t, uint32_t, + uint8_t, int, uint16_t); extern int peer_maximum_prefix_unset(struct peer *, afi_t, safi_t); extern int peer_clear(struct peer *, struct listnode **); @@ -1558,6 +1561,8 @@ static inline int afindex(afi_t afi, safi_t safi) case SAFI_ENCAP: return BGP_AF_IPV4_ENCAP; break; + case SAFI_FLOWSPEC: + return BGP_AF_IPV4_FLOWSPEC; default: return BGP_AF_MAX; break; @@ -1580,6 +1585,8 @@ static inline int afindex(afi_t afi, safi_t safi) case SAFI_ENCAP: return BGP_AF_IPV6_ENCAP; break; + case SAFI_FLOWSPEC: + return BGP_AF_IPV6_FLOWSPEC; default: return BGP_AF_MAX; break; @@ -1616,6 +1623,7 @@ static inline int peer_afi_active_nego(const struct peer *peer, afi_t afi) || peer->afc_nego[afi][SAFI_LABELED_UNICAST] || peer->afc_nego[afi][SAFI_MPLS_VPN] || peer->afc_nego[afi][SAFI_ENCAP] + || peer->afc_nego[afi][SAFI_FLOWSPEC] || peer->afc_nego[afi][SAFI_EVPN]) return 1; return 0; @@ -1628,12 +1636,14 @@ static inline int peer_group_af_configured(struct peer_group *group) if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] + || peer->afc[AFI_IP][SAFI_FLOWSPEC] || peer->afc[AFI_IP][SAFI_MPLS_VPN] || peer->afc[AFI_IP][SAFI_ENCAP] || peer->afc[AFI_IP6][SAFI_UNICAST] || peer->afc[AFI_IP6][SAFI_MULTICAST] || peer->afc[AFI_IP6][SAFI_LABELED_UNICAST] || peer->afc[AFI_IP6][SAFI_MPLS_VPN] || peer->afc[AFI_IP6][SAFI_ENCAP] + || peer->afc[AFI_IP6][SAFI_FLOWSPEC] || peer->afc[AFI_L2VPN][SAFI_EVPN]) return 1; return 0; diff --git a/bgpd/rfapi/rfapi_backend.h b/bgpd/rfapi/rfapi_backend.h index 4455d66a26..bcd894b884 100644 --- a/bgpd/rfapi/rfapi_backend.h +++ b/bgpd/rfapi/rfapi_backend.h @@ -37,13 +37,14 @@ void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h); extern void rfapiProcessUpdate(struct peer *peer, void *rfd, struct prefix *p, struct prefix_rd *prd, struct attr *attr, - afi_t afi, safi_t safi, u_char type, - u_char sub_type, uint32_t *label); + afi_t afi, safi_t safi, uint8_t type, + uint8_t sub_type, uint32_t *label); extern void rfapiProcessWithdraw(struct peer *peer, void *rfd, struct prefix *p, struct prefix_rd *prd, struct attr *attr, - afi_t afi, safi_t safi, u_char type, int kill); + afi_t afi, safi_t safi, uint8_t type, + int kill); extern void rfapiProcessPeerDown(struct peer *peer); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 348f1557e2..d5208f6966 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -503,7 +503,7 @@ int rfapiGetUnAddrOfVpnBi(struct bgp_info *bi, struct prefix *p) */ static struct bgp_info *rfapiBgpInfoCreate(struct attr *attr, struct peer *peer, void *rfd, struct prefix_rd *prd, - u_char type, u_char sub_type, + uint8_t type, uint8_t sub_type, uint32_t *label) { struct bgp_info *new; @@ -2879,7 +2879,7 @@ typedef void(rfapi_bi_filtered_import_f)(struct rfapi_import_table *, int, struct peer *, void *, struct prefix *, struct prefix *, afi_t, struct prefix_rd *, struct attr *, - u_char, u_char, uint32_t *); + uint8_t, uint8_t, uint32_t *); static void rfapiExpireEncapNow(struct rfapi_import_table *it, @@ -2932,8 +2932,8 @@ static void rfapiBgpInfoFilteredImportEncap( struct prefix *aux_prefix, /* Unused for encap routes */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_info */ - u_char type, /* part of bgp_info */ - u_char sub_type, /* part of bgp_info */ + uint8_t type, /* part of bgp_info */ + uint8_t sub_type, /* part of bgp_info */ uint32_t *label) /* part of bgp_info */ { struct route_table *rt = NULL; @@ -3391,8 +3391,8 @@ void rfapiBgpInfoFilteredImportVPN( struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_info */ - u_char type, /* part of bgp_info */ - u_char sub_type, /* part of bgp_info */ + uint8_t type, /* part of bgp_info */ + uint8_t sub_type, /* part of bgp_info */ uint32_t *label) /* part of bgp_info */ { struct route_table *rt = NULL; @@ -3869,8 +3869,8 @@ static void rfapiBgpInfoFilteredImportBadSafi( struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_info */ - u_char type, /* part of bgp_info */ - u_char sub_type, /* part of bgp_info */ + uint8_t type, /* part of bgp_info */ + uint8_t sub_type, /* part of bgp_info */ uint32_t *label) /* part of bgp_info */ { vnc_zlog_debug_verbose("%s: Error, bad safi", __func__); @@ -3896,8 +3896,8 @@ rfapiBgpInfoFilteredImportFunction(safi_t safi) void rfapiProcessUpdate(struct peer *peer, void *rfd, /* set when looped from RFP/RFAPI */ struct prefix *p, struct prefix_rd *prd, - struct attr *attr, afi_t afi, safi_t safi, u_char type, - u_char sub_type, uint32_t *label) + struct attr *attr, afi_t afi, safi_t safi, uint8_t type, + uint8_t sub_type, uint32_t *label) { struct bgp *bgp; struct rfapi *h; @@ -3981,7 +3981,7 @@ void rfapiProcessUpdate(struct peer *peer, void rfapiProcessWithdraw(struct peer *peer, void *rfd, struct prefix *p, struct prefix_rd *prd, struct attr *attr, afi_t afi, - safi_t safi, u_char type, int kill) + safi_t safi, uint8_t type, int kill) { struct bgp *bgp; struct rfapi *h; @@ -4232,7 +4232,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp, struct bgp_info *bi; for (bi = rn2->info; bi; bi = bi->next) { - u_int32_t label = 0; + uint32_t label = 0; if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED)) diff --git a/bgpd/rfapi/rfapi_import.h b/bgpd/rfapi/rfapi_import.h index fc5bb01cef..84b7ca3a76 100644 --- a/bgpd/rfapi/rfapi_import.h +++ b/bgpd/rfapi/rfapi_import.h @@ -148,8 +148,8 @@ extern void rfapiBgpInfoFilteredImportVPN( struct prefix *aux_prefix, /* AFI_ETHER: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_info */ - u_char type, /* part of bgp_info */ - u_char sub_type, /* part of bgp_info */ + uint8_t type, /* part of bgp_info */ + uint8_t sub_type, /* part of bgp_info */ uint32_t *label); /* part of bgp_info */ extern struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList( diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index c5b3094b1e..5fb44bb492 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -1068,7 +1068,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, inet_ntop(pfx_vn.family, &pfx_vn.u.prefix, buf_ntop, BUFSIZ)); if (bi->extra) { - u_int32_t l = decode_label(&bi->extra->label[0]); + uint32_t l = decode_label(&bi->extra->label[0]); snprintf(buf_vn, BUFSIZ, "Label: %d", l); } else /* should never happen */ { @@ -1180,7 +1180,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, } } if (tun_type != BGP_ENCAP_TYPE_MPLS && bi->extra) { - u_int32_t l = decode_label(&bi->extra->label[0]); + uint32_t l = decode_label(&bi->extra->label[0]); if (!MPLS_LABEL_IS_NULL(l)) { fp(out, " Label: %d", l); if (nlines == 1) @@ -1631,7 +1631,7 @@ void rfapiPrintDescriptor(struct vty *vty, struct rfapi_descriptor *rfd) } for (afi = AFI_IP; afi < AFI_MAX; ++afi) { - u_char family; + uint8_t family; family = afi2family(afi); if (!family) diff --git a/bgpd/rfapi/vnc_debug.c b/bgpd/rfapi/vnc_debug.c index 3e9b5ed6b9..2b08ea493c 100644 --- a/bgpd/rfapi/vnc_debug.c +++ b/bgpd/rfapi/vnc_debug.c @@ -85,10 +85,9 @@ DEFUN (debug_bgp_vnc, DEFUN (no_debug_bgp_vnc, no_debug_bgp_vnc_cmd, - "<no debug|undebug> bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", + "no debug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", NO_STR DEBUG_STR - "Undebug\n" BGP_STR VNC_STR "rfapi query handling\n" @@ -98,10 +97,8 @@ DEFUN (no_debug_bgp_vnc, { size_t i; - if (strmatch(argv[0]->text, "no")) - argc--, argv++; for (i = 0; i < (sizeof(vncdebug) / sizeof(struct vnc_debug)); ++i) { - if (strmatch(argv[3]->text, vncdebug[i].name)) { + if (strmatch(argv[argc - 1]->text, vncdebug[i].name)) { if (vty->node == CONFIG_NODE) { conf_vnc_debug &= ~vncdebug[i].bit; term_vnc_debug &= ~vncdebug[i].bit; @@ -117,6 +114,20 @@ DEFUN (no_debug_bgp_vnc, return CMD_WARNING_CONFIG_FAILED; } +#if CONFDATE > 20190402 +CPP_NOTICE("bgpd: time to remove undebug commands") +#endif +ALIAS_HIDDEN(no_debug_bgp_vnc, + undebug_bgp_vnc_cmd, + "undebug bgp vnc <rfapi-query|import-bi-attach|import-del-remote|verbose>", + "Undebug\n" + BGP_STR + VNC_STR + "rfapi query handling\n" + "import BI atachment\n" + "import delete remote routes\n" + "verbose logging\n") + /*********************************************************************** * no debug bgp vnc all @@ -124,10 +135,9 @@ DEFUN (no_debug_bgp_vnc, DEFUN (no_debug_bgp_vnc_all, no_debug_bgp_vnc_all_cmd, - "<no debug|undebug> all bgp vnc", + "no debug all bgp vnc", NO_STR DEBUG_STR - "Undebug command\n" "Disable all VNC debugging\n" BGP_STR VNC_STR) @@ -138,6 +148,17 @@ DEFUN (no_debug_bgp_vnc_all, return CMD_SUCCESS; } +#if CONFDATE > 20190402 +CPP_NOTICE("bgpd: time to remove undebug commands") +#endif +ALIAS_HIDDEN (no_debug_bgp_vnc_all, + undebug_bgp_vnc_all_cmd, + "undebug all bgp vnc", + "Undebug\n" + "Disable all VNC debugging\n" + BGP_STR + VNC_STR) + /*********************************************************************** * show/save ***********************************************************************/ @@ -188,6 +209,12 @@ void vnc_debug_init(void) install_element(ENABLE_NODE, &debug_bgp_vnc_cmd); install_element(CONFIG_NODE, &debug_bgp_vnc_cmd); install_element(ENABLE_NODE, &no_debug_bgp_vnc_cmd); + install_element(CONFIG_NODE, &no_debug_bgp_vnc_cmd); + install_element(ENABLE_NODE, &undebug_bgp_vnc_cmd); + install_element(CONFIG_NODE, &undebug_bgp_vnc_cmd); install_element(ENABLE_NODE, &no_debug_bgp_vnc_all_cmd); + install_element(CONFIG_NODE, &no_debug_bgp_vnc_all_cmd); + install_element(ENABLE_NODE, &undebug_bgp_vnc_all_cmd); + install_element(CONFIG_NODE, &undebug_bgp_vnc_all_cmd); } diff --git a/bgpd/rfapi/vnc_export_table.h b/bgpd/rfapi/vnc_export_table.h index aa38233e8f..3ccf8661e7 100644 --- a/bgpd/rfapi/vnc_export_table.h +++ b/bgpd/rfapi/vnc_export_table.h @@ -39,8 +39,8 @@ struct vnc_export_info { struct vnc_export_info *next; struct route_node *node; struct peer *peer; - u_char type; - u_char subtype; + uint8_t type; + uint8_t subtype; uint32_t lifetime; struct thread *timer; }; diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c index 4f54166434..4bc5535e1b 100644 --- a/bgpd/rfapi/vnc_import_bgp.c +++ b/bgpd/rfapi/vnc_import_bgp.c @@ -124,14 +124,14 @@ struct prefix_bag { struct bgp_info *ubi; /* unicast route */ }; -static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, - 0xf8, 0xfc, 0xfe, 0xff}; +static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, + 0xf8, 0xfc, 0xfe, 0xff}; int vnc_prefix_cmp(void *pfx1, void *pfx2) { int offset; int shift; - u_char mask; + uint8_t mask; struct prefix *p1 = pfx1; struct prefix *p2 = pfx2; @@ -154,8 +154,8 @@ int vnc_prefix_cmp(void *pfx1, void *pfx2) } /* Set both prefix's head pointer. */ - const u_char *pp1 = (const u_char *)&p1->u.prefix; - const u_char *pp2 = (const u_char *)&p2->u.prefix; + const uint8_t *pp1 = (const uint8_t *)&p1->u.prefix; + const uint8_t *pp2 = (const uint8_t *)&p2->u.prefix; while (offset--) { if (*pp1 < *pp2) @@ -1762,7 +1762,7 @@ static void vnc_import_bgp_exterior_add_route_it( bi_interior = bi_interior->next) { struct prefix_rd *prd; struct attr new_attr; - u_int32_t label = 0; + uint32_t label = 0; if (!is_usable_interior_route(bi_interior)) continue; @@ -1941,7 +1941,7 @@ void vnc_import_bgp_exterior_del_route( for (bi_interior = rn->info; bi_interior; bi_interior = bi_interior->next) { struct prefix_rd *prd; - u_int32_t label = 0; + uint32_t label = 0; if (!is_usable_interior_route(bi_interior)) continue; @@ -2102,7 +2102,7 @@ void vnc_import_bgp_exterior_add_route_interior( struct prefix_rd *prd; struct attr new_attr; - u_int32_t label = 0; + uint32_t label = 0; ++count; /* debugging */ @@ -2194,7 +2194,7 @@ void vnc_import_bgp_exterior_add_route_interior( struct bgp_info *bi; struct prefix_rd *prd; struct attr new_attr; - u_int32_t label = 0; + uint32_t label = 0; /* do pull-down */ @@ -2336,7 +2336,7 @@ void vnc_import_bgp_exterior_add_route_interior( struct prefix_rd *prd; struct attr new_attr; - u_int32_t label = 0; + uint32_t label = 0; /* do pull-down */ @@ -2476,7 +2476,7 @@ void vnc_import_bgp_exterior_del_route_interior( &cursor)) { struct prefix_rd *prd; - u_int32_t label = 0; + uint32_t label = 0; if (bi_interior->extra) { prd = &bi_interior->extra->vnc.import.rd; @@ -2549,7 +2549,7 @@ void vnc_import_bgp_exterior_del_route_interior( struct prefix_rd *prd; struct attr new_attr; - u_int32_t label = 0; + uint32_t label = 0; if (bi->type == ZEBRA_ROUTE_BGP_DIRECT_EXT) continue; diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index 6afcd21a10..7d564ef113 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -58,7 +58,7 @@ static struct zclient *zclient_vnc = NULL; /* * Routes coming from zebra get added to VNC here */ -static void vnc_redistribute_add(struct prefix *p, u_int32_t metric, +static void vnc_redistribute_add(struct prefix *p, uint32_t metric, uint8_t type) { struct bgp *bgp = bgp_get_default(); @@ -436,7 +436,7 @@ static void vnc_zebra_route_msg(struct prefix *p, unsigned int nhp_count, static void -nve_list_to_nh_array(u_char family, struct list *nve_list, +nve_list_to_nh_array(uint8_t family, struct list *nve_list, unsigned int *nh_count_ret, void **nh_ary_ret, /* returned address array */ void **nhp_ary_ret) /* returned pointer array */ diff --git a/debianpkg/backports/ubuntu17.10/debian/control b/debianpkg/backports/ubuntu17.10/debian/control index 692501db18..1bc3c4e4b5 100644 --- a/debianpkg/backports/ubuntu17.10/debian/control +++ b/debianpkg/backports/ubuntu17.10/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Nobody <nobody@frrouting.org> Uploaders: Nobody <nobody@frrouting.org> XSBC-Original-Maintainer: <maintainers@frrouting.org> -Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr +Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, libpython-dev Standards-Version: 3.9.6 Homepage: http://www.frrouting.org/ diff --git a/debianpkg/backports/ubuntu18.04/debian/control b/debianpkg/backports/ubuntu18.04/debian/control index d28f9332ce..1e31ad6d51 100644 --- a/debianpkg/backports/ubuntu18.04/debian/control +++ b/debianpkg/backports/ubuntu18.04/debian/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Nobody <nobody@frrouting.org> Uploaders: Nobody <nobody@frrouting.org> XSBC-Original-Maintainer: <maintainers@frrouting.org> -Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, python-sphinx +Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), imagemagick, ghostscript, groff, autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, python-sphinx, libpython-dev Standards-Version: 3.9.6 Homepage: http://www.frrouting.org/ diff --git a/debianpkg/control b/debianpkg/control index bbd4c43b42..468581045b 100644 --- a/debianpkg/control +++ b/debianpkg/control @@ -4,7 +4,7 @@ Priority: optional Maintainer: Nobody <nobody@frrouting.org> Uploaders: Nobody <nobody@frrouting.org> XSBC-Original-Maintainer: <maintainers@frrouting.org> -Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, python-sphinx +Build-Depends: debhelper (>= 7.0.50~), libncurses5-dev, libreadline-dev, texlive-latex-base, texlive-generic-recommended, libpam0g-dev | libpam-dev, libcap-dev, texinfo (>= 4.7), autotools-dev, libpcre3-dev, gawk, chrpath, libsnmp-dev, git, dh-autoreconf, libjson-c-dev, libjson-c2 | libjson-c3, dh-systemd, libsystemd-dev, bison, flex, libc-ares-dev, pkg-config, python (>= 2.7), python-ipaddr, python-sphinx, libpython-dev Standards-Version: 3.9.6 Homepage: http://www.frrouting.org/ diff --git a/doc/developer/_static/overrides.css b/doc/developer/_static/overrides.css new file mode 100644 index 0000000000..1e0de66c55 --- /dev/null +++ b/doc/developer/_static/overrides.css @@ -0,0 +1,4 @@ +/* remove max-width restriction */ +div.body { + max-width: none; +} diff --git a/doc/developer/building-frr-on-alpine.rst b/doc/developer/building-frr-on-alpine.rst index 68031b3b61..f0f2aee138 100644 --- a/doc/developer/building-frr-on-alpine.rst +++ b/doc/developer/building-frr-on-alpine.rst @@ -1,4 +1,4 @@ -Building FRR dev packages on Alpine Linux from Git Source +Alpine Linux 3.7+ ========================================================= For building Alpine Linux dev packages, we use docker. @@ -34,26 +34,38 @@ This will put the apk packages in: Usage ----- -To add the packages to a docker image, create a Dockerfile in ./docker/pkgs: +To create a base image with the frr packages installed: :: - FROM alpine:3.7 - RUN mkdir -p /pkgs - ADD apk/ /pkgs/ - RUN apk add --no-cache --allow-untrusted /pkgs/x86_64/*.apk + docker build --rm -f docker/alpine/Dockerfile -t frr:latest . -And build a docker image: +Or, if you don't have a git checkout of the sources, you can build a base +image directly off the github account: :: - docker build --rm --force-rm -t alpine-dev-pkgs:latest docker/pkgs + docker build --rm -f docker/alpine/Dockerfile -t frr:latest \ + https://github.com/frrouting/frr.git -And run the image: +And to run the image: :: - docker run -it --rm alpine-dev-pkgs:latest /bin/sh + docker run -it --rm frr:latest /bin/sh Currently, we only package the raw daemons and example files, so, you'll need to run the daemons by hand (or, better, orchestrate in the Dockerfile). + +We can also build directly from docker-compose, with a docker-compose.yml file +like this one: + +:: + + version: '2.2' + + services: + frr: + build: + context: https://github.com/frrouting/frr.git + dockerfile: docker/alpine/Dockerfile diff --git a/doc/developer/building.rst b/doc/developer/building.rst index a10e4a245c..c7a53734d9 100644 --- a/doc/developer/building.rst +++ b/doc/developer/building.rst @@ -21,3 +21,4 @@ Building FRR building-frr-on-ubuntu1204 building-frr-on-ubuntu1404 building-frr-on-ubuntu1604 + building-frr-on-ubuntu1804 diff --git a/doc/developer/cli.rst b/doc/developer/cli.rst index 82dd8af1ba..291860d967 100644 --- a/doc/developer/cli.rst +++ b/doc/developer/cli.rst @@ -8,6 +8,48 @@ features or modifying existing code it is necessary to create or modify CLI commands. FRR has a powerful internal CLI system that does most of the heavy lifting for you. +Modes +----- +FRR's CLI is organized by modes. Each mode is associated with some set of +functionality, e.g. EVPN, or some underlying object such as an interface. Each +mode contains a set of commands that control the associated functionality or +object. Users move between the modes by entering a command, which is usually +different for each source and destination mode. + +A summary of the modes is given in the following figure. + +.. graphviz:: ../figures/nodes.dot + +.. seealso:: :ref:`cli-data-structures` + +Walkup +^^^^^^ +FRR exhibits, for historical reasons, a peculiar behavior called 'walkup'. +Suppose a user is in ``OSPF_NODE``, which contains only OSPF-specific commands, +and enters the following command: :: + + ip route 192.168.100.0/24 10.0.2.2 + +This command is not defined in ``OSPF_NODE``, so the matcher will fail to match +the command in that node. The matcher will then check "parent" nodes of +``OSPF_NODE``. In this case the direct parent of ``OSPF_NODE`` is +``CONFIG_NODE``, so the current node switches to ``CONFIG_NODE`` and the command +is tried in that node. Since static route commands are defined in +``CONFIG_NODE`` the command succeeds. The procedure of attempting to execute +unmatched commands by sequentially "walking up" to parent nodes only happens in +children (direct and indirect) below ``CONFIG_NODE`` and stops at +``CONFIG_NODE``. + +Unfortunately, the internal representation of the various modes is not actually +a graph. Instead, there is an array. The parent-child relationships are not +explicitly defined in any datastructure but instead are hard-coded into the +specific commands that switch nodes. For walkup, there is a function that takes +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. + +Defining Commands +----------------- All definitions for the CLI system are exposed in ``lib/command.h``. In this header there are a set of macros used to define commands. These macros are collectively referred to as "DEFUNs", because of their syntax: @@ -37,10 +79,9 @@ constructs for hooking into the CLI. In order these are: the command definition In the above example, ``command_name`` is the function name, -``command_name_cmd`` is the command name, ``"example..."`` is the definition -and the last argument is the doc string. The block following the macro is the -body of the handler function, details on which are presented later in this -section. +``command_name_cmd`` is the command name, ``"example..."`` is the definition and +the last argument is the doc string. The block following the macro is the body +of the handler function, details on which are presented later in this section. In order to make the command show up to the user it must be installed into the CLI graph. To do this, call: @@ -48,16 +89,15 @@ CLI graph. To do this, call: ``install_element(NODE, &command_name_cmd);`` This will install the command into the specified CLI node. Usually these calls -are grouped together in a CLI initialization function for a set of commands, -and the DEFUNs themselves are grouped into the same source file to avoid -cluttering the codebase. The names of these files follow the form -``*_vty.[ch]`` by convention. Please do not scatter individual CLI commands in -the middle of source files; instead expose the necessary functions in a header -and place the command definition in a ``*_vty.[ch]`` file. +are grouped together in a CLI initialization function for a set of commands, and +the DEFUNs themselves are grouped into the same source file to avoid cluttering +the codebase. The names of these files follow the form ``*_vty.[ch]`` by +convention. Please do not scatter individual CLI commands in the middle of +source files; instead expose the necessary functions in a header and place the +command definition in a ``*_vty.[ch]`` file. Definition Grammar ------------------- - +^^^^^^^^^^^^^^^^^^ FRR uses its own grammar for defining CLI commands. The grammar draws from syntax commonly seen in \*nix manpages and should be fairly intuitive. The parser is implemented in Bison and the lexer in Flex. These may be found in @@ -68,10 +108,9 @@ parser is implemented in Bison and the lexer in Flex. These may be found in to look. Bison is very stable and if it detects a syntax error, 99% of the time it will be a syntax error in your definition. -The formal grammar in BNF is given below. This is the grammar implemented in -the Bison parser. At runtime, the Bison parser reads all of the CLI strings and -builds a combined directed graph that is used to match and interpret user -input. +The formal grammar in BNF is given below. This is the grammar implemented in the +Bison parser. At runtime, the Bison parser reads all of the CLI strings and +builds a combined directed graph that is used to match and interpret user input. Human-friendly explanations of how to use this grammar are given a bit later in this section alongside information on the :ref:`cli-data-structures` constructed @@ -108,15 +147,15 @@ by the parser. : `simple_token` Tokens -~~~~~~ +^^^^^^ The various capitalized tokens in the BNF above are in fact themselves placeholders, but not defined as such in the formal grammar; the grammar provides the structure, and the tokens are actually more like a type system for -the strings you write in your CLI definitions. A CLI definition string is -broken apart and each piece is assigned a type by the lexer based on a set of -regular expressions. The parser uses the type information to verify the string -and determine the structure of the CLI graph; additional metadata (such as the -raw text of each token) is encoded into the graph as it is constructed by the +the strings you write in your CLI definitions. A CLI definition string is broken +apart and each piece is assigned a type by the lexer based on a set of regular +expressions. The parser uses the type information to verify the string and +determine the structure of the CLI graph; additional metadata (such as the raw +text of each token) is encoded into the graph as it is constructed by the parser, but this is merely a dumb copy job. Here is a brief summary of the various token types along with examples. @@ -151,29 +190,29 @@ context: :: - example command FOO - example command (22-49) - example command A.B.C.D/X + example command FOO + example command (22-49) + example command A.B.C.D/X The following table demonstrates the matcher's choice for a selection of possible user input. -+-----------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ -| Input | Matched command | Reason | -+=============================+===========================+==============================================================================================================+ -| example command eLi7eH4xx0r | example command FOO | ``eLi7eH4xx0r`` is not an integer or IPv4 prefix, | -| | | but FOO is a variable and matches all input. | -+-----------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ -| example command 42 | example command (22-49) | ``42`` is not an IPv4 prefix. It does match both | -| | | ``(22-49)`` and ``FOO``, but RANGE tokens are more specific and have a higher priority than VARIABLE tokens. | -+-----------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ -| example command 10.3.3.0/24 | example command A.B.C.D/X | The user entered an IPv4 prefix, which is best matched by the last command. | -+-----------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ ++---------------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ +| Input | Matched command | Reason | ++=================================+===========================+==============================================================================================================+ +| ``example command eLi7eH4xx0r`` | example command FOO | ``eLi7eH4xx0r`` is not an integer or IPv4 prefix, | +| | | but FOO is a variable and matches all input. | ++---------------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ +| ``example command 42`` | example command (22-49) | ``42`` is not an IPv4 prefix. It does match both | +| | | ``(22-49)`` and ``FOO``, but RANGE tokens are more specific and have a higher priority than VARIABLE tokens. | ++---------------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ +| ``example command 10.3.3.0/24`` | example command A.B.C.D/X | The user entered an IPv4 prefix, which is best matched by the last command. | ++---------------------------------+---------------------------+--------------------------------------------------------------------------------------------------------------+ Rules -~~~~~ - -There are also constructs which allow optional tokens, mutual exclusion, one-or-more selection and repetition. +^^^^^ +There are also constructs which allow optional tokens, mutual exclusion, +one-or-more selection and repetition. - ``<angle|brackets>`` -- Contain sequences of tokens separated by pipes and provide mutual exclusion. User input matches at most one option. @@ -205,253 +244,293 @@ Some general notes: implementing new CLI. Variable Names --------------- - -The parser tries to fill the "varname" field on each token. This can -happen either manually or automatically. Manual specifications work by -appending ``"$name"`` after the input specifier: +^^^^^^^^^^^^^^ +The parser tries to fill the "varname" field on each token. This can happen +either manually or automatically. Manual specifications work by appending +``$name`` after the input specifier: :: - foo bar$cmd WORD$name A.B.C.D$ip + foo bar$cmd WORD$name A.B.C.D$ip -Note that you can also assign variable names to fixed input tokens, this -can be useful if multiple commands share code. You can also use "$name" -after a multiple-choice option: +Note that you can also assign variable names to fixed input tokens, this can be +useful if multiple commands share code. You can also use "$name" after a +multiple-choice option: :: - foo bar <A.B.C.D|X:X::X:X>$addr [optionA|optionB]$mode + foo bar <A.B.C.D|X:X::X:X>$addr [optionA|optionB]$mode -The variable name is in this case assigned to the last token in each of -the branches. +The variable name is in this case assigned to the last token in each of the +branches. -Automatic assignment of variable names works by applying the following -rules: +Automatic assignment of variable names works by applying the following rules: - manual names always have priority -- a "[no]" at the beginning receives "no" as varname on the "no" token -- VARIABLE tokens whose text is not "WORD" or "NAME" receive a cleaned - lowercase version of the token text as varname, e.g. "ROUTE-MAP" - becomes "route\_map". -- other variable tokens (i.e. everything except "fixed") receive the - text of the preceding fixed token as varname, if one can be found. - E.g.: "ip route A.B.C.D/M INTERFACE" assigns "route" to the - "A.B.C.D/M" token. - -These rules should make it possible to avoid manual varname assignment -in 90% of the cases. +- a ``[no]`` at the beginning receives ``no`` as varname on the ``no`` token +- ``VARIABLE`` tokens whose text is not ``WORD`` or ``NAME`` receive a cleaned + lowercase version of the token text as varname, e.g. ``ROUTE-MAP`` becomes + ``route_map``. +- other variable tokens (i.e. everything except "fixed") receive the text of + the preceding fixed token as varname, if one can be found. E.g. + ``ip route A.B.C.D/M INTERFACE`` assigns "route" to the ``A.B.C.D/M`` token. -DEFPY ------ +These rules should make it possible to avoid manual varname assignment in 90% of +the cases. -``DEFPY(...)`` is an enhanced version of ``DEFUN()`` which is -preprocessed by ``python/clidef.py``. The python script parses the -command definition string, extracts variable names and types, and -generates a C wrapper function that parses the variables and passes them -on. This means that in the CLI function body, you will receive -additional parameters with appropriate types. +Doc Strings +^^^^^^^^^^^ +Each token in a command definition should be documented with a brief doc string +that informs a user of the meaning and/or purpose of the subsequent command +tree. These strings are provided as the last parameter to DEFUN macros, +concatenated together and separated by an escaped newline (``\n``). These are +best explained by example. -This is best explained by an example: +:: + + DEFUN (config_terminal, + config_terminal_cmd, + "configure terminal", + "Configuration from vty interface\n" + "Configuration terminal\n") + +The last parameter is split into two lines for readability. Two newline +delimited doc strings are present, one for each token in the command. The second +string documents the functionality of the ``terminal`` command in the +``configure`` subtree. + +Note that the first string, for ``configure`` does not contain documentation for +'terminal'. This is because the CLI is best envisioned as a tree, with tokens +defining branches. An imaginary ``start`` token is the root of every command in +a CLI node. Each subsequent written token descends into a subtree, so the +documentation for that token ideally summarizes all the functionality contained +in the subtree. + +A consequence of this structure is that the developer must be careful to use the +same doc strings when defining multiple commands that are part of the same tree. +Commands which share prefixes must share the same doc strings for those +prefixes. On startup the parser will generate warnings if it notices +inconsistent doc strings. Behavior is undefined; the same token may show up +twice in completions, with different doc strings, or it may show up once with a +random doc string. Parser warnings should be heeded and fixed to avoid confusing +users. + +The number of doc strings provided must be equal to the amount of tokens present +in the command definition, read left to right, ignoring any special constructs. + +In the examples below, each arrowed token needs a doc string. :: - DEFPY(func, func_cmd, "[no] foo bar A.B.C.D (0-99)$num", "...help...") + "show ip bgp" + ^ ^ ^ + + "command <foo|bar> [example]" + ^ ^ ^ ^ + +DEFPY +^^^^^ +``DEFPY(...)`` is an enhanced version of ``DEFUN()`` which is preprocessed by +:file:`python/clidef.py`. The python script parses the command definition +string, extracts variable names and types, and generates a C wrapper function +that parses the variables and passes them on. This means that in the CLI +function body, you will receive additional parameters with appropriate types. + +This is best explained by an example. Invoking ``DEFPY`` like this: + +.. code-block:: c + + DEFPY(func, func_cmd, "[no] foo bar A.B.C.D (0-99)$num", "...help...") - => +defines the handler function like this: - func(self, vty, argc, argv, /* standard CLI arguments */ +.. code-block:: c - const char *no, /* unparsed "no" */ - struct in_addr bar, /* parsed IP address */ - const char *bar_str, /* unparsed IP address */ - long num, /* parsed num */ - const char *num_str) /* unparsed num */ + func(self, vty, argc, argv, /* standard CLI arguments */ + const char *no, /* unparsed "no" */ + struct in_addr bar, /* parsed IP address */ + const char *bar_str, /* unparsed IP address */ + long num, /* parsed num */ + const char *num_str) /* unparsed num */ -Note that as documented in the previous section, "bar" is automatically -applied as variable name for "A.B.C.D". The python code then detects -this is an IP address argument and generates code to parse it into a -``struct in_addr``, passing it in ``bar``. The raw value is passed in -``bar_str``. The range/number argument works in the same way with the -explicitly given variable name. +Note that as documented in the previous section, ``bar`` is automatically +applied as variable name for ``A.B.C.D``. The Python script then detects this as +an IP address argument and generates code to parse it into a ``struct in_addr``, +passing it in ``bar``. The raw value is passed in ``bar_str``. The range/number +argument works in the same way with the explicitly given variable name. Type rules -~~~~~~~~~~ - -+-----------------------------+--------------------------------+--------------------------+ -| Token(s) | Type | Value if omitted by user | -+=============================+================================+==========================+ -| ``A.B.C.D`` | ``struct in_addr`` | 0.0.0.0 | -+-----------------------------+--------------------------------+--------------------------+ -| ``X:X::X:X`` | ``struct in6_addr`` | \:: | -+-----------------------------+--------------------------------+--------------------------+ -| ``A.B.C.D + X:X::X:X`` | ``const union sockunion *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| ``A.B.C.D/M`` | ``const struct prefix_ipv4 *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| ``X:X::X:X/M`` | ``const struct prefix_ipv6 *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| ``A.B.C.D/M + X:X::X:X/M`` | ``const struct prefix *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| ``(0-9)`` | ``long`` | 0 | -+-----------------------------+--------------------------------+--------------------------+ -| ``VARIABLE`` | ``const char *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| ``word`` | ``const char *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ -| *all other* | ``const char *`` | NULL | -+-----------------------------+--------------------------------+--------------------------+ +"""""""""" + ++----------------------------+--------------------------------+--------------------------+ +| Token(s) | Type | Value if omitted by user | ++============================+================================+==========================+ +| ``A.B.C.D`` | ``struct in_addr`` | ``0.0.0.0`` | ++----------------------------+--------------------------------+--------------------------+ +| ``X:X::X:X`` | ``struct in6_addr`` | ``::`` | ++----------------------------+--------------------------------+--------------------------+ +| ``A.B.C.D + X:X::X:X`` | ``const union sockunion *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| ``A.B.C.D/M`` | ``const struct prefix_ipv4 *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| ``X:X::X:X/M`` | ``const struct prefix_ipv6 *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| ``A.B.C.D/M + X:X::X:X/M`` | ``const struct prefix *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| ``(0-9)`` | ``long`` | ``0`` | ++----------------------------+--------------------------------+--------------------------+ +| ``VARIABLE`` | ``const char *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| ``word`` | ``const char *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ +| *all other* | ``const char *`` | ``NULL`` | ++----------------------------+--------------------------------+--------------------------+ Note the following details: - Not all parameters are pointers, some are passed as values. -- When the type is not ``const char *``, there will be an extra - ``_str`` argument with type ``const char *``. -- You can give a variable name not only to ``VARIABLE`` tokens but also - to ``word`` tokens (e.g. constant words). This is useful if some - parts of a command are optional. The type will be ``const char *``. +- When the type is not ``const char *``, there will be an extra ``_str`` + argument with type ``const char *``. +- You can give a variable name not only to ``VARIABLE`` tokens but also to + ``word`` tokens (e.g. constant words). This is useful if some parts of a + command are optional. The type will be ``const char *``. - ``[no]`` will be passed as ``const char *no``. -- Pointers will be NULL when the argument is optional and the user did - not use it. -- If a parameter is not a pointer, but is optional and the user didn't - use it, the default value will be passed. Check the ``_str`` argument - if you need to determine whether the parameter was omitted. -- If the definition contains multiple parameters with the same variable - name, they will be collapsed into a single function parameter. The - python code will detect if the types are compatible (i.e. IPv4 + IPv6 - variantes) and choose a corresponding C type. -- The standard DEFUN parameters (self, vty, argc, argv) are still - present and can be used. A DEFUN can simply be **edited into a DEFPY - without further changes and it will still work**; this allows easy - forward migration. -- A file may contain both DEFUN and DEFPY statements. +- Pointers will be ``NULL`` when the argument is optional and the user did not + use it. +- If a parameter is not a pointer, but is optional and the user didn't use it, + the default value will be passed. Check the ``_str`` argument if you need to + determine whether the parameter was omitted. +- If the definition contains multiple parameters with the same variable name, + they will be collapsed into a single function parameter. The python code will + detect if the types are compatible (i.e. IPv4 + IPv6 variants) and choose a + corresponding C type. +- The standard DEFUN parameters (``self, vty, argc, argv``) are still present + and can be used. A DEFUN can simply be **edited into a DEFPY without further + changes and it will still work**; this allows easy forward migration. +- A file may contain both ``DEFUN`` and ``DEFPY`` statements. Getting a parameter dump -~~~~~~~~~~~~~~~~~~~~~~~~ - -The clidef.py script can be called to get a list of DEFUNs/DEFPYs with -the parameter name/type list: +"""""""""""""""""""""""" +The clidef.py script can be called to get a list of DEFUNs/DEFPYs with the +parameter name/type list: :: - lib/clippy python/clidef.py --all-defun --show lib/plist.c > /dev/null + lib/clippy python/clidef.py --all-defun --show lib/plist.c > /dev/null The generated code is printed to stdout, the info dump to stderr. The -``--all-defun`` argument will make it process DEFUN blocks as well as -DEFPYs, which is useful prior to converting some DEFUNs. **The dump does -not list the ``_str`` arguments** to keep the output shorter. +``--all-defun`` argument will make it process DEFUN blocks as well as DEFPYs, +which is useful prior to converting some DEFUNs. **The dump does not list the +``_str`` arguments** to keep the output shorter. -Note that the clidef.py script cannot be run with python directly, it -needs to be run with *clippy* since the latter makes the CLI parser -available. +Note that the ``clidef.py`` script cannot be run with python directly, it needs +to be run with *clippy* since the latter makes the CLI parser available. Include & Makefile requirements -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +""""""""""""""""""""""""""""""" +A source file that uses DEFPY needs to include the ``*_clippy.c`` file **before +all DEFPY statements**: -A source file that uses DEFPY needs to include the ``_clippy.c`` file -**before all DEFPY statements**: +.. code-block:: c -:: + /* GPL header */ + #include ... + ... + #ifndef VTYSH_EXTRACT_PL + #include "daemon/filename_clippy.c" + #endif - /* GPL header */ - #include ... + DEFPY(...) + DEFPY(...) - ... + install_element(...) - #include "daemon/filename_clippy.c" +This dependency needs to be marked in ``Makefile.am`` or ``subdir.am``: (there +is no ordering requirement) - DEFPY(...) - DEFPY(...) +.. code-block:: make - install_element(...) + include ../common.am -This dependency needs to be marked in Makefile.am: (there is no ordering -requirement) + # ... -:: + # if linked into a LTLIBRARY (.la/.so): + filename.lo: filename_clippy.c - include ../common.am + # if linked into an executable or static library (.a): + filename.o: filename_clippy.c - # ... +Handlers +^^^^^^^^ +The block that follows a CLI definition is executed when a user enters input +that matches the definition. Its function signature looks like this: - # if linked into a LTLIBRARY (.la/.so): - filename.lo: filename_clippy.c +.. code-block:: c - # if linked into an executable or static library (.a): - filename.o: filename_clippy.c + int (*func) (const struct cmd_element *, struct vty *, int, struct cmd_token *[]); -Doc Strings ------------ +The first argument is the command definition struct. The last argument is an +ordered array of tokens that correspond to the path taken through the graph, and +the argument just prior to that is the length of the array. -Each token in a command definition should be documented with a brief doc string -that informs a user of the meaning and/or purpose of the subsequent command -tree. These strings are provided as the last parameter to DEFUN macros, -concatenated together and separated by an escaped newline (\n). These are best -explained by example. +The arrangement of the token array has changed from Quagga's CLI implementation. +In the old system, missing arguments were padded with ``NULL`` so that the same +parts of a command would show up at the same indices regardless of what was +entered. The new system does not perform such padding and therefore it is +generally *incorrect* to assume consistent indices in this array. As a simple +example: + +Command definition: :: - DEFUN (config_terminal, - config_terminal_cmd, - "configure terminal", - "Configuration from vty interface\n" - "Configuration terminal\n") + command [foo] <bar|baz> -The last parameter is split into two lines for readability. Two newline -delimited doc strings are present, one for each token in the command. -The second string documents the functionality of the 'terminal' command -in the 'configure' tree. - -Note that the first string, for 'configure' does not contain -documentation for 'terminal'. This is because the CLI is best envisioned -as a tree, with tokens defining branches. An imaginary 'start' token is -the root of every command in a CLI node. Each subsequent written token -descends into a subtree, so the documentation for that token ideally -summarizes all the functionality contained in the subtree. - -A consequence of this structure is that the developer must be careful to -use the same doc strings when defining multiple commands that are part -of the same tree. Commands which share prefixes must share the same doc -strings for those prefixes. On startup the parser will generate warnings -if it notices inconsistent doc strings. Behavior is undefined; the same -token may show up twice in completions, with different doc strings, or -it may show up once with a random doc string. Parser warnings should be -heeded and fixed to avoid confusing users. - -The number of doc strings provided must be equal to the amount of tokens -present in the command definition, read left to right, ignoring any -special constructs. +User enters: -In the examples below, each arrowed token needs a doc string. +:: + + command foo bar + +Array: + +:: + + [0] -> command + [1] -> foo + [2] -> bar + +User enters: :: - "show ip bgp" - ^ ^ ^ + command baz + +Array: + +:: + + [0] -> command + [1] -> baz - "command <foo|bar> [example]" - ^ ^ ^ ^ .. _cli-data-structures: Data Structures --------------- +On startup, the CLI parser sequentially parses each command string definition +and constructs a directed graph with each token forming a node. This graph is +the basis of the entire CLI system. It is used to match user input in order to +generate command completions and match commands to functions. -On startup, the CLI parser sequentially parses each command string -definition and constructs a directed graph with each token forming a -node. This graph is the basis of the entire CLI system. It is used to -match user input in order to generate command completions and match -commands to functions. - -There is one graph per CLI node (not the same as a graph node in the CLI -graph). The CLI node struct keeps a reference to its graph (see -lib/command.h). +There is one graph per CLI node (not the same as a graph node in the CLI graph). +The CLI node struct keeps a reference to its graph (see :file:`lib/command.h`). While most of the graph maintains the form of a tree, special constructs -outlined in the Rules section introduce some quirks. <>, [] and {} form -self-contained 'subgraphs'. Each subgraph is a tree except that all of -the 'leaves' actually share a child node. This helps with minimizing -graph size and debugging. +outlined in the Rules section introduce some quirks. ``<>``, ``[]`` and ``{}`` +form self-contained 'subgraphs'. Each subgraph is a tree except that all of the +'leaves' actually share a child node. This helps with minimizing graph size and +debugging. As a working example, here is the graph of the following command: :: @@ -468,8 +547,8 @@ input. They're necessary in order to deduplicate these constructs where applicable. Options follow the same form, except that there is an edge from the ``FORK`` -node to the ``JOIN`` node. Since all of the subgraphs in the example command -are optional, all of them have this edge. +node to the ``JOIN`` node. Since all of the subgraphs in the example command are +optional, all of them have this edge. Keywords follow the same form, except that there is an edge from ``JOIN`` to ``FORK``. Because of this the CLI graph cannot be called acyclic. There is @@ -482,24 +561,23 @@ repeating the same input indefinitely. The leaves of the graph are nodes that have no out edges. These nodes are special; their data section does not contain a token, as most nodes do, or -NULL, as in ``FORK``/``JOIN`` nodes, but instead has a pointer to a -cmd\_element. All paths through the graph that terminate on a leaf are -guaranteed to be defined by that command. When a user enters a complete -command, the command matcher tokenizes the input and executes a DFS on the CLI -graph. If it is simultaneously able to exhaust all input (one input token per -graph node), and then find exactly one leaf connected to the last node it -reaches, then the input has matched the corresponding command and the command -is executed. If it finds more than one node, then the command is ambiguous -(more on this in deduplication). If it cannot exhaust all input, the command is -unknown. If it exhausts all input but does not find an edge node, the command -is incomplete. +``NULL``, as in ``FORK``/``JOIN`` nodes, but instead has a pointer to a +``cmd_element``. All paths through the graph that terminate on a leaf are +guaranteed to be defined by that command. When a user enters a complete command, +the command matcher tokenizes the input and executes a DFS on the CLI graph. If +it is simultaneously able to exhaust all input (one input token per graph node), +and then find exactly one leaf connected to the last node it reaches, then the +input has matched the corresponding command and the command is executed. If it +finds more than one node, then the command is ambiguous (more on this in +deduplication). If it cannot exhaust all input, the command is unknown. If it +exhausts all input but does not find an edge node, the command is incomplete. The parser uses an incremental strategy to build the CLI graph for a node. Each command is parsed into its own graph, and then this graph is merged into the -overall graph. During this merge step, the parser makes a best-effort attempt -to remove duplicate nodes. If it finds a node in the overall graph that is -equal to a node in the corresponding position in the command graph, it will -intelligently merge the properties from the node in the command graph into the +overall graph. During this merge step, the parser makes a best-effort attempt to +remove duplicate nodes. If it finds a node in the overall graph that is equal to +a node in the corresponding position in the command graph, it will intelligently +merge the properties from the node in the command graph into the already-existing node. Subgraphs are also checked for isomorphism and merged where possible. The definition of whether two nodes are 'equal' is based on the equality of some set of token properties; read the parser source for the most @@ -508,123 +586,171 @@ up-to-date definition of equality. When the parser is unable to deduplicate some complicated constructs, this can result in two identical paths through separate parts of the graph. If this occurs and the user enters input that matches these paths, they will receive an -'ambiguous command' error and will be unable to execute the command. Most of -the time the parser can detect and warn about duplicate commands, but it will -not always be able to do this. Hence care should be taken before defining a -new command to ensure it is not defined elsewhere. +'ambiguous command' error and will be unable to execute the command. Most of the +time the parser can detect and warn about duplicate commands, but it will not +always be able to do this. Hence care should be taken before defining a new +command to ensure it is not defined elsewhere. -Command handlers ----------------- +struct cmd\_token +^^^^^^^^^^^^^^^^^ + +.. code-block:: c + + /* Command token struct. */ + struct cmd_token + { + enum cmd_token_type type; // token type + uint8_t attr; // token attributes + bool allowrepeat; // matcher can match token repetitively? + + char *text; // token text + char *desc; // token description + long long min, max; // for ranges + char *arg; // user input that matches this token + char *varname; // variable name + }; + +This struct is used in the CLI graph to match input against. It is also used to +pass user input to command handler functions, as it is frequently useful for +handlers to have access to that information. When a command is matched, the +sequence of ``cmd_tokens`` that form the matching path are duplicated and placed +in order into ``*argv[]``. Before this happens the ``->arg`` field is set to +point at the snippet of user input that matched it. + +For most nontrivial commands the handler function will need to determine which +of the possible matching inputs was entered. Previously this was done by looking +at the first few characters of input. This is now considered an anti-pattern and +should be avoided. Instead, the ``->type`` or ``->text`` fields for this logic. +The ``->type`` field can be used when the possible inputs differ in type. When +the possible types are the same, use the ``->text`` field. This field has the +full text of the corresponding token in the definition string and using it makes +for much more readable code. An example is helpful. -The block that follows a CLI definition is executed when a user enters -input that matches the definition. Its function signature looks like -this: +Command definition: :: - int (*func) (const struct cmd_element *, struct vty *, int, struct cmd_token *[]); - -The first argument is the command definition struct. The last argument -is an ordered array of tokens that correspond to the path taken through -the graph, and the argument just prior to that is the length of the -array. + command <(1-10)|foo|BAR> -The arrangement of the token array has changed from the prior -incarnation of the CLI system. In the old system, missing arguments were -padded with NULLs so that the same parts of a command would show up at -the same indices regardless of what was entered. The new system does not -perform such padding and therefore it is generally *incorrect* to assume -consistent indices in this array. As a simple example: +In this example, the user may enter any one of: +- an integer between 1 and 10 +- "foo" +- anything at all -Command definition: +If the user enters "command f", then: :: - command [foo] <bar|baz> + argv[1]->type == WORD_TKN + argv[1]->arg == "f" + argv[1]->text == "foo" -User enters: +Range tokens have some special treatment; a token with ``->type == RANGE_TKN`` +will have the ``->min`` and ``->max`` fields set to the bounding values of the +range. -:: +struct cmd\_element +^^^^^^^^^^^^^^^^^^^ - command foo bar +.. code-block:: c -Array: + struct cmd_node { + /* Node index. */ + enum node_type node; -:: + /* Prompt character at vty interface. */ + const char *prompt; - [0] -> command - [1] -> foo - [2] -> bar + /* Is this node's configuration goes to vtysh ? */ + int vtysh; -User enters: + /* Node's configuration write function */ + int (*func)(struct vty *); -:: + /* Node's command graph */ + struct graph *cmdgraph; - command baz + /* Vector of this node's command list. */ + vector cmd_vector; -Array: + /* Hashed index of command node list, for de-dupping primarily */ + struct hash *cmd_hash; + }; -:: +This struct corresponds to a CLI mode. The last three fields are most relevant +here. - [0] -> command - [1] -> baz +cmdgraph + This is a pointer to the command graph that was described in the first part + of this section. It is the datastructure used for matching user input to + commands. -Command abbreviation & matching priority ----------------------------------------- +cmd_vector + This is a list of all the ``struct cmd_element`` defined in the mode. -As in the prior implementation, it is possible for users to elide parts -of tokens when the CLI matcher does not need them to make an unambiguous -match. This is best explained by example. +cmd_hash + This is a hash table of all the ``struct cmd_element`` defined in the mode. + When ``install_element`` is called, it checks that the element it is given is + not already present in the hash table as a safeguard against duplicate calls + resulting in a command being defined twice, which renders the command + ambiguous. + +All ``struct cmd_node`` are themselves held in a static vector defined in +:file:`lib/command.c` that defines the global CLI space. + +Command Abbreviation & Matching Priority +---------------------------------------- +It is possible for users to elide parts of tokens when the CLI matcher does not +need them to make an unambiguous match. This is best explained by example. Command definitions: :: - command dog cow - command dog crow + command dog cow + command dog crow User input: :: - c d c -> ambiguous command - c d co -> match "command dog cow" + c d c -> ambiguous command + c d co -> match "command dog cow" + -In the new implementation, this functionality has improved. Where -previously the parser would stop at the first ambiguous token, it will -now look ahead and attempt to disambiguate based on tokens later on in -the input string. +The parser will look ahead and attempt to disambiguate the input based on tokens +later on in the input string. Command definitions: :: - show ip bgp A.B.C.D - show ipv6 bgp X:X::X:X + show ip bgp A.B.C.D + show ipv6 bgp X:X::X:X User enters: :: - s i b 4.3.2.1 -> match "show ip bgp A.B.C.D" - s i b ::e0 -> match "show ipv6 bgp X:X::X:X" + s i b 4.3.2.1 -> match "show ip bgp A.B.C.D" + s i b ::e0 -> match "show ipv6 bgp X:X::X:X" -Previously both of these commands would be ambiguous since 'i' does not -explicitly select either 'ip' or 'ipv6'. However, since the user later -provides a token that matches only one of the commands (an IPv4 or IPv6 -address) the parser is able to look ahead and select the appropriate -command. This has some implications for parsing the argv\*[] that is -passed to the command handler. +Reading left to right, both of these commands would be ambiguous since 'i' does +not explicitly select either 'ip' or 'ipv6'. However, since the user later +provides a token that matches only one of the commands (an IPv4 or IPv6 address) +the parser is able to look ahead and select the appropriate command. This has +some implications for parsing the ``*argv[]`` that is passed to the command +handler. Now consider a command definition such as: :: - command <foo|VAR> + command <foo|VAR> -'foo' only matches the string 'foo', but 'VAR' matches any input, -including 'foo'. Who wins? In situations like this the matcher will -always choose the 'better' match, so 'foo' will win. +'foo' only matches the string 'foo', but 'VAR' matches any input, including +'foo'. Who wins? In situations like this the matcher will always choose the +'better' match, so 'foo' will win. Consider also: @@ -638,88 +764,29 @@ User input: show ip foo -'ip' partially matches 'ipv6' but exactly matches 'ip', so 'ip' will +``ip`` partially matches ``ipv6`` but exactly matches ``ip``, so ``ip`` will win. -struct cmd\_token ------------------ - -:: - - /* Command token struct. */ - struct cmd_token - { - enum cmd_token_type type; // token type - u_char attr; // token attributes - bool allowrepeat; // matcher allowed to match token repetitively? - - char *text; // token text - char *desc; // token description - long long min, max; // for ranges - char *arg; // user input that matches this token - char *varname; // variable name - }; - -This struct is used in the CLI graph to match input against. It is also -used to pass user input to command handler functions, as it is -frequently useful for handlers to have access to that information. When -a command is matched, the sequence of cmd\_tokens that form the matching -path are duplicated and placed in order into argv\*[]. Before this -happens the ->arg field is set to point at the snippet of user input -that matched it. - -For most nontrivial commands the handler function will need to determine -which of the possible matching inputs was entered. Previously this was -done by looking at the first few characters of input. This is now -considered an anti-pattern and should be avoided. Instead, the ->type or -->text fields for this logic. The ->type field can be used when the -possible inputs differ in type. When the possible types are the same, -use the ->text field. This field has the full text of the corresponding -token in the definition string and using it makes for much more readable -code. An example is helpful. - -Command definition: - -:: - - command <(1-10)|foo|BAR> - -In this example, the user may enter any one of: \* an integer between 1 -and 10 \* "foo" \* anything at all - -If the user enters "command f", then: - -:: - - argv[1]->type == WORD_TKN - argv[1]->arg == "f" - argv[1]->text == "foo" - -Range tokens have some special treatment; a token with ->type == -RANGE\_TKN will have the ->min and ->max fields set to the bounding -values of the range. - Permutations ------------ - -Finally, it is sometimes useful to check all the possible combinations -of input that would match an arbitrary definition string. There is a -tool in tools/ called 'permutations' that reads CLI definition strings -on stdin and prints out all matching input permutations. It also dumps a -text representation of the graph, which is more useful for debugging -than anything else. It looks like this: +Finally, it is sometimes useful to check all the possible combinations of input +that would match an arbitrary definition string. There is a tool in +:file:`tools/permutations` that reads CLI definition strings on ``stdin`` and +prints out all matching input permutations. It also dumps a text representation +of the graph, which is more useful for debugging than anything else. It looks +like this: :: - $ ./permutations "show [ip] bgp [<view|vrf> WORD]" + $ ./permutations "show [ip] bgp [<view|vrf> WORD]" - show ip bgp view WORD - show ip bgp vrf WORD - show ip bgp - show bgp view WORD - show bgp vrf WORD - show bgp + show ip bgp view WORD + show ip bgp vrf WORD + show ip bgp + show bgp view WORD + show bgp vrf WORD + show bgp -This functionality is also built into VTY/VTYSH; the 'list permutations' -command will list all possible matching input permutations in the -current CLI node. +This functionality is also built into VTY/VTYSH; the ``list permutations`` +command will list all possible matching input permutations in the current CLI +node. diff --git a/doc/developer/conf.py b/doc/developer/conf.py index e2293b2a6b..9ae1991817 100644 --- a/doc/developer/conf.py +++ b/doc/developer/conf.py @@ -32,7 +32,7 @@ rst_prolog = '' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.todo'] +extensions = ['sphinx.ext.todo', 'sphinx.ext.graphviz'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -188,7 +188,7 @@ html_favicon = '../figures/frr-logo-icon.png' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied @@ -339,3 +339,5 @@ def setup(app): # object type for FRR CLI commands, can be extended to document parent CLI # node later on app.add_object_type('clicmd', 'clicmd') + # css overrides for HTML theme + app.add_stylesheet('overrides.css') diff --git a/doc/developer/next-hop-tracking.rst b/doc/developer/next-hop-tracking.rst index 284db1ef53..25e2d1fe1a 100644 --- a/doc/developer/next-hop-tracking.rst +++ b/doc/developer/next-hop-tracking.rst @@ -264,19 +264,19 @@ Zebra data structure RNH table:: - O - / \ - O O - / \ - O O - - struct rnh - { - u_char flags; - struct route_entry *state; - struct list *client_list; - struct route_node *node; - }; + . O + / \ + O O + / \ + O O + + struct rnh + { + uint8_t flags; + struct route_entry *state; + struct list *client_list; + struct route_node *node; + }; User interface changes ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/developer/workflow.rst b/doc/developer/workflow.rst index ff66007f8d..33dfe12be9 100644 --- a/doc/developer/workflow.rst +++ b/doc/developer/workflow.rst @@ -256,7 +256,15 @@ After submitting your changes - Wait for reviewers. Someone will review your code or be assigned to review your code. - - Respond to any comments or concerns the reviewer has. + - Respond to any comments or concerns the reviewer has. Use e-mail or + add a comment via github to respond or to let the reviewer know how + their comment or concern is addressed. + - An author must never delete or manually dismiss someone else's comments + or review. (A review may be overridden by agreement in the weekly + technical meeting.) + - Automatically generated comments, e.g., those generated by CI systems, + may be deleted by authors and others when such comments are not the most + recent results from that automated comment source. - After all comments and concerns are addressed, expect your patch to be merged. @@ -471,6 +479,14 @@ checkpatch.sh When convenient it is preferred that these be cleaned up inline, but this is not required. + In general, a developer should heed the information reported by checkpatch. + However, some flexibility is needed for cases where human judgement yields + better clarity than the script. Accordingly, it may be appropriate to + ignore some checkpatch.sh warnings per discussion among the submitter(s) + and reviewer(s) of a change. Misreporting of errors by the script is + possible. When this occurs, a patch for checkpatch should be added to + the pull request to correct the false error report. + If the script finds one or more WARNINGs it will exit with 1. If it finds one or more ERRORs it will exit with 2. @@ -480,6 +496,12 @@ responsibility for properly formatting your code ultimately lies on the shoulders of the submitter. As such, it is recommended to double-check the results of these tools to avoid delays in merging your submission. +In some cases, these tools modify or flag the format in ways that go beyond or +even conflict [#tool_style_conflicts]_ with the canonical documented Linux +kernel style. In these cases, the Linux kernel style takes priority; +non-canonical issues flagged by the tools are not compulsory but rather are +opportunities for discussion among the submitter(s) and reviewer(s) of a change. + **Whitespace changes in untouched parts of the code are not acceptable in patches that change actual code.** To change/fix formatting issues, please create a separate patch that only does formatting changes and @@ -496,6 +518,35 @@ For GNU coding style, use ``indent`` with the following invocation: indent -nut -nfc1 file_for_submission.c + +Historically, FRR used fixed-width integral types that do not exist in any +standard but were defined by most platforms at some point. Officially these +types are not guaranteed to exist. Therefore, please use the fixed-width +integral types introduced in the C99 standard when contributing new code to +FRR. If you need to convert a large amount of code to use the correct types, +there is a shell script in :file:`tools/convert-fixedwidth.sh` that will do the +necessary replacements. + ++-----------+--------------------------+ +| Incorrect | Correct | ++===========+==========================+ +| u_int8_t | uint8_t | ++-----------+--------------------------+ +| u_int16_t | uint16_t | ++-----------+--------------------------+ +| u_int32_t | uint32_t | ++-----------+--------------------------+ +| u_int64_t | uint64_t | ++-----------+--------------------------+ +| u_char | uint8_t or unsigned char | ++-----------+--------------------------+ +| u_short | unsigned short | ++-----------+--------------------------+ +| u_int | unsigned int | ++-----------+--------------------------+ +| u_long | unsigned long | ++-----------+--------------------------+ + Exceptions ^^^^^^^^^^ @@ -671,7 +722,21 @@ either: In all cases, compatibility pieces should be marked with compiler/preprocessor annotations to print warnings at compile time, pointing to the appropriate update path. A ``-Werror`` build should fail -if compatibility bits are used. +if compatibility bits are used. To avoid compilation issues in released +code, such compiler/preprocessor annotations must be ignored +non-development branches. For example: + + #if defined(VERSION_TYPE_DEV) && CONFDATE > 20180403 + CPP_NOTICE("Use of <XYZ> is deprecated, please use <ABC>") + #endif + + +Preferably, the shell script :file:`tools/fixup-deprecated.py` will be +updated along with making non-backwards compatible code changes, or an +alternate script should be introduced, to update the code to match the +change. When the script is updated, there is no need to preserve the +deprecated code. Note that this does not apply to user interface +changes, just internal code, macros and libraries. Miscellaneous ------------- @@ -839,3 +904,10 @@ particular command does. .. _GitHub: https://github.com/frrouting/frr .. _GitHub issues: https://github.com/frrouting/frr/issues + +.. rubric:: Footnotes + +.. [#tool_style_conflicts] For example, lines over 80 characters are allowed + for text strings to make it possible to search the code for them: please + see `Linux kernel style (breaking long lines and strings) <https://www.kernel.org/doc/html/v4.10/process/coding-style.html#breaking-long-lines-and-strings>`_ + and `Issue #1794 <https://github.com/FRRouting/frr/issues/1794>`_. diff --git a/doc/figures/nodes.dot b/doc/figures/nodes.dot new file mode 100644 index 0000000000..d0e234958f --- /dev/null +++ b/doc/figures/nodes.dot @@ -0,0 +1,64 @@ +/* + * FRR CLI modes and their relationships. + * + * Each edge is labeled with the command that causes a transition along that + * edge. Exit commands and their back edges are implicit. + */ +digraph climodes { + ratio = "auto" + mincross = 2.0 + graph [fontsize = 9] + rankdir = LR + + AUTH_NODE -> VIEW_NODE -> ENABLE_NODE; + VIEW_NODE -> AUTH_ENABLE_NODE -> ENABLE_NODE; + ENABLE_NODE -> CONFIG_NODE [ label="configure terminal" ]; + CONFIG_NODE -> RIP_NODE [ label="router rip" ]; + CONFIG_NODE -> RIPNG_NODE [ label="router ripng" ]; + CONFIG_NODE -> BABEL_NODE [ label="router babel" ]; + CONFIG_NODE -> EIGRP_NODE [ label="router eigrp (1-65535)" ]; + CONFIG_NODE -> BGP_NODE [ label="router bgp ASN" ]; + subgraph cluster0 { + BGP_NODE -> BGP_VPNV4_NODE [ label="address-family vpnv4 [unicast]" ]; + BGP_NODE -> BGP_VPNV6_NODE [ label="address-family vpnv6 [unicast]" ]; + BGP_NODE -> BGP_IPV4_NODE [ label="address-family ipv4 [unicast]" ]; + BGP_NODE -> BGP_IPV4L_NODE [ label="address-family ipv4 labeled-unicast" ]; + BGP_NODE -> BGP_IPV4M_NODE [ label="address-family ipv4 multicast" ]; + BGP_NODE -> BGP_IPV6_NODE [ label="address-family ipv6 [unicast]" ]; + BGP_NODE -> BGP_IPV6L_NODE [ label="address-family ipv6 labeled-unicast" ]; + BGP_NODE -> BGP_IPV6M_NODE [ label="address-family ipv6 multicast" ]; + BGP_NODE -> BGP_FLOWSPECV4_NODE [ label="address-family ipv4 flowspec" ]; + BGP_NODE -> BGP_FLOWSPECV6_NODE [ label="address-family ipv6 flowspec" ]; + BGP_NODE -> BGP_EVPN_NODE [ label="address-family l2vpn evpn" ]; + BGP_EVPN_NODE -> BGP_EVPN_VNI_NODE [ label="vni (1-16777215)" ]; + BGP_NODE -> BGP_VRF_POLICY_NODE [ label="vrf-policy NAME" ]; + BGP_NODE -> BGP_VNC_DEFAULTS_NODE [ label="vnc defaults" ]; + BGP_NODE -> BGP_VNC_NVE_GROUP_NODE [ label="vnc nve-group NAME" ]; + BGP_NODE -> BGP_VNC_L2_GROUP_NODE [ label="vnc l2-group NAME" ]; + } + subgraph cluster1 { + LDP_NODE -> LDP_IPV4_NODE [ label="address-family ipv4" ]; + LDP_NODE -> LDP_IPV6_NODE [ label="address-family ipv6" ]; + LDP_IPV4_NODE -> LDP_IPV4_IFACE_NODE [ label="interface IFNAME" ]; + LDP_IPV6_NODE -> LDP_IPV6_IFACE_NODE [ label="interface IFNAME" ]; + LDP_NODE -> LDP_L2VPN_NODE [ label="address-family l2vpn WORD type vpls" ]; + LDP_NODE -> LDP_PSEUDOWIRE_NODE [ label="member pseudowire IFNAME" ]; + } + CONFIG_NODE -> OSPF_NODE [ label="router ospf [(1-65535)] [vrf NAME]" ]; + CONFIG_NODE -> OSPF6_NODE [ label="router ospf6" ]; + CONFIG_NODE -> LDP_NODE [ label="mpls ldp" ]; + CONFIG_NODE -> ISIS_NODE [ label="router isis WORD" ]; + CONFIG_NODE -> RMAP_NODE [ label="route-map WORD <deny|permit> (1-65535)" ]; + CONFIG_NODE -> PW_NODE [ label="pseudowire IFNAME" ]; + CONFIG_NODE -> VTY_NODE [ label="line vty" ]; + CONFIG_NODE -> KEYCHAIN_NODE [ label="key chain WORD" ]; + CONFIG_NODE -> KEYCHAIN_KEY_NODE [ label="key (0-2147483647)" ]; + KEYCHAIN_NODE -> KEYCHAIN_KEY_NODE [ label="key (0-2147483647)" ]; + KEYCHAIN_KEY_NODE -> KEYCHAIN_NODE [ label="no key (0-2147483647)" ]; + CONFIG_NODE -> LOGICALROUTER_NODE [ label="logical-router (1-65535) ns NAME" ]; + CONFIG_NODE -> VRF_NODE [ label="vrf NAME" ]; + CONFIG_NODE -> INTERFACE_NODE [ label="interface IFNAME vrf NAME" ]; + INTERFACE_NODE -> LINK_PARAMS_NODE [ label="link-params" ]; + CONFIG_NODE -> NH_GROUP_NODE [ label="nexthop-group NAME" ]; + CONFIG_NODE -> RPKI_NODE [ label="rpki" ]; +} diff --git a/doc/manpages/vtysh.rst b/doc/manpages/vtysh.rst index 2db746020d..3e496956c2 100644 --- a/doc/manpages/vtysh.rst +++ b/doc/manpages/vtysh.rst @@ -53,6 +53,12 @@ OPTIONS available for the vtysh command: When executing cli that does not invoke a vtysh shell, if an error ocurrs ignore it for purposes of return codes from vtysh. +.. option:: -u, --user + + Restrict access to configuration commands by preventing use of the "enable" command. This option provides the same limited "security" as password-protected telnet access. *This security should not be relied on in production environments.* + + Caveat emptor: VTYSH was never designed to be a privilege broker and is not built using secure coding practices. No guarantees of security are provided for this option and under no circumstances should this option be used to provide any semblance of secure read-only access to FRR. + .. option:: -h, --help Display a usage message on standard output and exit. diff --git a/doc/user/_static/overrides.css b/doc/user/_static/overrides.css new file mode 100644 index 0000000000..1e0de66c55 --- /dev/null +++ b/doc/user/_static/overrides.css @@ -0,0 +1,4 @@ +/* remove max-width restriction */ +div.body { + max-width: none; +} diff --git a/doc/user/bgp.rst b/doc/user/bgp.rst index a444822757..7a508b0df6 100644 --- a/doc/user/bgp.rst +++ b/doc/user/bgp.rst @@ -29,7 +29,8 @@ be specified (:ref:`common-invocation-options`). .. option:: -p <port> .. option:: --bgp_port <port> - Set the bgp protocol's port number. + Set the bgp protocol's port number. When port number is 0, that means do not + listen bgp port. .. option:: -r .. option:: --retain @@ -604,9 +605,8 @@ Defining Peer .. index:: neighbor PEER remote-as ASN .. clicmd:: neighbor PEER remote-as ASN - Creates a new neighbor whose remote-as is ASN. PEER can be an IPv4 address - or an IPv6 address.:: + or an IPv6 address or an interface to use for the connection.:: router bgp 1 neighbor 10.0.0.1 remote-as 2 @@ -618,6 +618,19 @@ Defining Peer can't find neighbor 10.0.0.1 +.. index:: neighbor PEER remote-as internal +.. clicmd:: neighbor PEER remote-as internal + + Create a peer as you would when you specify an ASN, except that if the + peers ASN is different than mine as specified under the :clicmd:`router bgp ASN` + command the connection will be denied. + +.. index:: neighbor PEER remote-as external +.. clicmd:: neighbor PEER remote-as external + + Create a peer as you would when you specify an ASN, except that if the + peers ASN is the same as mine as specified under the :clicmd:`router bgp ASN` + command the connection will be denied. .. _bgp-peer-commands: @@ -2076,19 +2089,9 @@ How to set up a 6-Bone connection :: - zebra configuration - =================== - ! - ! Actually there is no need to configure zebra - ! - bgpd configuration ================== ! - ! This means that routes go through zebra and into the kernel. - ! - router zebra - ! ! MP-BGP configuration ! router bgp 7675 @@ -2112,8 +2115,6 @@ How to set up a 6-Bone connection set ipv6 nexthop global 3ffe:1cfa:0:2:2c0:4fff:fe68:a225 set ipv6 nexthop local fe80::2c0:4fff:fe68:a225 ! - ! logfile FILENAME is obsolete. Please use log file FILENAME - log file bgpd.log ! diff --git a/doc/user/conf.py b/doc/user/conf.py index efe1023740..7a77e492ce 100644 --- a/doc/user/conf.py +++ b/doc/user/conf.py @@ -188,7 +188,7 @@ html_favicon = '../figures/frr-logo-icon.png' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -# html_static_path = ['_static'] +html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied @@ -339,3 +339,5 @@ def setup(app): # object type for FRR CLI commands, can be extended to document parent CLI # node later on app.add_object_type('clicmd', 'clicmd') + # css overrides for HTML theme + app.add_stylesheet('overrides.css') diff --git a/doc/user/routemap.rst b/doc/user/routemap.rst index acf63a6122..97094c2d6b 100644 --- a/doc/user/routemap.rst +++ b/doc/user/routemap.rst @@ -198,7 +198,42 @@ Route Map Set Command .. index:: set ip next-hop IPV4_ADDRESS .. clicmd:: set ip next-hop IPV4_ADDRESS - Set the BGP nexthop address. + Set the BGP nexthop address to the specified IPV4_ADDRESS. For both + incoming and outgoing route-maps. + +.. index:: set ip next-hop peer-address +.. clicmd:: set ip next-hop peer-address + + Set the BGP nexthop address to the address of the peer. For an incoming + route-map this means the ip address of our peer is used. For an outgoing + route-map this means the ip address of our self is used to establish the + peering with our neighbor. + +.. index:: set ip next-hop unchanged +.. clicmd:: set ip next-hop unchanged + + Set the route-map as unchanged. Pass the route-map through without + changing it's value. + +.. index:: set ipv6 next-hop peer-address +.. clicmd:: set ipv6 next-hop peer-address + + Set the BGP nexthop address to the address of the peer. For an incoming + route-map this means the ipv6 address of our peer is used. For an outgoing + route-map this means the ip address of our self is used to establish the + peering with our neighbor. + +.. index:: set ipv6 next-hop prefer-global +.. clicmd:: set ipv6 next-hop prefer-global + + For Incoming and Import Route-maps if we receive a v6 global and v6 LL + address for the route, then prefer to use the global address as the nexthop. + +.. index:: set ipv6 next-hop global IPV6_ADDRESS +.. clicmd:: set ipv6 next-hop global IPV6_ADDRESS + + Set the next-hop to the specified IPV6_ADDRESS for both incoming and + outgoing route-maps. .. index:: set local-preference LOCAL_PREF .. clicmd:: set local-preference LOCAL_PREF @@ -225,11 +260,6 @@ Route Map Set Command Set the BGP community attribute. -.. index:: set ipv6 next-hop global IPV6_ADDRESS -.. clicmd:: set ipv6 next-hop global IPV6_ADDRESS - - Set the BGP-4+ global IPv6 nexthop address. - .. index:: set ipv6 next-hop local IPV6_ADDRESS .. clicmd:: set ipv6 next-hop local IPV6_ADDRESS diff --git a/doc/user/vtysh.rst b/doc/user/vtysh.rst index 52d54f4123..71aab3975e 100644 --- a/doc/user/vtysh.rst +++ b/doc/user/vtysh.rst @@ -33,6 +33,16 @@ daemons will change ownership of their sockets to). To restrict access to FRR configuration, make sure no unauthorized users are members of the |INSTALL_VTY_GROUP| group. +.. warning:: + + VTYSH implements a CLI option ``-u, --user`` that disallows entering the + characters "en" on the command line, which ideally restricts access to + configuration commands. However, VTYSH was never designed to be a privilege + broker and is not built using secure coding practices. No guarantees of + security are provided for this option and under no circumstances should this + option be used to provide any semblance of security or read-only access to + FRR. + PAM support (experimental) -------------------------- diff --git a/docker/.gitignore b/docker/.gitignore index e9beab556e..6f91eb5ec3 100644 --- a/docker/.gitignore +++ b/docker/.gitignore @@ -1,2 +1 @@ -src.tar pkgs/ diff --git a/docker/alpine/Dockerfile b/docker/alpine/Dockerfile index e186fdccdf..6bd7d90aef 100644 --- a/docker/alpine/Dockerfile +++ b/docker/alpine/Dockerfile @@ -12,8 +12,7 @@ RUN apk add --no-cache abuild acct alpine-sdk attr autoconf automake bash \ patch pax-utils pcre perl pkgconf python2 python2-dev readline \ readline-dev sqlite-libs squashfs-tools sudo tar texinfo xorriso xz-libs \ groff gzip bc py-sphinx -RUN mkdir -p /src -ADD src.tar /src +ADD . /src RUN (cd /src && \ ./bootstrap.sh && \ ./configure \ @@ -22,9 +21,13 @@ RUN (cd /src && \ make dist) FROM alpine:3.7 as alpine-builder RUN apk add --no-cache abuild alpine-sdk && mkdir -p /pkgs/apk -ADD alpine-build.sh /usr/bin/ -ADD builder /etc/sudoers.d +ADD docker/alpine/alpine-build.sh /usr/bin/ +ADD docker/alpine/builder /etc/sudoers.d COPY --from=source-builder /src/*.tar.gz /src/alpine/APKBUILD /dist/ RUN adduser -D -G abuild builder && chown -R builder /dist /pkgs USER builder RUN /usr/bin/alpine-build.sh +FROM alpine:3.7 +RUN mkdir -p /pkgs/apk +COPY --from=alpine-builder /pkgs/apk/ /pkgs/apk/ +RUN apk add --no-cache --allow-untrusted /pkgs/apk/x86_64/*.apk diff --git a/docker/alpine/build.sh b/docker/alpine/build.sh index 357ea12dee..40ed1194fe 100755 --- a/docker/alpine/build.sh +++ b/docker/alpine/build.sh @@ -9,12 +9,8 @@ set -x ## c=`git rev-parse --short=10 HEAD` commit=`printf '%u\n' 0x$c` -git archive --format=tar $c > docker/alpine/src.tar -(cd docker/alpine && \ - docker build --build-arg commit=$commit --rm --force-rm -t \ - frr:alpine-$c . && \ - rm -f src.tar) - +docker build -f docker/alpine/Dockerfile \ + --build-arg commit=$commit -t frr:alpine-$c . id=`docker create frr:alpine-$c` docker cp ${id}:/pkgs/ docker docker rm $id diff --git a/eigrpd/eigrp_dump.c b/eigrpd/eigrp_dump.c index 8857be78e8..651a9339d7 100644 --- a/eigrpd/eigrp_dump.c +++ b/eigrpd/eigrp_dump.c @@ -117,11 +117,11 @@ void eigrp_ip_header_dump(struct ip *iph) zlog_debug("ip_hl %u", iph->ip_hl); zlog_debug("ip_tos %u", iph->ip_tos); zlog_debug("ip_len %u", iph->ip_len); - zlog_debug("ip_id %u", (u_int32_t)iph->ip_id); - zlog_debug("ip_off %u", (u_int32_t)iph->ip_off); + zlog_debug("ip_id %u", (uint32_t)iph->ip_id); + zlog_debug("ip_off %u", (uint32_t)iph->ip_off); zlog_debug("ip_ttl %u", iph->ip_ttl); zlog_debug("ip_p %u", iph->ip_p); - zlog_debug("ip_sum 0x%x", (u_int32_t)iph->ip_sum); + zlog_debug("ip_sum 0x%x", (uint32_t)iph->ip_sum); zlog_debug("ip_src %s", inet_ntoa(iph->ip_src)); zlog_debug("ip_dst %s", inet_ntoa(iph->ip_dst)); } @@ -156,7 +156,7 @@ const char *eigrp_if_name_string(struct eigrp_interface *ei) const char *eigrp_topology_ip_string(struct eigrp_prefix_entry *tn) { static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - u_int32_t ifaddr; + uint32_t ifaddr; ifaddr = ntohl(tn->destination->u.prefix4.s_addr); snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%u.%u.%u.%u", @@ -169,7 +169,7 @@ const char *eigrp_topology_ip_string(struct eigrp_prefix_entry *tn) const char *eigrp_if_ip_string(struct eigrp_interface *ei) { static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - u_int32_t ifaddr; + uint32_t ifaddr; if (!ei) return "inactive"; @@ -185,7 +185,7 @@ const char *eigrp_if_ip_string(struct eigrp_interface *ei) const char *eigrp_neigh_ip_string(struct eigrp_neighbor *nbr) { static char buf[EIGRP_IF_STRING_MAXLEN] = ""; - u_int32_t ifaddr; + uint32_t ifaddr; ifaddr = ntohl(nbr->src.s_addr); snprintf(buf, EIGRP_IF_STRING_MAXLEN, "%u.%u.%u.%u", diff --git a/eigrpd/eigrp_fsm.c b/eigrpd/eigrp_fsm.c index a4ee5b11dc..4107d44090 100644 --- a/eigrpd/eigrp_fsm.c +++ b/eigrpd/eigrp_fsm.c @@ -170,7 +170,7 @@ struct { }, }; -static const char *packet_type2str(u_char packet_type) +static const char *packet_type2str(uint8_t packet_type) { if (packet_type == EIGRP_OPC_UPDATE) return "Update"; @@ -264,7 +264,7 @@ eigrp_get_fsm_event(struct eigrp_fsm_action_message *msg) // struct eigrp *eigrp = msg->eigrp; struct eigrp_prefix_entry *prefix = msg->prefix; struct eigrp_nexthop_entry *entry = msg->entry; - u_char actual_state = prefix->state; + uint8_t actual_state = prefix->state; enum metric_change change; if (entry == NULL) { diff --git a/eigrpd/eigrp_hello.c b/eigrpd/eigrp_hello.c index bba028f1e8..6d74670514 100644 --- a/eigrpd/eigrp_hello.c +++ b/eigrpd/eigrp_hello.c @@ -108,7 +108,7 @@ int eigrp_hello_timer(struct thread *thread) * @param[in] nbr neighbor the ACK should be sent to * @param[in] param pointer packet TLV is stored to * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Encode Parameter TLV, used to convey metric weights and the hold time. @@ -183,7 +183,7 @@ eigrp_hello_parameter_decode(struct eigrp_neighbor *nbr, return nbr; } -static u_char +static uint8_t eigrp_hello_authentication_decode(struct stream *s, struct eigrp_tlv_hdr_type *tlv_header, struct eigrp_neighbor *nbr) @@ -268,15 +268,15 @@ static void eigrp_peer_termination_decode(struct eigrp_neighbor *nbr, * @param[in] nbr_addr pointer to neighbor address for Peer * Termination TLV * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Function used to encode Peer Termination TLV to Hello packet. */ -static u_int16_t eigrp_peer_termination_encode(struct stream *s, - struct in_addr *nbr_addr) +static uint16_t eigrp_peer_termination_encode(struct stream *s, + struct in_addr *nbr_addr) { - u_int16_t length = EIGRP_TLV_PEER_TERMINATION_LEN; + uint16_t length = EIGRP_TLV_PEER_TERMINATION_LEN; /* fill in type and length */ stream_putw(s, EIGRP_TLV_PEER_TERMINATION); @@ -405,8 +405,8 @@ void eigrp_hello_receive(struct eigrp *eigrp, struct ip *iph, inet_ntoa(nbr->src)); } -u_int32_t FRR_MAJOR; -u_int32_t FRR_MINOR; +uint32_t FRR_MAJOR; +uint32_t FRR_MINOR; void eigrp_sw_version_initialize(void) { @@ -428,16 +428,16 @@ void eigrp_sw_version_initialize(void) * * @param[in,out] s packet stream TLV is stored to * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Store the software version in the specified location. * This consists of two bytes of OS version, and two bytes of EIGRP * revision number. */ -static u_int16_t eigrp_sw_version_encode(struct stream *s) +static uint16_t eigrp_sw_version_encode(struct stream *s) { - u_int16_t length = EIGRP_TLV_SW_VERSION_LEN; + uint16_t length = EIGRP_TLV_SW_VERSION_LEN; // setup the tlv fields stream_putw(s, EIGRP_TLV_SW_VERSION); @@ -464,9 +464,9 @@ static u_int16_t eigrp_sw_version_encode(struct stream *s) * If doing mutli-topology, then store the supported TID list. * This is currently a place holder function */ -static u_int16_t eigrp_tidlist_encode(struct stream *s) +static uint16_t eigrp_tidlist_encode(struct stream *s) { - // u_int16_t length = EIGRP_TLV_SW_VERSION_LEN; + // uint16_t length = EIGRP_TLV_SW_VERSION_LEN; return 0; } @@ -475,15 +475,15 @@ static u_int16_t eigrp_tidlist_encode(struct stream *s) * * @param[in,out] s packet stream TLV is stored to * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Part of conditional receive process * */ -static u_int16_t eigrp_sequence_encode(struct stream *s) +static uint16_t eigrp_sequence_encode(struct stream *s) { - u_int16_t length = EIGRP_TLV_SEQ_BASE_LEN; + uint16_t length = EIGRP_TLV_SEQ_BASE_LEN; struct eigrp *eigrp; struct eigrp_interface *ei; struct listnode *node, *node2, *nnode2; @@ -507,7 +507,7 @@ static u_int16_t eigrp_sequence_encode(struct stream *s) for (ALL_LIST_ELEMENTS_RO(eigrp->eiflist, node, ei)) { for (ALL_LIST_ELEMENTS(ei->nbrs, node2, nnode2, nbr)) { if (nbr->multicast_queue->count > 0) { - length += (u_int16_t)stream_put_ipv4( + length += (uint16_t)stream_put_ipv4( s, nbr->src.s_addr); found = 1; } @@ -532,15 +532,15 @@ static u_int16_t eigrp_sequence_encode(struct stream *s) * * @param[in,out] s packet stream TLV is stored to * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Part of conditional receive process * */ -static u_int16_t eigrp_next_sequence_encode(struct stream *s) +static uint16_t eigrp_next_sequence_encode(struct stream *s) { - u_int16_t length = EIGRP_NEXT_SEQUENCE_TLV_SIZE; + uint16_t length = EIGRP_NEXT_SEQUENCE_TLV_SIZE; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -562,7 +562,7 @@ static u_int16_t eigrp_next_sequence_encode(struct stream *s) * @param[in] ei pointer to interface hello packet came in on * @param[in,out] s packet stream TLV is stored to * - * @return u_int16_t number of bytes added to packet stream + * @return uint16_t number of bytes added to packet stream * * @par * Encode Parameter TLV, used to convey metric weights and the hold time. @@ -571,10 +571,10 @@ static u_int16_t eigrp_next_sequence_encode(struct stream *s) * Note the addition of K6 for the new extended metrics, and does not apply to * older TLV packet formats. */ -static u_int16_t eigrp_hello_parameter_encode(struct eigrp_interface *ei, - struct stream *s, u_char flags) +static uint16_t eigrp_hello_parameter_encode(struct eigrp_interface *ei, + struct stream *s, uint8_t flags) { - u_int16_t length = EIGRP_TLV_PARAMETER_LEN; + uint16_t length = EIGRP_TLV_PARAMETER_LEN; // add in the parameters TLV stream_putw(s, EIGRP_TLV_PARAMETER); @@ -622,12 +622,12 @@ static u_int16_t eigrp_hello_parameter_encode(struct eigrp_interface *ei, * */ static struct eigrp_packet *eigrp_hello_encode(struct eigrp_interface *ei, - in_addr_t addr, u_int32_t ack, - u_char flags, + in_addr_t addr, uint32_t ack, + uint8_t flags, struct in_addr *nbr_addr) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; // allocate a new packet to be sent ep = eigrp_packet_new(ei->ifp->mtu, NULL); @@ -749,7 +749,7 @@ void eigrp_hello_send_ack(struct eigrp_neighbor *nbr) * sending. If no packets are currently queues, the packet will be * sent immadiatly */ -void eigrp_hello_send(struct eigrp_interface *ei, u_char flags, +void eigrp_hello_send(struct eigrp_interface *ei, uint8_t flags, struct in_addr *nbr_addr) { struct eigrp_packet *ep = NULL; diff --git a/eigrpd/eigrp_interface.c b/eigrpd/eigrp_interface.c index 2897e262c9..cd459fdc42 100644 --- a/eigrpd/eigrp_interface.c +++ b/eigrpd/eigrp_interface.c @@ -320,7 +320,7 @@ void eigrp_if_set_multicast(struct eigrp_interface *ei) } } -u_char eigrp_default_iftype(struct interface *ifp) +uint8_t eigrp_default_iftype(struct interface *ifp) { if (if_is_pointopoint(ifp)) return EIGRP_IFTYPE_POINTOPOINT; @@ -413,32 +413,32 @@ struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *eigrp, return NULL; } -u_int32_t eigrp_bandwidth_to_scaled(u_int32_t bandwidth) +uint32_t eigrp_bandwidth_to_scaled(uint32_t bandwidth) { uint64_t temp_bandwidth = (256ull * 10000000) / bandwidth; temp_bandwidth = temp_bandwidth < EIGRP_MAX_METRIC ? temp_bandwidth : EIGRP_MAX_METRIC; - return (u_int32_t)temp_bandwidth; + return (uint32_t)temp_bandwidth; } -u_int32_t eigrp_scaled_to_bandwidth(u_int32_t scaled) +uint32_t eigrp_scaled_to_bandwidth(uint32_t scaled) { uint64_t temp_scaled = scaled * (256ull * 10000000); temp_scaled = temp_scaled < EIGRP_MAX_METRIC ? temp_scaled : EIGRP_MAX_METRIC; - return (u_int32_t)temp_scaled; + return (uint32_t)temp_scaled; } -u_int32_t eigrp_delay_to_scaled(u_int32_t delay) +uint32_t eigrp_delay_to_scaled(uint32_t delay) { return delay * 256; } -u_int32_t eigrp_scaled_to_delay(u_int32_t scaled) +uint32_t eigrp_scaled_to_delay(uint32_t scaled) { return scaled / 256; } diff --git a/eigrpd/eigrp_interface.h b/eigrpd/eigrp_interface.h index 0999c938f6..a18b0b7015 100644 --- a/eigrpd/eigrp_interface.h +++ b/eigrpd/eigrp_interface.h @@ -44,7 +44,7 @@ extern struct eigrp_interface *eigrp_if_new(struct eigrp *, struct interface *, extern int eigrp_if_up(struct eigrp_interface *); extern void eigrp_if_stream_set(struct eigrp_interface *); extern void eigrp_if_set_multicast(struct eigrp_interface *); -extern u_char eigrp_default_iftype(struct interface *); +extern uint8_t eigrp_default_iftype(struct interface *); extern void eigrp_if_free(struct eigrp_interface *, int); extern int eigrp_if_down(struct eigrp_interface *); extern void eigrp_if_stream_unset(struct eigrp_interface *); @@ -58,10 +58,10 @@ extern struct eigrp_interface *eigrp_if_lookup_by_name(struct eigrp *, /* Simulate down/up on the interface. */ extern void eigrp_if_reset(struct interface *); -extern u_int32_t eigrp_bandwidth_to_scaled(u_int32_t); -extern u_int32_t eigrp_scaled_to_bandwidth(u_int32_t); -extern u_int32_t eigrp_delay_to_scaled(u_int32_t); -extern u_int32_t eigrp_scaled_to_delay(u_int32_t); +extern uint32_t eigrp_bandwidth_to_scaled(uint32_t); +extern uint32_t eigrp_scaled_to_bandwidth(uint32_t); +extern uint32_t eigrp_delay_to_scaled(uint32_t); +extern uint32_t eigrp_scaled_to_delay(uint32_t); #endif /* ZEBRA_EIGRP_INTERFACE_H_ */ diff --git a/eigrpd/eigrp_neighbor.c b/eigrpd/eigrp_neighbor.c index 77bd93f6be..3bf75072a3 100644 --- a/eigrpd/eigrp_neighbor.c +++ b/eigrpd/eigrp_neighbor.c @@ -206,12 +206,12 @@ int holddown_timer_expired(struct thread *thread) return 0; } -u_char eigrp_nbr_state_get(struct eigrp_neighbor *nbr) +uint8_t eigrp_nbr_state_get(struct eigrp_neighbor *nbr) { return (nbr->state); } -void eigrp_nbr_state_set(struct eigrp_neighbor *nbr, u_char state) +void eigrp_nbr_state_set(struct eigrp_neighbor *nbr, uint8_t state) { nbr->state = state; @@ -302,7 +302,7 @@ int eigrp_nbr_count_get(void) struct listnode *node, *node2, *nnode2; struct eigrp_neighbor *nbr; struct eigrp *eigrp = eigrp_lookup(); - u_int32_t counter; + uint32_t counter; if (eigrp == NULL) { zlog_debug("EIGRP Routing Process not enabled"); diff --git a/eigrpd/eigrp_neighbor.h b/eigrpd/eigrp_neighbor.h index b939e25e5e..21a8c6a004 100644 --- a/eigrpd/eigrp_neighbor.h +++ b/eigrpd/eigrp_neighbor.h @@ -43,8 +43,8 @@ extern int holddown_timer_expired(struct thread *); extern int eigrp_neighborship_check(struct eigrp_neighbor *, struct TLV_Parameter_Type *); extern void eigrp_nbr_state_update(struct eigrp_neighbor *); -extern void eigrp_nbr_state_set(struct eigrp_neighbor *, u_char state); -extern u_char eigrp_nbr_state_get(struct eigrp_neighbor *); +extern void eigrp_nbr_state_set(struct eigrp_neighbor *, uint8_t state); +extern uint8_t eigrp_nbr_state_get(struct eigrp_neighbor *); extern int eigrp_nbr_count_get(void); extern const char *eigrp_nbr_state_str(struct eigrp_neighbor *); extern struct eigrp_neighbor *eigrp_nbr_lookup_by_addr(struct eigrp_interface *, diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c index a70a7fc765..2578fecb35 100644 --- a/eigrpd/eigrp_network.c +++ b/eigrpd/eigrp_network.c @@ -150,7 +150,7 @@ void eigrp_adjust_sndbuflen(struct eigrp *eigrp, unsigned int buflen) int eigrp_if_ipmulticast(struct eigrp *top, struct prefix *p, unsigned int ifindex) { - u_char val; + uint8_t val; int ret, len; val = 0; @@ -368,8 +368,8 @@ int eigrp_network_unset(struct eigrp *eigrp, struct prefix *p) return 1; } -u_int32_t eigrp_calculate_metrics(struct eigrp *eigrp, - struct eigrp_metrics metric) +uint32_t eigrp_calculate_metrics(struct eigrp *eigrp, + struct eigrp_metrics metric) { uint64_t temp_metric; temp_metric = 0; @@ -396,13 +396,13 @@ u_int32_t eigrp_calculate_metrics(struct eigrp *eigrp, + eigrp->k_values[3]); if (temp_metric <= EIGRP_MAX_METRIC) - return (u_int32_t)temp_metric; + return (uint32_t)temp_metric; else return EIGRP_MAX_METRIC; } -u_int32_t eigrp_calculate_total_metrics(struct eigrp *eigrp, - struct eigrp_nexthop_entry *entry) +uint32_t eigrp_calculate_total_metrics(struct eigrp *eigrp, + struct eigrp_nexthop_entry *entry) { struct eigrp_interface *ei = entry->ei; @@ -412,9 +412,9 @@ u_int32_t eigrp_calculate_total_metrics(struct eigrp *eigrp, + (uint64_t)eigrp_delay_to_scaled(ei->params.delay); entry->total_metric.delay = temp_delay > EIGRP_MAX_METRIC ? EIGRP_MAX_METRIC - : (u_int32_t)temp_delay; + : (uint32_t)temp_delay; - u_int32_t bw = eigrp_bandwidth_to_scaled(ei->params.bandwidth); + uint32_t bw = eigrp_bandwidth_to_scaled(ei->params.bandwidth); entry->total_metric.bandwidth = entry->total_metric.bandwidth > bw ? bw : entry->total_metric.bandwidth; @@ -422,8 +422,8 @@ u_int32_t eigrp_calculate_total_metrics(struct eigrp *eigrp, return eigrp_calculate_metrics(eigrp, entry->total_metric); } -u_char eigrp_metrics_is_same(struct eigrp_metrics metric1, - struct eigrp_metrics metric2) +uint8_t eigrp_metrics_is_same(struct eigrp_metrics metric1, + struct eigrp_metrics metric2) { if ((metric1.bandwidth == metric2.bandwidth) && (metric1.delay == metric2.delay) diff --git a/eigrpd/eigrp_network.h b/eigrpd/eigrp_network.h index 77bd1416fc..b3c76bbecc 100644 --- a/eigrpd/eigrp_network.h +++ b/eigrpd/eigrp_network.h @@ -43,10 +43,11 @@ extern int eigrp_if_drop_allspfrouters(struct eigrp *top, struct prefix *p, unsigned int ifindex); extern void eigrp_adjust_sndbuflen(struct eigrp *, unsigned int); -extern u_int32_t eigrp_calculate_metrics(struct eigrp *, struct eigrp_metrics); -extern u_int32_t eigrp_calculate_total_metrics(struct eigrp *, - struct eigrp_nexthop_entry *); -extern u_char eigrp_metrics_is_same(struct eigrp_metrics, struct eigrp_metrics); +extern uint32_t eigrp_calculate_metrics(struct eigrp *, struct eigrp_metrics); +extern uint32_t eigrp_calculate_total_metrics(struct eigrp *, + struct eigrp_nexthop_entry *); +extern uint8_t eigrp_metrics_is_same(struct eigrp_metrics, + struct eigrp_metrics); extern void eigrp_external_routes_refresh(struct eigrp *, int); #endif /* EIGRP_NETWORK_H_ */ diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c index e2cd44429e..990d1dc08e 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -87,14 +87,14 @@ static int eigrp_retrans_count_exceeded(struct eigrp_packet *ep, } int eigrp_make_md5_digest(struct eigrp_interface *ei, struct stream *s, - u_char flags) + uint8_t flags) { struct key *key = NULL; struct keychain *keychain; unsigned char digest[EIGRP_AUTH_TYPE_MD5_LEN]; MD5_CTX ctx; - u_char *ibuf; + uint8_t *ibuf; size_t backup_get, backup_end; struct TLV_MD5_Authentication_Type *auth_TLV; @@ -157,14 +157,14 @@ int eigrp_make_md5_digest(struct eigrp_interface *ei, struct stream *s, int eigrp_check_md5_digest(struct stream *s, struct TLV_MD5_Authentication_Type *authTLV, - struct eigrp_neighbor *nbr, u_char flags) + struct eigrp_neighbor *nbr, uint8_t flags) { MD5_CTX ctx; unsigned char digest[EIGRP_AUTH_TYPE_MD5_LEN]; unsigned char orig[EIGRP_AUTH_TYPE_MD5_LEN]; struct key *key = NULL; struct keychain *keychain; - u_char *ibuf; + uint8_t *ibuf; size_t backup_end; struct TLV_MD5_Authentication_Type *auth_TLV; struct eigrp_header *eigrph; @@ -242,7 +242,7 @@ int eigrp_check_md5_digest(struct stream *s, } int eigrp_make_sha256_digest(struct eigrp_interface *ei, struct stream *s, - u_char flags) + uint8_t flags) { struct key *key = NULL; struct keychain *keychain; @@ -304,7 +304,7 @@ int eigrp_make_sha256_digest(struct eigrp_interface *ei, struct stream *s, int eigrp_check_sha256_digest(struct stream *s, struct TLV_SHA256_Authentication_Type *authTLV, - struct eigrp_neighbor *nbr, u_char flags) + struct eigrp_neighbor *nbr, uint8_t flags) { return 1; } @@ -319,13 +319,13 @@ int eigrp_write(struct thread *thread) struct ip iph; struct msghdr msg; struct iovec iov[2]; - u_int32_t seqno, ack; + uint32_t seqno, ack; int ret; int flags = 0; struct listnode *node; #ifdef WANT_EIGRP_WRITE_FRAGMENT - static u_int16_t ipid = 0; + static uint16_t ipid = 0; #endif /* WANT_EIGRP_WRITE_FRAGMENT */ #define EIGRP_WRITE_IPHL_SHIFT 2 @@ -479,8 +479,8 @@ int eigrp_read(struct thread *thread) struct interface *ifp; struct eigrp_neighbor *nbr; - u_int16_t opcode = 0; - u_int16_t length = 0; + uint16_t opcode = 0; + uint16_t length = 0; /* first of all get interface pointer. */ eigrp = THREAD_ARG(thread); @@ -706,7 +706,7 @@ static struct stream *eigrp_recv_packet(int fd, struct interface **ifp, { int ret; struct ip *iph; - u_int16_t ip_len; + uint16_t ip_len; unsigned int ifindex = 0; struct iovec iov; /* Header and data both require alignment. */ @@ -729,7 +729,7 @@ static struct stream *eigrp_recv_packet(int fd, struct interface **ifp, zlog_warn( "eigrp_recv_packet: discarding runt packet of length %d " "(ip header size is %u)", - ret, (u_int)sizeof(iph)); + ret, (unsigned int)sizeof(iph)); return NULL; } @@ -864,7 +864,7 @@ void eigrp_send_packet_reliably(struct eigrp_neighbor *nbr) /* Calculate EIGRP checksum */ void eigrp_packet_checksum(struct eigrp_interface *ei, struct stream *s, - u_int16_t length) + uint16_t length) { struct eigrp_header *eigrph; @@ -876,16 +876,15 @@ void eigrp_packet_checksum(struct eigrp_interface *ei, struct stream *s, /* Make EIGRP header. */ void eigrp_packet_header_init(int type, struct eigrp *eigrp, struct stream *s, - u_int32_t flags, u_int32_t sequence, - u_int32_t ack) + uint32_t flags, uint32_t sequence, uint32_t ack) { struct eigrp_header *eigrph; stream_reset(s); eigrph = (struct eigrp_header *)STREAM_DATA(s); - eigrph->version = (u_char)EIGRP_HEADER_VERSION; - eigrph->opcode = (u_char)type; + eigrph->version = (uint8_t)EIGRP_HEADER_VERSION; + eigrph->opcode = (uint8_t)type; eigrph->checksum = 0; eigrph->vrid = htons(eigrp->vrid); @@ -1159,10 +1158,10 @@ struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *s) return tlv; } -u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s, - struct eigrp_prefix_entry *pe) +uint16_t eigrp_add_internalTLV_to_stream(struct stream *s, + struct eigrp_prefix_entry *pe) { - u_int16_t length; + uint16_t length; stream_putw(s, EIGRP_TLV_IPv4_INT); switch (pe->destination->prefixlen) { @@ -1245,8 +1244,8 @@ u_int16_t eigrp_add_internalTLV_to_stream(struct stream *s, return length; } -u_int16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s, - struct eigrp_interface *ei) +uint16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s, + struct eigrp_interface *ei) { struct key *key; struct keychain *keychain; @@ -1285,8 +1284,8 @@ u_int16_t eigrp_add_authTLV_MD5_to_stream(struct stream *s, return 0; } -u_int16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s, - struct eigrp_interface *ei) +uint16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *s, + struct eigrp_interface *ei) { struct key *key; struct keychain *keychain; diff --git a/eigrpd/eigrp_packet.h b/eigrpd/eigrp_packet.h index 00e1c7eac7..f354615fdb 100644 --- a/eigrpd/eigrp_packet.h +++ b/eigrpd/eigrp_packet.h @@ -42,9 +42,9 @@ extern struct eigrp_packet *eigrp_packet_duplicate(struct eigrp_packet *, extern void eigrp_packet_free(struct eigrp_packet *); extern void eigrp_packet_delete(struct eigrp_interface *); extern void eigrp_packet_header_init(int, struct eigrp *, struct stream *, - u_int32_t, u_int32_t, u_int32_t); + uint32_t, uint32_t, uint32_t); extern void eigrp_packet_checksum(struct eigrp_interface *, struct stream *, - u_int16_t); + uint16_t); extern struct eigrp_fifo *eigrp_fifo_new(void); extern struct eigrp_packet *eigrp_fifo_next(struct eigrp_fifo *); @@ -56,12 +56,12 @@ extern void eigrp_fifo_reset(struct eigrp_fifo *); extern void eigrp_send_packet_reliably(struct eigrp_neighbor *); extern struct TLV_IPv4_Internal_type *eigrp_read_ipv4_tlv(struct stream *); -extern u_int16_t eigrp_add_internalTLV_to_stream(struct stream *, - struct eigrp_prefix_entry *); -extern u_int16_t eigrp_add_authTLV_MD5_to_stream(struct stream *, - struct eigrp_interface *); -extern u_int16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *, - struct eigrp_interface *); +extern uint16_t eigrp_add_internalTLV_to_stream(struct stream *, + struct eigrp_prefix_entry *); +extern uint16_t eigrp_add_authTLV_MD5_to_stream(struct stream *, + struct eigrp_interface *); +extern uint16_t eigrp_add_authTLV_SHA256_to_stream(struct stream *, + struct eigrp_interface *); extern int eigrp_unack_packet_retrans(struct thread *); extern int eigrp_unack_multicast_packet_retrans(struct thread *); @@ -71,7 +71,7 @@ extern int eigrp_unack_multicast_packet_retrans(struct thread *); * eigrp_hello.c */ extern void eigrp_sw_version_initialize(void); -extern void eigrp_hello_send(struct eigrp_interface *, u_char, +extern void eigrp_hello_send(struct eigrp_interface *, uint8_t, struct in_addr *); extern void eigrp_hello_send_ack(struct eigrp_neighbor *); extern void eigrp_hello_receive(struct eigrp *, struct ip *, @@ -108,7 +108,7 @@ extern void eigrp_send_query(struct eigrp_interface *); extern void eigrp_query_receive(struct eigrp *, struct ip *, struct eigrp_header *, struct stream *, struct eigrp_interface *, int); -extern u_int32_t eigrp_query_send_all(struct eigrp *); +extern uint32_t eigrp_query_send_all(struct eigrp *); /* * These externs are found in eigrp_reply.c @@ -143,15 +143,15 @@ extern struct TLV_SHA256_Authentication_Type *eigrp_authTLV_SHA256_new(void); extern void eigrp_authTLV_SHA256_free(struct TLV_SHA256_Authentication_Type *); extern int eigrp_make_md5_digest(struct eigrp_interface *, struct stream *, - u_char); + uint8_t); extern int eigrp_check_md5_digest(struct stream *, struct TLV_MD5_Authentication_Type *, - struct eigrp_neighbor *, u_char); + struct eigrp_neighbor *, uint8_t); extern int eigrp_make_sha256_digest(struct eigrp_interface *, struct stream *, - u_char); + uint8_t); extern int eigrp_check_sha256_digest(struct stream *, struct TLV_SHA256_Authentication_Type *, - struct eigrp_neighbor *, u_char); + struct eigrp_neighbor *, uint8_t); extern void eigrp_IPv4_InternalTLV_free(struct TLV_IPv4_Internal_type *); diff --git a/eigrpd/eigrp_query.c b/eigrpd/eigrp_query.c index 72780f7a03..00234bb35c 100644 --- a/eigrpd/eigrp_query.c +++ b/eigrpd/eigrp_query.c @@ -54,12 +54,12 @@ #include "eigrpd/eigrp_fsm.h" #include "eigrpd/eigrp_memory.h" -u_int32_t eigrp_query_send_all(struct eigrp *eigrp) +uint32_t eigrp_query_send_all(struct eigrp *eigrp) { struct eigrp_interface *iface; struct listnode *node, *node2, *nnode2; struct eigrp_prefix_entry *pe; - u_int32_t counter; + uint32_t counter; if (eigrp == NULL) { zlog_debug("EIGRP Routing Process not enabled"); @@ -93,8 +93,8 @@ void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph, struct TLV_IPv4_Internal_type *tlv; struct prefix dest_addr; - u_int16_t type; - u_int16_t length; + uint16_t type; + uint16_t length; /* increment statistics. */ ei->query_in++; @@ -111,7 +111,7 @@ void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph, type = stream_getw(s); switch (type) { case EIGRP_TLV_IPv4_INT: - stream_set_getp(s, s->getp - sizeof(u_int16_t)); + stream_set_getp(s, s->getp - sizeof(uint16_t)); tlv = eigrp_read_ipv4_tlv(s); @@ -161,7 +161,7 @@ void eigrp_query_receive(struct eigrp *eigrp, struct ip *iph, void eigrp_send_query(struct eigrp_interface *ei) { struct eigrp_packet *ep = NULL; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; struct listnode *node, *nnode, *node2, *nnode2; struct eigrp_neighbor *nbr; struct eigrp_prefix_entry *pe; diff --git a/eigrpd/eigrp_reply.c b/eigrpd/eigrp_reply.c index ae2d0c0904..a702c1fbd1 100644 --- a/eigrpd/eigrp_reply.c +++ b/eigrpd/eigrp_reply.c @@ -63,7 +63,7 @@ void eigrp_send_reply(struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; struct eigrp_interface *ei = nbr->ei; struct eigrp *eigrp = ei->eigrp; struct eigrp_prefix_entry *pe2; @@ -132,7 +132,7 @@ void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph, struct eigrp_neighbor *nbr; struct TLV_IPv4_Internal_type *tlv; - u_int16_t type; + uint16_t type; /* increment statistics. */ ei->reply_in++; @@ -153,7 +153,7 @@ void eigrp_reply_receive(struct eigrp *eigrp, struct ip *iph, struct prefix dest_addr; - stream_set_getp(s, s->getp - sizeof(u_int16_t)); + stream_set_getp(s, s->getp - sizeof(uint16_t)); tlv = eigrp_read_ipv4_tlv(s); diff --git a/eigrpd/eigrp_routemap.c b/eigrpd/eigrp_routemap.c index 9f80c6c017..ee8d5f7582 100644 --- a/eigrpd/eigrp_routemap.c +++ b/eigrpd/eigrp_routemap.c @@ -255,8 +255,8 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - // u_int32_t *metric; - // u_int32_t check; + // uint32_t *metric; + // uint32_t check; // struct rip_info *rinfo; // struct eigrp_nexthop_entry *te; // struct eigrp_prefix_entry *pe; @@ -286,9 +286,9 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, /* Route map `match metric' match statement. `arg' is METRIC value */ static void *route_match_metric_compile(const char *arg) { - // u_int32_t *metric; + // uint32_t *metric; // - // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_int32_t)); + // metric = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (uint32_t)); // *metric = atoi (arg); // // if(*metric > 0) @@ -529,7 +529,7 @@ static struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = { static route_map_result_t route_match_tag(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - // u_short *tag; + // unsigned short *tag; // struct rip_info *rinfo; // // if (type == RMAP_EIGRP) @@ -549,9 +549,9 @@ static route_map_result_t route_match_tag(void *rule, struct prefix *prefix, /* Route map `match tag' match statement. `arg' is TAG value */ static void *route_match_tag_compile(const char *arg) { - // u_short *tag; + // unsigned short *tag; // - // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); + // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short)); // *tag = atoi (arg); // // return tag; @@ -721,7 +721,7 @@ static struct route_map_rule_cmd route_set_ip_nexthop_cmd = { static route_map_result_t route_set_tag(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - // u_short *tag; + // unsigned short *tag; // struct rip_info *rinfo; // // if(type == RMAP_RIP) @@ -738,12 +738,12 @@ static route_map_result_t route_set_tag(void *rule, struct prefix *prefix, } /* Route map `tag' compile function. Given string is converted - to u_short. */ + to unsigned short. */ static void *route_set_tag_compile(const char *arg) { - // u_short *tag; + // unsigned short *tag; // - // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short)); + // tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned short)); // *tag = atoi (arg); // // return tag; diff --git a/eigrpd/eigrp_siaquery.c b/eigrpd/eigrp_siaquery.c index 70df29c1f1..d398d75724 100644 --- a/eigrpd/eigrp_siaquery.c +++ b/eigrpd/eigrp_siaquery.c @@ -62,7 +62,7 @@ void eigrp_siaquery_receive(struct eigrp *eigrp, struct ip *iph, struct eigrp_neighbor *nbr; struct TLV_IPv4_Internal_type *tlv; - u_int16_t type; + uint16_t type; /* increment statistics. */ ei->siaQuery_in++; @@ -80,7 +80,7 @@ void eigrp_siaquery_receive(struct eigrp *eigrp, struct ip *iph, if (type == EIGRP_TLV_IPv4_INT) { struct prefix dest_addr; - stream_set_getp(s, s->getp - sizeof(u_int16_t)); + stream_set_getp(s, s->getp - sizeof(uint16_t)); tlv = eigrp_read_ipv4_tlv(s); @@ -117,7 +117,7 @@ void eigrp_send_siaquery(struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; ep = eigrp_packet_new(nbr->ei->ifp->mtu, nbr); diff --git a/eigrpd/eigrp_siareply.c b/eigrpd/eigrp_siareply.c index b71e80cfcb..3b7a82b665 100644 --- a/eigrpd/eigrp_siareply.c +++ b/eigrpd/eigrp_siareply.c @@ -61,7 +61,7 @@ void eigrp_siareply_receive(struct eigrp *eigrp, struct ip *iph, struct eigrp_neighbor *nbr; struct TLV_IPv4_Internal_type *tlv; - u_int16_t type; + uint16_t type; /* increment statistics. */ ei->siaReply_in++; @@ -79,7 +79,7 @@ void eigrp_siareply_receive(struct eigrp *eigrp, struct ip *iph, if (type == EIGRP_TLV_IPv4_INT) { struct prefix dest_addr; - stream_set_getp(s, s->getp - sizeof(u_int16_t)); + stream_set_getp(s, s->getp - sizeof(uint16_t)); tlv = eigrp_read_ipv4_tlv(s); @@ -116,7 +116,7 @@ void eigrp_send_siareply(struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; ep = eigrp_packet_new(nbr->ei->ifp->mtu, nbr); diff --git a/eigrpd/eigrp_snmp.c b/eigrpd/eigrp_snmp.c index 5647476a6d..e418b40343 100644 --- a/eigrpd/eigrp_snmp.c +++ b/eigrpd/eigrp_snmp.c @@ -167,16 +167,16 @@ oid eigrp_oid[] = {EIGRPMIB}; #define UINTEGER ASN_UNSIGNED /* Hook functions. */ -static u_char *eigrpVpnEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); -static u_char *eigrpTraffStatsEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *eigrpTopologyEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *eigrpPeerEntry(struct variable *, oid *, size_t *, int, size_t *, +static uint8_t *eigrpVpnEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *eigrpInterfaceEntry(struct variable *, oid *, size_t *, int, +static uint8_t *eigrpTraffStatsEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *eigrpTopologyEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); +static uint8_t *eigrpPeerEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *eigrpInterfaceEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); struct variable eigrp_variables[] = { @@ -599,9 +599,9 @@ static struct eigrp_neighbor *eigrpNbrLookup(struct variable *v, oid *name, } -static u_char *eigrpVpnEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *eigrpVpnEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct eigrp *eigrp; @@ -657,9 +657,9 @@ static uint32_t eigrp_neighbor_count(struct eigrp *eigrp) } -static u_char *eigrpTraffStatsEntry(struct variable *v, oid *name, - size_t *length, int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *eigrpTraffStatsEntry(struct variable *v, oid *name, + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { struct eigrp *eigrp; struct eigrp_interface *ei; @@ -913,9 +913,9 @@ static u_char *eigrpTraffStatsEntry(struct variable *v, oid *name, return NULL; } -static u_char *eigrpTopologyEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *eigrpTopologyEntry(struct variable *v, oid *name, + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { struct eigrp *eigrp; struct eigrp_interface *ei; @@ -1061,9 +1061,9 @@ static u_char *eigrpTopologyEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *eigrpPeerEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *eigrpPeerEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct eigrp *eigrp; struct eigrp_interface *ei; @@ -1194,9 +1194,9 @@ static u_char *eigrpPeerEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *eigrpInterfaceEntry(struct variable *v, oid *name, - size_t *length, int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *eigrpInterfaceEntry(struct variable *v, oid *name, + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { struct eigrp *eigrp; struct eigrp_interface *ei; @@ -1383,13 +1383,13 @@ static u_char *eigrpInterfaceEntry(struct variable *v, oid *name, on this interface. */ keylist = keychain_list_get(); for (ALL_LIST_ELEMENTS(keylist, node, nnode, keychain)) { - return (u_char *)keychain->name; + return (uint8_t *)keychain->name; } if (eigrp && keychain) { *var_len = str_len(keychain->name); - return (u_char *)keychain->name; + return (uint8_t *)keychain->name; } else - return (u_char *)"TEST"; + return (uint8_t *)"TEST"; break; default: return NULL; diff --git a/eigrpd/eigrp_structs.h b/eigrpd/eigrp_structs.h index ea281fc974..95bcfe50e7 100644 --- a/eigrpd/eigrp_structs.h +++ b/eigrpd/eigrp_structs.h @@ -52,43 +52,43 @@ struct eigrp_master { time_t start_time; /* Various EIGRP global configuration. */ - u_char options; + uint8_t options; #define EIGRP_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */ }; struct eigrp_metrics { - u_int32_t delay; - u_int32_t bandwidth; + uint32_t delay; + uint32_t bandwidth; unsigned char mtu[3]; - u_char hop_count; - u_char reliability; - u_char load; - u_char tag; - u_char flags; + uint8_t hop_count; + uint8_t reliability; + uint8_t load; + uint8_t tag; + uint8_t flags; }; struct eigrp { - u_int16_t AS; /* Autonomous system number */ - u_int16_t vrid; /* Virtual Router ID */ - u_char k_values[6]; /*Array for K values configuration*/ - u_char variance; /*Metric variance multiplier*/ - u_char max_paths; /*Maximum allowed paths for 1 prefix*/ + uint16_t AS; /* Autonomous system number */ + uint16_t vrid; /* Virtual Router ID */ + uint8_t k_values[6]; /*Array for K values configuration*/ + uint8_t variance; /*Metric variance multiplier*/ + uint8_t max_paths; /*Maximum allowed paths for 1 prefix*/ /*Name of this EIGRP instance*/ char *name; /* EIGRP Router ID. */ - u_int32_t router_id; /* Configured automatically. */ - u_int32_t router_id_static; /* Configured manually. */ + uint32_t router_id; /* Configured automatically. */ + uint32_t router_id_static; /* Configured manually. */ struct list *eiflist; /* eigrp interfaces */ - u_char passive_interface_default; /* passive-interface default */ + uint8_t passive_interface_default; /* passive-interface default */ unsigned int fd; unsigned int maxsndbuflen; - u_int32_t sequence_number; /*Global EIGRP sequence number*/ + uint32_t sequence_number; /*Global EIGRP sequence number*/ struct stream *ibuf; struct list *oi_write_q; @@ -128,7 +128,7 @@ struct eigrp { char *name; struct route_map *map; int metric_config; - u_int32_t metric; + uint32_t metric; } route_map[ZEBRA_ROUTE_MAX]; QOBJ_FIELDS @@ -136,14 +136,14 @@ struct eigrp { DECLARE_QOBJ_TYPE(eigrp) struct eigrp_if_params { - u_char passive_interface; - u_int32_t v_hello; - u_int16_t v_wait; - u_char type; /* type of interface */ - u_int32_t bandwidth; - u_int32_t delay; - u_char reliability; - u_char load; + uint8_t passive_interface; + uint32_t v_hello; + uint16_t v_wait; + uint8_t type; /* type of interface */ + uint32_t bandwidth; + uint32_t delay; + uint8_t reliability; + uint8_t load; char *auth_keychain; /* Associated keychain with interface*/ int auth_type; /* EIGRP authentication type */ @@ -172,10 +172,10 @@ struct eigrp_interface { /* To which multicast groups do we currently belong? */ - u_char multicast_memberships; + uint8_t multicast_memberships; /* EIGRP Network Type. */ - u_char type; + uint8_t type; struct prefix *address; /* Interface prefix */ struct connected *connected; /* Pointer to connected */ @@ -190,22 +190,22 @@ struct eigrp_interface { int on_write_q; /* Statistics fields. */ - u_int32_t hello_in; /* Hello message input count. */ - u_int32_t update_in; /* Update message input count. */ - u_int32_t query_in; /* Querry message input count. */ - u_int32_t reply_in; /* Reply message input count. */ - u_int32_t hello_out; /* Hello message output count. */ - u_int32_t update_out; /* Update message output count. */ - u_int32_t query_out; /* Query message output count. */ - u_int32_t reply_out; /* Reply message output count. */ - u_int32_t siaQuery_in; - u_int32_t siaQuery_out; - u_int32_t siaReply_in; - u_int32_t siaReply_out; - u_int32_t ack_out; - u_int32_t ack_in; - - u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */ + uint32_t hello_in; /* Hello message input count. */ + uint32_t update_in; /* Update message input count. */ + uint32_t query_in; /* Querry message input count. */ + uint32_t reply_in; /* Reply message input count. */ + uint32_t hello_out; /* Hello message output count. */ + uint32_t update_out; /* Update message output count. */ + uint32_t query_out; /* Query message output count. */ + uint32_t reply_out; /* Reply message output count. */ + uint32_t siaQuery_in; + uint32_t siaQuery_out; + uint32_t siaReply_in; + uint32_t siaReply_out; + uint32_t ack_out; + uint32_t ack_in; + + uint32_t crypt_seqnum; /* Cryptographic Sequence Number */ /* Access-list. */ struct access_list *list[EIGRP_FILTER_MAX]; @@ -231,30 +231,32 @@ struct eigrp_neighbor { struct eigrp_interface *ei; /* EIGRP neighbor Information */ - u_char state; /* neigbor status. */ + uint8_t state; /* neigbor status. */ - u_int32_t recv_sequence_number; /* Last received sequence Number. */ - u_int32_t init_sequence_number; + uint32_t recv_sequence_number; /* Last received sequence Number. */ + uint32_t init_sequence_number; /*If packet is unacknowledged, we try to send it again 16 times*/ - u_char retrans_counter; + uint8_t retrans_counter; struct in_addr src; /* Neighbor Src address. */ - u_char os_rel_major; // system version - just for show - u_char os_rel_minor; // system version - just for show - u_char tlv_rel_major; // eigrp version - tells us what TLV format to use - u_char tlv_rel_minor; // eigrp version - tells us what TLV format to use + uint8_t os_rel_major; // system version - just for show + uint8_t os_rel_minor; // system version - just for show + uint8_t tlv_rel_major; // eigrp version - tells us what TLV format to + // use + uint8_t tlv_rel_minor; // eigrp version - tells us what TLV format to + // use - u_char K1; - u_char K2; - u_char K3; - u_char K4; - u_char K5; - u_char K6; + uint8_t K1; + uint8_t K2; + uint8_t K3; + uint8_t K4; + uint8_t K5; + uint8_t K6; /* Timer values. */ - u_int16_t v_holddown; + uint16_t v_holddown; /* Threads. */ struct thread *t_holddown; @@ -264,7 +266,7 @@ struct eigrp_neighbor { struct eigrp_fifo *retrans_queue; struct eigrp_fifo *multicast_queue; - u_int32_t crypt_seqnum; /* Cryptographic Sequence Number. */ + uint32_t crypt_seqnum; /* Cryptographic Sequence Number. */ /* prefixes not received from neighbor during Graceful restart */ struct list *nbr_gr_prefixes; @@ -291,12 +293,12 @@ struct eigrp_packet { struct thread *t_retrans_timer; /*Packet retransmission counter*/ - u_char retrans_counter; + uint8_t retrans_counter; - u_int32_t sequence_number; + uint32_t sequence_number; /* EIGRP packet length. */ - u_int16_t length; + uint16_t length; struct eigrp_neighbor *nbr; }; @@ -309,14 +311,14 @@ struct eigrp_fifo { }; struct eigrp_header { - u_char version; - u_char opcode; - u_int16_t checksum; - u_int32_t flags; - u_int32_t sequence; - u_int32_t ack; - u_int16_t vrid; - u_int16_t ASNumber; + uint8_t version; + uint8_t opcode; + uint16_t checksum; + uint32_t flags; + uint32_t sequence; + uint32_t ack; + uint16_t vrid; + uint16_t ASNumber; char *tlv[0]; } __attribute__((packed)); @@ -332,109 +334,109 @@ struct eigrp_header { * +-----+------------------+ */ struct eigrp_tlv_hdr_type { - u_int16_t type; - u_int16_t length; + uint16_t type; + uint16_t length; uint8_t value[0]; } __attribute__((packed)); struct TLV_Parameter_Type { - u_int16_t type; - u_int16_t length; - u_char K1; - u_char K2; - u_char K3; - u_char K4; - u_char K5; - u_char K6; - u_int16_t hold_time; + uint16_t type; + uint16_t length; + uint8_t K1; + uint8_t K2; + uint8_t K3; + uint8_t K4; + uint8_t K5; + uint8_t K6; + uint16_t hold_time; } __attribute__((packed)); struct TLV_MD5_Authentication_Type { - u_int16_t type; - u_int16_t length; - u_int16_t auth_type; - u_int16_t auth_length; - u_int32_t key_id; - u_int32_t key_sequence; - u_char Nullpad[8]; - u_char digest[EIGRP_AUTH_TYPE_MD5_LEN]; + uint16_t type; + uint16_t length; + uint16_t auth_type; + uint16_t auth_length; + uint32_t key_id; + uint32_t key_sequence; + uint8_t Nullpad[8]; + uint8_t digest[EIGRP_AUTH_TYPE_MD5_LEN]; } __attribute__((packed)); struct TLV_SHA256_Authentication_Type { - u_int16_t type; - u_int16_t length; - u_int16_t auth_type; - u_int16_t auth_length; - u_int32_t key_id; - u_int32_t key_sequence; - u_char Nullpad[8]; - u_char digest[EIGRP_AUTH_TYPE_SHA256_LEN]; + uint16_t type; + uint16_t length; + uint16_t auth_type; + uint16_t auth_length; + uint32_t key_id; + uint32_t key_sequence; + uint8_t Nullpad[8]; + uint8_t digest[EIGRP_AUTH_TYPE_SHA256_LEN]; } __attribute__((packed)); struct TLV_Sequence_Type { - u_int16_t type; - u_int16_t length; - u_char addr_length; + uint16_t type; + uint16_t length; + uint8_t addr_length; struct in_addr *addresses; } __attribute__((packed)); struct TLV_Next_Multicast_Sequence { - u_int16_t type; - u_int16_t length; - u_int32_t multicast_sequence; + uint16_t type; + uint16_t length; + uint32_t multicast_sequence; } __attribute__((packed)); struct TLV_Software_Type { - u_int16_t type; - u_int16_t length; - u_char vender_major; - u_char vender_minor; - u_char eigrp_major; - u_char eigrp_minor; + uint16_t type; + uint16_t length; + uint8_t vender_major; + uint8_t vender_minor; + uint8_t eigrp_major; + uint8_t eigrp_minor; } __attribute__((packed)); struct TLV_IPv4_Internal_type { - u_int16_t type; - u_int16_t length; + uint16_t type; + uint16_t length; struct in_addr forward; /*Metrics*/ struct eigrp_metrics metric; - u_char prefix_length; + uint8_t prefix_length; unsigned char destination_part[4]; struct in_addr destination; } __attribute__((packed)); struct TLV_IPv4_External_type { - u_int16_t type; - u_int16_t length; + uint16_t type; + uint16_t length; struct in_addr next_hop; struct in_addr originating_router; - u_int32_t originating_as; - u_int32_t administrative_tag; - u_int32_t external_metric; - u_int16_t reserved; - u_char external_protocol; - u_char external_flags; + uint32_t originating_as; + uint32_t administrative_tag; + uint32_t external_metric; + uint16_t reserved; + uint8_t external_protocol; + uint8_t external_flags; /*Metrics*/ struct eigrp_metrics metric; - u_char prefix_length; + uint8_t prefix_length; unsigned char destination_part[4]; struct in_addr destination; } __attribute__((packed)); /* EIGRP Peer Termination TLV - used for hard restart */ struct TLV_Peer_Termination_type { - u_int16_t type; - u_int16_t length; - u_char unknown; - u_int32_t neighbor_ip; + uint16_t type; + uint16_t length; + uint8_t unknown; + uint32_t neighbor_ip; } __attribute__((packed)); /* Who executed Graceful restart */ @@ -445,15 +447,15 @@ enum GR_type { EIGRP_GR_MANUAL, EIGRP_GR_FILTER }; /* EIGRP Topology table node structure */ struct eigrp_prefix_entry { struct list *entries, *rij; - u_int32_t fdistance; // FD - u_int32_t rdistance; // RD - u_int32_t distance; // D + uint32_t fdistance; // FD + uint32_t rdistance; // RD + uint32_t distance; // D struct eigrp_metrics reported_metric; // RD for sending - u_char nt; // network type - u_char state; // route fsm state - u_char af; // address family - u_char req_action; // required action + uint8_t nt; // network type + uint8_t state; // route fsm state + uint8_t af; // address family + uint8_t req_action; // required action struct prefix *destination; @@ -468,15 +470,15 @@ struct eigrp_prefix_entry { /* EIGRP Topology table record structure */ struct eigrp_nexthop_entry { struct eigrp_prefix_entry *prefix; - u_int32_t reported_distance; // distance reported by neighbor - u_int32_t distance; // sum of reported distance and link cost to - // advertised neighbor + uint32_t reported_distance; // distance reported by neighbor + uint32_t distance; // sum of reported distance and link cost to + // advertised neighbor struct eigrp_metrics reported_metric; struct eigrp_metrics total_metric; struct eigrp_neighbor *adv_router; // ip address of advertising neighbor - u_char flags; // used for marking successor and FS + uint8_t flags; // used for marking successor and FS struct eigrp_interface *ei; // pointer for case of connected entry }; @@ -491,7 +493,7 @@ typedef enum { /* EIGRP Finite State Machine */ struct eigrp_fsm_action_message { - u_char packet_type; // UPDATE, QUERY, SIAQUERY, SIAREPLY + uint8_t packet_type; // UPDATE, QUERY, SIAQUERY, SIAREPLY struct eigrp *eigrp; // which thread sent mesg struct eigrp_neighbor *adv_router; // advertising neighbor struct eigrp_nexthop_entry *entry; diff --git a/eigrpd/eigrp_topology.c b/eigrpd/eigrp_topology.c index bab47ea133..2d1bc46e6b 100644 --- a/eigrpd/eigrp_topology.c +++ b/eigrpd/eigrp_topology.c @@ -362,7 +362,7 @@ eigrp_topology_update_distance(struct eigrp_fsm_action_message *msg) struct eigrp_prefix_entry *prefix = msg->prefix; struct eigrp_nexthop_entry *entry = msg->entry; enum metric_change change = METRIC_SAME; - u_int32_t new_reported_distance; + uint32_t new_reported_distance; assert(entry); diff --git a/eigrpd/eigrp_update.c b/eigrpd/eigrp_update.c index baaf7f6891..bd80ea366f 100644 --- a/eigrpd/eigrp_update.c +++ b/eigrpd/eigrp_update.c @@ -176,13 +176,13 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, struct TLV_IPv4_Internal_type *tlv; struct eigrp_prefix_entry *pe; struct eigrp_nexthop_entry *ne; - u_int32_t flags; - u_int16_t type; - u_int16_t length; - u_char same; + uint32_t flags; + uint16_t type; + uint16_t length; + uint8_t same; struct prefix dest_addr; - u_char graceful_restart; - u_char graceful_restart_final; + uint8_t graceful_restart; + uint8_t graceful_restart_final; struct list *nbr_prefixes = NULL; /* increment statistics. */ @@ -297,7 +297,7 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, type = stream_getw(s); switch (type) { case EIGRP_TLV_IPv4_INT: - stream_set_getp(s, s->getp - sizeof(u_int16_t)); + stream_set_getp(s, s->getp - sizeof(uint16_t)); tlv = eigrp_read_ipv4_tlv(s); @@ -418,7 +418,7 @@ void eigrp_update_receive(struct eigrp *eigrp, struct ip *iph, void eigrp_update_send_init(struct eigrp_neighbor *nbr) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; ep = eigrp_packet_new(nbr->ei->ifp->mtu, nbr); @@ -463,7 +463,7 @@ void eigrp_update_send_init(struct eigrp_neighbor *nbr) static void eigrp_update_place_on_nbr_queue(struct eigrp_neighbor *nbr, struct eigrp_packet *ep, - u_int32_t seq_no, int length) + uint32_t seq_no, int length) { if ((nbr->ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) && (nbr->ei->params.auth_keychain != NULL)) { @@ -525,15 +525,15 @@ static void eigrp_update_send_to_all_nbrs(struct eigrp_interface *ei, void eigrp_update_send_EOT(struct eigrp_neighbor *nbr) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; struct eigrp_nexthop_entry *te; struct eigrp_prefix_entry *pe; struct listnode *node2, *nnode2; struct eigrp_interface *ei = nbr->ei; struct eigrp *eigrp = ei->eigrp; struct prefix *dest_addr; - u_int32_t seq_no = eigrp->sequence_number; - u_int16_t mtu = ei->ifp->mtu; + uint32_t seq_no = eigrp->sequence_number; + uint16_t mtu = ei->ifp->mtu; struct route_node *rn; ep = eigrp_packet_new(mtu, nbr); @@ -600,15 +600,15 @@ void eigrp_update_send(struct eigrp_interface *ei) struct eigrp_packet *ep; struct listnode *node, *nnode; struct eigrp_prefix_entry *pe; - u_char has_tlv; + uint8_t has_tlv; struct eigrp *eigrp = ei->eigrp; struct prefix *dest_addr; - u_int32_t seq_no = eigrp->sequence_number; + uint32_t seq_no = eigrp->sequence_number; if (ei->nbrs->count == 0) return; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; ep = eigrp_packet_new(ei->ifp->mtu, NULL); @@ -634,7 +634,7 @@ void eigrp_update_send(struct eigrp_interface *ei) continue; if ((length + EIGRP_TLV_MAX_IPV4_BYTE) - > (u_int16_t)ei->ifp->mtu) { + > (uint16_t)ei->ifp->mtu) { if ((ei->params.auth_type == EIGRP_AUTH_TYPE_MD5) && (ei->params.auth_keychain != NULL)) { eigrp_make_md5_digest(ei, ep->s, @@ -743,13 +743,13 @@ void eigrp_update_send_all(struct eigrp *eigrp, static void eigrp_update_send_GR_part(struct eigrp_neighbor *nbr) { struct eigrp_packet *ep; - u_int16_t length = EIGRP_HEADER_LEN; + uint16_t length = EIGRP_HEADER_LEN; struct eigrp_prefix_entry *pe; struct prefix *dest_addr; struct eigrp_interface *ei = nbr->ei; struct eigrp *eigrp = ei->eigrp; struct list *prefixes; - u_int32_t flags; + uint32_t flags; unsigned int send_prefixes; struct route_node *rn; diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 96c96411f5..190c18777e 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -608,7 +608,7 @@ DEFUN (eigrp_if_delay, VTY_DECLVAR_CONTEXT(interface, ifp); struct eigrp_interface *ei = ifp->info; struct eigrp *eigrp; - u_int32_t delay; + uint32_t delay; eigrp = eigrp_lookup(); if (eigrp == NULL) { @@ -666,7 +666,7 @@ DEFUN (eigrp_if_bandwidth, { VTY_DECLVAR_CONTEXT(interface, ifp); struct eigrp_interface *ei = ifp->info; - u_int32_t bandwidth; + uint32_t bandwidth; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -727,7 +727,7 @@ DEFUN (eigrp_if_ip_hellointerval, { VTY_DECLVAR_CONTEXT(interface, ifp); struct eigrp_interface *ei = ifp->info; - u_int32_t hello; + uint32_t hello; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -790,7 +790,7 @@ DEFUN (eigrp_if_ip_holdinterval, { VTY_DECLVAR_CONTEXT(interface, ifp); struct eigrp_interface *ei = ifp->info; - u_int32_t hold; + uint32_t hold; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -821,7 +821,7 @@ DEFUN (eigrp_ip_summary_address, "Summary <network>/<length>, e.g. 192.168.0.0/16\n") { // VTY_DECLVAR_CONTEXT(interface, ifp); - // u_int32_t AS; + // uint32_t AS; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -848,7 +848,7 @@ DEFUN (no_eigrp_ip_summary_address, "Summary <network>/<length>, e.g. 192.168.0.0/16\n") { // VTY_DECLVAR_CONTEXT(interface, ifp); - // u_int32_t AS; + // uint32_t AS; struct eigrp *eigrp; eigrp = eigrp_lookup(); @@ -1120,7 +1120,7 @@ DEFUN (eigrp_variance, "Metric variance multiplier\n") { struct eigrp *eigrp; - u_char variance; + uint8_t variance; eigrp = eigrp_lookup(); if (eigrp == NULL) { @@ -1164,7 +1164,7 @@ DEFUN (eigrp_maximum_paths, "Number of paths\n") { struct eigrp *eigrp; - u_char max; + uint8_t max; eigrp = eigrp_lookup(); if (eigrp == NULL) { diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c index fd7a233238..24d1253cb9 100644 --- a/eigrpd/eigrpd.c +++ b/eigrpd/eigrpd.c @@ -96,7 +96,7 @@ void eigrp_router_id_update(struct eigrp *eigrp) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - u_int32_t router_id, router_id_old; + uint32_t router_id, router_id_old; router_id_old = eigrp->router_id; diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c index a6e1a55a9f..81495d0a79 100644 --- a/isisd/isis_adjacency.c +++ b/isisd/isis_adjacency.c @@ -51,7 +51,7 @@ extern struct isis *isis; -static struct isis_adjacency *adj_alloc(const u_char *id) +static struct isis_adjacency *adj_alloc(const uint8_t *id) { struct isis_adjacency *adj; @@ -61,7 +61,7 @@ static struct isis_adjacency *adj_alloc(const u_char *id) return adj; } -struct isis_adjacency *isis_new_adj(const u_char *id, const u_char *snpa, +struct isis_adjacency *isis_new_adj(const uint8_t *id, const uint8_t *snpa, int level, struct isis_circuit *circuit) { struct isis_adjacency *adj; @@ -96,7 +96,7 @@ struct isis_adjacency *isis_new_adj(const u_char *id, const u_char *snpa, return adj; } -struct isis_adjacency *isis_adj_lookup(const u_char *sysid, struct list *adjdb) +struct isis_adjacency *isis_adj_lookup(const uint8_t *sysid, struct list *adjdb) { struct isis_adjacency *adj; struct listnode *node; @@ -108,7 +108,7 @@ struct isis_adjacency *isis_adj_lookup(const u_char *sysid, struct list *adjdb) return NULL; } -struct isis_adjacency *isis_adj_lookup_snpa(const u_char *ssnpa, +struct isis_adjacency *isis_adj_lookup_snpa(const uint8_t *ssnpa, struct list *adjdb) { struct listnode *node; diff --git a/isisd/isis_adjacency.h b/isisd/isis_adjacency.h index 2c3bd19af8..2f39378c00 100644 --- a/isisd/isis_adjacency.h +++ b/isisd/isis_adjacency.h @@ -69,9 +69,9 @@ struct isis_dis_record { }; struct isis_adjacency { - u_char snpa[ETH_ALEN]; /* NeighbourSNPAAddress */ - u_char sysid[ISIS_SYS_ID_LEN]; /* neighbourSystemIdentifier */ - u_char lanid[ISIS_SYS_ID_LEN + 1]; /* LAN id on bcast circuits */ + uint8_t snpa[ETH_ALEN]; /* NeighbourSNPAAddress */ + uint8_t sysid[ISIS_SYS_ID_LEN]; /* neighbourSystemIdentifier */ + uint8_t lanid[ISIS_SYS_ID_LEN + 1]; /* LAN id on bcast circuits */ int dischanges[ISIS_LEVELS]; /* how many DIS changes ? */ /* an array of N levels for M records */ struct isis_dis_record dis_record[DIS_RECORDS * ISIS_LEVELS]; @@ -86,13 +86,13 @@ struct isis_adjacency { struct in6_addr *ipv6_addresses; unsigned int ipv6_address_count; struct in6_addr router_address6; - u_char prio[ISIS_LEVELS]; /* priorityOfNeighbour for DIS */ + uint8_t prio[ISIS_LEVELS]; /* priorityOfNeighbour for DIS */ int circuit_t; /* from hello PDU hdr */ int level; /* level (1 or 2) */ enum isis_system_type sys_type; /* neighbourSystemType */ - u_int16_t hold_time; /* entryRemainingTime */ - u_int32_t last_upd; - u_int32_t last_flap; /* last time the adj flapped */ + uint16_t hold_time; /* entryRemainingTime */ + uint32_t last_upd; + uint32_t last_flap; /* last time the adj flapped */ enum isis_threeway_state threeway_state; uint32_t ext_circuit_id; int flaps; /* number of adjacency flaps */ @@ -104,10 +104,11 @@ struct isis_adjacency { struct isis_threeway_adj; -struct isis_adjacency *isis_adj_lookup(const u_char *sysid, struct list *adjdb); -struct isis_adjacency *isis_adj_lookup_snpa(const u_char *ssnpa, +struct isis_adjacency *isis_adj_lookup(const uint8_t *sysid, + struct list *adjdb); +struct isis_adjacency *isis_adj_lookup_snpa(const uint8_t *ssnpa, struct list *adjdb); -struct isis_adjacency *isis_new_adj(const u_char *id, const u_char *snpa, +struct isis_adjacency *isis_new_adj(const uint8_t *id, const uint8_t *snpa, int level, struct isis_circuit *circuit); void isis_delete_adj(void *adj); void isis_adj_process_threeway(struct isis_adjacency *adj, diff --git a/isisd/isis_bpf.c b/isisd/isis_bpf.c index 872bc5bc72..2cc2fefd9a 100644 --- a/isisd/isis_bpf.c +++ b/isisd/isis_bpf.c @@ -54,20 +54,20 @@ struct bpf_insn llcfilter[] = { 3), /* check second byte */ BPF_STMT(BPF_LD + BPF_B + BPF_ABS, ETHER_HDR_LEN + 2), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0x03, 0, 1), /* check third byte */ - BPF_STMT(BPF_RET + BPF_K, (u_int)-1), + BPF_STMT(BPF_RET + BPF_K, (unsigned int)-1), BPF_STMT(BPF_RET + BPF_K, 0)}; -u_int readblen = 0; -u_char *readbuff = NULL; +unsigned int readblen = 0; +uint8_t *readbuff = NULL; /* * Table 9 - Architectural constants for use with ISO 8802 subnetworks * ISO 10589 - 8.4.8 */ -u_char ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; -u_char ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; -u_char ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; -u_char ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; +uint8_t ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; +uint8_t ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; +uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; +uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; static char sock_buff[8192]; @@ -76,9 +76,9 @@ static int open_bpf_dev(struct isis_circuit *circuit) int i = 0, fd; char bpfdev[128]; struct ifreq ifr; - u_int blen, immediate; + unsigned int blen, immediate; #ifdef BIOCSSEESENT - u_int seesent; + unsigned int seesent; #endif struct timeval timeout; struct bpf_program bpf_prog; @@ -214,10 +214,10 @@ end: return retval; } -int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa) +int isis_recv_pdu_bcast(struct isis_circuit *circuit, uint8_t *ssnpa) { int bytesread = 0, bytestoread, offset, one = 1, err = ISIS_OK; - u_char *buff_ptr; + uint8_t *buff_ptr; struct bpf_hdr *bpf_hdr; assert(circuit->fd > 0); diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 2c443c71f7..6f4d72cb1f 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -209,7 +209,7 @@ void isis_circuit_add_addr(struct isis_circuit *circuit, struct prefix_ipv6 *ipv6; if (connected->address->family == AF_INET) { - u_int32_t addr = connected->address->u.prefix4.s_addr; + uint32_t addr = connected->address->u.prefix4.s_addr; addr = ntohl(addr); if (IPV4_NET0(addr) || IPV4_NET127(addr) || IN_CLASSD(addr) || IPV4_LINKLOCAL(addr)) @@ -1235,7 +1235,7 @@ ferr_r isis_circuit_passwd_unset(struct isis_circuit *circuit) } static int isis_circuit_passwd_set(struct isis_circuit *circuit, - u_char passwd_type, const char *passwd) + uint8_t passwd_type, const char *passwd) { int len; diff --git a/isisd/isis_circuit.h b/isisd/isis_circuit.h index 246279c6f3..8dbd7ac492 100644 --- a/isisd/isis_circuit.h +++ b/isisd/isis_circuit.h @@ -37,26 +37,26 @@ struct isis_lsp; struct password { struct password *next; int len; - u_char *pass; + uint8_t *pass; }; struct metric { - u_char metric_default; - u_char metric_error; - u_char metric_expense; - u_char metric_delay; + uint8_t metric_default; + uint8_t metric_error; + uint8_t metric_expense; + uint8_t metric_delay; }; struct isis_bcast_info { - u_char snpa[ETH_ALEN]; /* SNPA of this circuit */ + uint8_t snpa[ETH_ALEN]; /* SNPA of this circuit */ char run_dr_elect[2]; /* Should we run dr election ? */ struct thread *t_run_dr[2]; /* DR election thread */ struct thread *t_send_lan_hello[2]; /* send LAN IIHs in this thread */ struct list *adjdb[2]; /* adjacency dbs */ struct list *lan_neighs[2]; /* list of lx neigh snpa */ char is_dr[2]; /* Are we level x DR ? */ - u_char l1_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-1 DR */ - u_char l2_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-2 DR */ + uint8_t l1_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-1 DR */ + uint8_t l2_desig_is[ISIS_SYS_ID_LEN + 1]; /* level-2 DR */ struct thread *t_refresh_pseudo_lsp[2]; /* refresh pseudo-node LSPs */ }; @@ -67,7 +67,7 @@ struct isis_p2p_info { struct isis_circuit { int state; - u_char circuit_id; /* l1/l2 bcast CircuitID */ + uint8_t circuit_id; /* l1/l2 bcast CircuitID */ struct isis_area *area; /* back pointer to the area */ struct interface *interface; /* interface info from z */ int fd; /* IS-IS l1/2 socket */ @@ -89,7 +89,7 @@ struct isis_circuit { * circuit */ /* there is no real point in two streams, just for programming kicker */ - int (*rx)(struct isis_circuit *circuit, u_char *ssnpa); + int (*rx)(struct isis_circuit *circuit, uint8_t *ssnpa); struct stream *rcv_stream; /* Stream for receiving */ int (*tx)(struct isis_circuit *circuit, int level); struct stream *snd_stream; /* Stream for sending */ @@ -104,7 +104,7 @@ struct isis_circuit { struct isis_bcast_info bc; struct isis_p2p_info p2p; } u; - u_char priority[2]; /* l1/2 IS configured priority */ + uint8_t priority[2]; /* l1/2 IS configured priority */ int pad_hellos; /* add padding to Hello PDUs ? */ char ext_domain; /* externalDomain (boolean) */ int lsp_regenerate_pending[ISIS_LEVELS]; @@ -114,12 +114,12 @@ struct isis_circuit { struct isis_passwd passwd; /* Circuit rx/tx password */ int is_type; /* circuit is type == level of circuit * differentiated from circuit type (media) */ - u_int32_t hello_interval[2]; /* l1HelloInterval in msecs */ - u_int16_t hello_multiplier[2]; /* l1HelloMultiplier */ - u_int16_t csnp_interval[2]; /* level-1 csnp-interval in seconds */ - u_int16_t psnp_interval[2]; /* level-1 psnp-interval in seconds */ - u_int8_t metric[2]; - u_int32_t te_metric[2]; + uint32_t hello_interval[2]; /* l1HelloInterval in msecs */ + uint16_t hello_multiplier[2]; /* l1HelloMultiplier */ + uint16_t csnp_interval[2]; /* level-1 csnp-interval in seconds */ + uint16_t psnp_interval[2]; /* level-1 psnp-interval in seconds */ + uint8_t metric[2]; + uint32_t te_metric[2]; struct mpls_te_circuit *mtc; /* Support for MPLS-TE parameters - see isis_te.[c,h] */ int ip_router; /* Route IP ? */ @@ -129,20 +129,20 @@ struct isis_circuit { int ipv6_router; /* Route IPv6 ? */ struct list *ipv6_link; /* our link local IPv6 addresses */ struct list *ipv6_non_link; /* our non-link local IPv6 addresses */ - u_int16_t upadjcount[2]; + uint16_t upadjcount[2]; #define ISIS_CIRCUIT_FLAPPED_AFTER_SPF 0x01 - u_char flags; + uint8_t flags; bool disable_threeway_adj; /* * Counters as in 10589--11.2.5.9 */ - u_int32_t adj_state_changes; /* changesInAdjacencyState */ - u_int32_t init_failures; /* intialisationFailures */ - u_int32_t ctrl_pdus_rxed; /* controlPDUsReceived */ - u_int32_t ctrl_pdus_txed; /* controlPDUsSent */ - u_int32_t + uint32_t adj_state_changes; /* changesInAdjacencyState */ + uint32_t init_failures; /* intialisationFailures */ + uint32_t ctrl_pdus_rxed; /* controlPDUsReceived */ + uint32_t ctrl_pdus_txed; /* controlPDUsSent */ + uint32_t desig_changes[2]; /* lanLxDesignatedIntermediateSystemChanges */ - u_int32_t rej_adjacencies; /* rejectedAdjacencies */ + uint32_t rej_adjacencies; /* rejectedAdjacencies */ QOBJ_FIELDS }; diff --git a/isisd/isis_common.h b/isisd/isis_common.h index b157bb1836..809a3980df 100644 --- a/isisd/isis_common.h +++ b/isisd/isis_common.h @@ -28,30 +28,30 @@ * Area Address */ struct area_addr { - u_char addr_len; - u_char area_addr[20]; + uint8_t addr_len; + uint8_t area_addr[20]; }; struct isis_passwd { - u_char len; + uint8_t len; #define ISIS_PASSWD_TYPE_UNUSED 0 #define ISIS_PASSWD_TYPE_CLEARTXT 1 #define ISIS_PASSWD_TYPE_HMAC_MD5 54 #define ISIS_PASSWD_TYPE_PRIVATE 255 - u_char type; + uint8_t type; /* Authenticate SNPs? */ #define SNP_AUTH_SEND 0x01 #define SNP_AUTH_RECV 0x02 - u_char snp_auth; - u_char passwd[255]; + uint8_t snp_auth; + uint8_t passwd[255]; }; /* * Supported Protocol IDs */ struct nlpids { - u_char count; - u_char nlpids[4]; /* FIXME: enough ? */ + uint8_t count; + uint8_t nlpids[4]; /* FIXME: enough ? */ }; #endif diff --git a/isisd/isis_dlpi.c b/isisd/isis_dlpi.c index ccde4fbbe1..718f3a8982 100644 --- a/isisd/isis_dlpi.c +++ b/isisd/isis_dlpi.c @@ -54,14 +54,14 @@ static t_uscalar_t dlpi_ctl[1024]; /* DLPI control messages */ * ISO 10589 - 8.4.8 */ -u_char ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; -u_char ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; -u_char ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; -u_char ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; +uint8_t ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; +uint8_t ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; +uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; +uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; -static u_char sock_buff[8192]; +static uint8_t sock_buff[8192]; -static u_short pf_filter[] = { +static unsigned short pf_filter[] = { ENF_PUSHWORD + 0, /* Get the SSAP/DSAP values */ ENF_PUSHLIT | ENF_CAND, /* Check them */ ISO_SAP | (ISO_SAP << 8), @@ -248,23 +248,23 @@ static int dlpibind(int fd) return 0; } -static int dlpimcast(int fd, const u_char *mcaddr) +static int dlpimcast(int fd, const uint8_t *mcaddr) { struct { dl_enabmulti_req_t der; - u_char addr[ETHERADDRL]; + uint8_t addr[ETHERADDRL]; } dler; memset(&dler, 0, sizeof(dler)); dler.der.dl_primitive = DL_ENABMULTI_REQ; dler.der.dl_addr_length = sizeof(dler.addr); - dler.der.dl_addr_offset = dler.addr - (u_char *)&dler; + dler.der.dl_addr_offset = dler.addr - (uint8_t *)&dler; memcpy(dler.addr, mcaddr, sizeof(dler.addr)); dlpisend(fd, &dler, sizeof(dler), NULL, 0, 0); return dlpiok(fd, dler.der.dl_primitive); } -static int dlpiaddr(int fd, u_char *addr) +static int dlpiaddr(int fd, uint8_t *addr) { dl_phys_addr_req_t dpar; dl_phys_addr_ack_t *dpaa = (dl_phys_addr_ack_t *)dlpi_ctl; @@ -443,7 +443,7 @@ static int open_dlpi_dev(struct isis_circuit *circuit) struct strioctl sioc; pfil.Pf_Priority = 0; - pfil.Pf_FilterLen = sizeof(pf_filter) / sizeof(u_short); + pfil.Pf_FilterLen = sizeof(pf_filter) / sizeof(unsigned short); memcpy(pfil.Pf_Filter, pf_filter, sizeof(pf_filter)); /* pfmod does not support transparent ioctls */ sioc.ic_cmd = PFIOCSETF; @@ -495,7 +495,7 @@ end: return retval; } -int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa) +int isis_recv_pdu_bcast(struct isis_circuit *circuit, uint8_t *ssnpa) { struct pollfd fds[1]; struct strbuf ctlbuf, databuf; @@ -561,7 +561,7 @@ int isis_send_pdu_bcast(struct isis_circuit *circuit, int level) { dl_unitdata_req_t *dur = (dl_unitdata_req_t *)dlpi_ctl; char *dstaddr; - u_short *dstsap; + unsigned short *dstsap; int buflen; int rv; @@ -583,9 +583,9 @@ int isis_send_pdu_bcast(struct isis_circuit *circuit, int level) dstaddr = (char *)(dur + 1); if (circuit->sap_length < 0) { - dstsap = (u_short *)(dstaddr + ETHERADDRL); + dstsap = (unsigned short *)(dstaddr + ETHERADDRL); } else { - dstsap = (u_short *)dstaddr; + dstsap = (unsigned short *)dstaddr; dstaddr += circuit->sap_length; } if (level == 1) diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c index 84b0bb9739..99506a243d 100644 --- a/isisd/isis_dr.c +++ b/isisd/isis_dr.c @@ -126,7 +126,7 @@ int isis_dr_elect(struct isis_circuit *circuit, int level) struct listnode *node; struct isis_adjacency *adj, *adj_dr = NULL; struct list *list = list_new(); - u_char own_prio; + uint8_t own_prio; int biggest_prio = -1; int cmp_res, retval = ISIS_OK; @@ -223,7 +223,7 @@ int isis_dr_elect(struct isis_circuit *circuit, int level) int isis_dr_resign(struct isis_circuit *circuit, int level) { - u_char id[ISIS_SYS_ID_LEN + 2]; + uint8_t id[ISIS_SYS_ID_LEN + 2]; zlog_debug("isis_dr_resign l%d", level); @@ -274,7 +274,7 @@ int isis_dr_resign(struct isis_circuit *circuit, int level) int isis_dr_commence(struct isis_circuit *circuit, int level) { - u_char old_dr[ISIS_SYS_ID_LEN + 2]; + uint8_t old_dr[ISIS_SYS_ID_LEN + 2]; if (isis->debugs & DEBUG_EVENTS) zlog_debug("isis_dr_commence l%d", level); diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c index 17b043444c..1d29d1086d 100644 --- a/isisd/isis_dynhn.c +++ b/isisd/isis_dynhn.c @@ -76,7 +76,7 @@ static int dyn_cache_cleanup(struct thread *thread) return ISIS_OK; } -struct isis_dynhn *dynhn_find_by_id(const u_char *id) +struct isis_dynhn *dynhn_find_by_id(const uint8_t *id) { struct listnode *node = NULL; struct isis_dynhn *dyn = NULL; @@ -100,7 +100,7 @@ struct isis_dynhn *dynhn_find_by_name(const char *hostname) return NULL; } -void isis_dynhn_insert(const u_char *id, const char *hostname, int level) +void isis_dynhn_insert(const uint8_t *id, const char *hostname, int level) { struct isis_dynhn *dyn; @@ -116,7 +116,7 @@ void isis_dynhn_insert(const u_char *id, const char *hostname, int level) dyn->refresh = time(NULL); } -void isis_dynhn_remove(const u_char *id) +void isis_dynhn_remove(const uint8_t *id) { struct isis_dynhn *dyn; diff --git a/isisd/isis_dynhn.h b/isisd/isis_dynhn.h index 635d79f3f3..27133bd3fd 100644 --- a/isisd/isis_dynhn.h +++ b/isisd/isis_dynhn.h @@ -24,16 +24,16 @@ #define _ZEBRA_ISIS_DYNHN_H struct isis_dynhn { - u_char id[ISIS_SYS_ID_LEN]; + uint8_t id[ISIS_SYS_ID_LEN]; char hostname[256]; time_t refresh; int level; }; void dyn_cache_init(void); -void isis_dynhn_insert(const u_char *id, const char *hostname, int level); -void isis_dynhn_remove(const u_char *id); -struct isis_dynhn *dynhn_find_by_id(const u_char *id); +void isis_dynhn_insert(const uint8_t *id, const char *hostname, int level); +void isis_dynhn_remove(const uint8_t *id); +struct isis_dynhn *dynhn_find_by_id(const uint8_t *id); struct isis_dynhn *dynhn_find_by_name(const char *hostname); void dynhn_print_all(struct vty *vty); diff --git a/isisd/isis_events.c b/isisd/isis_events.c index bc35439926..349ec262c0 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -256,7 +256,7 @@ int isis_event_dis_status_change(struct thread *thread) } void isis_event_auth_failure(char *area_tag, const char *error_string, - u_char *sysid) + uint8_t *sysid) { if (isis->debugs & DEBUG_EVENTS) zlog_debug("ISIS-Evt (%s) Authentication failure %s from %s", diff --git a/isisd/isis_events.h b/isisd/isis_events.h index 0ed2059c65..c3d8cf046f 100644 --- a/isisd/isis_events.h +++ b/isisd/isis_events.h @@ -43,6 +43,6 @@ int isis_event_dis_status_change(struct thread *thread); #define AUTH_ERROR_TYPE_SNP 2 #define AUTH_ERROR_TYPE_HELLO 1 void isis_event_auth_failure(char *area_tag, const char *error_string, - u_char *sysid); + uint8_t *sysid); #endif /* _ZEBRA_ISIS_EVENTS_H */ diff --git a/isisd/isis_flags.c b/isisd/isis_flags.c index e28d90d3db..b1ece94e8e 100644 --- a/isisd/isis_flags.c +++ b/isisd/isis_flags.c @@ -68,9 +68,9 @@ void flags_free_index(struct flags *flags, long int index) return; } -int flags_any_set(u_int32_t *flags) +int flags_any_set(uint32_t *flags) { - u_int32_t zero[ISIS_MAX_CIRCUITS]; + uint32_t zero[ISIS_MAX_CIRCUITS]; memset(zero, 0x00, ISIS_MAX_CIRCUITS * 4); return bcmp(flags, zero, ISIS_MAX_CIRCUITS * 4); diff --git a/isisd/isis_flags.h b/isisd/isis_flags.h index 7d9572a2c2..b3449e1e59 100644 --- a/isisd/isis_flags.h +++ b/isisd/isis_flags.h @@ -39,7 +39,7 @@ struct flags { void flags_initialize(struct flags *flags); long int flags_get_index(struct flags *flags); void flags_free_index(struct flags *flags, long int index); -int flags_any_set(u_int32_t *flags); +int flags_any_set(uint32_t *flags); #define _ISIS_SET_FLAG(F, C) \ { \ diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index b2ba8b3932..95fa38223e 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -63,7 +63,7 @@ static int lsp_l2_refresh(struct thread *thread); static int lsp_l1_refresh_pseudo(struct thread *thread); static int lsp_l2_refresh_pseudo(struct thread *thread); -int lsp_id_cmp(u_char *id1, u_char *id2) +int lsp_id_cmp(uint8_t *id1, uint8_t *id2) { return memcmp(id1, id2, ISIS_SYS_ID_LEN + 2); } @@ -77,7 +77,7 @@ dict_t *lsp_db_init(void) return dict; } -struct isis_lsp *lsp_search(u_char *id, dict_t *lspdb) +struct isis_lsp *lsp_search(uint8_t *id, dict_t *lspdb) { dnode_t *node; @@ -87,7 +87,7 @@ struct isis_lsp *lsp_search(u_char *id, dict_t *lspdb) zlog_debug("searching db"); for (dn = dict_first(lspdb); dn; dn = dict_next(lspdb, dn)) { zlog_debug("%s\t%pX", - rawlspid_print((u_char *)dnode_getkey(dn)), + rawlspid_print((uint8_t *)dnode_getkey(dn)), dnode_get(dn)); } #endif /* EXTREME DEBUG */ @@ -176,7 +176,7 @@ static void lsp_remove_frags(struct list *frags, dict_t *lspdb) return; } -void lsp_search_and_destroy(u_char *id, dict_t *lspdb) +void lsp_search_and_destroy(uint8_t *id, dict_t *lspdb) { dnode_t *node; struct isis_lsp *lsp; @@ -392,9 +392,9 @@ static void lsp_seqno_update(struct isis_lsp *lsp0) return; } -static u_int8_t lsp_bits_generate(int level, int overload_bit, int attached_bit) +static uint8_t lsp_bits_generate(int level, int overload_bit, int attached_bit) { - u_int8_t lsp_bits = 0; + uint8_t lsp_bits = 0; if (level == IS_LEVEL_1) lsp_bits = IS_LEVEL_1; else @@ -498,7 +498,7 @@ struct isis_lsp *lsp_new_from_recv(struct isis_lsp_hdr *hdr, return lsp; } -struct isis_lsp *lsp_new(struct isis_area *area, u_char *lsp_id, +struct isis_lsp *lsp_new(struct isis_area *area, uint8_t *lsp_id, uint16_t rem_lifetime, uint32_t seqno, uint8_t lsp_bits, uint16_t checksum, struct isis_lsp *lsp0, int level) @@ -541,7 +541,7 @@ void lsp_insert(struct isis_lsp *lsp, dict_t *lspdb) /* * Build a list of LSPs with non-zero ht bounded by start and stop ids */ -void lsp_build_list_nonzero_ht(u_char *start_id, u_char *stop_id, +void lsp_build_list_nonzero_ht(uint8_t *start_id, uint8_t *stop_id, struct list *list, dict_t *lspdb) { dnode_t *first, *last, *curr; @@ -584,10 +584,10 @@ static void lsp_set_time(struct isis_lsp *lsp) stream_putw_at(lsp->pdu, 10, lsp->hdr.rem_lifetime); } -static void lspid_print(u_char *lsp_id, u_char *trg, char dynhost, char frag) +static void lspid_print(uint8_t *lsp_id, uint8_t *trg, char dynhost, char frag) { struct isis_dynhn *dyn = NULL; - u_char id[SYSID_STRLEN]; + uint8_t id[SYSID_STRLEN]; if (dynhost) dyn = dynhn_find_by_id(lsp_id); @@ -632,7 +632,7 @@ static const char *lsp_bits2string(uint8_t lsp_bits) /* this function prints the lsp on show isis database */ void lsp_print(struct isis_lsp *lsp, struct vty *vty, char dynhost) { - u_char LSPid[255]; + uint8_t LSPid[255]; char age_out[8]; lspid_print(lsp->hdr.lsp_id, LSPid, dynhost, 1); @@ -685,9 +685,9 @@ int lsp_print_all(struct vty *vty, dict_t *lspdb, char detail, char dynhost) return lsp_count; } -static u_int16_t lsp_rem_lifetime(struct isis_area *area, int level) +static uint16_t lsp_rem_lifetime(struct isis_area *area, int level) { - u_int16_t rem_lifetime; + uint16_t rem_lifetime; /* Add jitter to configured LSP lifetime */ rem_lifetime = @@ -704,11 +704,11 @@ static u_int16_t lsp_rem_lifetime(struct isis_area *area, int level) return rem_lifetime; } -static u_int16_t lsp_refresh_time(struct isis_lsp *lsp, u_int16_t rem_lifetime) +static uint16_t lsp_refresh_time(struct isis_lsp *lsp, uint16_t rem_lifetime) { struct isis_area *area = lsp->area; int level = lsp->level; - u_int16_t refresh_time; + uint16_t refresh_time; /* Add jitter to LSP refresh time */ refresh_time = @@ -1147,9 +1147,9 @@ static void lsp_build(struct isis_lsp *lsp, struct isis_area *area) int lsp_generate(struct isis_area *area, int level) { struct isis_lsp *oldlsp, *newlsp; - u_int32_t seq_num = 0; - u_char lspid[ISIS_SYS_ID_LEN + 2]; - u_int16_t rem_lifetime, refresh_time; + uint32_t seq_num = 0; + uint8_t lspid[ISIS_SYS_ID_LEN + 2]; + uint16_t rem_lifetime, refresh_time; if ((area == NULL) || (area->is_type & level) != level) return ISIS_ERROR; @@ -1217,8 +1217,8 @@ static int lsp_regenerate(struct isis_area *area, int level) dict_t *lspdb; struct isis_lsp *lsp, *frag; struct listnode *node; - u_char lspid[ISIS_SYS_ID_LEN + 2]; - u_int16_t rem_lifetime, refresh_time; + uint8_t lspid[ISIS_SYS_ID_LEN + 2]; + uint16_t rem_lifetime, refresh_time; if ((area == NULL) || (area->is_type & level) != level) return ISIS_ERROR; @@ -1324,7 +1324,7 @@ static int lsp_l2_refresh(struct thread *thread) int lsp_regenerate_schedule(struct isis_area *area, int level, int all_pseudo) { struct isis_lsp *lsp; - u_char id[ISIS_SYS_ID_LEN + 2]; + uint8_t id[ISIS_SYS_ID_LEN + 2]; time_t now, diff; long timeout; struct listnode *cnode; @@ -1521,8 +1521,8 @@ int lsp_generate_pseudo(struct isis_circuit *circuit, int level) { dict_t *lspdb = circuit->area->lspdb[level - 1]; struct isis_lsp *lsp; - u_char lsp_id[ISIS_SYS_ID_LEN + 2]; - u_int16_t rem_lifetime, refresh_time; + uint8_t lsp_id[ISIS_SYS_ID_LEN + 2]; + uint16_t rem_lifetime, refresh_time; if ((circuit->is_type & level) != level || (circuit->state != C_STATE_UP) @@ -1583,8 +1583,8 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level) { dict_t *lspdb = circuit->area->lspdb[level - 1]; struct isis_lsp *lsp; - u_char lsp_id[ISIS_SYS_ID_LEN + 2]; - u_int16_t rem_lifetime, refresh_time; + uint8_t lsp_id[ISIS_SYS_ID_LEN + 2]; + uint16_t rem_lifetime, refresh_time; if ((circuit->is_type & level) != level || (circuit->state != C_STATE_UP) @@ -1641,7 +1641,7 @@ static int lsp_regenerate_pseudo(struct isis_circuit *circuit, int level) static int lsp_l1_refresh_pseudo(struct thread *thread) { struct isis_circuit *circuit; - u_char id[ISIS_SYS_ID_LEN + 2]; + uint8_t id[ISIS_SYS_ID_LEN + 2]; circuit = THREAD_ARG(thread); @@ -1663,7 +1663,7 @@ static int lsp_l1_refresh_pseudo(struct thread *thread) static int lsp_l2_refresh_pseudo(struct thread *thread) { struct isis_circuit *circuit; - u_char id[ISIS_SYS_ID_LEN + 2]; + uint8_t id[ISIS_SYS_ID_LEN + 2]; circuit = THREAD_ARG(thread); @@ -1685,7 +1685,7 @@ static int lsp_l2_refresh_pseudo(struct thread *thread) int lsp_regenerate_schedule_pseudo(struct isis_circuit *circuit, int level) { struct isis_lsp *lsp; - u_char lsp_id[ISIS_SYS_ID_LEN + 2]; + uint8_t lsp_id[ISIS_SYS_ID_LEN + 2]; time_t now, diff; long timeout; int lvl; @@ -1796,7 +1796,7 @@ int lsp_tick(struct thread *thread) struct listnode *lspnode, *cnode; dnode_t *dnode, *dnode_next; int level; - u_int16_t rem_lifetime; + uint16_t rem_lifetime; time_t now = monotime(NULL); lsp_list = list_new(); @@ -1905,7 +1905,7 @@ int lsp_tick(struct thread *thread) return ISIS_OK; } -void lsp_purge_pseudo(u_char *id, struct isis_circuit *circuit, int level) +void lsp_purge_pseudo(uint8_t *id, struct isis_circuit *circuit, int level) { struct isis_lsp *lsp; diff --git a/isisd/isis_lsp.h b/isisd/isis_lsp.h index 550e7a0645..d531cb1576 100644 --- a/isisd/isis_lsp.h +++ b/isisd/isis_lsp.h @@ -37,8 +37,8 @@ struct isis_lsp { struct list *frags; struct isis_lsp *zero_lsp; } lspu; - u_int32_t SRMflags[ISIS_MAX_CIRCUITS]; - u_int32_t SSNflags[ISIS_MAX_CIRCUITS]; + uint32_t SRMflags[ISIS_MAX_CIRCUITS]; + uint32_t SSNflags[ISIS_MAX_CIRCUITS]; int level; /* L1 or L2? */ int scheduled; /* scheduled for sending */ time_t installed; @@ -68,14 +68,14 @@ struct isis_lsp *lsp_new_from_recv(struct isis_lsp_hdr *hdr, struct stream *stream, struct isis_lsp *lsp0, struct isis_area *area, int level); void lsp_insert(struct isis_lsp *lsp, dict_t *lspdb); -struct isis_lsp *lsp_search(u_char *id, dict_t *lspdb); +struct isis_lsp *lsp_search(uint8_t *id, dict_t *lspdb); -void lsp_build_list(u_char *start_id, u_char *stop_id, u_char num_lsps, +void lsp_build_list(uint8_t *start_id, uint8_t *stop_id, uint8_t num_lsps, struct list *list, dict_t *lspdb); -void lsp_build_list_nonzero_ht(u_char *start_id, u_char *stop_id, +void lsp_build_list_nonzero_ht(uint8_t *start_id, uint8_t *stop_id, struct list *list, dict_t *lspdb); -void lsp_search_and_destroy(u_char *id, dict_t *lspdb); -void lsp_purge_pseudo(u_char *id, struct isis_circuit *circuit, int level); +void lsp_search_and_destroy(uint8_t *id, dict_t *lspdb); +void lsp_purge_pseudo(uint8_t *id, struct isis_circuit *circuit, int level); void lsp_purge_non_exist(int level, struct isis_lsp_hdr *hdr, struct isis_area *area); @@ -89,7 +89,7 @@ void lsp_purge_non_exist(int level, struct isis_lsp_hdr *hdr, memcpy((I), isis->sysid, ISIS_SYS_ID_LEN); \ (I)[ISIS_SYS_ID_LEN] = 0; \ (I)[ISIS_SYS_ID_LEN + 1] = 0 -int lsp_id_cmp(u_char *id1, u_char *id2); +int lsp_id_cmp(uint8_t *id1, uint8_t *id2); int lsp_compare(char *areatag, struct isis_lsp *lsp, uint32_t seqno, uint16_t checksum, uint16_t rem_lifetime); void lsp_update(struct isis_lsp *lsp, struct isis_lsp_hdr *hdr, diff --git a/isisd/isis_misc.c b/isisd/isis_misc.c index 0a1d9aaa1a..c24917454a 100644 --- a/isisd/isis_misc.c +++ b/isisd/isis_misc.c @@ -56,7 +56,7 @@ char nlpidstring[30]; /* * This converts the isonet to its printable format */ -const char *isonet_print(const u_char *from, int len) +const char *isonet_print(const uint8_t *from, int len) { int i = 0; char *pos = isonet; @@ -87,11 +87,11 @@ const char *isonet_print(const u_char *from, int len) * Returns 0 on error, length of buff on ok * extract dot from the dotted str, and insert all the number in a buff */ -int dotformat2buff(u_char *buff, const char *dotted) +int dotformat2buff(uint8_t *buff, const char *dotted) { int dotlen, len = 0; const char *pos = dotted; - u_char number[3]; + uint8_t number[3]; int nextdotpos = 2; number[2] = '\0'; @@ -136,11 +136,11 @@ int dotformat2buff(u_char *buff, const char *dotted) /* * conversion of XXXX.XXXX.XXXX to memory */ -int sysid2buff(u_char *buff, const char *dotted) +int sysid2buff(uint8_t *buff, const char *dotted) { int len = 0; const char *pos = dotted; - u_char number[3]; + uint8_t number[3]; number[2] = '\0'; // surely not a sysid_string if not 14 length @@ -304,17 +304,17 @@ const char *syst2string(int type) /* * Print functions - we print to static vars */ -const char *snpa_print(const u_char *from) +const char *snpa_print(const uint8_t *from) { return isis_format_id(from, ISIS_SYS_ID_LEN); } -const char *sysid_print(const u_char *from) +const char *sysid_print(const uint8_t *from) { return isis_format_id(from, ISIS_SYS_ID_LEN); } -const char *rawlspid_print(const u_char *from) +const char *rawlspid_print(const uint8_t *from) { return isis_format_id(from, 8); } @@ -355,10 +355,10 @@ const char *isis_format_id(const uint8_t *id, size_t len) return rv; } -const char *time2string(u_int32_t time) +const char *time2string(uint32_t time) { char *pos = datestring; - u_int32_t rest; + uint32_t rest; if (time == 0) return "-"; @@ -421,7 +421,7 @@ unsigned long isis_jitter(unsigned long timer, unsigned long jitter) return timer; } -struct in_addr newprefix2inaddr(u_char *prefix_start, u_char prefix_masklen) +struct in_addr newprefix2inaddr(uint8_t *prefix_start, uint8_t prefix_masklen) { memset(&new_prefix, 0, sizeof(new_prefix)); memcpy(&new_prefix, prefix_start, @@ -435,7 +435,7 @@ struct in_addr newprefix2inaddr(u_char *prefix_start, u_char prefix_masklen) * Returns the dynamic hostname associated with the passed system ID. * If no dynamic hostname found then returns formatted system ID. */ -const char *print_sys_hostname(const u_char *sysid) +const char *print_sys_hostname(const uint8_t *sysid) { struct isis_dynhn *dyn; diff --git a/isisd/isis_misc.h b/isisd/isis_misc.h index b81db34df6..c551fde7d1 100644 --- a/isisd/isis_misc.h +++ b/isisd/isis_misc.h @@ -29,27 +29,27 @@ const char *circuit_t2string(int); const char *circuit_state2string(int state); const char *circuit_type2string(int type); const char *syst2string(int); -struct in_addr newprefix2inaddr(u_char *prefix_start, u_char prefix_masklen); +struct in_addr newprefix2inaddr(uint8_t *prefix_start, uint8_t prefix_masklen); /* * Converting input to memory stored format * return value of 0 indicates wrong input */ -int dotformat2buff(u_char *, const char *); -int sysid2buff(u_char *, const char *); +int dotformat2buff(uint8_t *, const char *); +int sysid2buff(uint8_t *, const char *); /* * Printing functions */ -const char *isonet_print(const u_char *, int len); -const char *sysid_print(const u_char *); -const char *snpa_print(const u_char *); -const char *rawlspid_print(const u_char *); +const char *isonet_print(const uint8_t *, int len); +const char *sysid_print(const uint8_t *); +const char *snpa_print(const uint8_t *); +const char *rawlspid_print(const uint8_t *); const char *isis_format_id(const uint8_t *id, size_t len); -const char *time2string(u_int32_t); +const char *time2string(uint32_t); const char *nlpid2str(uint8_t nlpid); /* typedef struct nlpids nlpids; */ char *nlpid2string(struct nlpids *); -const char *print_sys_hostname(const u_char *sysid); +const char *print_sys_hostname(const uint8_t *sysid); void zlog_dump_data(void *data, int len); /* diff --git a/isisd/isis_network.h b/isisd/isis_network.h index 4b25316062..cc8605d2e9 100644 --- a/isisd/isis_network.h +++ b/isisd/isis_network.h @@ -24,13 +24,13 @@ #ifndef _ZEBRA_ISIS_NETWORK_H #define _ZEBRA_ISIS_NETWORK_H -extern u_char ALL_L1_ISYSTEMS[]; -extern u_char ALL_L2_ISYSTEMS[]; +extern uint8_t ALL_L1_ISYSTEMS[]; +extern uint8_t ALL_L2_ISYSTEMS[]; int isis_sock_init(struct isis_circuit *circuit); -int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa); -int isis_recv_pdu_p2p(struct isis_circuit *circuit, u_char *ssnpa); +int isis_recv_pdu_bcast(struct isis_circuit *circuit, uint8_t *ssnpa); +int isis_recv_pdu_p2p(struct isis_circuit *circuit, uint8_t *ssnpa); int isis_send_pdu_bcast(struct isis_circuit *circuit, int level); int isis_send_pdu_p2p(struct isis_circuit *circuit, int level); diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index ebcf197a37..7a6c4dd2dc 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -60,7 +60,7 @@ static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit, { unsigned long lenp; int retval; - u_int16_t length; + uint16_t length; uint8_t pdu_type = (level == IS_LEVEL_1) ? L1_PARTIAL_SEQ_NUM : L2_PARTIAL_SEQ_NUM; @@ -80,7 +80,7 @@ static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit, stream_putl(circuit->snd_stream, hdr->seqno); stream_putw(circuit->snd_stream, hdr->checksum); - length = (u_int16_t)stream_get_endp(circuit->snd_stream); + length = (uint16_t)stream_get_endp(circuit->snd_stream); /* Update PDU length */ stream_putw_at(circuit->snd_stream, lenp, length); @@ -99,7 +99,7 @@ static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit, struct iih_info { struct isis_circuit *circuit; - u_char *ssnpa; + uint8_t *ssnpa; int level; uint8_t circ_type; @@ -462,9 +462,9 @@ static int process_lan_hello(struct iih_info *iih) } if (adj->dis_record[iih->level - 1].dis == ISIS_IS_DIS) { - u_char *dis = (iih->level == 1) - ? iih->circuit->u.bc.l1_desig_is - : iih->circuit->u.bc.l2_desig_is; + uint8_t *dis = (iih->level == 1) + ? iih->circuit->u.bc.l1_desig_is + : iih->circuit->u.bc.l2_desig_is; if (memcmp(dis, iih->dis, ISIS_SYS_ID_LEN + 1)) { thread_add_event(master, isis_event_dis_status_change, @@ -538,7 +538,7 @@ static int pdu_len_validate(uint16_t pdu_len, struct isis_circuit *circuit) } static int process_hello(uint8_t pdu_type, struct isis_circuit *circuit, - u_char *ssnpa) + uint8_t *ssnpa) { bool p2p_hello = (pdu_type == P2P_HELLO); int level = p2p_hello ? 0 @@ -689,7 +689,7 @@ out: * Section 7.3.15.1 - Action on receipt of a link state PDU */ static int process_lsp(uint8_t pdu_type, struct isis_circuit *circuit, - const u_char *ssnpa) + const uint8_t *ssnpa) { int level = (pdu_type == L1_LINK_STATE) ? ISIS_LEVEL1 : ISIS_LEVEL2; @@ -1052,7 +1052,7 @@ out: */ static int process_snp(uint8_t pdu_type, struct isis_circuit *circuit, - const u_char *ssnpa) + const uint8_t *ssnpa) { bool is_csnp = (pdu_type == L1_COMPLETE_SEQ_NUM || pdu_type == L2_COMPLETE_SEQ_NUM); @@ -1337,7 +1337,7 @@ static int pdu_size(uint8_t pdu_type, uint8_t *size) * PDU Dispatcher */ -int isis_handle_pdu(struct isis_circuit *circuit, u_char *ssnpa) +int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa) { int retval = ISIS_OK; @@ -1445,7 +1445,7 @@ int isis_handle_pdu(struct isis_circuit *circuit, u_char *ssnpa) int isis_receive(struct thread *thread) { struct isis_circuit *circuit; - u_char ssnpa[ETH_ALEN]; + uint8_t ssnpa[ETH_ALEN]; int retval; /* @@ -1522,9 +1522,9 @@ static void put_hello_hdr(struct isis_circuit *circuit, int level, stream_putw(circuit->snd_stream, 0); /* length is filled in later */ if (circuit->circ_type == CIRCUIT_T_BROADCAST) { - u_char *desig_is = (level == IS_LEVEL_1) - ? circuit->u.bc.l1_desig_is - : circuit->u.bc.l2_desig_is; + uint8_t *desig_is = (level == IS_LEVEL_1) + ? circuit->u.bc.l1_desig_is + : circuit->u.bc.l2_desig_is; stream_putc(circuit->snd_stream, circuit->priority[level - 1]); stream_put(circuit->snd_stream, desig_is, ISIS_SYS_ID_LEN + 1); } else { @@ -1847,7 +1847,7 @@ int send_csnp(struct isis_circuit *circuit, int level) memcpy(start, stop, ISIS_SYS_ID_LEN + 2); loop = 0; for (int i = ISIS_SYS_ID_LEN + 1; i >= 0; --i) { - if (start[i] < (u_char)0xff) { + if (start[i] < (uint8_t)0xff) { start[i] += 1; loop = 1; break; diff --git a/isisd/isis_pdu.h b/isisd/isis_pdu.h index 2d9100c10b..c69bfedeae 100644 --- a/isisd/isis_pdu.h +++ b/isisd/isis_pdu.h @@ -50,13 +50,13 @@ */ struct esis_fixed_hdr { - u_char idrp; - u_char length; - u_char version; - u_char id_len; - u_char pdu_type; - u_int16_t holdtime; - u_int16_t checksum; + uint8_t idrp; + uint8_t length; + uint8_t version; + uint8_t id_len; + uint8_t pdu_type; + uint16_t holdtime; + uint16_t checksum; } __attribute__((packed)); #define ESIS_FIXED_HDR_LEN 9 @@ -90,12 +90,12 @@ struct esis_fixed_hdr { * +-------+-------+-------+-------+-------+-------+-------+-------+ */ struct isis_lan_hello_hdr { - u_char circuit_t; - u_char source_id[ISIS_SYS_ID_LEN]; - u_int16_t hold_time; - u_int16_t pdu_len; - u_char prio; - u_char lan_id[ISIS_SYS_ID_LEN + 1]; + uint8_t circuit_t; + uint8_t source_id[ISIS_SYS_ID_LEN]; + uint16_t hold_time; + uint16_t pdu_len; + uint8_t prio; + uint8_t lan_id[ISIS_SYS_ID_LEN + 1]; } __attribute__((packed)); #define ISIS_LANHELLO_HDRLEN 19 @@ -115,11 +115,11 @@ struct isis_lan_hello_hdr { * +-------+-------+-------+-------+-------+-------+-------+-------+ */ struct isis_p2p_hello_hdr { - u_char circuit_t; - u_char source_id[ISIS_SYS_ID_LEN]; - u_int16_t hold_time; - u_int16_t pdu_len; - u_char local_id; + uint8_t circuit_t; + uint8_t source_id[ISIS_SYS_ID_LEN]; + uint16_t hold_time; + uint16_t pdu_len; + uint8_t local_id; } __attribute__((packed)); #define ISIS_P2PHELLO_HDRLEN 12 @@ -161,10 +161,10 @@ struct isis_lsp_hdr { * +-------+-------+-------+-------+-------+-------+-------+-------+ */ struct isis_complete_seqnum_hdr { - u_int16_t pdu_len; - u_char source_id[ISIS_SYS_ID_LEN + 1]; - u_char start_lsp_id[ISIS_SYS_ID_LEN + 2]; - u_char stop_lsp_id[ISIS_SYS_ID_LEN + 2]; + uint16_t pdu_len; + uint8_t source_id[ISIS_SYS_ID_LEN + 1]; + uint8_t start_lsp_id[ISIS_SYS_ID_LEN + 2]; + uint8_t stop_lsp_id[ISIS_SYS_ID_LEN + 2]; }; #define ISIS_CSNP_HDRLEN 25 @@ -179,8 +179,8 @@ struct isis_complete_seqnum_hdr { * +---------------------------------------------------------------+ */ struct isis_partial_seqnum_hdr { - u_int16_t pdu_len; - u_char source_id[ISIS_SYS_ID_LEN + 1]; + uint16_t pdu_len; + uint8_t source_id[ISIS_SYS_ID_LEN + 1]; }; #define ISIS_PSNP_HDRLEN 9 @@ -215,5 +215,5 @@ int send_l2_psnp(struct thread *thread); int send_lsp(struct thread *thread); void fill_fixed_hdr(uint8_t pdu_type, struct stream *stream); int send_hello(struct isis_circuit *circuit, int level); -int isis_handle_pdu(struct isis_circuit *circuit, u_char *ssnpa); +int isis_handle_pdu(struct isis_circuit *circuit, uint8_t *ssnpa); #endif /* _ZEBRA_ISIS_PDU_H */ diff --git a/isisd/isis_pfpacket.c b/isisd/isis_pfpacket.c index 852ad49c8a..6e56870ebd 100644 --- a/isisd/isis_pfpacket.c +++ b/isisd/isis_pfpacket.c @@ -67,10 +67,10 @@ static struct sock_fprog bpf = { * ISO 10589 - 8.4.8 */ -u_char ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; -u_char ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; -u_char ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; -u_char ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; +uint8_t ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14}; +uint8_t ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15}; +uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; +uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; static uint8_t discard_buff[8192]; static uint8_t sock_buff[8192]; @@ -216,7 +216,7 @@ end: return retval; } -static inline int llc_check(u_char *llc) +static inline int llc_check(uint8_t *llc) { if (*llc != ISO_SAP || *(llc + 1) != ISO_SAP || *(llc + 2) != 3) return 0; @@ -224,11 +224,11 @@ static inline int llc_check(u_char *llc) return 1; } -int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa) +int isis_recv_pdu_bcast(struct isis_circuit *circuit, uint8_t *ssnpa) { int bytesread, addr_len; struct sockaddr_ll s_addr; - u_char llc[LLC_LEN]; + uint8_t llc[LLC_LEN]; addr_len = sizeof(s_addr); @@ -300,7 +300,7 @@ int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa) return ISIS_OK; } -int isis_recv_pdu_p2p(struct isis_circuit *circuit, u_char *ssnpa) +int isis_recv_pdu_p2p(struct isis_circuit *circuit, uint8_t *ssnpa) { int bytesread, addr_len; struct sockaddr_ll s_addr; diff --git a/isisd/isis_redist.c b/isisd/isis_redist.c index 48fcf449c7..9c61512df4 100644 --- a/isisd/isis_redist.c +++ b/isisd/isis_redist.c @@ -239,7 +239,7 @@ static void isis_redist_ensure_default(struct isis *isis, int family) } /* Handle notification about route being added */ -void isis_redist_add(int type, struct prefix *p, u_char distance, +void isis_redist_add(int type, struct prefix *p, uint8_t distance, uint32_t metric) { int family = p->family; diff --git a/isisd/isis_redist.h b/isisd/isis_redist.h index 2bd40e849c..c12363d508 100644 --- a/isisd/isis_redist.h +++ b/isisd/isis_redist.h @@ -30,7 +30,7 @@ struct isis_ext_info { int origin; uint32_t metric; - u_char distance; + uint8_t distance; }; struct isis_redist { @@ -46,7 +46,7 @@ struct vty; struct route_table *get_ext_reach(struct isis_area *area, int family, int level); -void isis_redist_add(int type, struct prefix *p, u_char distance, +void isis_redist_add(int type, struct prefix *p, uint8_t distance, uint32_t metric); void isis_redist_delete(int type, struct prefix *p); int isis_redist_config_write(struct vty *vty, struct isis_area *area, diff --git a/isisd/isis_route.c b/isisd/isis_route.c index ad769f9886..c98e16e2bd 100644 --- a/isisd/isis_route.c +++ b/isisd/isis_route.c @@ -273,7 +273,7 @@ static int isis_route_info_same_attrib(struct isis_route_info *new, } static int isis_route_info_same(struct isis_route_info *new, - struct isis_route_info *old, u_char family) + struct isis_route_info *old, uint8_t family) { struct listnode *node; struct isis_nexthop *nexthop; @@ -317,15 +317,15 @@ static int isis_route_info_same(struct isis_route_info *new, return 1; } -struct isis_route_info *isis_route_create(struct prefix *prefix, u_int32_t cost, - u_int32_t depth, +struct isis_route_info *isis_route_create(struct prefix *prefix, uint32_t cost, + uint32_t depth, struct list *adjacencies, struct isis_area *area, int level) { struct route_node *route_node; struct isis_route_info *rinfo_new, *rinfo_old, *route_info = NULL; char buff[PREFIX2STR_BUFFER]; - u_char family; + uint8_t family; family = prefix->family; /* for debugs */ diff --git a/isisd/isis_route.h b/isisd/isis_route.h index 6c7d9aea95..82f37c29f2 100644 --- a/isisd/isis_route.h +++ b/isisd/isis_route.h @@ -43,15 +43,15 @@ struct isis_route_info { #define ISIS_ROUTE_FLAG_ACTIVE 0x01 /* active route for the prefix */ #define ISIS_ROUTE_FLAG_ZEBRA_SYNCED 0x02 /* set when route synced to zebra */ #define ISIS_ROUTE_FLAG_ZEBRA_RESYNC 0x04 /* set when route needs to sync */ - u_char flag; - u_int32_t cost; - u_int32_t depth; + uint8_t flag; + uint32_t cost; + uint32_t depth; struct list *nexthops; struct list *nexthops6; }; -struct isis_route_info *isis_route_create(struct prefix *prefix, u_int32_t cost, - u_int32_t depth, +struct isis_route_info *isis_route_create(struct prefix *prefix, uint32_t cost, + uint32_t depth, struct list *adjacencies, struct isis_area *area, int level); diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index dc86d4c105..a55a0e1902 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -81,12 +81,12 @@ struct isis_vertex { enum vertextype type; union { - u_char id[ISIS_SYS_ID_LEN + 1]; + uint8_t id[ISIS_SYS_ID_LEN + 1]; struct prefix prefix; } N; - u_int32_t d_N; /* d(N) Distance from this IS */ - u_int16_t depth; /* The depth in the imaginary tree */ + uint32_t d_N; /* d(N) Distance from this IS */ + uint16_t depth; /* The depth in the imaginary tree */ struct list *Adj_N; /* {Adj(N)} next hop or neighbor list */ struct list *parents; /* list of parents for ECMP */ uint64_t insert_counter; @@ -413,7 +413,7 @@ static void isis_vertex_id_init(struct isis_vertex *vertex, void *id, vertex->type = vtype; if (VTYPE_IS(vtype) || VTYPE_ES(vtype)) { - memcpy(vertex->N.id, (u_char *)id, ISIS_SYS_ID_LEN + 1); + memcpy(vertex->N.id, (uint8_t *)id, ISIS_SYS_ID_LEN + 1); } else if (VTYPE_IP(vtype)) { memcpy(&vertex->N.prefix, (struct prefix *)id, sizeof(struct prefix)); @@ -573,10 +573,10 @@ void spftree_area_adj_del(struct isis_area *area, struct isis_adjacency *adj) * associated with the given system ID. */ static struct isis_lsp *isis_root_system_lsp(struct isis_area *area, int level, - u_char *sysid) + uint8_t *sysid) { struct isis_lsp *lsp; - u_char lspid[ISIS_SYS_ID_LEN + 2]; + uint8_t lspid[ISIS_SYS_ID_LEN + 2]; memcpy(lspid, sysid, ISIS_SYS_ID_LEN); LSP_PSEUDO_ID(lspid) = 0; @@ -591,14 +591,14 @@ static struct isis_lsp *isis_root_system_lsp(struct isis_area *area, int level, * Add this IS to the root of SPT */ static struct isis_vertex *isis_spf_add_root(struct isis_spftree *spftree, - u_char *sysid) + uint8_t *sysid) { struct isis_vertex *vertex; struct isis_lsp *lsp; #ifdef EXTREME_DEBUG char buff[PREFIX2STR_BUFFER]; #endif /* EXTREME_DEBUG */ - u_char id[ISIS_SYS_ID_LEN + 1]; + uint8_t id[ISIS_SYS_ID_LEN + 1]; memcpy(id, sysid, ISIS_SYS_ID_LEN); LSP_PSEUDO_ID(id) = 0; @@ -805,14 +805,14 @@ static void process_N(struct isis_spftree *spftree, enum vertextype vtype, */ static int isis_spf_process_lsp(struct isis_spftree *spftree, struct isis_lsp *lsp, uint32_t cost, - uint16_t depth, u_char *root_sysid, + uint16_t depth, uint8_t *root_sysid, struct isis_vertex *parent) { bool pseudo_lsp = LSP_PSEUDO_ID(lsp->hdr.lsp_id); struct listnode *fragnode = NULL; uint32_t dist; enum vertextype vtype; - static const u_char null_sysid[ISIS_SYS_ID_LEN]; + static const uint8_t null_sysid[ISIS_SYS_ID_LEN]; struct isis_mt_router_info *mt_router_info = NULL; if (!lsp->tlvs) @@ -973,7 +973,8 @@ lspfragloop: } static int isis_spf_preload_tent(struct isis_spftree *spftree, - u_char *root_sysid, struct isis_vertex *parent) + uint8_t *root_sysid, + struct isis_vertex *parent) { struct isis_circuit *circuit; struct listnode *cnode, *anode, *ipnode; @@ -984,8 +985,8 @@ static int isis_spf_preload_tent(struct isis_spftree *spftree, struct prefix_ipv4 *ipv4; struct prefix prefix; int retval = ISIS_OK; - u_char lsp_id[ISIS_SYS_ID_LEN + 2]; - static u_char null_lsp_id[ISIS_SYS_ID_LEN + 2]; + uint8_t lsp_id[ISIS_SYS_ID_LEN + 2]; + static uint8_t null_lsp_id[ISIS_SYS_ID_LEN + 2]; struct prefix_ipv6 *ipv6; struct isis_circuit_mt_setting *circuit_mt; @@ -1252,13 +1253,13 @@ static void init_spt(struct isis_spftree *spftree, int mtid, int level, } static int isis_run_spf(struct isis_area *area, int level, int family, - u_char *sysid, struct timeval *nowtv) + uint8_t *sysid, struct timeval *nowtv) { int retval = ISIS_OK; struct isis_vertex *vertex; struct isis_vertex *root_vertex; struct isis_spftree *spftree = NULL; - u_char lsp_id[ISIS_SYS_ID_LEN + 2]; + uint8_t lsp_id[ISIS_SYS_ID_LEN + 2]; struct isis_lsp *lsp; struct route_table *table = NULL; struct timeval time_now; @@ -1446,7 +1447,7 @@ int isis_spf_schedule(struct isis_area *area, int level) } static void isis_print_paths(struct vty *vty, struct isis_vertex_queue *queue, - u_char *root_sysid) + uint8_t *root_sysid) { struct listnode *node; struct isis_vertex *vertex; @@ -1586,7 +1587,7 @@ void isis_spf_print(struct isis_spftree *spftree, struct vty *vty) vty_out(vty, "\n"); vty_out(vty, " last run duration : %u usec\n", - (u_int32_t)spftree->last_run_duration); + (uint32_t)spftree->last_run_duration); vty_out(vty, " run count : %u\n", spftree->runcount); } diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 5de936a6ea..d7d9ad0d43 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -316,7 +316,7 @@ uint8_t subtlvs_len(struct mpls_te_circuit *mtc) /* Following are various functions to set MPLS TE parameters */ static void set_circuitparams_admin_grp(struct mpls_te_circuit *mtc, - u_int32_t admingrp) + uint32_t admingrp) { SUBTLV_TYPE(mtc->admin_grp) = TE_SUBTLV_ADMIN_GRP; SUBTLV_LEN(mtc->admin_grp) = SUBTLV_DEF_SIZE; @@ -325,8 +325,8 @@ static void set_circuitparams_admin_grp(struct mpls_te_circuit *mtc, } static void __attribute__((unused)) -set_circuitparams_llri(struct mpls_te_circuit *mtc, u_int32_t local, - u_int32_t remote) +set_circuitparams_llri(struct mpls_te_circuit *mtc, uint32_t local, + uint32_t remote) { SUBTLV_TYPE(mtc->llri) = TE_SUBTLV_LLRI; SUBTLV_LEN(mtc->llri) = TE_SUBTLV_LLRI_SIZE; @@ -381,7 +381,7 @@ static void set_circuitparams_unrsv_bw(struct mpls_te_circuit *mtc, } static void set_circuitparams_te_metric(struct mpls_te_circuit *mtc, - u_int32_t te_metric) + uint32_t te_metric) { SUBTLV_TYPE(mtc->te_metric) = TE_SUBTLV_TE_METRIC; SUBTLV_LEN(mtc->te_metric) = TE_SUBTLV_TE_METRIC_SIZE; @@ -392,7 +392,7 @@ static void set_circuitparams_te_metric(struct mpls_te_circuit *mtc, } static void set_circuitparams_inter_as(struct mpls_te_circuit *mtc, - struct in_addr addr, u_int32_t as) + struct in_addr addr, uint32_t as) { /* Set the Remote ASBR IP address and then the associated AS number */ @@ -419,9 +419,9 @@ static void unset_circuitparams_inter_as(struct mpls_te_circuit *mtc) } static void set_circuitparams_av_delay(struct mpls_te_circuit *mtc, - u_int32_t delay, u_char anormal) + uint32_t delay, uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ SUBTLV_TYPE(mtc->av_delay) = TE_SUBTLV_AV_DELAY; SUBTLV_LEN(mtc->av_delay) = SUBTLV_DEF_SIZE; @@ -433,10 +433,10 @@ static void set_circuitparams_av_delay(struct mpls_te_circuit *mtc, } static void set_circuitparams_mm_delay(struct mpls_te_circuit *mtc, - u_int32_t low, u_int32_t high, - u_char anormal) + uint32_t low, uint32_t high, + uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ SUBTLV_TYPE(mtc->mm_delay) = TE_SUBTLV_MM_DELAY; SUBTLV_LEN(mtc->mm_delay) = TE_SUBTLV_MM_DELAY_SIZE; @@ -449,7 +449,7 @@ static void set_circuitparams_mm_delay(struct mpls_te_circuit *mtc, } static void set_circuitparams_delay_var(struct mpls_te_circuit *mtc, - u_int32_t jitter) + uint32_t jitter) { /* Note that TLV-length field is the size of array. */ SUBTLV_TYPE(mtc->delay_var) = TE_SUBTLV_DELAY_VAR; @@ -459,9 +459,9 @@ static void set_circuitparams_delay_var(struct mpls_te_circuit *mtc, } static void set_circuitparams_pkt_loss(struct mpls_te_circuit *mtc, - u_int32_t loss, u_char anormal) + uint32_t loss, uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ SUBTLV_TYPE(mtc->pkt_loss) = TE_SUBTLV_PKT_LOSS; SUBTLV_LEN(mtc->pkt_loss) = SUBTLV_DEF_SIZE; @@ -670,16 +670,16 @@ void isis_mpls_te_update(struct interface *ifp) * Followings are vty session control functions. *------------------------------------------------------------------------*/ -static u_char print_subtlv_admin_grp(struct sbuf *buf, int indent, - struct te_subtlv_admin_grp *tlv) +static uint8_t print_subtlv_admin_grp(struct sbuf *buf, int indent, + struct te_subtlv_admin_grp *tlv) { sbuf_push(buf, indent, "Administrative Group: 0x%" PRIx32 "\n", ntohl(tlv->value)); return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_llri(struct sbuf *buf, int indent, - struct te_subtlv_llri *tlv) +static uint8_t print_subtlv_llri(struct sbuf *buf, int indent, + struct te_subtlv_llri *tlv) { sbuf_push(buf, indent, "Link Local ID: %" PRIu32 "\n", ntohl(tlv->local)); @@ -689,8 +689,8 @@ static u_char print_subtlv_llri(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + TE_SUBTLV_LLRI_SIZE); } -static u_char print_subtlv_local_ipaddr(struct sbuf *buf, int indent, - struct te_subtlv_local_ipaddr *tlv) +static uint8_t print_subtlv_local_ipaddr(struct sbuf *buf, int indent, + struct te_subtlv_local_ipaddr *tlv) { sbuf_push(buf, indent, "Local Interface IP Address(es): %s\n", inet_ntoa(tlv->value)); @@ -698,8 +698,8 @@ static u_char print_subtlv_local_ipaddr(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_rmt_ipaddr(struct sbuf *buf, int indent, - struct te_subtlv_rmt_ipaddr *tlv) +static uint8_t print_subtlv_rmt_ipaddr(struct sbuf *buf, int indent, + struct te_subtlv_rmt_ipaddr *tlv) { sbuf_push(buf, indent, "Remote Interface IP Address(es): %s\n", inet_ntoa(tlv->value)); @@ -707,8 +707,8 @@ static u_char print_subtlv_rmt_ipaddr(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_max_bw(struct sbuf *buf, int indent, - struct te_subtlv_max_bw *tlv) +static uint8_t print_subtlv_max_bw(struct sbuf *buf, int indent, + struct te_subtlv_max_bw *tlv) { float fval; @@ -719,8 +719,8 @@ static u_char print_subtlv_max_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_max_rsv_bw(struct sbuf *buf, int indent, - struct te_subtlv_max_rsv_bw *tlv) +static uint8_t print_subtlv_max_rsv_bw(struct sbuf *buf, int indent, + struct te_subtlv_max_rsv_bw *tlv) { float fval; @@ -732,8 +732,8 @@ static u_char print_subtlv_max_rsv_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_unrsv_bw(struct sbuf *buf, int indent, - struct te_subtlv_unrsv_bw *tlv) +static uint8_t print_subtlv_unrsv_bw(struct sbuf *buf, int indent, + struct te_subtlv_unrsv_bw *tlv) { float fval1, fval2; int i; @@ -751,10 +751,10 @@ static u_char print_subtlv_unrsv_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + TE_SUBTLV_UNRSV_SIZE); } -static u_char print_subtlv_te_metric(struct sbuf *buf, int indent, - struct te_subtlv_te_metric *tlv) +static uint8_t print_subtlv_te_metric(struct sbuf *buf, int indent, + struct te_subtlv_te_metric *tlv) { - u_int32_t te_metric; + uint32_t te_metric; te_metric = tlv->value[2] | tlv->value[1] << 8 | tlv->value[0] << 16; sbuf_push(buf, indent, "Traffic Engineering Metric: %u\n", te_metric); @@ -762,8 +762,8 @@ static u_char print_subtlv_te_metric(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_ras(struct sbuf *buf, int indent, - struct te_subtlv_ras *tlv) +static uint8_t print_subtlv_ras(struct sbuf *buf, int indent, + struct te_subtlv_ras *tlv) { sbuf_push(buf, indent, "Inter-AS TE Remote AS number: %" PRIu32 "\n", ntohl(tlv->value)); @@ -771,8 +771,8 @@ static u_char print_subtlv_ras(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_rip(struct sbuf *buf, int indent, - struct te_subtlv_rip *tlv) +static uint8_t print_subtlv_rip(struct sbuf *buf, int indent, + struct te_subtlv_rip *tlv) { sbuf_push(buf, indent, "Inter-AS TE Remote ASBR IP address: %s\n", inet_ntoa(tlv->value)); @@ -780,14 +780,14 @@ static u_char print_subtlv_rip(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_av_delay(struct sbuf *buf, int indent, - struct te_subtlv_av_delay *tlv) +static uint8_t print_subtlv_av_delay(struct sbuf *buf, int indent, + struct te_subtlv_av_delay *tlv) { - u_int32_t delay; - u_int32_t A; + uint32_t delay; + uint32_t A; - delay = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; - A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; + delay = (uint32_t)ntohl(tlv->value) & TE_EXT_MASK; + A = (uint32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; sbuf_push(buf, indent, "%s Average Link Delay: %" PRIu32 " (micro-sec)\n", @@ -796,15 +796,15 @@ static u_char print_subtlv_av_delay(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_mm_delay(struct sbuf *buf, int indent, - struct te_subtlv_mm_delay *tlv) +static uint8_t print_subtlv_mm_delay(struct sbuf *buf, int indent, + struct te_subtlv_mm_delay *tlv) { - u_int32_t low, high; - u_int32_t A; + uint32_t low, high; + uint32_t A; - low = (u_int32_t)ntohl(tlv->low) & TE_EXT_MASK; - A = (u_int32_t)ntohl(tlv->low) & TE_EXT_ANORMAL; - high = (u_int32_t)ntohl(tlv->high) & TE_EXT_MASK; + low = (uint32_t)ntohl(tlv->low) & TE_EXT_MASK; + A = (uint32_t)ntohl(tlv->low) & TE_EXT_ANORMAL; + high = (uint32_t)ntohl(tlv->high) & TE_EXT_MASK; sbuf_push(buf, indent, "%s Min/Max Link Delay: %" PRIu32 " / %" PRIu32 " (micro-sec)\n", A ? "Anomalous" : "Normal", low, high); @@ -812,12 +812,12 @@ static u_char print_subtlv_mm_delay(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_delay_var(struct sbuf *buf, int indent, - struct te_subtlv_delay_var *tlv) +static uint8_t print_subtlv_delay_var(struct sbuf *buf, int indent, + struct te_subtlv_delay_var *tlv) { - u_int32_t jitter; + uint32_t jitter; - jitter = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; + jitter = (uint32_t)ntohl(tlv->value) & TE_EXT_MASK; sbuf_push(buf, indent, "Delay Variation: %" PRIu32 " (micro-sec)\n", jitter); @@ -825,16 +825,16 @@ static u_char print_subtlv_delay_var(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_pkt_loss(struct sbuf *buf, int indent, - struct te_subtlv_pkt_loss *tlv) +static uint8_t print_subtlv_pkt_loss(struct sbuf *buf, int indent, + struct te_subtlv_pkt_loss *tlv) { - u_int32_t loss; - u_int32_t A; + uint32_t loss; + uint32_t A; float fval; - loss = (u_int32_t)ntohl(tlv->value) & TE_EXT_MASK; + loss = (uint32_t)ntohl(tlv->value) & TE_EXT_MASK; fval = (float)(loss * LOSS_PRECISION); - A = (u_int32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; + A = (uint32_t)ntohl(tlv->value) & TE_EXT_ANORMAL; sbuf_push(buf, indent, "%s Link Packet Loss: %g (%%)\n", A ? "Anomalous" : "Normal", fval); @@ -842,8 +842,8 @@ static u_char print_subtlv_pkt_loss(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_res_bw(struct sbuf *buf, int indent, - struct te_subtlv_res_bw *tlv) +static uint8_t print_subtlv_res_bw(struct sbuf *buf, int indent, + struct te_subtlv_res_bw *tlv) { float fval; @@ -855,8 +855,8 @@ static u_char print_subtlv_res_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_ava_bw(struct sbuf *buf, int indent, - struct te_subtlv_ava_bw *tlv) +static uint8_t print_subtlv_ava_bw(struct sbuf *buf, int indent, + struct te_subtlv_ava_bw *tlv) { float fval; @@ -868,8 +868,8 @@ static u_char print_subtlv_ava_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_subtlv_use_bw(struct sbuf *buf, int indent, - struct te_subtlv_use_bw *tlv) +static uint8_t print_subtlv_use_bw(struct sbuf *buf, int indent, + struct te_subtlv_use_bw *tlv) { float fval; @@ -881,11 +881,11 @@ static u_char print_subtlv_use_bw(struct sbuf *buf, int indent, return (SUBTLV_HDR_SIZE + SUBTLV_DEF_SIZE); } -static u_char print_unknown_tlv(struct sbuf *buf, int indent, - struct subtlv_header *tlvh) +static uint8_t print_unknown_tlv(struct sbuf *buf, int indent, + struct subtlv_header *tlvh) { int i, rtn = 1; - u_char *v = (u_char *)tlvh; + uint8_t *v = (uint8_t *)tlvh; if (tlvh->length != 0) { sbuf_push(buf, indent, diff --git a/isisd/isis_te.h b/isisd/isis_te.h index 91bcb72698..e9eff08cd1 100644 --- a/isisd/isis_te.h +++ b/isisd/isis_te.h @@ -77,8 +77,8 @@ * used for Traffic Engineering. */ struct subtlv_header { - u_char type; /* sub_TLV_XXX type (see above) */ - u_char length; /* Value portion only, in byte */ + uint8_t type; /* sub_TLV_XXX type (see above) */ + uint8_t length; /* Value portion only, in byte */ }; #define MAX_SUBTLV_SIZE 256 @@ -102,7 +102,7 @@ struct subtlv_header { #define TE_SUBTLV_ADMIN_GRP 3 struct te_subtlv_admin_grp { struct subtlv_header header; /* Value length is 4 octets. */ - u_int32_t value; /* Admin. group membership. */ + uint32_t value; /* Admin. group membership. */ } __attribute__((__packed__)); /* Link Local/Remote Identifiers - RFC 5307 */ @@ -110,8 +110,8 @@ struct te_subtlv_admin_grp { #define TE_SUBTLV_LLRI_SIZE 8 struct te_subtlv_llri { struct subtlv_header header; /* Value length is 8 octets. */ - u_int32_t local; /* Link Local Identifier */ - u_int32_t remote; /* Link Remote Identifier */ + uint32_t local; /* Link Local Identifier */ + uint32_t remote; /* Link Remote Identifier */ } __attribute__((__packed__)); /* Link Sub-TLV: Local Interface IP Address - RFC 5305 */ @@ -155,14 +155,14 @@ struct te_subtlv_unrsv_bw { #define TE_SUBTLV_TE_METRIC_SIZE 3 struct te_subtlv_te_metric { struct subtlv_header header; /* Value length is 4 octets. */ - u_char value[3]; /* Link metric for TE purpose. */ + uint8_t value[3]; /* Link metric for TE purpose. */ } __attribute__((__packed__)); /* Remote AS Number sub-TLV - RFC5316 */ #define TE_SUBTLV_RAS 24 struct te_subtlv_ras { struct subtlv_header header; /* Value length is 4 octets. */ - u_int32_t value; /* Remote AS number */ + uint32_t value; /* Remote AS number */ } __attribute__((__packed__)); /* IPv4 Remote ASBR ID Sub-TLV - RFC5316 */ @@ -178,7 +178,7 @@ struct te_subtlv_rip { #define TE_SUBTLV_AV_DELAY 33 struct te_subtlv_av_delay { struct subtlv_header header; /* Value length is 4 bytes. */ - u_int32_t value; /* Average delay in micro-seconds only 24 bits => 0 ... + uint32_t value; /* Average delay in micro-seconds only 24 bits => 0 ... 16777215 with Anomalous Bit (A) as Upper most bit */ } __attribute__((__packed__)); @@ -188,10 +188,10 @@ struct te_subtlv_av_delay { #define TE_SUBTLV_MM_DELAY_SIZE 8 struct te_subtlv_mm_delay { struct subtlv_header header; /* Value length is 8 bytes. */ - u_int32_t low; /* low delay in micro-seconds only 24 bits => 0 ... + uint32_t low; /* low delay in micro-seconds only 24 bits => 0 ... 16777215 with Anomalous Bit (A) as Upper most bit */ - u_int32_t high; /* high delay in micro-seconds only 24 bits => 0 ... + uint32_t high; /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */ } __attribute__((__packed__)); @@ -199,7 +199,7 @@ struct te_subtlv_mm_delay { #define TE_SUBTLV_DELAY_VAR 35 struct te_subtlv_delay_var { struct subtlv_header header; /* Value length is 4 bytes. */ - u_int32_t value; /* interval in micro-seconds only 24 bits => 0 ... + uint32_t value; /* interval in micro-seconds only 24 bits => 0 ... 16777215 */ } __attribute__((__packed__)); @@ -207,7 +207,7 @@ struct te_subtlv_delay_var { #define TE_SUBTLV_PKT_LOSS 36 struct te_subtlv_pkt_loss { struct subtlv_header header; /* Value length is 4 bytes. */ - u_int32_t + uint32_t value; /* in percentage of total traffic only 24 bits (2^24 - 2) with Anomalous Bit (A) as Upper most bit */ } __attribute__((__packed__)); @@ -253,7 +253,7 @@ struct isis_mpls_te { status_t status; /* L1, L1-L2, L2-Only */ - u_int8_t level; + uint8_t level; /* RFC5316 */ interas_mode_t inter_as; @@ -275,10 +275,10 @@ struct mpls_te_circuit { /* Type of MPLS-TE circuit: STD_TE(RFC5305), INTER_AS(RFC5316), * INTER_AS_EMU(RFC5316 emulated) */ - u_int8_t type; + uint8_t type; /* Total size of sub_tlvs */ - u_char length; + uint8_t length; /* Store subTLV in network byte order. */ /* RFC5305 */ diff --git a/isisd/isis_tlvs.c b/isisd/isis_tlvs.c index 66a19e150f..d51eb3e519 100644 --- a/isisd/isis_tlvs.c +++ b/isisd/isis_tlvs.c @@ -2757,7 +2757,7 @@ void isis_tlvs_add_area_addresses(struct isis_tlvs *tlvs, void isis_tlvs_add_lan_neighbors(struct isis_tlvs *tlvs, struct list *neighbors) { struct listnode *node; - u_char *snpa; + uint8_t *snpa; for (ALL_LIST_ELEMENTS_RO(neighbors, node, snpa)) { struct isis_lan_neighbor *n = diff --git a/isisd/isis_vty.c b/isisd/isis_vty.c index 66d79b2e9f..ce2952c135 100644 --- a/isisd/isis_vty.c +++ b/isisd/isis_vty.c @@ -635,8 +635,8 @@ DEFUN (isis_hello_interval, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_interval[0] = (u_int16_t)interval; - circuit->hello_interval[1] = (u_int16_t)interval; + circuit->hello_interval[0] = (uint16_t)interval; + circuit->hello_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -682,7 +682,7 @@ DEFUN (isis_hello_interval_l1, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_interval[0] = (u_int16_t)interval; + circuit->hello_interval[0] = (uint16_t)interval; return CMD_SUCCESS; } @@ -728,7 +728,7 @@ DEFUN (isis_hello_interval_l2, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_interval[1] = (u_int16_t)interval; + circuit->hello_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -774,8 +774,8 @@ DEFUN (isis_hello_multiplier, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_multiplier[0] = (u_int16_t)mult; - circuit->hello_multiplier[1] = (u_int16_t)mult; + circuit->hello_multiplier[0] = (uint16_t)mult; + circuit->hello_multiplier[1] = (uint16_t)mult; return CMD_SUCCESS; } @@ -822,7 +822,7 @@ DEFUN (isis_hello_multiplier_l1, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_multiplier[0] = (u_int16_t)mult; + circuit->hello_multiplier[0] = (uint16_t)mult; return CMD_SUCCESS; } @@ -869,7 +869,7 @@ DEFUN (isis_hello_multiplier_l2, return CMD_WARNING_CONFIG_FAILED; } - circuit->hello_multiplier[1] = (u_int16_t)mult; + circuit->hello_multiplier[1] = (uint16_t)mult; return CMD_SUCCESS; } @@ -962,8 +962,8 @@ DEFUN (csnp_interval, return CMD_WARNING_CONFIG_FAILED; } - circuit->csnp_interval[0] = (u_int16_t)interval; - circuit->csnp_interval[1] = (u_int16_t)interval; + circuit->csnp_interval[0] = (uint16_t)interval; + circuit->csnp_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1009,7 +1009,7 @@ DEFUN (csnp_interval_l1, return CMD_WARNING_CONFIG_FAILED; } - circuit->csnp_interval[0] = (u_int16_t)interval; + circuit->csnp_interval[0] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1055,7 +1055,7 @@ DEFUN (csnp_interval_l2, return CMD_WARNING_CONFIG_FAILED; } - circuit->csnp_interval[1] = (u_int16_t)interval; + circuit->csnp_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1100,8 +1100,8 @@ DEFUN (psnp_interval, return CMD_WARNING_CONFIG_FAILED; } - circuit->psnp_interval[0] = (u_int16_t)interval; - circuit->psnp_interval[1] = (u_int16_t)interval; + circuit->psnp_interval[0] = (uint16_t)interval; + circuit->psnp_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1147,7 +1147,7 @@ DEFUN (psnp_interval_l1, return CMD_WARNING_CONFIG_FAILED; } - circuit->psnp_interval[0] = (u_int16_t)interval; + circuit->psnp_interval[0] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1193,7 +1193,7 @@ DEFUN (psnp_interval_l2, return CMD_WARNING_CONFIG_FAILED; } - circuit->psnp_interval[1] = (u_int16_t)interval; + circuit->psnp_interval[1] = (uint16_t)interval; return CMD_SUCCESS; } @@ -1618,7 +1618,7 @@ DEFUN (spf_interval, { int idx_number = 1; VTY_DECLVAR_CONTEXT(isis_area, area); - u_int16_t interval; + uint16_t interval; interval = atoi(argv[idx_number]->arg); area->min_spf_interval[0] = interval; @@ -1655,7 +1655,7 @@ DEFUN (spf_interval_l1, { int idx_number = 2; VTY_DECLVAR_CONTEXT(isis_area, area); - u_int16_t interval; + uint16_t interval; interval = atoi(argv[idx_number]->arg); area->min_spf_interval[0] = interval; @@ -1687,7 +1687,7 @@ DEFUN (spf_interval_l2, { int idx_number = 2; VTY_DECLVAR_CONTEXT(isis_area, area); - u_int16_t interval; + uint16_t interval; interval = atoi(argv[idx_number]->arg); area->min_spf_interval[1] = interval; @@ -1934,8 +1934,9 @@ DEFUN (no_lsp_refresh_interval, static int area_passwd_set(struct vty *vty, int level, int (*type_set)(struct isis_area *area, int level, - const char *passwd, u_char snp_auth), - const char *passwd, u_char snp_auth) + const char *passwd, + uint8_t snp_auth), + const char *passwd, uint8_t snp_auth) { VTY_DECLVAR_CONTEXT(isis_area, area); @@ -1963,7 +1964,7 @@ DEFUN (area_passwd_md5, int idx_password = 0; int idx_word = 2; int idx_type = 5; - u_char snp_auth = 0; + uint8_t snp_auth = 0; int level = strmatch(argv[idx_password]->text, "domain-password") ? IS_LEVEL_2 : IS_LEVEL_1; @@ -2006,7 +2007,7 @@ DEFUN (area_passwd_clear, int idx_password = 0; int idx_word = 2; int idx_type = 5; - u_char snp_auth = 0; + uint8_t snp_auth = 0; int level = strmatch(argv[idx_password]->text, "domain-password") ? IS_LEVEL_2 : IS_LEVEL_1; diff --git a/isisd/isisd.c b/isisd/isisd.c index 6d64e07705..6f04d72082 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -324,7 +324,7 @@ int area_net_title(struct vty *vty, const char *net_title) struct area_addr *addrp; struct listnode *node; - u_char buff[255]; + uint8_t buff[255]; /* We check that we are not over the maximal number of addresses */ if (listcount(area->area_addrs) >= isis->max_area_addrs) { @@ -411,7 +411,7 @@ int area_clear_net_title(struct vty *vty, const char *net_title) VTY_DECLVAR_CONTEXT(isis_area, area); struct area_addr addr, *addrp = NULL; struct listnode *node; - u_char buff[255]; + uint8_t buff[255]; addr.addr_len = dotformat2buff(buff, net_title); if (addr.addr_len < 8 || addr.addr_len > 20) { @@ -528,7 +528,7 @@ int show_isis_neighbor_common(struct vty *vty, const char *id, char detail) struct list *adjdb; struct isis_adjacency *adj; struct isis_dynhn *dynhn; - u_char sysid[ISIS_SYS_ID_LEN]; + uint8_t sysid[ISIS_SYS_ID_LEN]; int i; if (!isis) { @@ -597,7 +597,7 @@ int clear_isis_neighbor_common(struct vty *vty, const char *id) struct list *adjdb; struct isis_adjacency *adj; struct isis_dynhn *dynhn; - u_char sysid[ISIS_SYS_ID_LEN]; + uint8_t sysid[ISIS_SYS_ID_LEN]; int i; if (!isis) { @@ -1374,9 +1374,9 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) struct isis_lsp *lsp; struct isis_dynhn *dynhn; const char *pos = argv; - u_char lspid[ISIS_SYS_ID_LEN + 2]; + uint8_t lspid[ISIS_SYS_ID_LEN + 2]; char sysid[255]; - u_char number[3]; + uint8_t number[3]; int level, lsp_count; if (isis->area_list->count == 0) @@ -1401,7 +1401,7 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) if (strncmp(pos, "-", 1) == 0) { memcpy(number, ++pos, 2); lspid[ISIS_SYS_ID_LEN + 1] = - (u_char)strtol((char *)number, NULL, 16); + (uint8_t)strtol((char *)number, NULL, 16); pos -= 4; if (strncmp(pos, ".", 1) != 0) return CMD_WARNING; @@ -1409,7 +1409,7 @@ static int show_isis_database(struct vty *vty, const char *argv, int ui_level) if (strncmp(pos, ".", 1) == 0) { memcpy(number, ++pos, 2); lspid[ISIS_SYS_ID_LEN] = - (u_char)strtol((char *)number, NULL, 16); + (uint8_t)strtol((char *)number, NULL, 16); sysid[pos - argv - 1] = '\0'; } } @@ -1626,8 +1626,8 @@ void isis_area_lsp_mtu_set(struct isis_area *area, unsigned int lsp_mtu) } static int isis_area_passwd_set(struct isis_area *area, int level, - u_char passwd_type, const char *passwd, - u_char snp_auth) + uint8_t passwd_type, const char *passwd, + uint8_t snp_auth) { struct isis_passwd *dest; struct isis_passwd modified; @@ -1667,14 +1667,14 @@ int isis_area_passwd_unset(struct isis_area *area, int level) } int isis_area_passwd_cleartext_set(struct isis_area *area, int level, - const char *passwd, u_char snp_auth) + const char *passwd, uint8_t snp_auth) { return isis_area_passwd_set(area, level, ISIS_PASSWD_TYPE_CLEARTXT, passwd, snp_auth); } int isis_area_passwd_hmac_md5_set(struct isis_area *area, int level, - const char *passwd, u_char snp_auth) + const char *passwd, uint8_t snp_auth) { return isis_area_passwd_set(area, level, ISIS_PASSWD_TYPE_HMAC_MD5, passwd, snp_auth); diff --git a/isisd/isisd.h b/isisd/isisd.h index 85d3974fa6..d1ad9f3b8e 100644 --- a/isisd/isisd.h +++ b/isisd/isisd.h @@ -40,17 +40,17 @@ extern struct zebra_privs_t isisd_privs; /* #define EXTREME_DICT_DEBUG */ struct isis { - u_long process_id; + unsigned long process_id; int sysid_set; - u_char sysid[ISIS_SYS_ID_LEN]; /* SystemID for this IS */ - u_int32_t router_id; /* Router ID from zebra */ + uint8_t sysid[ISIS_SYS_ID_LEN]; /* SystemID for this IS */ + uint32_t router_id; /* Router ID from zebra */ struct list *area_list; /* list of IS-IS areas */ struct list *init_circ_list; struct list *nexthops; /* IPv4 next hops from this IS */ struct list *nexthops6; /* IPv6 next hops from this IS */ - u_char max_area_addrs; /* maximumAreaAdresses */ + uint8_t max_area_addrs; /* maximumAreaAdresses */ struct area_addr *man_area_addrs; /* manualAreaAddresses */ - u_int32_t debugs; /* bitmap for debug */ + uint32_t debugs; /* bitmap for debug */ time_t uptime; /* when did we start */ struct thread *t_dync_clean; /* dynamic hostname cache cleanup thread */ uint32_t circuit_ids_used[8]; /* 256 bits to track circuit ids 1 through 255 */ @@ -103,27 +103,27 @@ struct isis_area { char *area_tag; /* area addresses for this area */ struct list *area_addrs; - u_int16_t max_lsp_lifetime[ISIS_LEVELS]; + uint16_t max_lsp_lifetime[ISIS_LEVELS]; char is_type; /* level-1 level-1-2 or level-2-only */ /* are we overloaded? */ char overload_bit; /* L1/L2 router identifier for inter-area traffic */ char attached_bit; - u_int16_t lsp_refresh[ISIS_LEVELS]; + uint16_t lsp_refresh[ISIS_LEVELS]; /* minimum time allowed before lsp retransmission */ - u_int16_t lsp_gen_interval[ISIS_LEVELS]; + uint16_t lsp_gen_interval[ISIS_LEVELS]; /* min interval between between consequtive SPFs */ - u_int16_t min_spf_interval[ISIS_LEVELS]; + uint16_t min_spf_interval[ISIS_LEVELS]; /* the percentage of LSP mtu size used, before generating a new frag */ int lsp_frag_threshold; int ip_circuits; /* logging adjacency changes? */ - u_char log_adj_changes; + uint8_t log_adj_changes; /* multi topology settings */ struct list *mt_settings; int ipv6_circuits; /* Counters */ - u_int32_t circuit_state_changes; + uint32_t circuit_state_changes; struct isis_redist redist_settings[REDIST_PROTOCOL_COUNT] [ZEBRA_ROUTE_MAX + 1][ISIS_LEVELS]; struct route_table *ext_reach[REDIST_PROTOCOL_COUNT][ISIS_LEVELS]; @@ -158,9 +158,9 @@ void isis_area_lsp_refresh_set(struct isis_area *area, int level, /* IS_LEVEL_1 sets area_passwd, IS_LEVEL_2 domain_passwd */ int isis_area_passwd_unset(struct isis_area *area, int level); int isis_area_passwd_cleartext_set(struct isis_area *area, int level, - const char *passwd, u_char snp_auth); + const char *passwd, uint8_t snp_auth); int isis_area_passwd_hmac_md5_set(struct isis_area *area, int level, - const char *passwd, u_char snp_auth); + const char *passwd, uint8_t snp_auth); void isis_vty_init(void); /* Master of threads. */ diff --git a/isisd/iso_checksum.c b/isisd/iso_checksum.c index 25a870991a..0da6d5fc8c 100644 --- a/isisd/iso_checksum.c +++ b/isisd/iso_checksum.c @@ -45,11 +45,11 @@ * Based on Annex C.4 of ISO/IEC 8473 */ -int iso_csum_verify(u_char *buffer, int len, uint16_t csum, int offset) +int iso_csum_verify(uint8_t *buffer, int len, uint16_t csum, int offset) { - u_int16_t checksum; - u_int32_t c0; - u_int32_t c1; + uint16_t checksum; + uint32_t c0; + uint32_t c1; c0 = csum & 0xff00; c1 = csum & 0x00ff; diff --git a/isisd/iso_checksum.h b/isisd/iso_checksum.h index 5ba371fb40..357c75fa55 100644 --- a/isisd/iso_checksum.h +++ b/isisd/iso_checksum.h @@ -23,6 +23,6 @@ #ifndef _ZEBRA_ISO_CSUM_H #define _ZEBRA_ISO_CSUM_H -int iso_csum_verify(u_char *buffer, int len, uint16_t csum, int offset); +int iso_csum_verify(uint8_t *buffer, int len, uint16_t csum, int offset); #endif /* _ZEBRA_ISO_CSUM_H */ diff --git a/ldpd/lde.c b/ldpd/lde.c index 5aa53fd39e..03b62b482b 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -56,7 +56,7 @@ static void lde_map_free(void *); static int lde_address_add(struct lde_nbr *, struct lde_addr *); static int lde_address_del(struct lde_nbr *, struct lde_addr *); static void lde_address_list_free(struct lde_nbr *); -static void zclient_sync_init(u_short instance); +static void zclient_sync_init(unsigned short instance); static void lde_label_list_init(void); static int lde_get_label_chunk(void); static void on_get_label_chunk_response(uint32_t start, uint32_t end); @@ -1626,8 +1626,7 @@ lde_address_list_free(struct lde_nbr *ln) } } -static void -zclient_sync_init(u_short instance) +static void zclient_sync_init(unsigned short instance) { /* Initialize special zclient for synchronous message exchanges. */ zclient_sync = zclient_new_notify(master, &zclient_options_default); diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index a12a4b913e..c8b775cb8e 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -142,9 +142,9 @@ zebra_send_mpls_labels(int cmd, struct kroute *kr) stream_put_in_addr(s, &kr->nexthop.v4); break; case AF_INET6: - stream_write(s, (u_char *)&kr->prefix.v6, 16); + stream_write(s, (uint8_t *)&kr->prefix.v6, 16); stream_putc(s, kr->prefixlen); - stream_write(s, (u_char *)&kr->nexthop.v6, 16); + stream_write(s, (uint8_t *)&kr->nexthop.v6, 16); break; default: fatalx("kr_change: unknown af"); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 4824f1720b..ed0a5407b2 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -159,7 +159,7 @@ struct ldpd_init { char group[256]; char ctl_sock_path[MAXPATHLEN]; char zclient_serv_path[MAXPATHLEN]; - u_short instance; + unsigned short instance; }; union ldpd_addr { diff --git a/lib/agentx.c b/lib/agentx.c index f8845f1461..302bbf0a42 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -230,7 +230,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, size_t enamelen, const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, - u_char sptrap) + uint8_t sptrap) { oid objid_snmptrap[] = {1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0}; size_t objid_snmptrap_len = sizeof objid_snmptrap / sizeof(oid); @@ -248,7 +248,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, notification_oid_len = enamelen + 1; snmp_varlist_add_variable(¬ification_vars, objid_snmptrap, objid_snmptrap_len, ASN_OBJECT_ID, - (u_char *)notification_oid, + (uint8_t *)notification_oid, notification_oid_len * sizeof(oid)); /* Provided bindings */ @@ -256,7 +256,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, unsigned int j; oid oid[MAX_OID_LEN]; size_t oid_len, onamelen; - u_char *val; + uint8_t *val; size_t val_len; WriteMethod *wm = NULL; struct variable cvp; @@ -84,8 +84,8 @@ void bfd_info_free(struct bfd_info **bfd_info) * bfd_validate_param - Validate the BFD paramter information. */ int bfd_validate_param(struct vty *vty, const char *dm_str, const char *rx_str, - const char *tx_str, u_int8_t *dm_val, u_int32_t *rx_val, - u_int32_t *tx_val) + const char *tx_str, uint8_t *dm_val, uint32_t *rx_val, + uint32_t *tx_val) { *dm_val = strtoul(dm_str, NULL, 10); *rx_val = strtoul(rx_str, NULL, 10); @@ -96,9 +96,8 @@ int bfd_validate_param(struct vty *vty, const char *dm_str, const char *rx_str, /* * bfd_set_param - Set the configured BFD paramter values */ -void bfd_set_param(struct bfd_info **bfd_info, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, int defaults, - int *command) +void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, uint32_t min_tx, + uint8_t detect_mult, int defaults, int *command) { if (!*bfd_info) { *bfd_info = bfd_info_create(); @@ -343,7 +342,7 @@ static void bfd_last_update(time_t last_update, char *buf, size_t len) * bfd_show_param - Show the BFD parameter information. */ void bfd_show_param(struct vty *vty, struct bfd_info *bfd_info, int bfd_tag, - int extra_space, u_char use_json, json_object *json_obj) + int extra_space, uint8_t use_json, json_object *json_obj) { json_object *json_bfd = NULL; @@ -379,7 +378,7 @@ void bfd_show_param(struct vty *vty, struct bfd_info *bfd_info, int bfd_tag, * bfd_show_status - Show the BFD status information. */ static void bfd_show_status(struct vty *vty, struct bfd_info *bfd_info, - int bfd_tag, int extra_space, u_char use_json, + int bfd_tag, int extra_space, uint8_t use_json, json_object *json_bfd) { char time_buf[32]; @@ -403,7 +402,7 @@ static void bfd_show_status(struct vty *vty, struct bfd_info *bfd_info, * bfd_show_info - Show the BFD information. */ void bfd_show_info(struct vty *vty, struct bfd_info *bfd_info, int multihop, - int extra_space, u_char use_json, json_object *json_obj) + int extra_space, uint8_t use_json, json_object *json_obj) { json_object *json_bfd = NULL; @@ -37,7 +37,7 @@ #define BFD_GBL_FLAG_IN_SHUTDOWN (1 << 0) /* The daemon in shutdown */ struct bfd_gbl { - u_int16_t flags; + uint16_t flags; }; #define BFD_FLAG_PARAM_CFG (1 << 0) /* parameters have been configured */ @@ -55,12 +55,12 @@ enum bfd_sess_type { }; struct bfd_info { - u_int16_t flags; - u_int8_t detect_mult; - u_int32_t desired_min_tx; - u_int32_t required_min_rx; + uint16_t flags; + uint8_t detect_mult; + uint32_t desired_min_tx; + uint32_t required_min_rx; time_t last_update; - u_int8_t status; + uint8_t status; enum bfd_sess_type type; }; @@ -70,11 +70,11 @@ extern void bfd_info_free(struct bfd_info **bfd_info); extern int bfd_validate_param(struct vty *vty, const char *dm_str, const char *rx_str, const char *tx_str, - u_int8_t *dm_val, u_int32_t *rx_val, - u_int32_t *tx_val); + uint8_t *dm_val, uint32_t *rx_val, + uint32_t *tx_val); -extern void bfd_set_param(struct bfd_info **bfd_info, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, int defaults, +extern void bfd_set_param(struct bfd_info **bfd_info, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults, int *command); extern void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, int family, void *dst_ip, void *src_ip, @@ -90,11 +90,11 @@ extern struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp, const char *bfd_get_status_str(int status); extern void bfd_show_param(struct vty *vty, struct bfd_info *bfd_info, - int bfd_tag, int extra_space, u_char use_json, + int bfd_tag, int extra_space, uint8_t use_json, json_object *json_obj); extern void bfd_show_info(struct vty *vty, struct bfd_info *bfd_info, - int multihop, int extra_space, u_char use_json, + int multihop, int extra_space, uint8_t use_json, json_object *json_obj); extern void bfd_client_sendmsg(struct zclient *zclient, int command); diff --git a/lib/buffer.c b/lib/buffer.c index 191fbf875a..03202f1253 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -174,7 +174,7 @@ void buffer_put(struct buffer *b, const void *p, size_t size) } /* Insert character into the buffer. */ -void buffer_putc(struct buffer *b, u_char c) +void buffer_putc(struct buffer *b, uint8_t c) { buffer_put(b, &c, 1); } @@ -336,7 +336,7 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, "%s: growing iov array to %d; " "width %d, height %d, size %lu", __func__, iov_alloc, width, height, - (u_long)b->size); + (unsigned long)b->size); iov = XREALLOC(MTYPE_TMP, iov, iov_alloc * sizeof(*iov)); } else { @@ -456,7 +456,7 @@ in one shot. */ zlog_err( "%s: corruption detected: buffer queue empty, " "but written is %lu", - __func__, (u_long)written); + __func__, (unsigned long)written); break; } if (written < d->cp - d->sp) { diff --git a/lib/buffer.h b/lib/buffer.h index 130c677da8..0c945a2acf 100644 --- a/lib/buffer.h +++ b/lib/buffer.h @@ -37,7 +37,7 @@ extern void buffer_free(struct buffer *); /* Add the given data to the end of the buffer. */ extern void buffer_put(struct buffer *, const void *, size_t); /* Add a single character to the end of the buffer. */ -extern void buffer_putc(struct buffer *, u_char); +extern void buffer_putc(struct buffer *, uint8_t); /* Add a NUL-terminated string to the end of the buffer. */ extern void buffer_putstr(struct buffer *, const char *); /* Add given data, inline-expanding \n to \r\n */ diff --git a/lib/checksum.c b/lib/checksum.c index 8eef73e243..18e3850474 100644 --- a/lib/checksum.c +++ b/lib/checksum.c @@ -12,10 +12,10 @@ int /* return checksum in low-order 16 bits */ in_cksum(void *parg, int nbytes) { - u_short *ptr = parg; + unsigned short *ptr = parg; register long sum; /* assumes long == 32 bits */ - u_short oddbyte; - register u_short answer; /* assumes u_short == 16 bits */ + unsigned short oddbyte; + register unsigned short answer; /* assumes unsigned short == 16 bits */ /* * Our algorithm is simple, using a 32-bit accumulator (sum), @@ -32,7 +32,7 @@ int /* return checksum in low-order 16 bits */ /* mop up an odd byte, if necessary */ if (nbytes == 1) { oddbyte = 0; /* make sure top half is zero */ - *((u_char *)&oddbyte) = *(u_char *)ptr; /* one byte only */ + *((uint8_t *)&oddbyte) = *(uint8_t *)ptr; /* one byte only */ sum += oddbyte; } @@ -53,13 +53,13 @@ int /* return checksum in low-order 16 bits */ index required in the specification ISO 8473, Annex C.1 */ /* calling with offset == FLETCHER_CHECKSUM_VALIDATE will validate the checksum without modifying the buffer; a valid checksum returns 0 */ -u_int16_t fletcher_checksum(u_char *buffer, const size_t len, - const uint16_t offset) +uint16_t fletcher_checksum(uint8_t *buffer, const size_t len, + const uint16_t offset) { - u_int8_t *p; + uint8_t *p; int x, y, c0, c1; - u_int16_t checksum = 0; - u_int16_t *csum; + uint16_t checksum = 0; + uint16_t *csum; size_t partial_len, i, left = len; if (offset != FLETCHER_CHECKSUM_VALIDATE) @@ -67,7 +67,7 @@ u_int16_t fletcher_checksum(u_char *buffer, const size_t len, { assert(offset < (len - 1)); /* account for two bytes of checksum */ - csum = (u_int16_t *)(buffer + offset); + csum = (uint16_t *)(buffer + offset); *(csum) = 0; } diff --git a/lib/checksum.h b/lib/checksum.h index aecaaf6bcc..c2764e35fb 100644 --- a/lib/checksum.h +++ b/lib/checksum.h @@ -1,4 +1,4 @@ extern int in_cksum(void *, int); #define FLETCHER_CHECKSUM_VALIDATE 0xffff -extern u_int16_t fletcher_checksum(u_char *, const size_t len, - const uint16_t offset); +extern uint16_t fletcher_checksum(uint8_t *, const size_t len, + const uint16_t offset); diff --git a/lib/command.c b/lib/command.c index 5697c1d812..f244d67e86 100644 --- a/lib/command.c +++ b/lib/command.c @@ -55,7 +55,6 @@ const char *node_names[] = { "auth enable", // AUTH_ENABLE_NODE, "enable", // ENABLE_NODE, "config", // CONFIG_NODE, - "service", // SERVICE_NODE, "debug", // DEBUG_NODE, "vrf debug", // VRF_DEBUG_NODE, "vnc debug", // DEBUG_VNC_NODE, @@ -97,8 +96,6 @@ const char *node_names[] = { "ldp l2vpn", // LDP_L2VPN_NODE, "ldp", // LDP_PSEUDOWIRE_NODE, "isis", // ISIS_NODE, - "masc", // MASC_NODE, - "irdp", // IRDP_NODE, "static ip", // IP_NODE, "ipv4 access list", // ACCESS_NODE, "ipv4 prefix list", // PREFIX_NODE, @@ -118,6 +115,10 @@ const char *node_names[] = { "link-params", // LINK_PARAMS_NODE, "bgp evpn vni", // BGP_EVPN_VNI_NODE, "rpki", // RPKI_NODE + "bgp ipv4 flowspec", /* BGP_FLOWSPECV4_NODE + */ + "bgp ipv6 flowspec", /* BGP_FLOWSPECV6_NODE + */ }; /* Command vector which includes some level of command lists. Normally @@ -948,6 +949,8 @@ enum node_type node_parent(enum node_type node) switch (node) { case BGP_VPNV4_NODE: case BGP_VPNV6_NODE: + case BGP_FLOWSPECV4_NODE: + case BGP_FLOWSPECV6_NODE: case BGP_VRF_POLICY_NODE: case BGP_VNC_DEFAULTS_NODE: case BGP_VNC_NVE_GROUP_NODE: @@ -1308,7 +1311,6 @@ void cmd_exit(struct vty *vty) case LDP_L2VPN_NODE: case ISIS_NODE: case KEYCHAIN_NODE: - case MASC_NODE: case RMAP_NODE: case VTY_NODE: vty->node = CONFIG_NODE; @@ -1318,6 +1320,8 @@ void cmd_exit(struct vty *vty) case BGP_IPV4L_NODE: case BGP_VPNV4_NODE: case BGP_VPNV6_NODE: + case BGP_FLOWSPECV4_NODE: + case BGP_FLOWSPECV6_NODE: case BGP_VRF_POLICY_NODE: case BGP_VNC_DEFAULTS_NODE: case BGP_VNC_NVE_GROUP_NODE: @@ -1394,6 +1398,8 @@ DEFUN (config_end, case BGP_VNC_L2_GROUP_NODE: case BGP_VPNV4_NODE: case BGP_VPNV6_NODE: + case BGP_FLOWSPECV4_NODE: + case BGP_FLOWSPECV6_NODE: case BGP_IPV4_NODE: case BGP_IPV4M_NODE: case BGP_IPV4L_NODE: @@ -1415,7 +1421,6 @@ DEFUN (config_end, case ISIS_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: - case MASC_NODE: case VTY_NODE: case LINK_PARAMS_NODE: vty_config_unlock(vty); diff --git a/lib/command.h b/lib/command.h index 95d8ee99df..8d88ea1902 100644 --- a/lib/command.h +++ b/lib/command.h @@ -78,7 +78,6 @@ enum node_type { AUTH_ENABLE_NODE, /* Authentication mode for change enable. */ ENABLE_NODE, /* Enable node. */ CONFIG_NODE, /* Config node. Default mode of config file. */ - SERVICE_NODE, /* Service node. */ DEBUG_NODE, /* Debug node. */ VRF_DEBUG_NODE, /* Vrf Debug node. */ DEBUG_VNC_NODE, /* Debug VNC node. */ @@ -120,8 +119,6 @@ enum node_type { LDP_L2VPN_NODE, /* LDP L2VPN node */ LDP_PSEUDOWIRE_NODE, /* LDP Pseudowire node */ ISIS_NODE, /* ISIS protocol mode */ - MASC_NODE, /* MASC for multicast. */ - IRDP_NODE, /* ICMP Router Discovery Protocol mode. */ IP_NODE, /* Static ip route node. */ ACCESS_NODE, /* Access list node. */ PREFIX_NODE, /* Prefix list node. */ @@ -142,6 +139,8 @@ enum node_type { BGP_EVPN_VNI_NODE, /* BGP EVPN VNI */ RPKI_NODE, /* RPKI node for configuration of RPKI cache server connections.*/ + BGP_FLOWSPECV4_NODE, /* BGP IPv4 FLOWSPEC Address-Family */ + BGP_FLOWSPECV6_NODE, /* BGP IPv6 FLOWSPEC Address-Family */ NODE_TYPE_MAX, /* maximum */ }; @@ -329,7 +328,7 @@ struct cmd_node { #define BGP_SOFT_RSCLIENT_RIB_STR "Soft reconfig for rsclient RIB\n" #define OSPF_STR "OSPF information\n" #define NEIGHBOR_STR "Specify neighbor router\n" -#define DEBUG_STR "Debugging functions (see also 'undebug')\n" +#define DEBUG_STR "Debugging functions\n" #define UNDEBUG_STR "Disable debugging functions (see also 'debug')\n" #define ROUTER_STR "Enable a routing process\n" #define AS_STR "AS number\n" diff --git a/lib/command_graph.c b/lib/command_graph.c index f00b126536..3e8261cb3e 100644 --- a/lib/command_graph.c +++ b/lib/command_graph.c @@ -32,7 +32,7 @@ DEFINE_MTYPE_STATIC(LIB, CMD_TEXT, "Command Token Help") DEFINE_MTYPE(LIB, CMD_ARG, "Command Argument") DEFINE_MTYPE_STATIC(LIB, CMD_VAR, "Command Argument Name") -struct cmd_token *cmd_token_new(enum cmd_token_type type, u_char attr, +struct cmd_token *cmd_token_new(enum cmd_token_type type, uint8_t attr, const char *text, const char *desc) { struct cmd_token *token = @@ -198,7 +198,7 @@ static bool cmd_nodes_equal(struct graph_node *ga, struct graph_node *gb) } static void cmd_fork_bump_attr(struct graph_node *gn, struct graph_node *join, - u_char attr) + uint8_t attr) { size_t i; struct cmd_token *tok = gn->data; diff --git a/lib/filter.c b/lib/filter.c index ac73482216..5f391aa767 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -161,8 +161,8 @@ static int filter_match_cisco(struct filter *mfilter, struct prefix *p) { struct filter_cisco *filter; struct in_addr mask; - u_int32_t check_addr; - u_int32_t check_mask; + uint32_t check_addr; + uint32_t check_mask; filter = &mfilter->u.cfilter; check_addr = p->u.prefix4.s_addr & ~filter->addr_mask.s_addr; diff --git a/lib/graph.c b/lib/graph.c index 945a58e688..a9cc43f7c1 100644 --- a/lib/graph.c +++ b/lib/graph.c @@ -34,6 +34,15 @@ struct graph *graph_new() return graph; } +void graph_delete_graph(struct graph *graph) +{ + for (unsigned int i = vector_active(graph->nodes); i--; /**/) + graph_delete_node(graph, vector_slot(graph->nodes, i)); + + vector_free(graph->nodes); + XFREE(MTYPE_GRAPH, graph); +} + struct graph_node *graph_new_node(struct graph *graph, void *data, void (*del)(void *)) { @@ -127,12 +136,24 @@ void graph_remove_edge(struct graph_node *from, struct graph_node *to) } } -void graph_delete_graph(struct graph *graph) +struct graph_node *graph_find_node(struct graph *graph, void *data) { - // delete each node in the graph - for (unsigned int i = vector_active(graph->nodes); i--; /**/) - graph_delete_node(graph, vector_slot(graph->nodes, i)); + struct graph_node *g; - vector_free(graph->nodes); - XFREE(MTYPE_GRAPH, graph); + for (unsigned int i = vector_active(graph->nodes); i--; /**/) { + g = vector_slot(graph->nodes, i); + if (g->data == data) + return g; + } + + return NULL; +} + +bool graph_has_edge(struct graph_node *from, struct graph_node *to) +{ + for (unsigned int i = vector_active(from->to); i--; /**/) + if (vector_slot(from->to, i) == to) + return true; + + return false; } diff --git a/lib/graph.h b/lib/graph.h index 10ee00feda..d6dfef5a63 100644 --- a/lib/graph.h +++ b/lib/graph.h @@ -24,6 +24,7 @@ #ifndef _ZEBRA_COMMAND_GRAPH_H #define _ZEBRA_COMMAND_GRAPH_H +#include <stdbool.h> #include "vector.h" struct graph { @@ -91,4 +92,23 @@ void graph_remove_edge(struct graph_node *from, struct graph_node *to); */ void graph_delete_graph(struct graph *graph); +/* + * Finds a node in the graph. + * + * @param[in] graph the graph to search in + * @param[in] data the data to key off + * @return the first graph node whose data pointer matches `data` + */ +struct graph_node *graph_find_node(struct graph *graph, void *data); + + +/* + * Determines whether two nodes have a directed edge between them. + * + * @param from + * @param to + * @return whether there is a directed edge from `from` to `to`. + */ +bool graph_has_edge(struct graph_node *from, struct graph_node *to); + #endif /* _ZEBRA_COMMAND_GRAPH_H */ @@ -176,20 +176,20 @@ struct if_stats { /* Link Parameters for Traffic Engineering */ struct if_link_params { - u_int32_t lp_status; /* Status of Link Parameters: */ - u_int32_t te_metric; /* Traffic Engineering metric */ + uint32_t lp_status; /* Status of Link Parameters: */ + uint32_t te_metric; /* Traffic Engineering metric */ float default_bw; float max_bw; /* Maximum Bandwidth */ float max_rsv_bw; /* Maximum Reservable Bandwidth */ float unrsv_bw[MAX_CLASS_TYPE]; /* Unreserved Bandwidth per Class Type (8) */ - u_int32_t admin_grp; /* Administrative group */ - u_int32_t rmt_as; /* Remote AS number */ + uint32_t admin_grp; /* Administrative group */ + uint32_t rmt_as; /* Remote AS number */ struct in_addr rmt_ip; /* Remote IP address */ - u_int32_t av_delay; /* Link Average Delay */ - u_int32_t min_delay; /* Link Min Delay */ - u_int32_t max_delay; /* Link Max Delay */ - u_int32_t delay_var; /* Link Delay Variation */ + uint32_t av_delay; /* Link Average Delay */ + uint32_t min_delay; /* Link Min Delay */ + uint32_t max_delay; /* Link Max Delay */ + uint32_t delay_var; /* Link Delay Variation */ float pkt_loss; /* Link Packet Loss */ float res_bw; /* Residual Bandwidth */ float ava_bw; /* Available Bandwidth */ @@ -224,7 +224,7 @@ struct interface { #define IFINDEX_INTERNAL 0 /* Zebra internal interface status */ - u_char status; + uint8_t status; #define ZEBRA_INTERFACE_ACTIVE (1 << 0) #define ZEBRA_INTERFACE_SUB (1 << 1) #define ZEBRA_INTERFACE_LINKDETECTION (1 << 2) @@ -247,7 +247,7 @@ struct interface { /* Link-layer information and hardware address */ enum zebra_link_type ll_type; - u_char hw_addr[INTERFACE_HWADDR_MAX]; + uint8_t hw_addr[INTERFACE_HWADDR_MAX]; int hw_addr_len; /* interface bandwidth, kbits */ @@ -347,7 +347,7 @@ struct connected { struct interface *ifp; /* Flags for configuration. */ - u_char conf; + uint8_t conf; #define ZEBRA_IFC_REAL (1 << 0) #define ZEBRA_IFC_CONFIGURED (1 << 1) #define ZEBRA_IFC_QUEUED (1 << 2) @@ -367,7 +367,7 @@ struct connected { */ /* Flags for connected address. */ - u_char flags; + uint8_t flags; #define ZEBRA_IFA_SECONDARY (1 << 0) #define ZEBRA_IFA_PEER (1 << 1) #define ZEBRA_IFA_UNNUMBERED (1 << 2) diff --git a/lib/imsg-buffer.c b/lib/imsg-buffer.c index ba1e26820b..b83f1f76f2 100644 --- a/lib/imsg-buffer.c +++ b/lib/imsg-buffer.c @@ -59,7 +59,7 @@ struct ibuf *ibuf_dynamic(size_t len, size_t max) int ibuf_realloc(struct ibuf *buf, size_t len) { - u_char *b; + uint8_t *b; /* on static buffers max is eq size and so the following fails */ if (buf->wpos + len > buf->max) { diff --git a/lib/imsg.c b/lib/imsg.c index 1c2f480aab..0ea1dd6302 100644 --- a/lib/imsg.c +++ b/lib/imsg.c @@ -193,8 +193,8 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (datalen + IMSG_HEADER_SIZE); } -int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, int fd, const void *data, u_int16_t datalen) +int imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, + pid_t pid, int fd, const void *data, uint16_t datalen) { struct ibuf *wbuf; @@ -211,7 +211,7 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (1); } -int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, +int imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid, int fd, const struct iovec *iov, int iovcnt) { struct ibuf *wbuf; @@ -235,8 +235,8 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, u_int16_t datalen) +struct ibuf *imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, + pid_t pid, uint16_t datalen) { struct ibuf *wbuf; struct imsg_hdr hdr; @@ -261,7 +261,7 @@ struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (wbuf); } -int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) +int imsg_add(struct ibuf *msg, const void *data, uint16_t datalen) { if (datalen) if (ibuf_add(msg, data, datalen) == -1) { @@ -281,7 +281,7 @@ void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) if (msg->fd != -1) hdr->flags |= IMSGF_HASFD; - hdr->len = (u_int16_t)msg->wpos; + hdr->len = (uint16_t)msg->wpos; ibuf_close(&ibuf->w, msg); } diff --git a/lib/imsg.h b/lib/imsg.h index ddaf71344e..eed7074e4a 100644 --- a/lib/imsg.h +++ b/lib/imsg.h @@ -27,7 +27,7 @@ struct ibuf { TAILQ_ENTRY(ibuf) entry; - u_char *buf; + uint8_t *buf; size_t size; size_t max; size_t wpos; @@ -37,13 +37,13 @@ struct ibuf { struct msgbuf { TAILQ_HEAD(, ibuf) bufs; - u_int32_t queued; + uint32_t queued; int fd; }; struct ibuf_read { - u_char buf[IBUF_READ_SIZE]; - u_char *rptr; + uint8_t buf[IBUF_READ_SIZE]; + uint8_t *rptr; size_t wpos; }; @@ -63,11 +63,11 @@ struct imsgbuf { #define IMSGF_HASFD 1 struct imsg_hdr { - u_int32_t type; - u_int16_t len; - u_int16_t flags; - u_int32_t peerid; - u_int32_t pid; + uint32_t type; + uint16_t len; + uint16_t flags; + uint32_t peerid; + uint32_t pid; }; struct imsg { @@ -97,13 +97,12 @@ void msgbuf_drain(struct msgbuf *, size_t); void imsg_init(struct imsgbuf *, int); ssize_t imsg_read(struct imsgbuf *); ssize_t imsg_get(struct imsgbuf *, struct imsg *); -int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, - const void *, u_int16_t); -int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, +int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const void *, + uint16_t); +int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int, const struct iovec *, int); -struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, - u_int16_t); -int imsg_add(struct ibuf *, const void *, u_int16_t); +struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t); +int imsg_add(struct ibuf *, const void *, uint16_t); void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_free(struct imsg *); int imsg_flush(struct imsgbuf *); diff --git a/lib/ipaddr.h b/lib/ipaddr.h index 44bde45add..33591cb4e7 100644 --- a/lib/ipaddr.h +++ b/lib/ipaddr.h @@ -37,7 +37,7 @@ enum ipaddr_type_t { struct ipaddr { enum ipaddr_type_t ipa_type; union { - u_char addr; + uint8_t addr; struct in_addr _v4_addr; struct in6_addr _v6_addr; } ip; @@ -95,7 +95,7 @@ static inline char *ipaddr2str(struct ipaddr *ip, char *buf, int size) static inline void ipv4_to_ipv4_mapped_ipv6(struct in6_addr *in6, struct in_addr in) { - u_int32_t addr_type = htonl(0xFFFF); + uint32_t addr_type = htonl(0xFFFF); memset(in6, 0, sizeof(struct in6_addr)); memcpy((char *)in6 + 8, &addr_type, sizeof(addr_type)); diff --git a/lib/jhash.c b/lib/jhash.c index b943997b1b..cb6946f37e 100644 --- a/lib/jhash.c +++ b/lib/jhash.c @@ -59,22 +59,22 @@ * of bytes. No alignment or length assumptions are made about * the input key. */ -u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval) +uint32_t jhash(const void *key, uint32_t length, uint32_t initval) { - u_int32_t a, b, c, len; - const u_int8_t *k = key; + uint32_t a, b, c, len; + const uint8_t *k = key; len = length; a = b = JHASH_GOLDEN_RATIO; c = initval; while (len >= 12) { - a += (k[0] + ((u_int32_t)k[1] << 8) + ((u_int32_t)k[2] << 16) - + ((u_int32_t)k[3] << 24)); - b += (k[4] + ((u_int32_t)k[5] << 8) + ((u_int32_t)k[6] << 16) - + ((u_int32_t)k[7] << 24)); - c += (k[8] + ((u_int32_t)k[9] << 8) + ((u_int32_t)k[10] << 16) - + ((u_int32_t)k[11] << 24)); + a += (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + + ((uint32_t)k[3] << 24)); + b += (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) + + ((uint32_t)k[7] << 24)); + c += (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) + + ((uint32_t)k[11] << 24)); __jhash_mix(a, b, c); @@ -85,34 +85,34 @@ u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval) c += length; switch (len) { case 11: - c += ((u_int32_t)k[10] << 24); + c += ((uint32_t)k[10] << 24); /* fallthru */ case 10: - c += ((u_int32_t)k[9] << 16); + c += ((uint32_t)k[9] << 16); /* fallthru */ case 9: - c += ((u_int32_t)k[8] << 8); + c += ((uint32_t)k[8] << 8); /* fallthru */ case 8: - b += ((u_int32_t)k[7] << 24); + b += ((uint32_t)k[7] << 24); /* fallthru */ case 7: - b += ((u_int32_t)k[6] << 16); + b += ((uint32_t)k[6] << 16); /* fallthru */ case 6: - b += ((u_int32_t)k[5] << 8); + b += ((uint32_t)k[5] << 8); /* fallthru */ case 5: b += k[4]; /* fallthru */ case 4: - a += ((u_int32_t)k[3] << 24); + a += ((uint32_t)k[3] << 24); /* fallthru */ case 3: - a += ((u_int32_t)k[2] << 16); + a += ((uint32_t)k[2] << 16); /* fallthru */ case 2: - a += ((u_int32_t)k[1] << 8); + a += ((uint32_t)k[1] << 8); /* fallthru */ case 1: a += k[0]; @@ -123,12 +123,12 @@ u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval) return c; } -/* A special optimized version that handles 1 or more of u_int32_ts. - * The length parameter here is the number of u_int32_ts in the key. +/* A special optimized version that handles 1 or more of uint32_ts. + * The length parameter here is the number of uint32_ts in the key. */ -u_int32_t jhash2(const u_int32_t *k, u_int32_t length, u_int32_t initval) +uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval) { - u_int32_t a, b, c, len; + uint32_t a, b, c, len; a = b = JHASH_GOLDEN_RATIO; c = initval; @@ -165,7 +165,7 @@ u_int32_t jhash2(const u_int32_t *k, u_int32_t length, u_int32_t initval) * NOTE: In partilar the "c += length; __jhash_mix(a,b,c);" normally * done at the end is not done here. */ -u_int32_t jhash_3words(u_int32_t a, u_int32_t b, u_int32_t c, u_int32_t initval) +uint32_t jhash_3words(uint32_t a, uint32_t b, uint32_t c, uint32_t initval) { a += JHASH_GOLDEN_RATIO; b += JHASH_GOLDEN_RATIO; @@ -176,12 +176,12 @@ u_int32_t jhash_3words(u_int32_t a, u_int32_t b, u_int32_t c, u_int32_t initval) return c; } -u_int32_t jhash_2words(u_int32_t a, u_int32_t b, u_int32_t initval) +uint32_t jhash_2words(uint32_t a, uint32_t b, uint32_t initval) { return jhash_3words(a, b, 0, initval); } -u_int32_t jhash_1word(u_int32_t a, u_int32_t initval) +uint32_t jhash_1word(uint32_t a, uint32_t initval) { return jhash_3words(a, 0, 0, initval); } diff --git a/lib/jhash.h b/lib/jhash.h index 74ce6a3233..f8ab4209a8 100644 --- a/lib/jhash.h +++ b/lib/jhash.h @@ -24,13 +24,12 @@ * of bytes. No alignment or length assumptions are made about * the input key. */ -extern u_int32_t jhash(const void *key, u_int32_t length, u_int32_t initval); +extern uint32_t jhash(const void *key, uint32_t length, uint32_t initval); -/* A special optimized version that handles 1 or more of u_int32_ts. - * The length parameter here is the number of u_int32_ts in the key. +/* A special optimized version that handles 1 or more of uint32_ts. + * The length parameter here is the number of uint32_ts in the key. */ -extern u_int32_t jhash2(const u_int32_t *k, u_int32_t length, - u_int32_t initval); +extern uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval); /* A special ultra-optimized versions that knows they are hashing exactly * 3, 2 or 1 word(s). @@ -38,9 +37,9 @@ extern u_int32_t jhash2(const u_int32_t *k, u_int32_t length, * NOTE: In partilar the "c += length; __jhash_mix(a,b,c);" normally * done at the end is not done here. */ -extern u_int32_t jhash_3words(u_int32_t a, u_int32_t b, u_int32_t c, - u_int32_t initval); -extern u_int32_t jhash_2words(u_int32_t a, u_int32_t b, u_int32_t initval); -extern u_int32_t jhash_1word(u_int32_t a, u_int32_t initval); +extern uint32_t jhash_3words(uint32_t a, uint32_t b, uint32_t c, + uint32_t initval); +extern uint32_t jhash_2words(uint32_t a, uint32_t b, uint32_t initval); +extern uint32_t jhash_1word(uint32_t a, uint32_t initval); #endif /* _QUAGGA_JHASH_H */ diff --git a/lib/keychain.c b/lib/keychain.c index 39807cc7ce..c3e1a6d3c4 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -124,7 +124,7 @@ static void keychain_delete(struct keychain *keychain) keychain_free(keychain); } -static struct key *key_lookup(const struct keychain *keychain, u_int32_t index) +static struct key *key_lookup(const struct keychain *keychain, uint32_t index) { struct listnode *node; struct key *key; @@ -137,7 +137,7 @@ static struct key *key_lookup(const struct keychain *keychain, u_int32_t index) } struct key *key_lookup_for_accept(const struct keychain *keychain, - u_int32_t index) + uint32_t index) { struct listnode *node; struct key *key; @@ -197,7 +197,7 @@ struct key *key_lookup_for_send(const struct keychain *keychain) return NULL; } -static struct key *key_get(const struct keychain *keychain, u_int32_t index) +static struct key *key_get(const struct keychain *keychain, uint32_t index) { struct key *key; @@ -270,7 +270,7 @@ DEFUN_NOSH (key, int idx_number = 1; VTY_DECLVAR_CONTEXT(keychain, keychain); struct key *key; - u_int32_t index; + uint32_t index; index = strtoul(argv[idx_number]->arg, NULL, 10); key = key_get(keychain, index); @@ -289,7 +289,7 @@ DEFUN (no_key, int idx_number = 2; VTY_DECLVAR_CONTEXT(keychain, keychain); struct key *key; - u_int32_t index; + uint32_t index; index = strtoul(argv[idx_number]->arg, NULL, 10); key = key_lookup(keychain, index); @@ -469,7 +469,7 @@ static int key_lifetime_duration_set(struct vty *vty, struct key_range *krange, const char *duration_str) { time_t time_start; - u_int32_t duration; + uint32_t duration; time_start = key_str2time(stime_str, sday_str, smonth_str, syear_str); if (time_start < 0) { diff --git a/lib/keychain.h b/lib/keychain.h index ab016f35c4..49da9ba459 100644 --- a/lib/keychain.h +++ b/lib/keychain.h @@ -36,11 +36,11 @@ struct key_range { time_t start; time_t end; - u_char duration; + uint8_t duration; }; struct key { - u_int32_t index; + uint32_t index; char *string; @@ -53,7 +53,7 @@ DECLARE_QOBJ_TYPE(key) extern void keychain_init(void); extern struct keychain *keychain_lookup(const char *); -extern struct key *key_lookup_for_accept(const struct keychain *, u_int32_t); +extern struct key *key_lookup_for_accept(const struct keychain *, uint32_t); extern struct key *key_match_for_accept(const struct keychain *, const char *); extern struct key *key_lookup_for_send(const struct keychain *); diff --git a/lib/linklist.h b/lib/linklist.h index 46617b5f65..ae150158a6 100644 --- a/lib/linklist.h +++ b/lib/linklist.h @@ -84,7 +84,7 @@ extern void *listnode_head(struct list *); * and remove list_delete_original and the list_delete #define * Additionally remove list_free entirely */ -#if CONFDATE > 20181001 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20181001 CPP_NOTICE("list_delete without double pointer is deprecated, please fixup") #endif extern void list_delete_and_null(struct list **); @@ -296,7 +296,7 @@ static char *str_append(char *dst, int len, const char *src) return dst; } -static char *num_append(char *s, int len, u_long x) +static char *num_append(char *s, int len, unsigned long x) { char buf[30]; char *t; @@ -312,7 +312,7 @@ static char *num_append(char *s, int len, u_long x) } #if defined(SA_SIGINFO) || defined(HAVE_STACK_TRACE) -static char *hex_append(char *s, int len, u_long x) +static char *hex_append(char *s, int len, unsigned long x) { char buf[30]; char *t; @@ -321,7 +321,7 @@ static char *hex_append(char *s, int len, u_long x) return str_append(s, len, "0"); *(t = &buf[sizeof(buf) - 1]) = '\0'; while (x && (t > buf)) { - u_int cc = (x % 16); + unsigned int cc = (x % 16); *--t = ((cc < 10) ? ('0' + cc) : ('a' + cc - 10)); x /= 16; } @@ -446,10 +446,10 @@ void zlog_signal(int signo, const char *action s = num_append(LOC, now); #ifdef SA_SIGINFO s = str_append(LOC, " (si_addr 0x"); - s = hex_append(LOC, (u_long)(siginfo->si_addr)); + s = hex_append(LOC, (unsigned long)(siginfo->si_addr)); if (program_counter) { s = str_append(LOC, ", PC 0x"); - s = hex_append(LOC, (u_long)program_counter); + s = hex_append(LOC, (unsigned long)program_counter); } s = str_append(LOC, "); "); #else /* SA_SIGINFO */ @@ -596,7 +596,8 @@ void zlog_backtrace_sigsafe(int priority, void *program_counter) s = str_append(LOC, "[bt "); s = num_append(LOC, i); s = str_append(LOC, "] 0x"); - s = hex_append(LOC, (u_long)(array[i])); + s = hex_append( + LOC, (unsigned long)(array[i])); } *s = '\0'; if (priority @@ -720,11 +721,11 @@ void memory_oom(size_t size, const char *name) } /* Open log stream */ -void openzlog(const char *progname, const char *protoname, u_short instance, - int syslog_flags, int syslog_facility) +void openzlog(const char *progname, const char *protoname, + unsigned short instance, int syslog_flags, int syslog_facility) { struct zlog *zl; - u_int i; + unsigned int i; zl = XCALLOC(MTYPE_ZLOG, sizeof(struct zlog)); @@ -964,14 +965,17 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_RULE_ADD), DESC_ENTRY(ZEBRA_RULE_DELETE), DESC_ENTRY(ZEBRA_RULE_NOTIFY_OWNER), + DESC_ENTRY(ZEBRA_TABLE_MANAGER_CONNECT), + DESC_ENTRY(ZEBRA_GET_TABLE_CHUNK), + DESC_ENTRY(ZEBRA_RELEASE_TABLE_CHUNK), }; #undef DESC_ENTRY static const struct zebra_desc_table unknown = {0, "unknown", '?'}; -static const struct zebra_desc_table *zroute_lookup(u_int zroute) +static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) { - u_int i; + unsigned int i; if (zroute >= array_size(route_types)) { zlog_err("unknown zebra route type: %u", zroute); @@ -992,12 +996,12 @@ static const struct zebra_desc_table *zroute_lookup(u_int zroute) return &unknown; } -const char *zebra_route_string(u_int zroute) +const char *zebra_route_string(unsigned int zroute) { return zroute_lookup(zroute)->string; } -char zebra_route_char(u_int zroute) +char zebra_route_char(unsigned int zroute) { return zroute_lookup(zroute)->chr; } diff --git a/lib/log_int.h b/lib/log_int.h index 56823fb971..a7f8be9ae7 100644 --- a/lib/log_int.h +++ b/lib/log_int.h @@ -27,7 +27,7 @@ struct zlog { const char *ident; /* daemon name (first arg to openlog) */ const char *protoname; - u_short instance; + unsigned short instance; int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated logging destination */ int default_lvl; /* maxlvl to use if none is specified */ @@ -64,7 +64,7 @@ typedef struct { } md5_ctxt; extern void md5_init(md5_ctxt *); -extern void md5_loop(md5_ctxt *, const void *, u_int); +extern void md5_loop(md5_ctxt *, const void *, unsigned int); extern void md5_pad(md5_ctxt *); extern void md5_result(uint8_t *, md5_ctxt *); diff --git a/lib/memory.c b/lib/memory.c index 90d7d420a9..be8b100ba7 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -26,6 +26,7 @@ struct memgroup **mg_insert = &mg_first; DEFINE_MGROUP(LIB, "libfrr") DEFINE_MTYPE(LIB, TMP, "Temporary memory") +DEFINE_MTYPE(LIB, PREFIX_FLOWSPEC, "Prefix Flowspec") static inline void mt_count_alloc(struct memtype *mt, size_t size) { diff --git a/lib/memory.h b/lib/memory.h index 6de370514a..1fbbbe4231 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -127,6 +127,7 @@ struct memgroup { DECLARE_MGROUP(LIB) DECLARE_MTYPE(TMP) +DECLARE_MTYPE(PREFIX_FLOWSPEC) extern void *qmalloc(struct memtype *mt, size_t size) diff --git a/lib/mpls.h b/lib/mpls.h index 1a1819c2c0..4e5c70cf8c 100644 --- a/lib/mpls.h +++ b/lib/mpls.h @@ -124,8 +124,8 @@ enum lsp_types_t { /* Encode a label stack entry from fields; convert to network byte-order as * the Netlink interface expects MPLS labels to be in this format. */ -static inline mpls_lse_t mpls_lse_encode(mpls_label_t label, u_int32_t ttl, - u_int32_t exp, u_int32_t bos) +static inline mpls_lse_t mpls_lse_encode(mpls_label_t label, uint32_t ttl, + uint32_t exp, uint32_t bos) { mpls_lse_t lse; lse = htonl((label << MPLS_LS_LABEL_SHIFT) | (exp << MPLS_LS_EXP_SHIFT) @@ -139,8 +139,7 @@ static inline mpls_lse_t mpls_lse_encode(mpls_label_t label, u_int32_t ttl, * Netlink interface. */ static inline void mpls_lse_decode(mpls_lse_t lse, mpls_label_t *label, - u_int32_t *ttl, u_int32_t *exp, - u_int32_t *bos) + uint32_t *ttl, uint32_t *exp, uint32_t *bos) { mpls_lse_t local_lse; diff --git a/lib/netns_linux.c b/lib/netns_linux.c index 01616be711..3d61cecc03 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -412,9 +412,12 @@ void ns_init(void) return; errno = 0; #ifdef HAVE_NETNS - if (have_netns_enabled < 0) + if (have_netns_enabled < 0) { ns_default_ns_fd = open(NS_DEFAULT_NAME, O_RDONLY); - else { + if (ns_default_ns_fd == -1) + zlog_err("NS initialization failure %d(%s)", + errno, safe_strerror(errno)); + } else { ns_default_ns_fd = -1; default_ns = NULL; } @@ -422,9 +425,6 @@ void ns_init(void) ns_default_ns_fd = -1; default_ns = NULL; #endif /* HAVE_NETNS */ - if (ns_default_ns_fd == -1) - zlog_err("NS initialisation failure (%s)", - safe_strerror(errno)); ns_current_ns_fd = -1; ns_initialised = 1; } diff --git a/lib/network.c b/lib/network.c index 3f72b7141e..6d3350ad49 100644 --- a/lib/network.c +++ b/lib/network.c @@ -24,7 +24,7 @@ #include "network.h" /* Read nbytes from fd and store into ptr. */ -int readn(int fd, u_char *ptr, int nbytes) +int readn(int fd, uint8_t *ptr, int nbytes) { int nleft; int nread; @@ -47,7 +47,7 @@ int readn(int fd, u_char *ptr, int nbytes) } /* Write nbytes from ptr to fd. */ -int writen(int fd, const u_char *ptr, int nbytes) +int writen(int fd, const uint8_t *ptr, int nbytes) { int nleft; int nwritten; @@ -105,12 +105,12 @@ int set_cloexec(int fd) float htonf(float host) { - u_int32_t lu1, lu2; + uint32_t lu1, lu2; float convert; - memcpy(&lu1, &host, sizeof(u_int32_t)); + memcpy(&lu1, &host, sizeof(uint32_t)); lu2 = htonl(lu1); - memcpy(&convert, &lu2, sizeof(u_int32_t)); + memcpy(&convert, &lu2, sizeof(uint32_t)); return convert; } diff --git a/lib/network.h b/lib/network.h index 4faf992bc5..4703dc9b63 100644 --- a/lib/network.h +++ b/lib/network.h @@ -25,8 +25,8 @@ /* Both readn and writen are deprecated and will be removed. They are not suitable for use with non-blocking file descriptors. */ -extern int readn(int, u_char *, int); -extern int writen(int, const u_char *, int); +extern int readn(int, uint8_t *, int); +extern int writen(int, const uint8_t *, int); /* Set the file descriptor to use non-blocking I/O. Returns 0 for success, -1 on error. */ diff --git a/lib/nexthop.c b/lib/nexthop.c index fb7ccc169e..b1e9582b20 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -216,7 +216,7 @@ bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2) /* Update nexthop with label information. */ void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type, - u_int8_t num_labels, mpls_label_t *label) + uint8_t num_labels, mpls_label_t *label) { struct mpls_label_stack *nh_label; int i; diff --git a/lib/nexthop.h b/lib/nexthop.h index 568243d3a9..036fc5b888 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -71,7 +71,7 @@ struct nexthop { enum nexthop_types_t type; - u_char flags; + uint8_t flags; #define NEXTHOP_FLAG_ACTIVE (1 << 0) /* This nexthop is alive. */ #define NEXTHOP_FLAG_FIB (1 << 1) /* FIB nexthop. */ #define NEXTHOP_FLAG_RECURSIVE (1 << 2) /* Recursive nexthop. */ @@ -114,7 +114,7 @@ struct nexthop *nexthop_new(void); void nexthop_free(struct nexthop *nexthop); void nexthops_free(struct nexthop *nexthop); -void nexthop_add_labels(struct nexthop *, enum lsp_types_t, u_int8_t, +void nexthop_add_labels(struct nexthop *, enum lsp_types_t, uint8_t, mpls_label_t *); void nexthop_del_labels(struct nexthop *); @@ -26,7 +26,7 @@ #include "linklist.h" #include "vty.h" -typedef u_int32_t ns_id_t; +typedef uint32_t ns_id_t; /* the default NS ID */ #define NS_UNKNOWN UINT32_MAX diff --git a/lib/pid_output.c b/lib/pid_output.c index 9a7307bc4f..023a166f27 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -71,7 +71,8 @@ pid_t pid_output(const char *path) else if (ftruncate(fd, pidsize) < 0) zlog_err( "Could not truncate pid_file %s to %u bytes: %s", - path, (u_int)pidsize, safe_strerror(errno)); + path, (unsigned int)pidsize, + safe_strerror(errno)); } return pid; } diff --git a/lib/plist.c b/lib/plist.c index 9dd5e561a7..01b55f9f1d 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1812,8 +1812,8 @@ static int config_write_prefix_afi(afi_t afi, struct vty *vty) } struct stream *prefix_bgp_orf_entry(struct stream *s, struct prefix_list *plist, - u_char init_flag, u_char permit_flag, - u_char deny_flag) + uint8_t init_flag, uint8_t permit_flag, + uint8_t deny_flag) { struct prefix_list_entry *pentry; @@ -1821,15 +1821,15 @@ struct stream *prefix_bgp_orf_entry(struct stream *s, struct prefix_list *plist, return s; for (pentry = plist->head; pentry; pentry = pentry->next) { - u_char flag = init_flag; + uint8_t flag = init_flag; struct prefix *p = &pentry->prefix; flag |= (pentry->type == PREFIX_PERMIT ? permit_flag : deny_flag); stream_putc(s, flag); - stream_putl(s, (u_int32_t)pentry->seq); - stream_putc(s, (u_char)pentry->ge); - stream_putc(s, (u_char)pentry->le); + stream_putl(s, (uint32_t)pentry->seq); + stream_putc(s, (uint8_t)pentry->ge); + stream_putc(s, (uint8_t)pentry->le); stream_put_prefix(s, p); } @@ -1893,7 +1893,7 @@ void prefix_bgp_orf_remove_all(afi_t afi, char *name) /* return prefix count */ int prefix_bgp_show_prefix_list(struct vty *vty, afi_t afi, char *name, - u_char use_json) + uint8_t use_json) { struct prefix_list *plist; struct prefix_list_entry *pentry; diff --git a/lib/plist.h b/lib/plist.h index 9662f0311b..67e345a485 100644 --- a/lib/plist.h +++ b/lib/plist.h @@ -35,9 +35,9 @@ enum prefix_list_type { struct prefix_list; struct orf_prefix { - u_int32_t seq; - u_char ge; - u_char le; + uint32_t seq; + uint8_t ge; + uint8_t le; struct prefix p; }; @@ -67,10 +67,10 @@ prefix_list_apply_which_prefix(struct prefix_list *plist, struct prefix **which, extern struct prefix_list *prefix_bgp_orf_lookup(afi_t, const char *); extern struct stream *prefix_bgp_orf_entry(struct stream *, - struct prefix_list *, u_char, u_char, - u_char); + struct prefix_list *, uint8_t, + uint8_t, uint8_t); extern int prefix_bgp_orf_set(char *, afi_t, struct orf_prefix *, int, int); extern void prefix_bgp_orf_remove_all(afi_t, char *); -extern int prefix_bgp_show_prefix_list(struct vty *, afi_t, char *, u_char); +extern int prefix_bgp_show_prefix_list(struct vty *, afi_t, char *, uint8_t); #endif /* _QUAGGA_PLIST_H */ diff --git a/lib/prefix.c b/lib/prefix.c index 1344039498..b38dd94589 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -31,8 +31,8 @@ DEFINE_MTYPE_STATIC(LIB, PREFIX, "Prefix") /* Maskbit. */ -static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, - 0xf8, 0xfc, 0xfe, 0xff}; +static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, + 0xf8, 0xfc, 0xfe, 0xff}; static const struct in6_addr maskbytes6[] = { /* /0 */ {{{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -441,7 +441,7 @@ int is_zero_mac(struct ethaddr *mac) return 1; } -unsigned int prefix_bit(const u_char *prefix, const u_char prefixlen) +unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen) { unsigned int offset = prefixlen / 8; unsigned int shift = 7 - (prefixlen % 8); @@ -449,9 +449,9 @@ unsigned int prefix_bit(const u_char *prefix, const u_char prefixlen) return (prefix[offset] >> shift) & 1; } -unsigned int prefix6_bit(const struct in6_addr *prefix, const u_char prefixlen) +unsigned int prefix6_bit(const struct in6_addr *prefix, const uint8_t prefixlen) { - return prefix_bit((const u_char *)&prefix->s6_addr, prefixlen); + return prefix_bit((const uint8_t *)&prefix->s6_addr, prefixlen); } int str2family(const char *string) @@ -467,6 +467,21 @@ int str2family(const char *string) return -1; } +const char *family2str(int family) +{ + switch (family) { + case AF_INET: + return "IPv4"; + case AF_INET6: + return "IPv6"; + case AF_ETHERNET: + return "Ethernet"; + case AF_EVPN: + return "Evpn"; + } + return "?"; +} + /* Address Famiy Identifier to Address Family converter. */ int afi2family(afi_t afi) { @@ -523,6 +538,8 @@ const char *safi2str(safi_t safi) return "evpn"; case SAFI_LABELED_UNICAST: return "labeled-unicast"; + case SAFI_FLOWSPEC: + return "flowspec"; default: return "unknown"; } @@ -533,15 +550,33 @@ int prefix_match(const struct prefix *n, const struct prefix *p) { int offset; int shift; - const u_char *np, *pp; + const uint8_t *np, *pp; /* If n's prefix is longer than p's one return 0. */ if (n->prefixlen > p->prefixlen) return 0; + if (n->family == AF_FLOWSPEC) { + /* prefixlen is unused. look at fs prefix len */ + if (n->u.prefix_flowspec.prefixlen > + p->u.prefix_flowspec.prefixlen) + return 0; + + /* Set both prefix's head pointer. */ + np = (const uint8_t *)&n->u.prefix_flowspec.ptr; + pp = (const uint8_t *)&p->u.prefix_flowspec.ptr; + + offset = n->u.prefix_flowspec.prefixlen; + + while (offset--) + if (np[offset] != pp[offset]) + return 0; + return 1; + } + /* Set both prefix's head pointer. */ - np = (const u_char *)&n->u.prefix; - pp = (const u_char *)&p->u.prefix; + np = (const uint8_t *)&n->u.prefix; + pp = (const uint8_t *)&p->u.prefix; offset = n->prefixlen / PNBBY; shift = n->prefixlen % PNBBY; @@ -562,11 +597,11 @@ int prefix_match_network_statement(const struct prefix *n, { int offset; int shift; - const u_char *np, *pp; + const uint8_t *np, *pp; /* Set both prefix's head pointer. */ - np = (const u_char *)&n->u.prefix; - pp = (const u_char *)&p->u.prefix; + np = (const uint8_t *)&n->u.prefix; + pp = (const uint8_t *)&p->u.prefix; offset = n->prefixlen / PNBBY; shift = n->prefixlen % PNBBY; @@ -581,7 +616,6 @@ int prefix_match_network_statement(const struct prefix *n, return 1; } -/* Copy prefix from src to dest. */ void prefix_copy(struct prefix *dest, const struct prefix *src) { dest->family = src->family; @@ -600,6 +634,18 @@ void prefix_copy(struct prefix *dest, const struct prefix *src) } else if (src->family == AF_UNSPEC) { dest->u.lp.id = src->u.lp.id; dest->u.lp.adv_router = src->u.lp.adv_router; + } else if (src->family == AF_FLOWSPEC) { + void *temp; + int len; + + len = src->u.prefix_flowspec.prefixlen; + dest->u.prefix_flowspec.prefixlen = + src->u.prefix_flowspec.prefixlen; + dest->family = src->family; + temp = XCALLOC(MTYPE_PREFIX_FLOWSPEC, len); + dest->u.prefix_flowspec.ptr = (uintptr_t)temp; + memcpy((void *)dest->u.prefix_flowspec.ptr, + (void *)src->u.prefix_flowspec.ptr, len); } else { zlog_err("prefix_copy(): Unknown address family %d", src->family); @@ -639,6 +685,15 @@ int prefix_same(const struct prefix *p1, const struct prefix *p2) if (!memcmp(&p1->u.prefix_evpn, &p2->u.prefix_evpn, sizeof(struct evpn_addr))) return 1; + if (p1->family == AF_FLOWSPEC) { + if (p1->u.prefix_flowspec.prefixlen != + p2->u.prefix_flowspec.prefixlen) + return 0; + if (!memcmp(&p1->u.prefix_flowspec.ptr, + &p2->u.prefix_flowspec.ptr, + p2->u.prefix_flowspec.prefixlen)) + return 1; + } } return 0; } @@ -659,12 +714,30 @@ int prefix_cmp(const struct prefix *p1, const struct prefix *p2) int shift; /* Set both prefix's head pointer. */ - const u_char *pp1 = (const u_char *)&p1->u.prefix; - const u_char *pp2 = (const u_char *)&p2->u.prefix; + const uint8_t *pp1; + const uint8_t *pp2; - if (p1->family != p2->family || p1->prefixlen != p2->prefixlen) + if (p1->family != p2->family) return 1; + if (p1->family == AF_FLOWSPEC) { + pp1 = (const uint8_t *)p1->u.prefix_flowspec.ptr; + pp2 = (const uint8_t *)p2->u.prefix_flowspec.ptr; + + if (p1->u.prefix_flowspec.prefixlen != + p2->u.prefix_flowspec.prefixlen) + return 1; + offset = p1->u.prefix_flowspec.prefixlen; + while (offset--) + if (pp1[offset] != pp2[offset]) + return 1; + return 0; + } + pp1 = (const uint8_t *)&p1->u.prefix; + pp2 = (const uint8_t *)&p2->u.prefix; + + if (p1->prefixlen != p2->prefixlen) + return 1; offset = p1->prefixlen / PNBBY; shift = p1->prefixlen % PNBBY; @@ -689,11 +762,11 @@ int prefix_common_bits(const struct prefix *p1, const struct prefix *p2) { int pos, bit; int length = 0; - u_char xor ; + uint8_t xor ; /* Set both prefix's head pointer. */ - const u_char *pp1 = (const u_char *)&p1->u.prefix; - const u_char *pp2 = (const u_char *)&p2->u.prefix; + const uint8_t *pp1 = (const uint8_t *)&p1->u.prefix; + const uint8_t *pp2 = (const uint8_t *)&p2->u.prefix; if (p1->family == AF_INET) length = IPV4_MAX_BYTELEN; @@ -787,7 +860,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p) XFREE(MTYPE_TMP, cp); /* Get prefix length. */ - plen = (u_char)atoi(++pnt); + plen = (uint8_t)atoi(++pnt); if (plen > IPV4_MAX_PREFIXLEN) return 0; @@ -821,7 +894,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p) if (pnt) { /* Get prefix length. */ - plen = (u_char)atoi(++pnt); + plen = (uint8_t)atoi(++pnt); if (plen > 48) { ret = 0; goto done; @@ -883,7 +956,7 @@ 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. */ -u_char ip_masklen(struct in_addr netmask) +uint8_t ip_masklen(struct in_addr netmask) { uint32_t tmp = ~ntohl(netmask.s_addr); if (tmp) @@ -953,7 +1026,7 @@ int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p) XFREE(MTYPE_TMP, cp); if (ret == 0) return 0; - plen = (u_char)atoi(++pnt); + plen = (uint8_t)atoi(++pnt); if (plen > IPV6_MAX_BITLEN) return 0; p->prefixlen = plen; @@ -964,7 +1037,7 @@ int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p) } /* Convert struct in6_addr netmask into integer. - * FIXME return u_char as ip_maskleni() does. */ + * FIXME return uint8_t as ip_maskleni() does. */ int ip6_masklen(struct in6_addr netmask) { int len = 0; @@ -996,14 +1069,14 @@ void masklen2ip6(const int masklen, struct in6_addr *netmask) void apply_mask_ipv6(struct prefix_ipv6 *p) { - u_char *pnt; + uint8_t *pnt; int index; int offset; index = p->prefixlen / 8; if (index < 16) { - pnt = (u_char *)&p->prefix; + pnt = (uint8_t *)&p->prefix; offset = p->prefixlen % 8; pnt[index] &= maskbit[offset]; @@ -1135,7 +1208,7 @@ int str2prefix(const char *str, struct prefix *p) static const char *prefixevpn2str(const struct prefix *p, char *str, int size) { - u_char family; + uint8_t family; char buf[PREFIX2STR_BUFFER]; char buf2[ETHER_ADDR_STRLEN]; @@ -1207,6 +1280,10 @@ const char *prefix2str(union prefixconstptr pu, char *str, int size) prefixevpn2str(p, str, size); break; + case AF_FLOWSPEC: + sprintf(str, "FS prefix"); + break; + default: sprintf(str, "UNK prefix"); break; @@ -1244,7 +1321,7 @@ int all_digit(const char *str) void apply_classful_mask_ipv4(struct prefix_ipv4 *p) { - u_int32_t destination; + uint32_t destination; destination = ntohl(p->prefix.s_addr); @@ -1292,8 +1369,8 @@ int netmask_str2prefix_str(const char *net_str, const char *mask_str, { struct in_addr network; struct in_addr mask; - u_char prefixlen; - u_int32_t destination; + uint8_t prefixlen; + uint32_t destination; int ret; ret = inet_aton(net_str, &network); @@ -1386,6 +1463,24 @@ unsigned prefix_hash_key(void *pp) { struct prefix copy; + if (((struct prefix *)pp)->family == AF_FLOWSPEC) { + uint32_t len; + void *temp; + + /* make sure *all* unused bits are zero, + * particularly including alignment / + * padding and unused prefix bytes. + */ + memset(©, 0, sizeof(copy)); + prefix_copy(©, (struct prefix *)pp); + len = jhash((void *)copy.u.prefix_flowspec.ptr, + copy.u.prefix_flowspec.prefixlen, + 0x55aa5a5a); + temp = (void *)copy.u.prefix_flowspec.ptr; + XFREE(MTYPE_PREFIX_FLOWSPEC, temp); + copy.u.prefix_flowspec.ptr = (uintptr_t)NULL; + return len; + } /* make sure *all* unused bits are zero, particularly including * alignment / * padding and unused prefix bytes. */ diff --git a/lib/prefix.h b/lib/prefix.h index 1724225817..f01c85b811 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -45,7 +45,7 @@ * own to simplify internal handling */ struct ethaddr { - u_char octet[ETH_ALEN]; + uint8_t octet[ETH_ALEN]; } __attribute__((packed)); @@ -58,15 +58,15 @@ struct ethaddr { /* EVPN address (RFC 7432) */ struct evpn_addr { - u_char route_type; - u_char ip_prefix_length; + uint8_t route_type; + uint8_t ip_prefix_length; struct ethaddr mac; uint32_t eth_tag; struct ipaddr ip; #if 0 union { - u_char addr; + uint8_t addr; struct in_addr v4_addr; struct in6_addr v6_addr; } ip; @@ -106,12 +106,21 @@ struct evpn_addr { #define AF_EVPN (AF_MAX + 1) #endif +#if !defined(AF_FLOWSPEC) +#define AF_FLOWSPEC (AF_MAX + 2) +#endif + +struct flowspec_prefix { + uint16_t prefixlen; /* length in bytes */ + uintptr_t ptr; +}; + /* FRR generic prefix structure. */ struct prefix { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; union { - u_char prefix; + uint8_t prefix; struct in_addr prefix4; struct in6_addr prefix6; struct { @@ -119,64 +128,72 @@ struct prefix { struct in_addr adv_router; } lp; struct ethaddr prefix_eth; /* AF_ETHERNET */ - u_char val[16]; + uint8_t val[16]; uintptr_t ptr; struct evpn_addr prefix_evpn; /* AF_EVPN */ + struct flowspec_prefix prefix_flowspec; /* AF_FLOWSPEC */ } u __attribute__((aligned(8))); }; /* IPv4 prefix structure. */ struct prefix_ipv4 { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct in_addr prefix __attribute__((aligned(8))); }; /* IPv6 prefix structure. */ struct prefix_ipv6 { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct in6_addr prefix __attribute__((aligned(8))); }; struct prefix_ls { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct in_addr id __attribute__((aligned(8))); struct in_addr adv_router; }; /* Prefix for routing distinguisher. */ struct prefix_rd { - u_char family; - u_char prefixlen; - u_char val[8] __attribute__((aligned(8))); + uint8_t family; + uint8_t prefixlen; + uint8_t val[8] __attribute__((aligned(8))); }; /* Prefix for ethernet. */ struct prefix_eth { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */ }; /* EVPN prefix structure. */ struct prefix_evpn { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct evpn_addr prefix __attribute__((aligned(8))); }; /* Prefix for a generic pointer */ struct prefix_ptr { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; uintptr_t prefix __attribute__((aligned(8))); }; +/* Prefix for a Flowspec entry */ +struct prefix_fs { + uint8_t family; + uint8_t prefixlen; /* unused */ + struct flowspec_prefix prefix __attribute__((aligned(8))); +}; + struct prefix_sg { - u_char family; - u_char prefixlen; + uint8_t family; + uint8_t prefixlen; struct in_addr src __attribute__((aligned(8))); struct in_addr grp; }; @@ -191,6 +208,7 @@ union prefixptr { struct prefix_ipv4 *p4; struct prefix_ipv6 *p6; struct prefix_evpn *evp; + const struct prefix_fs *fs; } __attribute__((transparent_union)); union prefixconstptr { @@ -198,6 +216,7 @@ union prefixconstptr { const struct prefix_ipv4 *p4; const struct prefix_ipv6 *p6; const struct prefix_evpn *evp; + const struct prefix_fs *fs; } __attribute__((transparent_union)); #ifndef INET_ADDRSTRLEN @@ -235,11 +254,11 @@ static inline void ipv4_addr_copy(struct in_addr *dst, } #define IPV4_ADDR_COPY(D,S) ipv4_addr_copy((D), (S)) -#define IPV4_NET0(a) ((((u_int32_t) (a)) & 0xff000000) == 0x00000000) -#define IPV4_NET127(a) ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000) -#define IPV4_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffff0000) == 0xa9fe0000) -#define IPV4_CLASS_DE(a) ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000) -#define IPV4_MC_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffffff00) == 0xe0000000) +#define IPV4_NET0(a) ((((uint32_t)(a)) & 0xff000000) == 0x00000000) +#define IPV4_NET127(a) ((((uint32_t)(a)) & 0xff000000) == 0x7f000000) +#define IPV4_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffff0000) == 0xa9fe0000) +#define IPV4_CLASS_DE(a) ((((uint32_t)(a)) & 0xe0000000) == 0xe0000000) +#define IPV4_MC_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffffff00) == 0xe0000000) /* Max bit/byte length of IPv6 address. */ #define IPV6_MAX_BYTELEN 16 @@ -271,13 +290,14 @@ static inline void ipv4_addr_copy(struct in_addr *dst, extern int str2family(const char *); extern int afi2family(afi_t); extern afi_t family2afi(int); +extern const char *family2str(int family); 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 u_char *prefix, const u_char prefixlen); +extern unsigned int prefix_bit(const uint8_t *prefix, const uint8_t prefixlen); extern unsigned int prefix6_bit(const struct in6_addr *prefix, - const u_char prefixlen); + const uint8_t prefixlen); extern struct prefix *prefix_new(void); extern void prefix_free(struct prefix *); @@ -318,7 +338,7 @@ extern void apply_mask_ipv4(struct prefix_ipv4 *); extern int prefix_ipv4_any(const struct prefix_ipv4 *); extern void apply_classful_mask_ipv4(struct prefix_ipv4 *); -extern u_char ip_masklen(struct in_addr); +extern uint8_t ip_masklen(struct in_addr); extern void masklen2ip(const int, struct in_addr *); /* returns the network portion of the host address */ extern in_addr_t ipv4_network_addr(in_addr_t hostaddr, int masklen); diff --git a/lib/sigevent.c b/lib/sigevent.c index d55f368dfb..d299760fab 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -284,7 +284,7 @@ static void trap_default_signals(void) }; static const struct { const int *sigs; - u_int nsigs; + unsigned int nsigs; void (*handler)(int signo #ifdef SA_SIGINFO , @@ -296,10 +296,10 @@ static void trap_default_signals(void) {exit_signals, array_size(exit_signals), exit_handler}, {ignore_signals, array_size(ignore_signals), NULL}, }; - u_int i; + unsigned int i; for (i = 0; i < array_size(sigmap); i++) { - u_int j; + unsigned int j; for (j = 0; j < sigmap[i].nsigs; j++) { struct sigaction oact; diff --git a/lib/smux.c b/lib/smux.c index 9a0063df21..51abfccba3 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -56,7 +56,7 @@ struct subtree { /* Tree's oid. */ oid name[MAX_OID_LEN]; - u_char name_len; + uint8_t name_len; /* List of the variables. */ struct variable *variables; @@ -189,11 +189,11 @@ static int smux_socket(void) } static void smux_getresp_send(oid objid[], size_t objid_len, long reqid, - long errstat, long errindex, u_char val_type, + long errstat, long errindex, uint8_t val_type, void *arg, size_t arg_len) { - u_char buf[BUFSIZ]; - u_char *ptr, *h1, *h1e, *h2, *h2e; + uint8_t buf[BUFSIZ]; + uint8_t *ptr, *h1, *h1e, *h2, *h2e; size_t len, length; ptr = buf; @@ -207,30 +207,33 @@ static void smux_getresp_send(oid objid[], size_t objid_len, long reqid, h1 = ptr; /* Place holder h1 for complete sequence */ - ptr = asn_build_sequence(ptr, &len, (u_char)SMUX_GETRSP, 0); + ptr = asn_build_sequence(ptr, &len, (uint8_t)SMUX_GETRSP, 0); h1e = ptr; - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - &reqid, sizeof(reqid)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &reqid, + sizeof(reqid)); if (debug_smux) zlog_debug("SMUX GETRSP errstat: %ld", errstat); - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - &errstat, sizeof(errstat)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + &errstat, sizeof(errstat)); if (debug_smux) zlog_debug("SMUX GETRSP errindex: %ld", errindex); - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - &errindex, sizeof(errindex)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + &errindex, sizeof(errindex)); h2 = ptr; /* Place holder h2 for one variable */ ptr = asn_build_sequence(ptr, &len, - (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); + (uint8_t)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); h2e = ptr; ptr = snmp_build_var_op(ptr, objid, &objid_len, val_type, arg_len, arg, @@ -238,10 +241,11 @@ static void smux_getresp_send(oid objid[], size_t objid_len, long reqid, /* Now variable size is known, fill in size */ asn_build_sequence(h2, &length, - (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), ptr - h2e); + (uint8_t)(ASN_SEQUENCE | ASN_CONSTRUCTOR), + ptr - h2e); /* Fill in size of whole sequence */ - asn_build_sequence(h1, &length, (u_char)SMUX_GETRSP, ptr - h1e); + asn_build_sequence(h1, &length, (uint8_t)SMUX_GETRSP, ptr - h1e); if (debug_smux) zlog_debug("SMUX getresp send: %td", (ptr - buf)); @@ -249,14 +253,14 @@ static void smux_getresp_send(oid objid[], size_t objid_len, long reqid, send(smux_sock, buf, (ptr - buf), 0); } -static u_char *smux_var(u_char *ptr, size_t len, oid objid[], size_t *objid_len, - size_t *var_val_len, u_char *var_val_type, - void **var_value) +static uint8_t *smux_var(uint8_t *ptr, size_t len, oid objid[], + size_t *objid_len, size_t *var_val_len, + uint8_t *var_val_type, void **var_value) { - u_char type; - u_char val_type; + uint8_t type; + uint8_t val_type; size_t val_len; - u_char *val; + uint8_t *val; if (debug_smux) zlog_debug("SMUX var parse: len %zd", len); @@ -347,7 +351,7 @@ static u_char *smux_var(u_char *ptr, size_t len, oid objid[], size_t *objid_len, ucd-snmp smux and as such suppose, that the peer receives in the message only one variable. Fortunately, IBM seems to do the same in AIX. */ -static int smux_set(oid *reqid, size_t *reqid_len, u_char val_type, void *val, +static int smux_set(oid *reqid, size_t *reqid_len, uint8_t val_type, void *val, size_t val_len, int action) { int j; @@ -357,7 +361,7 @@ static int smux_set(oid *reqid, size_t *reqid_len, u_char val_type, void *val, oid *suffix; size_t suffix_len; int result; - u_char *statP = NULL; + uint8_t *statP = NULL; WriteMethod *write_method = NULL; struct listnode *node, *nnode; @@ -414,7 +418,7 @@ static int smux_set(oid *reqid, size_t *reqid_len, u_char val_type, void *val, return SNMP_ERR_NOSUCHNAME; } -static int smux_get(oid *reqid, size_t *reqid_len, int exact, u_char *val_type, +static int smux_get(oid *reqid, size_t *reqid_len, int exact, uint8_t *val_type, void **val, size_t *val_len) { int j; @@ -481,7 +485,7 @@ static int smux_get(oid *reqid, size_t *reqid_len, int exact, u_char *val_type, } static int smux_getnext(oid *reqid, size_t *reqid_len, int exact, - u_char *val_type, void **val, size_t *val_len) + uint8_t *val_type, void **val, size_t *val_len) { int j; oid save[MAX_OID_LEN]; @@ -572,9 +576,9 @@ static int smux_getnext(oid *reqid, size_t *reqid_len, int exact, } /* GET message header. */ -static u_char *smux_parse_get_header(u_char *ptr, size_t *len, long *reqid) +static uint8_t *smux_parse_get_header(uint8_t *ptr, size_t *len, long *reqid) { - u_char type; + uint8_t type; long errstat; long errindex; @@ -600,12 +604,12 @@ static u_char *smux_parse_get_header(u_char *ptr, size_t *len, long *reqid) return ptr; } -static void smux_parse_set(u_char *ptr, size_t len, int action) +static void smux_parse_set(uint8_t *ptr, size_t len, int action) { long reqid; oid oid[MAX_OID_LEN]; size_t oid_len; - u_char val_type; + uint8_t val_type; void *val; size_t val_len; int ret; @@ -633,12 +637,12 @@ static void smux_parse_set(u_char *ptr, size_t len, int action) 0); } -static void smux_parse_get(u_char *ptr, size_t len, int exact) +static void smux_parse_get(uint8_t *ptr, size_t len, int exact) { long reqid; oid oid[MAX_OID_LEN]; size_t oid_len; - u_char val_type; + uint8_t val_type; void *val; size_t val_len; int ret; @@ -669,7 +673,7 @@ static void smux_parse_get(u_char *ptr, size_t len, int exact) } /* Parse SMUX_CLOSE message. */ -static void smux_parse_close(u_char *ptr, int len) +static void smux_parse_close(uint8_t *ptr, int len) { long reason = 0; @@ -681,9 +685,9 @@ static void smux_parse_close(u_char *ptr, int len) } /* SMUX_RRSP message. */ -static void smux_parse_rrsp(u_char *ptr, size_t len) +static void smux_parse_rrsp(uint8_t *ptr, size_t len) { - u_char val; + uint8_t val; long errstat; ptr = asn_parse_int(ptr, &len, &val, &errstat, sizeof(errstat)); @@ -693,17 +697,17 @@ static void smux_parse_rrsp(u_char *ptr, size_t len) } /* Parse SMUX message. */ -static int smux_parse(u_char *ptr, size_t len) +static int smux_parse(uint8_t *ptr, size_t len) { /* This buffer we'll use for SOUT message. We could allocate it with malloc and save only static pointer/lenght, but IMHO static buffer is a faster solusion. */ - static u_char sout_save_buff[SMUXMAXPKTSIZE]; + static uint8_t sout_save_buff[SMUXMAXPKTSIZE]; static int sout_save_len = 0; int len_income = len; /* see note below: YYY */ - u_char type; - u_char rollback; + uint8_t type; + uint8_t rollback; rollback = ptr[2]; /* important only for SMUX_SOUT */ @@ -813,7 +817,7 @@ static int smux_read(struct thread *t) { int sock; int len; - u_char buf[SMUXMAXPKTSIZE]; + uint8_t buf[SMUXMAXPKTSIZE]; int ret; /* Clear thread. */ @@ -864,8 +868,8 @@ static int smux_read(struct thread *t) static int smux_open(int sock) { - u_char buf[BUFSIZ]; - u_char *ptr; + uint8_t buf[BUFSIZ]; + uint8_t *ptr; size_t len; long version; const char progname[] = FRR_SMUX_NAME "-" FRR_VERSION; @@ -880,32 +884,36 @@ static int smux_open(int sock) len = BUFSIZ; /* SMUX Header. As placeholder. */ - ptr = asn_build_header(ptr, &len, (u_char)SMUX_OPEN, 0); + ptr = asn_build_header(ptr, &len, (uint8_t)SMUX_OPEN, 0); /* SMUX Open. */ version = 0; - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - &version, sizeof(version)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + &version, sizeof(version)); /* SMUX connection oid. */ - ptr = asn_build_objid(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_OBJECT_ID), - smux_oid, smux_oid_len); + ptr = asn_build_objid( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), + smux_oid, smux_oid_len); /* SMUX connection description. */ - ptr = asn_build_string(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_OCTET_STR), - (const u_char *)progname, strlen(progname)); + ptr = asn_build_string( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), + (const uint8_t *)progname, strlen(progname)); /* SMUX connection password. */ - ptr = asn_build_string(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_OCTET_STR), - (u_char *)smux_passwd, strlen(smux_passwd)); + ptr = asn_build_string( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), + (uint8_t *)smux_passwd, strlen(smux_passwd)); /* Fill in real SMUX header. We exclude ASN header size (2). */ len = BUFSIZ; - asn_build_header(buf, &len, (u_char)SMUX_OPEN, (ptr - buf) - 2); + asn_build_header(buf, &len, (uint8_t)SMUX_OPEN, (ptr - buf) - 2); return send(sock, buf, (ptr - buf), 0); } @@ -919,15 +927,15 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, size_t enamelen, const oid *name, size_t namelen, const oid *iname, size_t inamelen, const struct trap_object *trapobj, size_t trapobjlen, - u_char sptrap) + uint8_t sptrap) { unsigned int i; - u_char buf[BUFSIZ]; - u_char *ptr; + uint8_t buf[BUFSIZ]; + uint8_t *ptr; size_t len, length; struct in_addr addr; unsigned long val; - u_char *h1, *h1e; + uint8_t *h1, *h1e; ptr = buf; len = BUFSIZ; @@ -938,42 +946,46 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, return 0; /* SMUX header. */ - ptr = asn_build_header(ptr, &len, (u_char)SMUX_TRAP, 0); + ptr = asn_build_header(ptr, &len, (uint8_t)SMUX_TRAP, 0); /* Sub agent enterprise oid. */ - ptr = asn_build_objid(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_OBJECT_ID), - smux_oid, smux_oid_len); + ptr = asn_build_objid( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), + smux_oid, smux_oid_len); /* IP address. */ addr.s_addr = 0; - ptr = asn_build_string(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_IPADDRESS), - (u_char *)&addr, sizeof(addr)); + ptr = asn_build_string( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_IPADDRESS), + (uint8_t *)&addr, sizeof(addr)); /* Generic trap integer. */ val = SNMP_TRAP_ENTERPRISESPECIFIC; - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - (long *)&val, sizeof(val)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + (long *)&val, sizeof(val)); /* Specific trap integer. */ val = sptrap; - ptr = asn_build_int(ptr, &len, (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE - | ASN_INTEGER), - (long *)&val, sizeof(val)); + ptr = asn_build_int( + ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + (long *)&val, sizeof(val)); /* Timeticks timestamp. */ val = 0; ptr = asn_build_unsigned_int( ptr, &len, - (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_TIMETICKS), &val, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_TIMETICKS), &val, sizeof(val)); /* Variables. */ h1 = ptr; ptr = asn_build_sequence(ptr, &len, - (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); + (uint8_t)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); /* Iteration for each objects. */ @@ -984,7 +996,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, size_t oid_len; void *val; size_t val_len; - u_char val_type; + uint8_t val_type; /* Make OID. */ if (trapobj[i].namelen > 0) { @@ -1013,7 +1025,7 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, } smux_oid_dump("Trap", oid, oid_len); zlog_info("BUFSIZ: %d // oid_len: %lu", BUFSIZ, - (u_long)oid_len); + (unsigned long)oid_len); } ret = smux_get(oid, &oid_len, 1, &val_type, &val, &val_len); @@ -1028,19 +1040,20 @@ int smux_trap(struct variable *vp, size_t vp_len, const oid *ename, /* Now variable size is known, fill in size */ asn_build_sequence(h1, &length, - (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), ptr - h1e); + (uint8_t)(ASN_SEQUENCE | ASN_CONSTRUCTOR), + ptr - h1e); /* Fill in size of whole sequence */ len = BUFSIZ; - asn_build_header(buf, &len, (u_char)SMUX_TRAP, (ptr - buf) - 2); + asn_build_header(buf, &len, (uint8_t)SMUX_TRAP, (ptr - buf) - 2); return send(smux_sock, buf, (ptr - buf), 0); } static int smux_register(int sock) { - u_char buf[BUFSIZ]; - u_char *ptr; + uint8_t buf[BUFSIZ]; + uint8_t *ptr; int ret; size_t len; long priority; @@ -1055,26 +1068,26 @@ static int smux_register(int sock) len = BUFSIZ; /* SMUX RReq Header. */ - ptr = asn_build_header(ptr, &len, (u_char)SMUX_RREQ, 0); + ptr = asn_build_header(ptr, &len, (uint8_t)SMUX_RREQ, 0); /* Register MIB tree. */ - ptr = asn_build_objid( - ptr, &len, - (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), - subtree->name, subtree->name_len); + ptr = asn_build_objid(ptr, &len, + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE + | ASN_OBJECT_ID), + subtree->name, subtree->name_len); /* Priority. */ priority = -1; ptr = asn_build_int( ptr, &len, - (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &priority, sizeof(priority)); /* Operation. */ operation = 2; /* Register R/W */ ptr = asn_build_int( ptr, &len, - (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), + (uint8_t)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), &operation, sizeof(operation)); if (debug_smux) { @@ -1085,7 +1098,8 @@ static int smux_register(int sock) } len = BUFSIZ; - asn_build_header(buf, &len, (u_char)SMUX_RREQ, (ptr - buf) - 2); + asn_build_header(buf, &len, (uint8_t)SMUX_RREQ, + (ptr - buf) - 2); ret = send(sock, buf, (ptr - buf), 0); if (ret < 0) return ret; diff --git a/lib/smux.h b/lib/smux.h index 987414c0d1..9adfacb3e4 100644 --- a/lib/smux.h +++ b/lib/smux.h @@ -59,11 +59,11 @@ struct trap_object { #define SNMP_INTEGER(V) \ (*var_len = sizeof(snmp_int_val), snmp_int_val = V, \ - (u_char *)&snmp_int_val) + (uint8_t *)&snmp_int_val) #define SNMP_IPADDRESS(V) \ (*var_len = sizeof(struct in_addr), snmp_in_addr_val = V, \ - (u_char *)&snmp_in_addr_val) + (uint8_t *)&snmp_in_addr_val) extern void smux_init(struct thread_master *tm); extern void smux_register_mib(const char *, struct variable *, size_t, int, @@ -96,7 +96,7 @@ extern int smux_header_table(struct variable *, oid *, size_t *, int, size_t *, */ extern int smux_trap(struct variable *, size_t, const oid *, size_t, const oid *, size_t, const oid *, size_t, - const struct trap_object *, size_t, u_char); + const struct trap_object *, size_t, uint8_t); extern int oid_compare(const oid *, int, const oid *, int); extern void oid2in_addr(oid[], int, struct in_addr *); diff --git a/lib/snmp.c b/lib/snmp.c index fefd7ba37d..f11d9dc8cf 100644 --- a/lib/snmp.c +++ b/lib/snmp.c @@ -53,12 +53,12 @@ void *oid_copy(void *dest, const void *src, size_t size) void oid2in_addr(oid oid[], int len, struct in_addr *addr) { int i; - u_char *pnt; + uint8_t *pnt; if (len == 0) return; - pnt = (u_char *)addr; + pnt = (uint8_t *)addr; for (i = 0; i < len; i++) *pnt++ = oid[i]; @@ -67,12 +67,12 @@ void oid2in_addr(oid oid[], int len, struct in_addr *addr) void oid_copy_addr(oid oid[], struct in_addr *addr, int len) { int i; - u_char *pnt; + uint8_t *pnt; if (len == 0) return; - pnt = (u_char *)addr; + pnt = (uint8_t *)addr; for (i = 0; i < len; i++) oid[i] = *pnt++; diff --git a/lib/sockopt.c b/lib/sockopt.c index d100991a33..1d8d9990df 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -56,7 +56,7 @@ void setsockopt_so_sendbuf(const int sock, int size) int getsockopt_so_sendbuf(const int sock) { - u_int32_t optval; + uint32_t optval; socklen_t optlen = sizeof(optval); int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&optval, &optlen); @@ -382,7 +382,7 @@ int setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, #endif } -int setsockopt_ipv4_multicast_loop(int sock, u_char val) +int setsockopt_ipv4_multicast_loop(int sock, uint8_t val) { int ret; @@ -584,9 +584,9 @@ int sockopt_tcp_signature(int sock, union sockunion *su, const char *password) #define TCP_MD5_AUTH_ADD 1 #define TCP_MD5_AUTH_DEL 2 struct tcp_rfc2385_cmd { - u_int8_t command; /* Command - Add/Delete */ - u_int32_t address; /* IPV4 address associated */ - u_int8_t keylen; /* MD5 Key len (do NOT assume 0 terminated + uint8_t command; /* Command - Add/Delete */ + uint32_t address; /* IPV4 address associated */ + uint8_t keylen; /* MD5 Key len (do NOT assume 0 terminated ascii) */ void *key; /* MD5 Key */ } cmd; diff --git a/lib/sockopt.h b/lib/sockopt.h index 7be36222da..f54f60ffd7 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -81,7 +81,7 @@ extern int setsockopt_ipv4_multicast(int sock, int optname, struct in_addr if_addr, unsigned int mcast_addr, ifindex_t ifindex); -extern int setsockopt_ipv4_multicast_loop(int sock, u_char val); +extern int setsockopt_ipv4_multicast_loop(int sock, uint8_t val); extern int setsockopt_ipv4_tos(int sock, int tos); diff --git a/lib/sockunion.c b/lib/sockunion.c index ab8d8be3e5..28a7f647cb 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -486,18 +486,18 @@ size_t sockunion_get_addrlen(const union sockunion *su) return family2addrsize(sockunion_family(su)); } -const u_char *sockunion_get_addr(const union sockunion *su) +const uint8_t *sockunion_get_addr(const union sockunion *su) { switch (sockunion_family(su)) { case AF_INET: - return (const u_char *)&su->sin.sin_addr.s_addr; + return (const uint8_t *)&su->sin.sin_addr.s_addr; case AF_INET6: - return (const u_char *)&su->sin6.sin6_addr; + return (const uint8_t *)&su->sin6.sin6_addr; } return NULL; } -void sockunion_set(union sockunion *su, int family, const u_char *addr, +void sockunion_set(union sockunion *su, int family, const uint8_t *addr, size_t bytes) { if (family2addrsize(family) != bytes) @@ -622,10 +622,10 @@ static int in6addr_cmp(const struct in6_addr *addr1, const struct in6_addr *addr2) { unsigned int i; - const u_char *p1, *p2; + const uint8_t *p1, *p2; - p1 = (const u_char *)addr1; - p2 = (const u_char *)addr2; + p1 = (const uint8_t *)addr1; + p2 = (const uint8_t *)addr2; for (i = 0; i < sizeof(struct in6_addr); i++) { if (p1[i] > p2[i]) diff --git a/lib/sockunion.h b/lib/sockunion.h index 67a7a46272..b585aee5b4 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -73,8 +73,8 @@ extern unsigned int sockunion_hash(const union sockunion *); extern size_t family2addrsize(int family); extern size_t sockunion_get_addrlen(const union sockunion *); -extern const u_char *sockunion_get_addr(const union sockunion *); -extern void sockunion_set(union sockunion *, int family, const u_char *addr, +extern const uint8_t *sockunion_get_addr(const union sockunion *); +extern void sockunion_set(union sockunion *, int family, const uint8_t *addr, size_t bytes); extern union sockunion *sockunion_str2su(const char *str); diff --git a/lib/stream.c b/lib/stream.c index 3c08d4454b..927a3d3d55 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -171,7 +171,7 @@ struct stream *stream_dupcat(struct stream *s1, struct stream *s2, size_t stream_resize(struct stream *s, size_t newsize) { - u_char *newdata; + uint8_t *newdata; STREAM_VERIFY_SANE(s); newdata = XREALLOC(MTYPE_STREAM_DATA, s->data, newsize); @@ -299,11 +299,11 @@ void stream_get(void *dst, struct stream *s, size_t size) } /* Get next character from the stream. */ -inline bool stream_getc2(struct stream *s, u_char *byte) +inline bool stream_getc2(struct stream *s, uint8_t *byte) { STREAM_VERIFY_SANE(s); - if (STREAM_READABLE(s) < sizeof(u_char)) { + if (STREAM_READABLE(s) < sizeof(uint8_t)) { STREAM_BOUND_WARN2(s, "get char"); return false; } @@ -312,13 +312,13 @@ inline bool stream_getc2(struct stream *s, u_char *byte) return true; } -u_char stream_getc(struct stream *s) +uint8_t stream_getc(struct stream *s) { - u_char c; + uint8_t c; STREAM_VERIFY_SANE(s); - if (STREAM_READABLE(s) < sizeof(u_char)) { + if (STREAM_READABLE(s) < sizeof(uint8_t)) { STREAM_BOUND_WARN(s, "get char"); return 0; } @@ -328,13 +328,13 @@ u_char stream_getc(struct stream *s) } /* Get next character from the stream. */ -u_char stream_getc_from(struct stream *s, size_t from) +uint8_t stream_getc_from(struct stream *s, size_t from) { - u_char c; + uint8_t c; STREAM_VERIFY_SANE(s); - if (!GETP_VALID(s, from + sizeof(u_char))) { + if (!GETP_VALID(s, from + sizeof(uint8_t))) { STREAM_BOUND_WARN(s, "get char"); return 0; } @@ -360,13 +360,13 @@ inline bool stream_getw2(struct stream *s, uint16_t *word) } /* Get next word from the stream. */ -u_int16_t stream_getw(struct stream *s) +uint16_t stream_getw(struct stream *s) { - u_int16_t w; + uint16_t w; STREAM_VERIFY_SANE(s); - if (STREAM_READABLE(s) < sizeof(u_int16_t)) { + if (STREAM_READABLE(s) < sizeof(uint16_t)) { STREAM_BOUND_WARN(s, "get "); return 0; } @@ -378,13 +378,13 @@ u_int16_t stream_getw(struct stream *s) } /* Get next word from the stream. */ -u_int16_t stream_getw_from(struct stream *s, size_t from) +uint16_t stream_getw_from(struct stream *s, size_t from) { - u_int16_t w; + uint16_t w; STREAM_VERIFY_SANE(s); - if (!GETP_VALID(s, from + sizeof(u_int16_t))) { + if (!GETP_VALID(s, from + sizeof(uint16_t))) { STREAM_BOUND_WARN(s, "get "); return 0; } @@ -396,9 +396,9 @@ u_int16_t stream_getw_from(struct stream *s, size_t from) } /* Get next 3-byte from the stream. */ -u_int32_t stream_get3_from(struct stream *s, size_t from) +uint32_t stream_get3_from(struct stream *s, size_t from) { - u_int32_t l; + uint32_t l; STREAM_VERIFY_SANE(s); @@ -414,9 +414,9 @@ u_int32_t stream_get3_from(struct stream *s, size_t from) return l; } -u_int32_t stream_get3(struct stream *s) +uint32_t stream_get3(struct stream *s) { - u_int32_t l; + uint32_t l; STREAM_VERIFY_SANE(s); @@ -433,13 +433,13 @@ u_int32_t stream_get3(struct stream *s) } /* Get next long word from the stream. */ -u_int32_t stream_getl_from(struct stream *s, size_t from) +uint32_t stream_getl_from(struct stream *s, size_t from) { - u_int32_t l; + uint32_t l; STREAM_VERIFY_SANE(s); - if (!GETP_VALID(s, from + sizeof(u_int32_t))) { + if (!GETP_VALID(s, from + sizeof(uint32_t))) { STREAM_BOUND_WARN(s, "get long"); return 0; } @@ -482,13 +482,13 @@ inline bool stream_getl2(struct stream *s, uint32_t *l) return true; } -u_int32_t stream_getl(struct stream *s) +uint32_t stream_getl(struct stream *s) { - u_int32_t l; + uint32_t l; STREAM_VERIFY_SANE(s); - if (STREAM_READABLE(s) < sizeof(u_int32_t)) { + if (STREAM_READABLE(s) < sizeof(uint32_t)) { STREAM_BOUND_WARN(s, "get long"); return 0; } @@ -549,19 +549,19 @@ uint64_t stream_getq(struct stream *s) } /* Get next long word from the stream. */ -u_int32_t stream_get_ipv4(struct stream *s) +uint32_t stream_get_ipv4(struct stream *s) { - u_int32_t l; + uint32_t l; STREAM_VERIFY_SANE(s); - if (STREAM_READABLE(s) < sizeof(u_int32_t)) { + if (STREAM_READABLE(s) < sizeof(uint32_t)) { STREAM_BOUND_WARN(s, "get ipv4"); return 0; } - memcpy(&l, s->data + s->getp, sizeof(u_int32_t)); - s->getp += sizeof(u_int32_t); + memcpy(&l, s->data + s->getp, sizeof(uint32_t)); + s->getp += sizeof(uint32_t); return l; } @@ -615,37 +615,37 @@ void stream_put(struct stream *s, const void *src, size_t size) } /* Put character to the stream. */ -int stream_putc(struct stream *s, u_char c) +int stream_putc(struct stream *s, uint8_t c) { STREAM_VERIFY_SANE(s); - if (STREAM_WRITEABLE(s) < sizeof(u_char)) { + if (STREAM_WRITEABLE(s) < sizeof(uint8_t)) { STREAM_BOUND_WARN(s, "put"); return 0; } s->data[s->endp++] = c; - return sizeof(u_char); + return sizeof(uint8_t); } /* Put word to the stream. */ -int stream_putw(struct stream *s, u_int16_t w) +int stream_putw(struct stream *s, uint16_t w) { STREAM_VERIFY_SANE(s); - if (STREAM_WRITEABLE(s) < sizeof(u_int16_t)) { + if (STREAM_WRITEABLE(s) < sizeof(uint16_t)) { STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[s->endp++] = (u_char)(w >> 8); - s->data[s->endp++] = (u_char)w; + s->data[s->endp++] = (uint8_t)(w >> 8); + s->data[s->endp++] = (uint8_t)w; return 2; } /* Put long word to the stream. */ -int stream_put3(struct stream *s, u_int32_t l) +int stream_put3(struct stream *s, uint32_t l) { STREAM_VERIFY_SANE(s); @@ -654,27 +654,27 @@ int stream_put3(struct stream *s, u_int32_t l) return 0; } - s->data[s->endp++] = (u_char)(l >> 16); - s->data[s->endp++] = (u_char)(l >> 8); - s->data[s->endp++] = (u_char)l; + s->data[s->endp++] = (uint8_t)(l >> 16); + s->data[s->endp++] = (uint8_t)(l >> 8); + s->data[s->endp++] = (uint8_t)l; return 3; } /* Put long word to the stream. */ -int stream_putl(struct stream *s, u_int32_t l) +int stream_putl(struct stream *s, uint32_t l) { STREAM_VERIFY_SANE(s); - if (STREAM_WRITEABLE(s) < sizeof(u_int32_t)) { + if (STREAM_WRITEABLE(s) < sizeof(uint32_t)) { STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[s->endp++] = (u_char)(l >> 24); - s->data[s->endp++] = (u_char)(l >> 16); - s->data[s->endp++] = (u_char)(l >> 8); - s->data[s->endp++] = (u_char)l; + s->data[s->endp++] = (uint8_t)(l >> 24); + s->data[s->endp++] = (uint8_t)(l >> 16); + s->data[s->endp++] = (uint8_t)(l >> 8); + s->data[s->endp++] = (uint8_t)l; return 4; } @@ -689,14 +689,14 @@ int stream_putq(struct stream *s, uint64_t q) return 0; } - s->data[s->endp++] = (u_char)(q >> 56); - s->data[s->endp++] = (u_char)(q >> 48); - s->data[s->endp++] = (u_char)(q >> 40); - s->data[s->endp++] = (u_char)(q >> 32); - s->data[s->endp++] = (u_char)(q >> 24); - s->data[s->endp++] = (u_char)(q >> 16); - s->data[s->endp++] = (u_char)(q >> 8); - s->data[s->endp++] = (u_char)q; + s->data[s->endp++] = (uint8_t)(q >> 56); + s->data[s->endp++] = (uint8_t)(q >> 48); + s->data[s->endp++] = (uint8_t)(q >> 40); + s->data[s->endp++] = (uint8_t)(q >> 32); + s->data[s->endp++] = (uint8_t)(q >> 24); + s->data[s->endp++] = (uint8_t)(q >> 16); + s->data[s->endp++] = (uint8_t)(q >> 8); + s->data[s->endp++] = (uint8_t)q; return 8; } @@ -721,11 +721,11 @@ int stream_putd(struct stream *s, double d) return stream_putq(s, u.o); } -int stream_putc_at(struct stream *s, size_t putp, u_char c) +int stream_putc_at(struct stream *s, size_t putp, uint8_t c) { STREAM_VERIFY_SANE(s); - if (!PUT_AT_VALID(s, putp + sizeof(u_char))) { + if (!PUT_AT_VALID(s, putp + sizeof(uint8_t))) { STREAM_BOUND_WARN(s, "put"); return 0; } @@ -735,22 +735,22 @@ int stream_putc_at(struct stream *s, size_t putp, u_char c) return 1; } -int stream_putw_at(struct stream *s, size_t putp, u_int16_t w) +int stream_putw_at(struct stream *s, size_t putp, uint16_t w) { STREAM_VERIFY_SANE(s); - if (!PUT_AT_VALID(s, putp + sizeof(u_int16_t))) { + if (!PUT_AT_VALID(s, putp + sizeof(uint16_t))) { STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[putp] = (u_char)(w >> 8); - s->data[putp + 1] = (u_char)w; + s->data[putp] = (uint8_t)(w >> 8); + s->data[putp + 1] = (uint8_t)w; return 2; } -int stream_put3_at(struct stream *s, size_t putp, u_int32_t l) +int stream_put3_at(struct stream *s, size_t putp, uint32_t l) { STREAM_VERIFY_SANE(s); @@ -758,25 +758,25 @@ int stream_put3_at(struct stream *s, size_t putp, u_int32_t l) STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[putp] = (u_char)(l >> 16); - s->data[putp + 1] = (u_char)(l >> 8); - s->data[putp + 2] = (u_char)l; + s->data[putp] = (uint8_t)(l >> 16); + s->data[putp + 1] = (uint8_t)(l >> 8); + s->data[putp + 2] = (uint8_t)l; return 3; } -int stream_putl_at(struct stream *s, size_t putp, u_int32_t l) +int stream_putl_at(struct stream *s, size_t putp, uint32_t l) { STREAM_VERIFY_SANE(s); - if (!PUT_AT_VALID(s, putp + sizeof(u_int32_t))) { + if (!PUT_AT_VALID(s, putp + sizeof(uint32_t))) { STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[putp] = (u_char)(l >> 24); - s->data[putp + 1] = (u_char)(l >> 16); - s->data[putp + 2] = (u_char)(l >> 8); - s->data[putp + 3] = (u_char)l; + s->data[putp] = (uint8_t)(l >> 24); + s->data[putp + 1] = (uint8_t)(l >> 16); + s->data[putp + 2] = (uint8_t)(l >> 8); + s->data[putp + 3] = (uint8_t)l; return 4; } @@ -789,31 +789,31 @@ int stream_putq_at(struct stream *s, size_t putp, uint64_t q) STREAM_BOUND_WARN(s, "put"); return 0; } - s->data[putp] = (u_char)(q >> 56); - s->data[putp + 1] = (u_char)(q >> 48); - s->data[putp + 2] = (u_char)(q >> 40); - s->data[putp + 3] = (u_char)(q >> 32); - s->data[putp + 4] = (u_char)(q >> 24); - s->data[putp + 5] = (u_char)(q >> 16); - s->data[putp + 6] = (u_char)(q >> 8); - s->data[putp + 7] = (u_char)q; + s->data[putp] = (uint8_t)(q >> 56); + s->data[putp + 1] = (uint8_t)(q >> 48); + s->data[putp + 2] = (uint8_t)(q >> 40); + s->data[putp + 3] = (uint8_t)(q >> 32); + s->data[putp + 4] = (uint8_t)(q >> 24); + s->data[putp + 5] = (uint8_t)(q >> 16); + s->data[putp + 6] = (uint8_t)(q >> 8); + s->data[putp + 7] = (uint8_t)q; return 8; } /* Put long word to the stream. */ -int stream_put_ipv4(struct stream *s, u_int32_t l) +int stream_put_ipv4(struct stream *s, uint32_t l) { STREAM_VERIFY_SANE(s); - if (STREAM_WRITEABLE(s) < sizeof(u_int32_t)) { + if (STREAM_WRITEABLE(s) < sizeof(uint32_t)) { STREAM_BOUND_WARN(s, "put"); return 0; } - memcpy(s->data + s->endp, &l, sizeof(u_int32_t)); - s->endp += sizeof(u_int32_t); + memcpy(s->data + s->endp, &l, sizeof(uint32_t)); + s->endp += sizeof(uint32_t); - return sizeof(u_int32_t); + return sizeof(uint32_t); } /* Put long word to the stream. */ @@ -821,15 +821,15 @@ int stream_put_in_addr(struct stream *s, struct in_addr *addr) { STREAM_VERIFY_SANE(s); - if (STREAM_WRITEABLE(s) < sizeof(u_int32_t)) { + if (STREAM_WRITEABLE(s) < sizeof(uint32_t)) { STREAM_BOUND_WARN(s, "put"); return 0; } - memcpy(s->data + s->endp, addr, sizeof(u_int32_t)); - s->endp += sizeof(u_int32_t); + memcpy(s->data + s->endp, addr, sizeof(uint32_t)); + s->endp += sizeof(uint32_t); - return sizeof(u_int32_t); + return sizeof(uint32_t); } /* Put in_addr at location in the stream. */ @@ -862,7 +862,7 @@ int stream_put_in6_addr_at(struct stream *s, size_t putp, struct in6_addr *addr) /* Put prefix by nlri type format. */ int stream_put_prefix_addpath(struct stream *s, struct prefix *p, - int addpath_encode, u_int32_t addpath_tx_id) + int addpath_encode, uint32_t addpath_tx_id) { size_t psize; size_t psize_with_addpath; @@ -876,16 +876,16 @@ int stream_put_prefix_addpath(struct stream *s, struct prefix *p, else psize_with_addpath = psize; - if (STREAM_WRITEABLE(s) < (psize_with_addpath + sizeof(u_char))) { + if (STREAM_WRITEABLE(s) < (psize_with_addpath + sizeof(uint8_t))) { STREAM_BOUND_WARN(s, "put"); return 0; } if (addpath_encode) { - s->data[s->endp++] = (u_char)(addpath_tx_id >> 24); - s->data[s->endp++] = (u_char)(addpath_tx_id >> 16); - s->data[s->endp++] = (u_char)(addpath_tx_id >> 8); - s->data[s->endp++] = (u_char)addpath_tx_id; + s->data[s->endp++] = (uint8_t)(addpath_tx_id >> 24); + s->data[s->endp++] = (uint8_t)(addpath_tx_id >> 16); + s->data[s->endp++] = (uint8_t)(addpath_tx_id >> 8); + s->data[s->endp++] = (uint8_t)addpath_tx_id; } s->data[s->endp++] = p->prefixlen; @@ -905,7 +905,7 @@ int stream_put_labeled_prefix(struct stream *s, struct prefix *p, mpls_label_t *label) { size_t psize; - u_char *label_pnt = (u_char *)label; + uint8_t *label_pnt = (uint8_t *)label; STREAM_VERIFY_SANE(s); @@ -1060,7 +1060,7 @@ size_t stream_write(struct stream *s, const void *ptr, size_t size) * Use stream_get_pnt_to if you must, but decoding streams properly * is preferred */ -u_char *stream_pnt(struct stream *s) +uint8_t *stream_pnt(struct stream *s) { STREAM_VERIFY_SANE(s); return s->data + s->getp; diff --git a/lib/stream.h b/lib/stream.h index e738040d34..cc74e22a67 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -123,7 +123,7 @@ struct stream_fifo { #define STREAM_CONCAT_REMAIN(S1, S2, size) ((size) - (S1)->endp - (S2)->endp) /* deprecated macros - do not use in new code */ -#if CONFDATE > 20181128 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20181128 CPP_NOTICE("lib: time to remove deprecated stream.h macros") #endif #define STREAM_PNT(S) stream_pnt((S)) @@ -148,7 +148,7 @@ extern size_t stream_resize(struct stream *, size_t); extern size_t stream_get_getp(struct stream *); extern size_t stream_get_endp(struct stream *); extern size_t stream_get_size(struct stream *); -extern u_char *stream_get_data(struct stream *); +extern uint8_t *stream_get_data(struct stream *); /** * Create a new stream structure; copy offset bytes from s1 to the new @@ -165,43 +165,43 @@ extern void stream_forward_endp(struct stream *, size_t); /* steam_put: NULL source zeroes out size_t bytes of stream */ extern void stream_put(struct stream *, const void *, size_t); -extern int stream_putc(struct stream *, u_char); -extern int stream_putc_at(struct stream *, size_t, u_char); -extern int stream_putw(struct stream *, u_int16_t); -extern int stream_putw_at(struct stream *, size_t, u_int16_t); -extern int stream_put3(struct stream *, u_int32_t); -extern int stream_put3_at(struct stream *, size_t, u_int32_t); -extern int stream_putl(struct stream *, u_int32_t); -extern int stream_putl_at(struct stream *, size_t, u_int32_t); +extern int stream_putc(struct stream *, uint8_t); +extern int stream_putc_at(struct stream *, size_t, uint8_t); +extern int stream_putw(struct stream *, uint16_t); +extern int stream_putw_at(struct stream *, size_t, uint16_t); +extern int stream_put3(struct stream *, uint32_t); +extern int stream_put3_at(struct stream *, size_t, uint32_t); +extern int stream_putl(struct stream *, uint32_t); +extern int stream_putl_at(struct stream *, size_t, uint32_t); extern int stream_putq(struct stream *, uint64_t); extern int stream_putq_at(struct stream *, size_t, uint64_t); -extern int stream_put_ipv4(struct stream *, u_int32_t); +extern int stream_put_ipv4(struct stream *, uint32_t); extern int stream_put_in_addr(struct stream *, struct in_addr *); extern int stream_put_in_addr_at(struct stream *, size_t, struct in_addr *); extern int stream_put_in6_addr_at(struct stream *, size_t, struct in6_addr *); extern int stream_put_prefix_addpath(struct stream *, struct prefix *, int addpath_encode, - u_int32_t addpath_tx_id); + uint32_t addpath_tx_id); extern int stream_put_prefix(struct stream *, struct prefix *); extern int stream_put_labeled_prefix(struct stream *, struct prefix *, mpls_label_t *); extern void stream_get(void *, struct stream *, size_t); extern bool stream_get2(void *data, struct stream *s, size_t size); extern void stream_get_from(void *, struct stream *, size_t, size_t); -extern u_char stream_getc(struct stream *); -extern bool stream_getc2(struct stream *s, u_char *byte); -extern u_char stream_getc_from(struct stream *, size_t); -extern u_int16_t stream_getw(struct stream *); +extern uint8_t stream_getc(struct stream *); +extern bool stream_getc2(struct stream *s, uint8_t *byte); +extern uint8_t stream_getc_from(struct stream *, size_t); +extern uint16_t stream_getw(struct stream *); extern bool stream_getw2(struct stream *s, uint16_t *word); -extern u_int16_t stream_getw_from(struct stream *, size_t); -extern u_int32_t stream_get3(struct stream *); -extern u_int32_t stream_get3_from(struct stream *, size_t); -extern u_int32_t stream_getl(struct stream *); +extern uint16_t stream_getw_from(struct stream *, size_t); +extern uint32_t stream_get3(struct stream *); +extern uint32_t stream_get3_from(struct stream *, size_t); +extern uint32_t stream_getl(struct stream *); extern bool stream_getl2(struct stream *s, uint32_t *l); -extern u_int32_t stream_getl_from(struct stream *, size_t); +extern uint32_t stream_getl_from(struct stream *, size_t); extern uint64_t stream_getq(struct stream *); extern uint64_t stream_getq_from(struct stream *, size_t); -extern u_int32_t stream_get_ipv4(struct stream *); +extern uint32_t stream_get_ipv4(struct stream *); /* IEEE-754 floats */ extern float stream_getf(struct stream *); @@ -238,7 +238,7 @@ extern int stream_flush(struct stream *, int); extern int stream_empty(struct stream *); /* is the stream empty? */ /* deprecated */ -extern u_char *stream_pnt(struct stream *); +extern uint8_t *stream_pnt(struct stream *); /* Stream fifo. */ extern struct stream_fifo *stream_fifo_new(void); diff --git a/lib/table.c b/lib/table.c index 76062cd10c..3adb793891 100644 --- a/lib/table.c +++ b/lib/table.c @@ -142,20 +142,26 @@ static void route_table_free(struct route_table *rt) } /* Utility mask array. */ -static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, - 0xf8, 0xfc, 0xfe, 0xff}; +static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, + 0xf8, 0xfc, 0xfe, 0xff}; /* Common prefix route genaration. */ static void route_common(const struct prefix *n, const struct prefix *p, struct prefix *new) { int i; - u_char diff; - u_char mask; + uint8_t diff; + uint8_t mask; + const uint8_t *np; + const uint8_t *pp; + uint8_t *newp; - const u_char *np = (const u_char *)&n->u.prefix; - const u_char *pp = (const u_char *)&p->u.prefix; - u_char *newp = (u_char *)&new->u.prefix; + if (n->family == AF_FLOWSPEC) + return prefix_copy(new, p); + np = (const uint8_t *)&n->u.prefix; + pp = (const uint8_t *)&p->u.prefix; + + newp = (uint8_t *)&new->u.prefix; for (i = 0; i < p->prefixlen / 8; i++) { if (np[i] == pp[i]) @@ -277,8 +283,8 @@ struct route_node *route_node_get(struct route_table *const table, struct route_node *node; struct route_node *match; struct route_node *inserted; - u_char prefixlen = p->prefixlen; - const u_char *prefix = &p->u.prefix; + uint8_t prefixlen = p->prefixlen; + const uint8_t *prefix = &p->u.prefix; apply_mask((struct prefix *)p); node = hash_get(table->hash, (void *)p, NULL); diff --git a/lib/thread.c b/lib/thread.c index d26be1541f..f3129e39e8 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -621,7 +621,7 @@ struct timeval thread_timer_remain(struct thread *thread) } /* Get new thread. */ -static struct thread *thread_get(struct thread_master *m, u_char type, +static struct thread *thread_get(struct thread_master *m, uint8_t type, int (*func)(struct thread *), void *arg, debugargdef) { diff --git a/lib/vlan.h b/lib/vlan.h index 5e735aac1f..6d15e62dfc 100644 --- a/lib/vlan.h +++ b/lib/vlan.h @@ -23,7 +23,7 @@ #define __VLAN_H__ /* VLAN Identifier */ -typedef u_int16_t vlanid_t; +typedef uint16_t vlanid_t; #define VLANID_MAX 4095 #endif /* __VLAN_H__ */ @@ -343,10 +343,11 @@ void *vrf_info_lookup(vrf_id_t vrf_id) #define VRF_BITMAP_BIT_OFFSET(_id) ((_id) % VRF_BITMAP_NUM_OF_BITS_IN_GROUP) #define VRF_BITMAP_INDEX_IN_GROUP(_bit_offset) ((_bit_offset) / CHAR_BIT) -#define VRF_BITMAP_FLAG(_bit_offset) (((u_char)1) << ((_bit_offset) % CHAR_BIT)) +#define VRF_BITMAP_FLAG(_bit_offset) \ + (((uint8_t)1) << ((_bit_offset) % CHAR_BIT)) struct vrf_bitmap { - u_char *groups[VRF_BITMAP_NUM_OF_GROUPS]; + uint8_t *groups[VRF_BITMAP_NUM_OF_GROUPS]; }; vrf_bitmap_t vrf_bitmap_init(void) @@ -373,8 +374,8 @@ void vrf_bitmap_free(vrf_bitmap_t bmap) void vrf_bitmap_set(vrf_bitmap_t bmap, vrf_id_t vrf_id) { struct vrf_bitmap *bm = (struct vrf_bitmap *)bmap; - u_char group = VRF_BITMAP_GROUP(vrf_id); - u_char offset = VRF_BITMAP_BIT_OFFSET(vrf_id); + uint8_t group = VRF_BITMAP_GROUP(vrf_id); + uint8_t offset = VRF_BITMAP_BIT_OFFSET(vrf_id); if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN) return; @@ -390,8 +391,8 @@ void vrf_bitmap_set(vrf_bitmap_t bmap, vrf_id_t vrf_id) void vrf_bitmap_unset(vrf_bitmap_t bmap, vrf_id_t vrf_id) { struct vrf_bitmap *bm = (struct vrf_bitmap *)bmap; - u_char group = VRF_BITMAP_GROUP(vrf_id); - u_char offset = VRF_BITMAP_BIT_OFFSET(vrf_id); + uint8_t group = VRF_BITMAP_GROUP(vrf_id); + uint8_t offset = VRF_BITMAP_BIT_OFFSET(vrf_id); if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN || bm->groups[group] == NULL) @@ -404,8 +405,8 @@ void vrf_bitmap_unset(vrf_bitmap_t bmap, vrf_id_t vrf_id) int vrf_bitmap_check(vrf_bitmap_t bmap, vrf_id_t vrf_id) { struct vrf_bitmap *bm = (struct vrf_bitmap *)bmap; - u_char group = VRF_BITMAP_GROUP(vrf_id); - u_char offset = VRF_BITMAP_BIT_OFFSET(vrf_id); + uint8_t group = VRF_BITMAP_GROUP(vrf_id); + uint8_t offset = VRF_BITMAP_BIT_OFFSET(vrf_id); if (bmap == VRF_BITMAP_NULL || vrf_id == VRF_UNKNOWN || bm->groups[group] == NULL) @@ -641,6 +642,17 @@ int vrf_is_mapped_on_netns(vrf_id_t vrf_id) } /* vrf CLI commands */ +DEFUN_NOSH(vrf_exit, + vrf_exit_cmd, + "exit-vrf", + "Exit current mode and down to previous mode\n") +{ + /* We have to set vrf context to default vrf */ + VTY_PUSH_CONTEXT(VRF_NODE, vrf_get(VRF_DEFAULT, VRF_DEFAULT_NAME)); + vty->node = CONFIG_NODE; + return CMD_SUCCESS; +} + DEFUN_NOSH (vrf, vrf_cmd, "vrf NAME", @@ -798,6 +810,7 @@ void vrf_cmd_init(int (*writefunc)(struct vty *vty), install_element(CONFIG_NODE, &no_vrf_cmd); install_node(&vrf_node, writefunc); install_default(VRF_NODE); + install_element(VRF_NODE, &vrf_exit_cmd); if (vrf_is_backend_netns() && ns_have_netns()) { /* Install NS commands. */ vrf_daemon_privs = daemon_privs; @@ -73,7 +73,7 @@ struct vrf { char name[VRF_NAMSIZ + 1]; /* Zebra internal VRF status */ - u_char status; + uint8_t status; #define VRF_ACTIVE (1 << 0) /* VRF is up in kernel */ #define VRF_CONFIGURED (1 << 1) /* VRF has some FRR configuration */ @@ -160,9 +160,9 @@ int vty_out(struct vty *vty, const char *format, ...) /* Pointer p must point out buffer. */ if (vty->type != VTY_TERM) - buffer_put(vty->obuf, (u_char *)p, len); + buffer_put(vty->obuf, (uint8_t *)p, len); else - buffer_put_crlf(vty->obuf, (u_char *)p, len); + buffer_put_crlf(vty->obuf, (uint8_t *)p, len); /* If p is not different with buf, it is allocated buffer. */ if (p != buf) @@ -731,7 +731,6 @@ static void vty_end_config(struct vty *vty) case ISIS_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: - case MASC_NODE: case VTY_NODE: case BGP_EVPN_VNI_NODE: vty_config_unlock(vty); @@ -1128,7 +1127,6 @@ static void vty_stop_input(struct vty *vty) case ISIS_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: - case MASC_NODE: case VTY_NODE: vty_config_unlock(vty); vty->node = ENABLE_NODE; @@ -1243,12 +1241,12 @@ static int vty_telnet_option(struct vty *vty, unsigned char *buf, int nbytes) "RFC 1073 violation detected: telnet NAWS option " "should send %d characters, but we received %lu", TELNET_NAWS_SB_LEN, - (u_long)vty->sb_len); + (unsigned long)vty->sb_len); else if (sizeof(vty->sb_buf) < TELNET_NAWS_SB_LEN) zlog_err( "Bug detected: sizeof(vty->sb_buf) %lu < %d, " "too small to handle the telnet NAWS option", - (u_long)sizeof(vty->sb_buf), + (unsigned long)sizeof(vty->sb_buf), TELNET_NAWS_SB_LEN); else { vty->width = ((vty->sb_buf[1] << 8) @@ -2057,7 +2055,7 @@ static int vtysh_read(struct thread *thread) struct vty *vty; unsigned char buf[VTY_READ_BUFSIZ]; unsigned char *p; - u_char header[4] = {0, 0, 0, 0}; + uint8_t header[4] = {0, 0, 0, 0}; sock = THREAD_FD(thread); vty = THREAD_ARG(thread); @@ -189,45 +189,6 @@ struct vty_arg { /* Integrated configuration file. */ #define INTEGRATE_DEFAULT_CONFIG "frr.conf" -#if CONFDATE > 20180401 -CPP_NOTICE("It's probably time to remove VTY_NEWLINE compatibility foo.") -#endif - -/* for compatibility */ -#define VNL "\n" CPP_WARN("VNL has been replaced with \\n.") -#define VTYNL "\n" CPP_WARN("VTYNL has been replaced with \\n.") -#define VTY_NEWLINE "\n" CPP_WARN("VTY_NEWLINE has been replaced with \\n.") -#define VTY_GET_INTEGER(desc, v, str) \ - { \ - (v) = strtoul((str), NULL, 10); \ - } \ - CPP_WARN("VTY_GET_INTEGER is no longer useful, use strtoul() or DEFPY.") -#define VTY_GET_INTEGER_RANGE(desc, v, str, min, max) \ - { \ - (v) = strtoul((str), NULL, 10); \ - } \ - CPP_WARN( \ - "VTY_GET_INTEGER_RANGE is no longer useful, use strtoul() or DEFPY.") -#define VTY_GET_ULONG(desc, v, str) \ - { \ - (v) = strtoul((str), NULL, 10); \ - } \ - CPP_WARN("VTY_GET_ULONG is no longer useful, use strtoul() or DEFPY.") -#define VTY_GET_ULL(desc, v, str) \ - { \ - (v) = strtoull((str), NULL, 10); \ - } \ - CPP_WARN("VTY_GET_ULL is no longer useful, use strtoull() or DEFPY.") -#define VTY_GET_IPV4_ADDRESS(desc, v, str) \ - inet_aton((str), &(v)) CPP_WARN( \ - "VTY_GET_IPV4_ADDRESS is no longer useful, use inet_aton() or DEFPY.") -#define VTY_GET_IPV4_PREFIX(desc, v, str) \ - str2prefix_ipv4((str), &(v)) CPP_WARN( \ - "VTY_GET_IPV4_PREFIX is no longer useful, use str2prefix_ipv4() or DEFPY.") -#define vty_outln(vty, str, ...) \ - vty_out(vty, str "\n", ##__VA_ARGS__) CPP_WARN( \ - "vty_outln is no longer useful, use vty_out(...\\n...)") - /* Default time out value */ #define VTY_TIMEOUT_DEFAULT 600 diff --git a/lib/vxlan.h b/lib/vxlan.h index 75c7b97347..ba3dbb05c8 100644 --- a/lib/vxlan.h +++ b/lib/vxlan.h @@ -23,7 +23,7 @@ #define __VXLAN_H__ /* VxLAN Network Identifier - 24-bit (RFC 7348) */ -typedef u_int32_t vni_t; +typedef uint32_t vni_t; #define VNI_MAX 16777215 /* (2^24 - 1) */ #endif /* __VXLAN_H__ */ diff --git a/lib/workqueue.h b/lib/workqueue.h index c9785de09a..6085820393 100644 --- a/lib/workqueue.h +++ b/lib/workqueue.h @@ -106,7 +106,7 @@ struct work_queue { } cycles; /* cycle counts */ /* private state */ - u_int16_t flags; /* user set flag */ + uint16_t flags; /* user set flag */ }; /* User API */ @@ -154,7 +154,7 @@ extern struct work_queue *work_queue_new(struct thread_master *, const char *); * The usage of work_queue_free is being transitioned to pass * in the double pointer to remove use after free's. */ -#if CONFDATE > 20190205 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20190205 CPP_NOTICE("work_queue_free without double pointer is deprecated, please fixup") #endif extern void work_queue_free_and_null(struct work_queue **); diff --git a/lib/zclient.c b/lib/zclient.c index 2cac71ac45..d23f62dcd7 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -88,10 +88,11 @@ void zclient_free(struct zclient *zclient) XFREE(MTYPE_ZCLIENT, zclient); } -u_short *redist_check_instance(struct redist_proto *red, u_short instance) +unsigned short *redist_check_instance(struct redist_proto *red, + unsigned short instance) { struct listnode *node; - u_short *id; + unsigned short *id; if (!red->instances) return NULL; @@ -103,23 +104,23 @@ u_short *redist_check_instance(struct redist_proto *red, u_short instance) return NULL; } -void redist_add_instance(struct redist_proto *red, u_short instance) +void redist_add_instance(struct redist_proto *red, unsigned short instance) { - u_short *in; + unsigned short *in; red->enabled = 1; if (!red->instances) red->instances = list_new(); - in = XMALLOC(MTYPE_REDIST_INST, sizeof(u_short)); + in = XMALLOC(MTYPE_REDIST_INST, sizeof(unsigned short)); *in = instance; listnode_add(red->instances, in); } -void redist_del_instance(struct redist_proto *red, u_short instance) +void redist_del_instance(struct redist_proto *red, unsigned short instance) { - u_short *id; + unsigned short *id; id = redist_check_instance(red, instance); if (!id) @@ -294,9 +295,9 @@ void zclient_create_header(struct stream *s, uint16_t command, vrf_id_t vrf_id) stream_putw(s, command); } -int zclient_read_header(struct stream *s, int sock, u_int16_t *size, - u_char *marker, u_char *version, vrf_id_t *vrf_id, - u_int16_t *cmd) +int zclient_read_header(struct stream *s, int sock, uint16_t *size, + uint8_t *marker, uint8_t *version, vrf_id_t *vrf_id, + uint16_t *cmd) { if (stream_read(s, sock, ZEBRA_HEADER_SIZE) != ZEBRA_HEADER_SIZE) return -1; @@ -423,7 +424,7 @@ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) continue; struct listnode *node; - u_short *id; + unsigned short *id; for (ALL_LIST_ELEMENTS_RO( zclient->mi_redist[afi][i] @@ -488,7 +489,7 @@ void zclient_send_dereg_requests(struct zclient *zclient, vrf_id_t vrf_id) continue; struct listnode *node; - u_short *id; + unsigned short *id; for (ALL_LIST_ELEMENTS_RO( zclient->mi_redist[afi][i] @@ -594,8 +595,8 @@ int zclient_start(struct zclient *zclient) /* Initialize zebra client. Argument redist_default is unwanted redistribute route type. */ -void zclient_init(struct zclient *zclient, int redist_default, u_short instance, - struct zebra_privs_t *privs) +void zclient_init(struct zclient *zclient, int redist_default, + unsigned short instance, struct zebra_privs_t *privs) { int afi, i; @@ -730,7 +731,7 @@ int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p, * * XXX: No attention paid to alignment. */ -int zapi_ipv4_route(u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, +int zapi_ipv4_route(uint8_t cmd, struct zclient *zclient, struct prefix_ipv4 *p, struct zapi_ipv4 *api) { int i; @@ -765,7 +766,7 @@ int zapi_ipv4_route(u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, /* Put prefix information. */ psize = PSIZE(p->prefixlen); stream_putc(s, p->prefixlen); - stream_write(s, (u_char *)&p->prefix, psize); + stream_write(s, (uint8_t *)&p->prefix, psize); /* Nexthop, ifindex, distance and metric information. */ if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) { @@ -800,7 +801,7 @@ int zapi_ipv4_route(u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, return zclient_send_message(zclient); } -int zapi_ipv4_route_ipv6_nexthop(u_char cmd, struct zclient *zclient, +int zapi_ipv4_route_ipv6_nexthop(uint8_t cmd, struct zclient *zclient, struct prefix_ipv4 *p, struct zapi_ipv6 *api) { int i; @@ -835,7 +836,7 @@ int zapi_ipv4_route_ipv6_nexthop(u_char cmd, struct zclient *zclient, /* Put prefix information. */ psize = PSIZE(p->prefixlen); stream_putc(s, p->prefixlen); - stream_write(s, (u_char *)&p->prefix, psize); + stream_write(s, (uint8_t *)&p->prefix, psize); /* Nexthop, ifindex, distance and metric information. */ if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) { @@ -843,7 +844,7 @@ int zapi_ipv4_route_ipv6_nexthop(u_char cmd, struct zclient *zclient, for (i = 0; i < api->nexthop_num; i++) { stream_putc(s, NEXTHOP_TYPE_IPV6); - stream_write(s, (u_char *)api->nexthop[i], 16); + stream_write(s, (uint8_t *)api->nexthop[i], 16); /* For labeled-unicast, each nexthop is followed by * label. */ if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)) @@ -870,7 +871,7 @@ int zapi_ipv4_route_ipv6_nexthop(u_char cmd, struct zclient *zclient, return zclient_send_message(zclient); } -int zapi_ipv6_route(u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, +int zapi_ipv6_route(uint8_t cmd, struct zclient *zclient, struct prefix_ipv6 *p, struct prefix_ipv6 *src_p, struct zapi_ipv6 *api) { int i; @@ -909,12 +910,12 @@ int zapi_ipv6_route(u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, /* Put prefix information. */ psize = PSIZE(p->prefixlen); stream_putc(s, p->prefixlen); - stream_write(s, (u_char *)&p->prefix, psize); + stream_write(s, (uint8_t *)&p->prefix, psize); if (CHECK_FLAG(api->message, ZAPI_MESSAGE_SRCPFX)) { psize = PSIZE(src_p->prefixlen); stream_putc(s, src_p->prefixlen); - stream_write(s, (u_char *)&src_p->prefix, psize); + stream_write(s, (uint8_t *)&src_p->prefix, psize); } /* Nexthop, ifindex, distance and metric information. */ @@ -923,7 +924,7 @@ int zapi_ipv6_route(u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, for (i = 0; i < api->nexthop_num; i++) { stream_putc(s, NEXTHOP_TYPE_IPV6); - stream_write(s, (u_char *)api->nexthop[i], 16); + stream_write(s, (uint8_t *)api->nexthop[i], 16); /* For labeled-unicast, each nexthop is followed by * label. */ if (CHECK_FLAG(api->message, ZAPI_MESSAGE_LABEL)) @@ -950,7 +951,7 @@ int zapi_ipv6_route(u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, return zclient_send_message(zclient); } -int zclient_route_send(u_char cmd, struct zclient *zclient, +int zclient_route_send(uint8_t cmd, struct zclient *zclient, struct zapi_route *api) { if (zapi_route_encode(cmd, zclient->obuf, api) < 0) @@ -958,7 +959,7 @@ int zclient_route_send(u_char cmd, struct zclient *zclient, return zclient_send_message(zclient); } -int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api) +int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) { struct zapi_nexthop *api_nh; int i; @@ -979,12 +980,12 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api) stream_putc(s, api->prefix.family); psize = PSIZE(api->prefix.prefixlen); stream_putc(s, api->prefix.prefixlen); - stream_write(s, (u_char *)&api->prefix.u.prefix, psize); + stream_write(s, (uint8_t *)&api->prefix.u.prefix, psize); if (CHECK_FLAG(api->message, ZAPI_MESSAGE_SRCPFX)) { psize = PSIZE(api->src_prefix.prefixlen); stream_putc(s, api->src_prefix.prefixlen); - stream_write(s, (u_char *)&api->src_prefix.prefix, psize); + stream_write(s, (uint8_t *)&api->src_prefix.prefix, psize); } /* Nexthops. */ @@ -1023,11 +1024,11 @@ int zapi_route_encode(u_char cmd, struct stream *s, struct zapi_route *api) stream_putl(s, api_nh->ifindex); break; case NEXTHOP_TYPE_IPV6: - stream_write(s, (u_char *)&api_nh->gate.ipv6, + stream_write(s, (uint8_t *)&api_nh->gate.ipv6, 16); break; case NEXTHOP_TYPE_IPV6_IFINDEX: - stream_write(s, (u_char *)&api_nh->gate.ipv6, + stream_write(s, (uint8_t *)&api_nh->gate.ipv6, 16); stream_putl(s, api_nh->ifindex); break; @@ -1288,8 +1289,12 @@ struct nexthop *nexthop_from_zapi_nexthop(struct zapi_nexthop *znh) n->gate = znh->gate; /* - * This function does not currently handle labels + * This function currently handles labels */ + if (znh->label_num) { + nexthop_add_labels(n, ZEBRA_LSP_NONE, znh->label_num, + znh->labels); + } return n; } @@ -1364,7 +1369,7 @@ stream_failure: * sending client */ int zebra_redistribute_send(int command, struct zclient *zclient, afi_t afi, - int type, u_short instance, vrf_id_t vrf_id) + int type, unsigned short instance, vrf_id_t vrf_id) { struct stream *s; @@ -1385,7 +1390,7 @@ int zebra_redistribute_send(int command, struct zclient *zclient, afi_t afi, static void zclient_stream_get_prefix(struct stream *s, struct prefix *p) { size_t plen = prefix_blen(p); - u_char c; + uint8_t c; p->prefixlen = 0; if (plen == 0) @@ -1597,7 +1602,7 @@ struct interface *zebra_interface_link_params_read(struct stream *s) void zebra_interface_if_set_value(struct stream *s, struct interface *ifp) { - u_char link_params_status = 0; + uint8_t link_params_status = 0; /* Read interface's index. */ if_set_index(ifp, stream_getl(s)); @@ -1700,7 +1705,7 @@ size_t zebra_interface_link_params_write(struct stream *s, static int memconstant(const void *s, int c, size_t n) { - const u_char *p = s; + const uint8_t *p = s; while (n-- > 0) if (*p++ != c) @@ -1717,7 +1722,7 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, struct connected *ifc; struct prefix p, d, *dp; int plen; - u_char ifc_flags; + uint8_t ifc_flags; memset(&p, 0, sizeof(p)); memset(&d, 0, sizeof(d)); @@ -1882,14 +1887,14 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s, /* filter unwanted messages until the expected one arrives */ static int zclient_read_sync_response(struct zclient *zclient, - u_int16_t expected_cmd) + uint16_t expected_cmd) { struct stream *s; - u_int16_t size = -1; - u_char marker; - u_char version; + uint16_t size = -1; + uint8_t marker; + uint8_t version; vrf_id_t vrf_id; - u_int16_t cmd; + uint16_t cmd; fd_set readfds; int ret; @@ -1932,7 +1937,7 @@ int lm_label_manager_connect(struct zclient *zclient) { int ret; struct stream *s; - u_char result; + uint8_t result; if (zclient_debug) zlog_debug("Connecting to Label Manager"); @@ -1999,12 +2004,12 @@ int lm_label_manager_connect(struct zclient *zclient) * @param end To write last assigned chunk label to * @result 0 on success, -1 otherwise */ -int lm_get_label_chunk(struct zclient *zclient, u_char keep, +int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t chunk_size, uint32_t *start, uint32_t *end) { int ret; struct stream *s; - u_char response_keep; + uint8_t response_keep; if (zclient_debug) zlog_debug("Getting Label Chunk"); @@ -2122,6 +2127,168 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start, return 0; } +/** + * Connect to table manager in a syncronous way + * + * It first writes the request to zcient output buffer and then + * immediately reads the answer from the input buffer. + * + * @param zclient Zclient used to connect to table manager (zebra) + * @result Result of response + */ +int tm_table_manager_connect(struct zclient *zclient) +{ + int ret; + struct stream *s; + uint8_t result; + + if (zclient_debug) + zlog_debug("Connecting to Table Manager"); + + if (zclient->sock < 0) + return -1; + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, ZEBRA_TABLE_MANAGER_CONNECT, VRF_DEFAULT); + + /* proto */ + stream_putc(s, zclient->redist_default); + /* instance */ + stream_putw(s, zclient->instance); + + /* Put length at the first point of the stream. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + ret = zclient_send_message(zclient); + if (ret < 0) + return -1; + + if (zclient_debug) + zlog_debug("%s: Table manager connect request sent", + __func__); + + /* read response */ + if (zclient_read_sync_response(zclient, ZEBRA_TABLE_MANAGER_CONNECT) + != 0) + return -1; + + /* result */ + s = zclient->ibuf; + STREAM_GETC(s, result); + if (zclient_debug) + zlog_debug( + "%s: Table Manager connect response received, result %u", + __func__, result); + + return (int)result; +stream_failure: + return 0; +} + +/** + * Function to request a table chunk in a syncronous way + * + * It first writes the request to zclient output buffer and then + * immediately reads the answer from the input buffer. + * + * @param zclient Zclient used to connect to table manager (zebra) + * @param chunk_size Amount of table requested + * @param start to write first assigned chunk table RT ID to + * @param end To write last assigned chunk table RT ID to + * @result 0 on success, -1 otherwise + */ +int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, + uint32_t *start, uint32_t *end) +{ + int ret; + struct stream *s; + + if (zclient_debug) + zlog_debug("Getting Table Chunk"); + + if (zclient->sock < 0) + return -1; + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, ZEBRA_GET_TABLE_CHUNK, VRF_DEFAULT); + /* chunk size */ + stream_putl(s, chunk_size); + /* Put length at the first point of the stream. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + ret = writen(zclient->sock, s->data, stream_get_endp(s)); + if (ret < 0) { + zlog_err("%s: can't write to zclient->sock", __func__); + close(zclient->sock); + zclient->sock = -1; + return -1; + } + if (ret == 0) { + zlog_err("%s: zclient->sock connection closed", __func__); + close(zclient->sock); + zclient->sock = -1; + return -1; + } + if (zclient_debug) + zlog_debug("%s: Table chunk request (%d bytes) sent", __func__, + ret); + + /* read response */ + if (zclient_read_sync_response(zclient, ZEBRA_GET_TABLE_CHUNK) != 0) + return -1; + + s = zclient->ibuf; + /* start and end table IDs */ + STREAM_GETL(s, *start); + STREAM_GETL(s, *end); + + if (zclient_debug) + zlog_debug("Table Chunk assign: %u - %u ", *start, *end); + +stream_failure: + return 0; +} + +/** + * Function to release a table chunk + * + * @param zclient Zclient used to connect to table manager (zebra) + * @param start First label of table + * @param end Last label of chunk + * @result 0 on success, -1 otherwise + */ +int tm_release_table_chunk(struct zclient *zclient, uint32_t start, + uint32_t end) +{ + struct stream *s; + + if (zclient_debug) + zlog_debug("Releasing Table Chunk"); + + if (zclient->sock < 0) + return -1; + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, ZEBRA_RELEASE_TABLE_CHUNK, VRF_DEFAULT); + + /* start */ + stream_putl(s, start); + /* end */ + stream_putl(s, end); + + /* Put length at the first point of the stream. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + + int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw) { struct stream *s; @@ -2144,7 +2311,7 @@ int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw) stream_put_in_addr(s, &pw->nexthop.ipv4); break; case AF_INET6: - stream_write(s, (u_char *)&pw->nexthop.ipv6, 16); + stream_write(s, (uint8_t *)&pw->nexthop.ipv6, 16); break; default: zlog_err("%s: unknown af", __func__); @@ -2247,7 +2414,8 @@ static int zclient_read(struct thread *thread) struct stream *ns; zlog_warn( "%s: message size %u exceeds buffer size %lu, expanding...", - __func__, length, (u_long)STREAM_SIZE(zclient->ibuf)); + __func__, length, + (unsigned long)STREAM_SIZE(zclient->ibuf)); ns = stream_new(length); stream_copy(ns, zclient->ibuf); stream_free(zclient->ibuf); @@ -2452,7 +2620,7 @@ static int zclient_read(struct thread *thread) } void zclient_redistribute(int command, struct zclient *zclient, afi_t afi, - int type, u_short instance, vrf_id_t vrf_id) + int type, unsigned short instance, vrf_id_t vrf_id) { if (instance) { diff --git a/lib/zclient.h b/lib/zclient.h index 8033488444..9d3e5c3702 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -132,10 +132,13 @@ typedef enum { ZEBRA_RULE_ADD, ZEBRA_RULE_DELETE, ZEBRA_RULE_NOTIFY_OWNER, + ZEBRA_TABLE_MANAGER_CONNECT, + ZEBRA_GET_TABLE_CHUNK, + ZEBRA_RELEASE_TABLE_CHUNK, } zebra_message_types_t; struct redist_proto { - u_char enabled; + uint8_t enabled; struct list *instances; }; @@ -173,8 +176,8 @@ struct zclient { struct thread *t_write; /* Redistribute information. */ - u_char redist_default; /* clients protocol */ - u_short instance; + uint8_t redist_default; /* clients protocol */ + unsigned short instance; struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX]; vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX]; @@ -270,12 +273,12 @@ struct zapi_nexthop { * to encode/decode. */ struct zapi_route { - u_char type; - u_short instance; + uint8_t type; + unsigned short instance; - u_int32_t flags; + uint32_t flags; - u_char message; + uint8_t message; /* * This is an enum but we are going to treat it as a uint8_t @@ -286,16 +289,16 @@ struct zapi_route { struct prefix prefix; struct prefix_ipv6 src_prefix; - u_int16_t nexthop_num; + uint16_t nexthop_num; struct zapi_nexthop nexthops[MULTIPATH_NUM]; - u_char distance; + uint8_t distance; - u_int32_t metric; + uint32_t metric; route_tag_t tag; - u_int32_t mtu; + uint32_t mtu; vrf_id_t vrf_id; @@ -306,31 +309,31 @@ struct zapi_route { /* Zebra IPv4 route message API. */ struct zapi_ipv4 { - u_char type; - u_short instance; + uint8_t type; + unsigned short instance; - u_int32_t flags; + uint32_t flags; - u_char message; + uint8_t message; safi_t safi; - u_char nexthop_num; + uint8_t nexthop_num; struct in_addr **nexthop; - u_char ifindex_num; + uint8_t ifindex_num; ifindex_t *ifindex; - u_char label_num; + uint8_t label_num; unsigned int *label; - u_char distance; + uint8_t distance; - u_int32_t metric; + uint32_t metric; route_tag_t tag; - u_int32_t mtu; + uint32_t mtu; vrf_id_t vrf_id; }; @@ -380,7 +383,7 @@ struct zclient_options { extern struct zclient *zclient_new(struct thread_master *); /* clang-format off */ -#if CONFDATE > 20181101 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20181101 CPP_NOTICE("zclient_new_notify can take over or zclient_new now"); #endif /* clang-format on */ @@ -394,7 +397,7 @@ extern struct zclient *zclient_new_notify(struct thread_master *m, zclient_new_notify((A), &zclient_options_default); \ CPP_WARN("Please transition to using zclient_new_notify"); -extern void zclient_init(struct zclient *, int, u_short, +extern void zclient_init(struct zclient *, int, unsigned short, struct zebra_privs_t *privs); extern int zclient_start(struct zclient *); extern void zclient_stop(struct zclient *); @@ -403,9 +406,10 @@ extern void zclient_free(struct zclient *); extern int zclient_socket_connect(struct zclient *); -extern u_short *redist_check_instance(struct redist_proto *, u_short); -extern void redist_add_instance(struct redist_proto *, u_short); -extern void redist_del_instance(struct redist_proto *, u_short); +extern unsigned short *redist_check_instance(struct redist_proto *, + unsigned short); +extern void redist_add_instance(struct redist_proto *, unsigned short); +extern void redist_del_instance(struct redist_proto *, unsigned short); /* * Send to zebra that the specified vrf is using label to resolve @@ -434,11 +438,12 @@ extern void zclient_send_interface_radv_req(struct zclient *zclient, /* Send redistribute command to zebra daemon. Do not update zclient state. */ extern int zebra_redistribute_send(int command, struct zclient *, afi_t, - int type, u_short instance, vrf_id_t vrf_id); + int type, unsigned short instance, + 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, - u_short instance, vrf_id_t vrf_id); + 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 *, @@ -483,9 +488,9 @@ extern void zclient_create_header(struct stream *, uint16_t, vrf_id_t); * - a marker mismatch was detected * - header size field specified more data than could be read */ -extern int zclient_read_header(struct stream *s, int sock, u_int16_t *size, - u_char *marker, u_char *version, - vrf_id_t *vrf_id, u_int16_t *cmd); +extern int zclient_read_header(struct stream *s, int sock, uint16_t *size, + uint8_t *marker, uint8_t *version, + vrf_id_t *vrf_id, uint16_t *cmd); /* * Parse header from ZAPI message stream into struct zmsghdr. * This function assumes the stream getp points at the first byte of the header. @@ -519,23 +524,29 @@ extern void zebra_interface_if_set_value(struct stream *, struct interface *); extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid); /* clang-format off */ -#if CONFDATE > 20180823 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180823 CPP_NOTICE("zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now"); #endif /* clang-format on */ -extern int zapi_ipv4_route(u_char, struct zclient *, struct prefix_ipv4 *, +extern int zapi_ipv4_route(uint8_t, struct zclient *, struct prefix_ipv4 *, struct zapi_ipv4 *) __attribute__((deprecated)); extern struct interface *zebra_interface_link_params_read(struct stream *); extern size_t zebra_interface_link_params_write(struct stream *, struct interface *); extern int lm_label_manager_connect(struct zclient *zclient); -extern int lm_get_label_chunk(struct zclient *zclient, u_char keep, +extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int lm_release_label_chunk(struct zclient *zclient, uint32_t start, uint32_t end); +extern int tm_table_manager_connect(struct zclient *zclient); +extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, + uint32_t *start, uint32_t *end); +extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start, + uint32_t end); + extern int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw); extern void zebra_read_pw_status_update(int command, struct zclient *zclient, @@ -545,47 +556,47 @@ extern void zebra_read_pw_status_update(int command, struct zclient *zclient, /* IPv6 prefix add and delete function prototype. */ struct zapi_ipv6 { - u_char type; - u_short instance; + uint8_t type; + unsigned short instance; - u_int32_t flags; + uint32_t flags; - u_char message; + uint8_t message; safi_t safi; - u_char nexthop_num; + uint8_t nexthop_num; struct in6_addr **nexthop; - u_char ifindex_num; + uint8_t ifindex_num; ifindex_t *ifindex; - u_char label_num; + uint8_t label_num; unsigned int *label; - u_char distance; + uint8_t distance; - u_int32_t metric; + uint32_t metric; route_tag_t tag; - u_int32_t mtu; + uint32_t mtu; vrf_id_t vrf_id; }; -extern int zapi_ipv6_route(u_char cmd, struct zclient *zclient, +extern int zapi_ipv6_route(uint8_t cmd, struct zclient *zclient, struct prefix_ipv6 *p, struct prefix_ipv6 *src_p, struct zapi_ipv6 *api) __attribute__((deprecated)); -extern int zapi_ipv4_route_ipv6_nexthop(u_char, struct zclient *, +extern int zapi_ipv4_route_ipv6_nexthop(uint8_t, struct zclient *, struct prefix_ipv4 *, struct zapi_ipv6 *) __attribute__((deprecated)); -extern int zclient_route_send(u_char, struct zclient *, struct zapi_route *); +extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *); extern int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p, bool exact_match, vrf_id_t vrf_id); -extern int zapi_route_encode(u_char, struct stream *, struct zapi_route *); +extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *); extern int zapi_route_decode(struct stream *, struct zapi_route *); bool zapi_route_notify_decode(struct stream *s, struct prefix *p, uint32_t *tableid, diff --git a/lib/zebra.h b/lib/zebra.h index 923f6f77c6..255e247221 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -25,11 +25,13 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ +#include "compiler.h" + #ifdef SUNOS_5 #define _XPG4_2 -typedef unsigned int u_int32_t; -typedef unsigned short u_int16_t; -typedef unsigned char u_int8_t; +typedef unsigned int uint32_t; +typedef unsigned short uint16_t; +typedef unsigned char uint8_t; #endif /* SUNOS_5 */ #include <unistd.h> @@ -433,7 +435,8 @@ typedef enum { SAFI_ENCAP = 4, SAFI_EVPN = 5, SAFI_LABELED_UNICAST = 6, - SAFI_MAX = 7 + SAFI_FLOWSPEC = 7, + SAFI_MAX = 8 } safi_t; /* @@ -461,7 +464,8 @@ typedef enum { IANA_SAFI_LABELED_UNICAST = 4, IANA_SAFI_ENCAP = 7, IANA_SAFI_EVPN = 70, - IANA_SAFI_MPLS_VPN = 128 + IANA_SAFI_MPLS_VPN = 128, + IANA_SAFI_FLOWSPEC = 133 } iana_safi_t; /* Default Administrative Distance of each protocol. */ @@ -494,8 +498,8 @@ typedef enum { ((atomic_store_explicit(PV, 0, memory_order_seq_cst))) /* Zebra types. Used in Zserv message header. */ -typedef u_int16_t zebra_size_t; -typedef u_int16_t zebra_command_t; +typedef uint16_t zebra_size_t; +typedef uint16_t zebra_command_t; /* VRF ID type. */ typedef uint32_t vrf_id_t; @@ -547,6 +551,8 @@ static inline safi_t safi_iana2int(iana_safi_t safi) return SAFI_EVPN; case IANA_SAFI_LABELED_UNICAST: return SAFI_LABELED_UNICAST; + case IANA_SAFI_FLOWSPEC: + return SAFI_FLOWSPEC; default: return SAFI_MAX; } @@ -567,6 +573,8 @@ static inline iana_safi_t safi_int2iana(safi_t safi) return IANA_SAFI_EVPN; case SAFI_LABELED_UNICAST: return IANA_SAFI_LABELED_UNICAST; + case SAFI_FLOWSPEC: + return IANA_SAFI_FLOWSPEC; default: return IANA_SAFI_RESERVED; } diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index fba045daeb..054a375cb8 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -134,7 +134,7 @@ static void nhrp_interface_update_nbma(struct interface *ifp) debugf(NHRP_DEBUG_IF, "%s: GRE: %x %x %x", ifp->name, nifp->grekey, nifp->linkidx, saddr.s_addr); if (saddr.s_addr) - sockunion_set(&nbma, AF_INET, (u_char *)&saddr.s_addr, + sockunion_set(&nbma, AF_INET, (uint8_t *)&saddr.s_addr, sizeof(saddr.s_addr)); else if (!nbmaifp && nifp->linkidx != IFINDEX_INTERNAL) nbmaifp = diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 7ffb80724b..01b8055b66 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -152,7 +152,7 @@ int ospf6_abr_originate_summary_to_area(struct ospf6_route *route, struct ospf6_inter_prefix_lsa *prefix_lsa; struct ospf6_inter_router_lsa *router_lsa; struct ospf6_route_table *summary_table = NULL; - u_int16_t type; + uint16_t type; char buf[PREFIX2STR_BUFFER]; int is_debug = 0; @@ -506,11 +506,11 @@ void ospf6_abr_range_reset_cost(struct ospf6 *ospf6) OSPF6_ABR_RANGE_CLEAR_COST(range); } -static inline u_int32_t ospf6_abr_range_compute_cost(struct ospf6_route *range, - struct ospf6 *o) +static inline uint32_t ospf6_abr_range_compute_cost(struct ospf6_route *range, + struct ospf6 *o) { struct ospf6_route *ro; - u_int32_t cost = 0; + uint32_t cost = 0; for (ro = ospf6_route_match_head(&range->prefix, o->route_table); ro; ro = ospf6_route_match_next(&range->prefix, ro)) { @@ -524,7 +524,7 @@ static inline u_int32_t ospf6_abr_range_compute_cost(struct ospf6_route *range, } static inline int -ospf6_abr_range_summary_needs_update(struct ospf6_route *range, u_int32_t cost) +ospf6_abr_range_summary_needs_update(struct ospf6_route *range, uint32_t cost) { int redo_summary = 0; @@ -560,7 +560,7 @@ ospf6_abr_range_summary_needs_update(struct ospf6_route *range, u_int32_t cost) static void ospf6_abr_range_update(struct ospf6_route *range) { - u_int32_t cost = 0; + uint32_t cost = 0; struct listnode *node, *nnode; struct ospf6_area *oa; int summary_orig = 0; @@ -686,15 +686,16 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) struct ospf6_route_table *table = NULL; struct ospf6_route *range, *route, *old = NULL; struct ospf6_route *abr_entry; - u_char type = 0; + uint8_t type = 0; char options[3] = {0, 0, 0}; - u_int8_t prefix_options = 0; - u_int32_t cost = 0; - u_char router_bits = 0; + uint8_t prefix_options = 0; + uint32_t cost = 0; + uint8_t router_bits = 0; char buf[PREFIX2STR_BUFFER]; int is_debug = 0; struct ospf6_inter_prefix_lsa *prefix_lsa = NULL; struct ospf6_inter_router_lsa *router_lsa = NULL; + struct ospf6_path *path; memset(&prefix, 0, sizeof(prefix)); @@ -900,6 +901,9 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) ospf6_route_copy_nexthops(route, abr_entry); + path = ospf6_path_dup(&route->path); + ospf6_copy_nexthops(path->nh_list, abr_entry->nh_list); + listnode_add_sort(route->paths, path); /* (7) If the routes are identical, copy the next hops over to existing route. ospf6's route table implementation will otherwise string both @@ -933,11 +937,11 @@ void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa) } } -void ospf6_abr_examin_brouter(u_int32_t router_id) +void ospf6_abr_examin_brouter(uint32_t router_id) { struct ospf6_lsa *lsa; struct ospf6_area *oa; - u_int16_t type; + uint16_t type; if (ospf6_is_router_abr(ospf6)) oa = ospf6->backbone; @@ -964,7 +968,7 @@ void ospf6_abr_examin_brouter(u_int32_t router_id) void ospf6_abr_reimport(struct ospf6_area *oa) { struct ospf6_lsa *lsa; - u_int16_t type; + uint16_t type; type = htons(OSPF6_LSTYPE_INTER_ROUTER); for (ALL_LSDB_TYPED(oa->lsdb, type, lsa)) @@ -1025,7 +1029,7 @@ static int ospf6_inter_area_prefix_lsa_show(struct vty *vty, lsa->header); vty_out(vty, " Metric: %lu\n", - (u_long)OSPF6_ABR_SUMMARY_METRIC(prefix_lsa)); + (unsigned long)OSPF6_ABR_SUMMARY_METRIC(prefix_lsa)); ospf6_prefix_options_printbuf(prefix_lsa->prefix.prefix_options, buf, sizeof(buf)); @@ -1069,7 +1073,7 @@ static int ospf6_inter_area_router_lsa_show(struct vty *vty, ospf6_options_printbuf(router_lsa->options, buf, sizeof(buf)); vty_out(vty, " Options: %s\n", buf); vty_out(vty, " Metric: %lu\n", - (u_long)OSPF6_ABR_SUMMARY_METRIC(router_lsa)); + (unsigned long)OSPF6_ABR_SUMMARY_METRIC(router_lsa)); inet_ntop(AF_INET, &router_lsa->router_id, buf, sizeof(buf)); vty_out(vty, " Destination Router ID: %s\n", buf); diff --git a/ospf6d/ospf6_abr.h b/ospf6d/ospf6_abr.h index 61a6a73420..abc383463f 100644 --- a/ospf6d/ospf6_abr.h +++ b/ospf6d/ospf6_abr.h @@ -35,17 +35,17 @@ extern unsigned char conf_debug_ospf6_abr; /* Inter-Area-Prefix-LSA */ #define OSPF6_INTER_PREFIX_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ struct ospf6_inter_prefix_lsa { - u_int32_t metric; + uint32_t metric; struct ospf6_prefix prefix; }; /* Inter-Area-Router-LSA */ #define OSPF6_INTER_ROUTER_LSA_FIX_SIZE 12U struct ospf6_inter_router_lsa { - u_char mbz; - u_char options[3]; - u_int32_t metric; - u_int32_t router_id; + uint8_t mbz; + uint8_t options[3]; + uint32_t metric; + uint32_t router_id; }; #define OSPF6_ABR_SUMMARY_METRIC(E) (ntohl ((E)->metric & htonl (0x00ffffff))) @@ -68,7 +68,7 @@ extern void ospf6_abr_originate_summary(struct ospf6_route *route); extern void ospf6_abr_examin_summary(struct ospf6_lsa *lsa, struct ospf6_area *oa); extern void ospf6_abr_defaults_to_stub(struct ospf6 *); -extern void ospf6_abr_examin_brouter(u_int32_t router_id); +extern void ospf6_abr_examin_brouter(uint32_t router_id); extern void ospf6_abr_reimport(struct ospf6_area *oa); extern void ospf6_abr_range_reset_cost(struct ospf6 *ospf6); extern void ospf6_abr_prefix_resummarize(struct ospf6 *ospf6); diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index 0a72806030..2cab69aac2 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -199,7 +199,7 @@ static void ospf6_area_no_summary_unset(struct ospf6 *ospf6, * @param o - ospf6 instance * @param df - display format for area ID */ -struct ospf6_area *ospf6_area_create(u_int32_t area_id, struct ospf6 *o, int df) +struct ospf6_area *ospf6_area_create(uint32_t area_id, struct ospf6 *o, int df) { struct ospf6_area *oa; @@ -298,7 +298,7 @@ void ospf6_area_delete(struct ospf6_area *oa) XFREE(MTYPE_OSPF6_AREA, oa); } -struct ospf6_area *ospf6_area_lookup(u_int32_t area_id, struct ospf6 *ospf6) +struct ospf6_area *ospf6_area_lookup(uint32_t area_id, struct ospf6 *ospf6) { struct ospf6_area *oa; struct listnode *n; @@ -384,7 +384,7 @@ void ospf6_area_show(struct vty *vty, struct ospf6_area *oa) #define OSPF6_CMD_AREA_GET(str, oa) \ { \ char *ep; \ - u_int32_t area_id = htonl(strtoul(str, &ep, 10)); \ + uint32_t area_id = htonl(strtoul(str, &ep, 10)); \ if (*ep && inet_pton(AF_INET, str, &area_id) != 1) { \ vty_out(vty, "Malformed Area-ID: %s\n", str); \ return CMD_SUCCESS; \ @@ -416,7 +416,7 @@ DEFUN (area_range, struct ospf6_area *oa; struct prefix prefix; struct ospf6_route *range; - u_int32_t cost = OSPF_AREA_RANGE_COST_UNSPEC; + uint32_t cost = OSPF_AREA_RANGE_COST_UNSPEC; OSPF6_CMD_AREA_GET(argv[idx_ipv4]->arg, oa); @@ -810,7 +810,7 @@ DEFUN (show_ipv6_ospf6_area_spf_tree, "Show SPF tree\n") { int idx_ipv4 = 4; - u_int32_t area_id; + uint32_t area_id; struct ospf6_area *oa; struct ospf6_vertex *root; struct ospf6_route *route; @@ -856,12 +856,12 @@ DEFUN (show_ipv6_ospf6_simulate_spf_tree_root, { int idx_ipv4 = 5; int idx_ipv4_2 = 7; - u_int32_t area_id; + uint32_t area_id; struct ospf6_area *oa; struct ospf6_vertex *root; struct ospf6_route *route; struct prefix prefix; - u_int32_t router_id; + uint32_t router_id; struct ospf6_route_table *spf_table; unsigned char tmp_debug_ospf6_spf = 0; diff --git a/ospf6d/ospf6_area.h b/ospf6d/ospf6_area.h index a44a432a0a..eaf3e5c6de 100644 --- a/ospf6d/ospf6_area.h +++ b/ospf6d/ospf6_area.h @@ -28,7 +28,7 @@ struct ospf6_area { struct ospf6 *ospf6; /* Area-ID */ - u_int32_t area_id; + uint32_t area_id; #define OSPF6_AREA_FMT_DOTTEDQUAD 1 #define OSPF6_AREA_FMT_DECIMAL 2 @@ -36,10 +36,10 @@ struct ospf6_area { char name[16]; /* flag */ - u_char flag; + uint8_t flag; /* OSPF Option */ - u_char options[3]; + uint8_t options[3]; /* Summary routes to be originated (includes Configured Address Ranges) */ @@ -60,11 +60,11 @@ struct ospf6_area { struct ospf6_route_table *spf_table; struct ospf6_route_table *route_table; - u_int32_t spf_calculation; /* SPF calculation count */ + uint32_t spf_calculation; /* SPF calculation count */ struct thread *thread_router_lsa; struct thread *thread_intra_prefix_lsa; - u_int32_t router_lsa_size_limit; + uint32_t router_lsa_size_limit; /* Area announce list */ struct { @@ -117,9 +117,9 @@ struct ospf6_area { /* prototypes */ extern int ospf6_area_cmp(void *va, void *vb); -extern struct ospf6_area *ospf6_area_create(u_int32_t, struct ospf6 *, int); +extern struct ospf6_area *ospf6_area_create(uint32_t, struct ospf6 *, int); extern void ospf6_area_delete(struct ospf6_area *); -extern struct ospf6_area *ospf6_area_lookup(u_int32_t, struct ospf6 *); +extern struct ospf6_area *ospf6_area_lookup(uint32_t, struct ospf6 *); extern void ospf6_area_enable(struct ospf6_area *); extern void ospf6_area_disable(struct ospf6_area *); diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index cd930f6c09..1b46b9c68d 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -813,8 +813,8 @@ void ospf6_asbr_lsa_remove(struct ospf6_lsa *lsa, void ospf6_asbr_lsentry_add(struct ospf6_route *asbr_entry) { struct ospf6_lsa *lsa; - u_int16_t type; - u_int32_t router; + uint16_t type; + uint32_t router; if (!CHECK_FLAG(asbr_entry->flag, OSPF6_ROUTE_BEST)) { char buf[16]; @@ -835,8 +835,8 @@ void ospf6_asbr_lsentry_add(struct ospf6_route *asbr_entry) void ospf6_asbr_lsentry_remove(struct ospf6_route *asbr_entry) { struct ospf6_lsa *lsa; - u_int16_t type; - u_int32_t router; + uint16_t type; + uint32_t router; type = htons(OSPF6_LSTYPE_AS_EXTERNAL); router = ospf6_linkstate_prefix_adv_router(&asbr_entry->prefix); @@ -997,7 +997,8 @@ void ospf6_asbr_send_externals_to_area(struct ospf6_area *oa) } void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, - struct prefix *prefix, u_int nexthop_num, + struct prefix *prefix, + unsigned int nexthop_num, struct in6_addr *nexthop, route_tag_t tag) { int ret; @@ -1486,7 +1487,7 @@ ospf6_routemap_rule_set_metric(void *rule, struct prefix *prefix, static void *ospf6_routemap_rule_set_metric_compile(const char *arg) { - u_int32_t metric; + uint32_t metric; char *endp; metric = strtoul(arg, &endp, 0); if (metric > OSPF_LS_INFINITY || *endp != '\0') @@ -1740,7 +1741,7 @@ static int ospf6_as_external_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, " Bits: %s\n", buf); vty_out(vty, " Metric: %5lu\n", - (u_long)OSPF6_ASBR_METRIC(external)); + (unsigned long)OSPF6_ASBR_METRIC(external)); ospf6_prefix_options_printbuf(external->prefix.prefix_options, buf, sizeof(buf)); @@ -1773,7 +1774,7 @@ static void ospf6_asbr_external_route_show(struct vty *vty, { struct ospf6_external_info *info = route->route_option; char prefix[PREFIX2STR_BUFFER], id[16], forwarding[64]; - u_int32_t tmp_id; + uint32_t tmp_id; prefix2str(&route->prefix, prefix, sizeof(prefix)); tmp_id = ntohl(info->id); @@ -1788,8 +1789,9 @@ static void ospf6_asbr_external_route_show(struct vty *vty, vty_out(vty, "%c %-32s %-15s type-%d %5lu %s\n", zebra_route_char(info->type), prefix, id, route->path.metric_type, - (u_long)(route->path.metric_type == 2 ? route->path.u.cost_e2 - : route->path.cost), + (unsigned long)(route->path.metric_type == 2 + ? route->path.u.cost_e2 + : route->path.cost), forwarding); } diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h index bd160a6456..9890ef0619 100644 --- a/ospf6d/ospf6_asbr.h +++ b/ospf6d/ospf6_asbr.h @@ -39,7 +39,7 @@ struct ospf6_external_info { int type; /* Originating Link State ID */ - u_int32_t id; + uint32_t id; struct in6_addr forwarding; @@ -51,7 +51,7 @@ struct ospf6_external_info { /* AS-External-LSA */ #define OSPF6_AS_EXTERNAL_LSA_MIN_SIZE 4U /* w/o IPv6 prefix */ struct ospf6_as_external_lsa { - u_int32_t bits_metric; + uint32_t bits_metric; struct ospf6_prefix prefix; /* followed by none or one forwarding address */ @@ -79,7 +79,7 @@ extern void ospf6_asbr_lsentry_remove(struct ospf6_route *asbr_entry); extern int ospf6_asbr_is_asbr(struct ospf6 *o); extern void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, struct prefix *prefix, - u_int nexthop_num, + unsigned int nexthop_num, struct in6_addr *nexthop, route_tag_t tag); extern void ospf6_asbr_redistribute_remove(int type, ifindex_t ifindex, diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c index e28af9d06d..7955121365 100644 --- a/ospf6d/ospf6_bfd.c +++ b/ospf6d/ospf6_bfd.c @@ -295,8 +295,8 @@ void ospf6_bfd_write_config(struct vty *vty, struct ospf6_interface *oi) * ospf6_bfd_if_param_set - Set the configured BFD paramter values for * interface. */ -static void ospf6_bfd_if_param_set(struct ospf6_interface *oi, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, +static void ospf6_bfd_if_param_set(struct ospf6_interface *oi, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults) { int command = 0; @@ -344,9 +344,9 @@ DEFUN (ipv6_ospf6_bfd_param, int idx_number_2 = 4; int idx_number_3 = 5; struct ospf6_interface *oi; - u_int32_t rx_val; - u_int32_t tx_val; - u_int8_t dm_val; + uint32_t rx_val; + uint32_t tx_val; + uint8_t dm_val; int ret; assert(ifp); diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 8524292215..7c60749d7e 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -101,7 +101,7 @@ static void ospf6_interface_lsdb_hook_remove(struct ospf6_lsa *lsa) ospf6_interface_lsdb_hook(lsa, ospf6_lsremove_to_spf_reason(lsa)); } -static u_char ospf6_default_iftype(struct interface *ifp) +static uint8_t ospf6_default_iftype(struct interface *ifp) { if (if_is_pointopoint(ifp)) return OSPF_IFTYPE_POINTOPOINT; @@ -111,11 +111,11 @@ static u_char ospf6_default_iftype(struct interface *ifp) return OSPF_IFTYPE_BROADCAST; } -static u_int32_t ospf6_interface_get_cost(struct ospf6_interface *oi) +static uint32_t ospf6_interface_get_cost(struct ospf6_interface *oi) { /* If all else fails, use default OSPF cost */ - u_int32_t cost; - u_int32_t bw, refbw; + uint32_t cost; + uint32_t bw, refbw; /* interface speed and bw can be 0 in some platforms, * use ospf default bw. If bw is configured then it would @@ -134,7 +134,7 @@ static u_int32_t ospf6_interface_get_cost(struct ospf6_interface *oi) if (CHECK_FLAG(oi->flag, OSPF6_INTERFACE_NOAUTOCOST)) cost = oi->cost; else { - cost = (u_int32_t)((double)refbw / (double)bw + (double)0.5); + cost = (uint32_t)((double)refbw / (double)bw + (double)0.5); if (cost < 1) cost = 1; else if (cost > UINT32_MAX) @@ -161,7 +161,7 @@ static void ospf6_interface_force_recalculate_cost(struct ospf6_interface *oi) static void ospf6_interface_recalculate_cost(struct ospf6_interface *oi) { - u_int32_t newcost; + uint32_t newcost; newcost = ospf6_interface_get_cost(oi); if (newcost == oi->cost) @@ -494,10 +494,10 @@ void ospf6_interface_connected_route_update(struct interface *ifp) OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(oi->area); } -static void ospf6_interface_state_change(u_char next_state, +static void ospf6_interface_state_change(uint8_t next_state, struct ospf6_interface *oi) { - u_char prev_state; + uint8_t prev_state; prev_state = oi->state; oi->state = next_state; @@ -610,12 +610,12 @@ static struct ospf6_neighbor *better_drouter(struct ospf6_neighbor *a, return a; } -static u_char dr_election(struct ospf6_interface *oi) +static uint8_t dr_election(struct ospf6_interface *oi) { struct listnode *node, *nnode; struct ospf6_neighbor *on, *drouter, *bdrouter, myself; struct ospf6_neighbor *best_drouter, *best_bdrouter; - u_char next_state = 0; + uint8_t next_state = 0; drouter = bdrouter = NULL; best_drouter = best_bdrouter = NULL; @@ -1346,7 +1346,7 @@ DEFUN (auto_cost_reference_bandwidth, struct ospf6_area *oa; struct ospf6_interface *oi; struct listnode *i, *j; - u_int32_t refbw; + uint32_t refbw; refbw = strtol(argv[idx_number]->arg, NULL, 10); if (refbw < 1 || refbw > 4294967) { diff --git a/ospf6d/ospf6_interface.h b/ospf6d/ospf6_interface.h index 9b9952beb6..553e89a227 100644 --- a/ospf6d/ospf6_interface.h +++ b/ospf6d/ospf6_interface.h @@ -48,50 +48,50 @@ struct ospf6_interface { /* Interface ID; use interface->ifindex */ /* ospf6 instance id */ - u_char instance_id; + uint8_t instance_id; /* I/F transmission delay */ - u_int32_t transdelay; + uint32_t transdelay; /* Network Type */ - u_char type; + uint8_t type; /* Router Priority */ - u_char priority; + uint8_t priority; /* Time Interval */ - u_int16_t hello_interval; - u_int16_t dead_interval; - u_int32_t rxmt_interval; + uint16_t hello_interval; + uint16_t dead_interval; + uint32_t rxmt_interval; - u_int32_t state_change; + uint32_t state_change; /* Cost */ - u_int32_t cost; + uint32_t cost; /* I/F MTU */ - u_int32_t ifmtu; + uint32_t ifmtu; /* Configured MTU */ - u_int32_t c_ifmtu; + uint32_t c_ifmtu; /* Interface State */ - u_char state; + uint8_t state; /* Interface socket setting trial counter, resets on success */ - u_char sso_try_cnt; + uint8_t sso_try_cnt; /* OSPF6 Interface flag */ char flag; /* MTU mismatch check */ - u_char mtu_ignore; + uint8_t mtu_ignore; /* Decision of DR Election */ - u_int32_t drouter; - u_int32_t bdrouter; - u_int32_t prev_drouter; - u_int32_t prev_bdrouter; + uint32_t drouter; + uint32_t bdrouter; + uint32_t prev_drouter; + uint32_t prev_bdrouter; /* Linklocal LSA Database: includes Link-LSA */ struct ospf6_lsdb *lsdb; @@ -119,17 +119,17 @@ struct ospf6_interface { void *bfd_info; /* Statistics Fields */ - u_int32_t hello_in; - u_int32_t hello_out; - u_int32_t db_desc_in; - u_int32_t db_desc_out; - u_int32_t ls_req_in; - u_int32_t ls_req_out; - u_int32_t ls_upd_in; - u_int32_t ls_upd_out; - u_int32_t ls_ack_in; - u_int32_t ls_ack_out; - u_int32_t discarded; + uint32_t hello_in; + uint32_t hello_out; + uint32_t db_desc_in; + uint32_t db_desc_out; + uint32_t ls_req_in; + uint32_t ls_req_out; + uint32_t ls_upd_in; + uint32_t ls_upd_out; + uint32_t ls_ack_in; + uint32_t ls_ack_out; + uint32_t discarded; QOBJ_FIELDS }; diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 0b7755a3f4..519c5e170f 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -49,8 +49,8 @@ #include "ospf6_spf.h" unsigned char conf_debug_ospf6_brouter = 0; -u_int32_t conf_debug_ospf6_brouter_specific_router_id; -u_int32_t conf_debug_ospf6_brouter_specific_area_id; +uint32_t conf_debug_ospf6_brouter_specific_router_id; +uint32_t conf_debug_ospf6_brouter_specific_area_id; #define MAX_LSA_PAYLOAD (1024 + 256) /******************************/ @@ -189,15 +189,15 @@ int ospf6_router_lsa_originate(struct thread *thread) struct ospf6_lsa_header *lsa_header; struct ospf6_lsa *lsa; - u_int32_t link_state_id = 0; + uint32_t link_state_id = 0; struct listnode *node, *nnode; struct listnode *j; struct ospf6_interface *oi; struct ospf6_neighbor *on, *drouter = NULL; struct ospf6_router_lsa *router_lsa; struct ospf6_router_lsdesc *lsdesc; - u_int16_t type; - u_int32_t router; + uint16_t type; + uint32_t router; int count; oa = (struct ospf6_area *)THREAD_ARG(thread); @@ -461,7 +461,7 @@ int ospf6_network_lsa_originate(struct thread *thread) struct ospf6_neighbor *on; struct ospf6_link_lsa *link_lsa; struct listnode *i; - u_int16_t type; + uint16_t type; oi = (struct ospf6_interface *)THREAD_ARG(thread); oi->thread_network_lsa = NULL; @@ -1142,7 +1142,7 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) struct ospf6_route_table *route_advertise; struct ospf6_link_lsa *link_lsa; char *start, *end, *current; - u_int16_t type; + uint16_t type; char buf[PREFIX2STR_BUFFER]; oi = (struct ospf6_interface *)THREAD_ARG(thread); @@ -1314,18 +1314,253 @@ int ospf6_intra_prefix_lsa_originate_transit(struct thread *thread) return 0; } +void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area *oa, + struct ospf6_route *old, + struct ospf6_route *route) +{ + struct ospf6_route *old_route; + struct ospf6_path *ecmp_path, *o_path = NULL; + struct listnode *anode, *anext; + struct listnode *nnode, *rnode, *rnext; + struct ospf6_nexthop *nh, *rnh; + char buf[PREFIX2STR_BUFFER]; + bool route_found = false; + + /* check for old entry match with new route origin, + * delete old entry. + */ + for (old_route = old; old_route; old_route = old_route->next) { + bool route_updated = false; + + if (!ospf6_route_is_same(old_route, route) || + (old_route->path.type != route->path.type)) + continue; + + /* Current and New route has same origin, + * delete old entry. + */ + for (ALL_LIST_ELEMENTS(old_route->paths, anode, anext, + o_path)) { + /* Check old route path and route has same + * origin. + */ + if (o_path->area_id != route->path.area_id || + (memcmp(&(o_path)->origin, &(route)->path.origin, + sizeof(struct ospf6_ls_origin)) != 0)) + continue; + + /* Cost is not same then delete current path */ + if (o_path->cost == route->path.cost) + continue; + + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&old_route->prefix, buf, + sizeof(buf)); + zlog_debug("%s: route %s cost old %u new %u is not same, replace route", + __PRETTY_FUNCTION__, buf, + o_path->cost, route->path.cost); + } + + /* Remove selected current rout path's nh from + * effective nh list. + */ + for (ALL_LIST_ELEMENTS_RO(o_path->nh_list, nnode, nh)) { + for (ALL_LIST_ELEMENTS(old_route->nh_list, + rnode, rnext, rnh)) { + if (!ospf6_nexthop_is_same(rnh, nh)) + continue; + listnode_delete(old_route->nh_list, + rnh); + ospf6_nexthop_delete(rnh); + route_updated = true; + } + } + + listnode_delete(old_route->paths, o_path); + ospf6_path_free(o_path); + + /* Current route's path (adv_router info) is similar + * to route being added. + * Replace current route's path with paths list head. + * Update FIB with effective NHs. + */ + if (listcount(old_route->paths)) { + if (old_route->path.origin.id == + route->path.origin.id && + old_route->path.origin.adv_router == + route->path.origin.adv_router) { + struct ospf6_path *h_path; + + h_path = (struct ospf6_path *) + listgetdata(listhead(old_route->paths)); + old_route->path.origin.type = + h_path->origin.type; + old_route->path.origin.id = + h_path->origin.id; + old_route->path.origin.adv_router = + h_path->origin.adv_router; + } + + if (route_updated) { + for (ALL_LIST_ELEMENTS(old_route->paths, + anode, anext, o_path)) { + ospf6_merge_nexthops( + old_route->nh_list, + o_path->nh_list); + } + /* Update ospf6 route table and + * RIB/FIB with effective + * nh_list + */ + if (oa->route_table->hook_add) + (*oa->route_table->hook_add) + (old_route); + break; + } + } else { + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&old_route->prefix, buf, + sizeof(buf)); + zlog_debug("%s: route %s old cost %u new cost %u, delete old entry.", + __PRETTY_FUNCTION__, buf, + old_route->path.cost, + route->path.cost); + } + ospf6_route_remove(old_route, + oa->route_table); + break; + } + } + if (route_updated) + break; + } + + for (old_route = old; old_route; old_route = old_route->next) { + + if (!ospf6_route_is_same(old_route, route) || + (old_route->path.type != route->path.type)) + continue; + + /* Old Route and New Route have Equal Cost, Merge NHs */ + if (old_route->path.cost == route->path.cost) { + route_found = true; + + /* check if this path exists already in + * route->paths list, if so, replace nh_list. + */ + for (ALL_LIST_ELEMENTS_RO(old_route->paths, anode, + o_path)) { + if (o_path->area_id == route->path.area_id && + (memcmp(&(o_path)->origin, + &(route)->path.origin, + sizeof(struct ospf6_ls_origin)) == 0)) + break; + } + /* If path is not found in old_route paths's list, + * add a new path to route paths list and merge + * nexthops in route->path->nh_list. + * Otherwise replace existing path's nh_list. + */ + if (o_path == NULL) { + ecmp_path = ospf6_path_dup(&route->path); + + /* Add a nh_list to new ecmp path */ + ospf6_copy_nexthops(ecmp_path->nh_list, + route->nh_list); + /* Merge nexthop to existing route's nh_list */ + ospf6_route_merge_nexthops(old_route, route); + /* Add the new path to route's path list */ + listnode_add_sort(old_route->paths, ecmp_path); + + UNSET_FLAG(old_route->flag, OSPF6_ROUTE_REMOVE); + SET_FLAG(old_route->flag, OSPF6_ROUTE_CHANGE); + /* Update RIB/FIB */ + if (oa->route_table->hook_add) + (*oa->route_table->hook_add) + (old_route); + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&route->prefix, buf, + sizeof(buf)); + zlog_debug("%s: route %s %p another path added with nh %u, effective paths %u nh %u", + __PRETTY_FUNCTION__, buf, + (void *)old_route, + listcount(ecmp_path->nh_list), + old_route->paths ? + listcount(old_route->paths) + : 0, + listcount(old_route->nh_list)); + } + } else { + for (ALL_LIST_ELEMENTS_RO(o_path->nh_list, + nnode, nh)) { + for (ALL_LIST_ELEMENTS( + old_route->nh_list, + rnode, rnext, rnh)) { + if (!ospf6_nexthop_is_same(rnh, + nh)) + continue; + + listnode_delete( + old_route->nh_list, + rnh); + ospf6_nexthop_delete(rnh); + } + } + list_delete_all_node(o_path->nh_list); + ospf6_copy_nexthops(o_path->nh_list, + route->nh_list); + + /* Merge nexthop to existing route's nh_list */ + ospf6_route_merge_nexthops(old_route, + route); + + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&route->prefix, + buf, sizeof(buf)); + zlog_debug("%s: existing route %s %p with effective paths %u nh count %u", + __PRETTY_FUNCTION__, buf, + (void *)old_route, + listcount(old_route->paths), + old_route->nh_list ? + listcount(old_route->nh_list) + : 0); + } + + UNSET_FLAG(old_route->flag, OSPF6_ROUTE_REMOVE); + SET_FLAG(old_route->flag, OSPF6_ROUTE_CHANGE); + /* Update ospf6 route table and RIB/FIB */ + if (oa->route_table->hook_add) + (*oa->route_table->hook_add) + (old_route); + } + /* Delete the new route its info added to existing + * route. + */ + ospf6_route_delete(route); + + break; + } + } + + if (!route_found) { + /* Add new route to existing node in ospf6 route table. */ + ospf6_route_add(route, oa->route_table); + } +} + void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) { struct ospf6_area *oa; struct ospf6_intra_prefix_lsa *intra_prefix_lsa; struct prefix ls_prefix; - struct ospf6_route *route, *ls_entry; + struct ospf6_route *route, *ls_entry, *old; int prefix_num; struct ospf6_prefix *op; char *start, *current, *end; char buf[PREFIX2STR_BUFFER]; struct interface *ifp; int direct_connect = 0; + struct ospf6_path *path; if (OSPF6_LSA_IS_MAXAGE(lsa)) return; @@ -1417,13 +1652,31 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa) ospf6_route_copy_nexthops(route, ls_entry); } - if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { - prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug(" route %s add with nh count %u", buf, - listcount(route->nh_list)); - } + path = ospf6_path_dup(&route->path); + ospf6_copy_nexthops(path->nh_list, route->path.nh_list); + listnode_add_sort(route->paths, path); - ospf6_route_add(route, oa->route_table); + old = ospf6_route_lookup(&route->prefix, oa->route_table); + if (old && (ospf6_route_cmp(route, old) == 0)) { + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&route->prefix, buf, sizeof(buf)); + zlog_debug(" Update route: %s old cost %u new cost %u nh count %u paths %u", + buf, + old->path.cost, route->path.cost, + listcount(route->nh_list), + listcount(route->paths)); + } + ospf6_intra_prefix_route_ecmp_path(oa, old, route); + } else { + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&route->prefix, buf, sizeof(buf)); + zlog_debug(" route %s add with cost %u nh %u paths %u", + buf, route->path.cost, + listcount(route->nh_list), + listcount(route->paths)); + } + ospf6_route_add(route, oa->route_table); + } prefix_num--; } @@ -1436,14 +1689,15 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) struct ospf6_area *oa; struct ospf6_intra_prefix_lsa *intra_prefix_lsa; struct prefix prefix; - struct ospf6_route *route, *nroute; + struct ospf6_route *route, *nroute, *route_to_del; int prefix_num; struct ospf6_prefix *op; char *start, *current, *end; char buf[PREFIX2STR_BUFFER]; if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) - zlog_debug("%s disappearing", lsa->name); + zlog_debug("%s: %s disappearing", __PRETTY_FUNCTION__, + lsa->name); oa = OSPF6_AREA(lsa->lsdb->data); @@ -1463,6 +1717,22 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) break; prefix_num--; + route_to_del = ospf6_route_create(); + + memset(&route_to_del->prefix, 0, sizeof(struct prefix)); + route_to_del->prefix.family = AF_INET6; + route_to_del->prefix.prefixlen = op->prefix_length; + ospf6_prefix_in6_addr(&route_to_del->prefix.u.prefix6, op); + + route_to_del->type = OSPF6_DEST_TYPE_NETWORK; + route_to_del->path.origin.type = lsa->header->type; + route_to_del->path.origin.id = lsa->header->id; + route_to_del->path.origin.adv_router = lsa->header->adv_router; + route_to_del->path.prefix_options = op->prefix_options; + route_to_del->path.area_id = oa->area_id; + route_to_del->path.type = OSPF6_PATH_TYPE_INTRA; + route_to_del->path.metric_type = 1; + memset(&prefix, 0, sizeof(struct prefix)); prefix.family = AF_INET6; prefix.prefixlen = op->prefix_length; @@ -1482,20 +1752,161 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) continue; if (route->path.type != OSPF6_PATH_TYPE_INTRA) continue; - if (route->path.origin.type != lsa->header->type - || route->path.origin.id != lsa->header->id - || route->path.origin.adv_router - != lsa->header->adv_router) + /* Route has multiple ECMP paths, remove matching + * path. Update current route's effective nh list + * after removal of one of the path. + */ + if (listcount(route->paths) > 1) { + struct listnode *anode, *anext; + struct listnode *nnode, *rnode, *rnext; + struct ospf6_nexthop *nh, *rnh; + struct ospf6_path *o_path; + bool nh_updated = false; + + /* Iterate all paths of route to find maching + * with LSA remove info. + * If route->path is same, replace + * from paths list. + */ + for (ALL_LIST_ELEMENTS(route->paths, anode, + anext, o_path)) { + if ((o_path->origin.type != + lsa->header->type) || + (o_path->origin.adv_router != + lsa->header->adv_router) || + (o_path->origin.id != + lsa->header->id)) + continue; + + if (IS_OSPF6_DEBUG_EXAMIN + (INTRA_PREFIX)) { + prefix2str(&prefix, buf, + sizeof(buf)); + zlog_debug( + "%s: route %s path found with cost %u nh %u to remove.", + __PRETTY_FUNCTION__, + buf, o_path->cost, + listcount( + o_path->nh_list)); + } + /* Remove old route from global + * ospf6 route table. + * nh_update section will add + * back with effective nh. + */ + if (oa->route_table->hook_remove) + (*oa->route_table->hook_remove) + (route); + /* Remove found path's nh_list from + * the route's nh_list. + */ + for (ALL_LIST_ELEMENTS_RO( + o_path->nh_list, + nnode, nh)) { + for (ALL_LIST_ELEMENTS( + route->nh_list, + rnode, rnext, rnh)) { + if ( + !ospf6_nexthop_is_same( + rnh, nh)) + continue; + listnode_delete( + route->nh_list, + rnh); + ospf6_nexthop_delete( + rnh); + } + } + /* Delete the path from route's + * path list + */ + listnode_delete(route->paths, o_path); + ospf6_path_free(o_path); + nh_updated = true; + break; + } + + if (nh_updated) { + + /* Iterate all paths and merge nexthop, + * unlesss any of the nexthop similar to + * ones deleted as part of path + * deletion. + */ + for (ALL_LIST_ELEMENTS(route->paths, + anode, anext, o_path)) { + ospf6_merge_nexthops( + route->nh_list, + o_path->nh_list); + } + + if (IS_OSPF6_DEBUG_EXAMIN( + INTRA_PREFIX)) { + prefix2str(&route->prefix, buf, + sizeof(buf)); + zlog_debug("%s: route %s update paths %u nh %u" + , __PRETTY_FUNCTION__, + buf, + listcount(route->paths), + listcount( + route->nh_list)); + } + + /* route's primary path is similar + * to LSA, replace route's primary + * path with route's paths list + * head. + */ + if ((route->path.origin.id == + lsa->header->id) && + (route->path.origin.adv_router + == lsa->header->adv_router)) { + struct ospf6_path *h_path; + + h_path = (struct ospf6_path *) + listgetdata(listhead( + route->paths)); + route->path.origin.type = + h_path->origin.type; + route->path.origin.id = + h_path->origin.id; + route->path.origin.adv_router = + h_path->origin.adv_router; + } + + /* Update Global Route table and + * RIB/FIB with effective + * nh_list + */ + if (oa->route_table->hook_add) + (*oa->route_table->hook_add) + (route); + } continue; - if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { - prefix2str(&route->prefix, buf, sizeof(buf)); - zlog_debug("remove %s", buf); + } else { + + if (route->path.origin.type != lsa->header->type + || route->path.origin.id != lsa->header->id + || route->path.origin.adv_router + != lsa->header->adv_router) + continue; + + if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) { + prefix2str(&route->prefix, buf, + sizeof(buf)); + zlog_debug("route remove %s with path %u cost %u nh %u", + buf, route->path.type, + route->path.cost, + listcount(route->nh_list)); + } + ospf6_route_remove(route, oa->route_table); } - ospf6_route_remove(route, oa->route_table); } if (route) ospf6_route_unlock(route); + + ospf6_route_delete(route_to_del); } if (current != end && IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX)) @@ -1505,7 +1916,7 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa) void ospf6_intra_route_calculation(struct ospf6_area *oa) { struct ospf6_route *route, *nroute; - u_int16_t type; + uint16_t type; struct ospf6_lsa *lsa; void (*hook_add)(struct ospf6_route *) = NULL; void (*hook_remove)(struct ospf6_route *) = NULL; @@ -1558,7 +1969,7 @@ void ospf6_intra_route_calculation(struct ospf6_area *oa) static void ospf6_brouter_debug_print(struct ospf6_route *brouter) { - u_int32_t brouter_id; + uint32_t brouter_id; char brouter_name[16]; char area_name[16]; char destination[64]; @@ -1614,7 +2025,7 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) struct ospf6_route *brouter, *nbrouter, *copy; void (*hook_add)(struct ospf6_route *) = NULL; void (*hook_remove)(struct ospf6_route *) = NULL; - u_int32_t brouter_id; + uint32_t brouter_id; char brouter_name[16]; if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(oa->area_id)) @@ -1735,9 +2146,6 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) && CHECK_FLAG(brouter->flag, OSPF6_ROUTE_ADD)) { UNSET_FLAG(brouter->flag, OSPF6_ROUTE_REMOVE); UNSET_FLAG(brouter->flag, OSPF6_ROUTE_ADD); - zlog_debug("%s: EVENT unset REOUTE_REMOVE and ROUTE_ADD brouter %s", - __PRETTY_FUNCTION__, brouter_name); - ospf6_brouter_debug_print(brouter); } if (CHECK_FLAG(brouter->flag, OSPF6_ROUTE_REMOVE)) { @@ -1861,7 +2269,7 @@ DEFUN (debug_ospf6_brouter_router, ) { int idx_ipv4 = 4; - u_int32_t router_id; + uint32_t router_id; inet_pton(AF_INET, argv[idx_ipv4]->arg, &router_id); OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ON(router_id); return CMD_SUCCESS; @@ -1892,7 +2300,7 @@ DEFUN (debug_ospf6_brouter_area, ) { int idx_ipv4 = 4; - u_int32_t area_id; + uint32_t area_id; inet_pton(AF_INET, argv[idx_ipv4]->arg, &area_id); OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ON(area_id); return CMD_SUCCESS; diff --git a/ospf6d/ospf6_intra.h b/ospf6d/ospf6_intra.h index 07f0f124ec..672e288bf3 100644 --- a/ospf6d/ospf6_intra.h +++ b/ospf6d/ospf6_intra.h @@ -23,8 +23,8 @@ /* Debug option */ extern unsigned char conf_debug_ospf6_brouter; -extern u_int32_t conf_debug_ospf6_brouter_specific_router_id; -extern u_int32_t conf_debug_ospf6_brouter_specific_area_id; +extern uint32_t conf_debug_ospf6_brouter_specific_router_id; +extern uint32_t conf_debug_ospf6_brouter_specific_area_id; #define OSPF6_DEBUG_BROUTER_SUMMARY 0x01 #define OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER 0x02 #define OSPF6_DEBUG_BROUTER_SPECIFIC_AREA 0x04 @@ -73,20 +73,20 @@ extern u_int32_t conf_debug_ospf6_brouter_specific_area_id; /* Router-LSA */ #define OSPF6_ROUTER_LSA_MIN_SIZE 4U struct ospf6_router_lsa { - u_char bits; - u_char options[3]; + uint8_t bits; + uint8_t options[3]; /* followed by ospf6_router_lsdesc(s) */ }; /* Link State Description in Router-LSA */ #define OSPF6_ROUTER_LSDESC_FIX_SIZE 16U struct ospf6_router_lsdesc { - u_char type; - u_char reserved; - u_int16_t metric; /* output cost */ - u_int32_t interface_id; - u_int32_t neighbor_interface_id; - u_int32_t neighbor_router_id; + uint8_t type; + uint8_t reserved; + uint16_t metric; /* output cost */ + uint32_t interface_id; + uint32_t neighbor_interface_id; + uint32_t neighbor_router_id; }; #define OSPF6_ROUTER_LSDESC_POINTTOPOINT 1 @@ -117,15 +117,15 @@ enum stub_router_mode { /* Network-LSA */ #define OSPF6_NETWORK_LSA_MIN_SIZE 4U struct ospf6_network_lsa { - u_char reserved; - u_char options[3]; + uint8_t reserved; + uint8_t options[3]; /* followed by ospf6_netowrk_lsd(s) */ }; /* Link State Description in Router-LSA */ #define OSPF6_NETWORK_LSDESC_FIX_SIZE 4U struct ospf6_network_lsdesc { - u_int32_t router_id; + uint32_t router_id; }; #define NETWORK_LSDESC_GET_NBR_ROUTERID(x) \ (((struct ospf6_network_lsdesc *)(x))->router_id) @@ -133,20 +133,20 @@ struct ospf6_network_lsdesc { /* Link-LSA */ #define OSPF6_LINK_LSA_MIN_SIZE 24U /* w/o 1st IPv6 prefix */ struct ospf6_link_lsa { - u_char priority; - u_char options[3]; + uint8_t priority; + uint8_t options[3]; struct in6_addr linklocal_addr; - u_int32_t prefix_num; + uint32_t prefix_num; /* followed by ospf6 prefix(es) */ }; /* Intra-Area-Prefix-LSA */ #define OSPF6_INTRA_PREFIX_LSA_MIN_SIZE 12U /* w/o 1st IPv6 prefix */ struct ospf6_intra_prefix_lsa { - u_int16_t prefix_num; - u_int16_t ref_type; - u_int32_t ref_id; - u_int32_t ref_adv_router; + uint16_t prefix_num; + uint16_t ref_type; + uint32_t ref_id; + uint32_t ref_adv_router; /* followed by ospf6 prefix(es) */ }; @@ -213,11 +213,11 @@ struct ospf6_intra_prefix_lsa { } while (0) /* Function Prototypes */ -extern char *ospf6_router_lsdesc_lookup(u_char type, u_int32_t interface_id, - u_int32_t neighbor_interface_id, - u_int32_t neighbor_router_id, +extern char *ospf6_router_lsdesc_lookup(uint8_t type, uint32_t interface_id, + uint32_t neighbor_interface_id, + uint32_t neighbor_router_id, struct ospf6_lsa *lsa); -extern char *ospf6_network_lsdesc_lookup(u_int32_t router_id, +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); @@ -231,6 +231,9 @@ extern void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa); extern int 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, + struct ospf6_route *old, + struct ospf6_route *route); extern void ospf6_intra_init(void); diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index e060879f4b..8b720b6d84 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -47,11 +47,11 @@ vector ospf6_lsa_handler_vector; static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) { - u_char *start, *end, *current; + uint8_t *start, *end, *current; char byte[4]; - start = (u_char *)lsa->header + sizeof(struct ospf6_lsa_header); - end = (u_char *)lsa->header + ntohs(lsa->header->length); + start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header); + end = (uint8_t *)lsa->header + ntohs(lsa->header->length); vty_out(vty, " Unknown contents:\n"); for (current = start; current < end; current++) { @@ -84,7 +84,7 @@ void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler) vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler); } -const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) +const struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type) { const struct ospf6_lsa_handler *handler = NULL; unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK; @@ -100,7 +100,7 @@ const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) return handler; } -const char *ospf6_lstype_name(u_int16_t type) +const char *ospf6_lstype_name(uint16_t type) { static char buf[8]; const struct ospf6_lsa_handler *handler; @@ -113,7 +113,7 @@ const char *ospf6_lstype_name(u_int16_t type) return buf; } -const char *ospf6_lstype_short_name(u_int16_t type) +const char *ospf6_lstype_short_name(uint16_t type) { static char buf[8]; const struct ospf6_lsa_handler *handler; @@ -126,7 +126,7 @@ const char *ospf6_lstype_short_name(u_int16_t type) return buf; } -u_char ospf6_lstype_debug(u_int16_t type) +uint8_t ospf6_lstype_debug(uint16_t type) { const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); @@ -207,11 +207,11 @@ void ospf6_lsa_age_set(struct ospf6_lsa *lsa) /* this function calculates current age from its birth, then update age field of LSA header. return value is current age */ -u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa) +uint16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa) { struct timeval now; - u_int32_t ulage; - u_int16_t age; + uint32_t ulage; + uint16_t age; assert(lsa); assert(lsa->header); @@ -237,7 +237,7 @@ u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa) } /* update age field of LSA header with adding InfTransDelay */ -void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, u_int32_t transdelay) +void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, uint32_t transdelay) { unsigned short age; @@ -292,8 +292,8 @@ void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa) int ospf6_lsa_compare(struct ospf6_lsa *a, struct ospf6_lsa *b) { int32_t seqnuma, seqnumb; - u_int16_t cksuma, cksumb; - u_int16_t agea, ageb; + uint16_t cksuma, cksumb; + uint16_t agea, ageb; assert(a && a->header); assert(b && b->header); @@ -355,7 +355,7 @@ void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header) zlog_debug(" [%s Id:%s Adv:%s]", ospf6_lstype_name(header->type), id, adv_router); zlog_debug(" Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d", - ntohs(header->age), (u_long)ntohl(header->seqnum), + ntohs(header->age), (unsigned long)ntohl(header->seqnum), ntohs(header->checksum), ntohs(header->length)); } @@ -394,13 +394,13 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n", ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), - (u_long)ntohl(lsa->header->seqnum), + (unsigned long)ntohl(lsa->header->seqnum), handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0)); } else if (type != OSPF6_LSTYPE_UNKNOWN) { sprintf(tmpbuf, "%-4s %-15s%-15s%4hu %8lx", ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), - (u_long)ntohl(lsa->header->seqnum)); + (unsigned long)ntohl(lsa->header->seqnum)); while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt) != NULL) { @@ -411,17 +411,17 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "%-4s %-15s%-15s%4hu %8lx\n", ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), - (u_long)ntohl(lsa->header->seqnum)); + (unsigned long)ntohl(lsa->header->seqnum)); } } void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa) { - u_char *start, *end, *current; + uint8_t *start, *end, *current; char byte[4]; - start = (u_char *)lsa->header; - end = (u_char *)lsa->header + ntohs(lsa->header->length); + start = (uint8_t *)lsa->header; + end = (uint8_t *)lsa->header + ntohs(lsa->header->length); vty_out(vty, "\n"); vty_out(vty, "%s:\n", lsa->name); @@ -456,7 +456,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "Link State ID: %s\n", id); vty_out(vty, "Advertising Router: %s\n", adv_router); vty_out(vty, "LS Sequence Number: %#010lx\n", - (u_long)ntohl(lsa->header->seqnum)); + (unsigned long)ntohl(lsa->header->seqnum)); vty_out(vty, "CheckSum: %#06hx Length: %hu\n", ntohs(lsa->header->checksum), ntohs(lsa->header->length)); vty_out(vty, "Flag: %x \n", lsa->flag); @@ -490,7 +490,7 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "Link State ID: %s\n", id); vty_out(vty, "Advertising Router: %s\n", adv_router); vty_out(vty, "LS Sequence Number: %#010lx\n", - (u_long)ntohl(lsa->header->seqnum)); + (unsigned long)ntohl(lsa->header->seqnum)); vty_out(vty, "CheckSum: %#06hx Length: %hu\n", ntohs(lsa->header->checksum), ntohs(lsa->header->length)); vty_out(vty, "Duration: %s\n", duration); @@ -512,7 +512,7 @@ struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header) { struct ospf6_lsa *lsa = NULL; struct ospf6_lsa_header *new_header = NULL; - u_int16_t lsa_size = 0; + uint16_t lsa_size = 0; /* size of the entire LSA */ lsa_size = ntohs(header->length); /* XXX vulnerable */ @@ -743,26 +743,28 @@ void ospf6_flush_self_originated_lsas_now(void) one-based. */ unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsa_header) { - u_char *buffer = (u_char *)&lsa_header->type; - int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */ + uint8_t *buffer = (uint8_t *)&lsa_header->type; + int type_offset = + buffer - (uint8_t *)&lsa_header->age; /* should be 2 */ /* Skip the AGE field */ - u_int16_t len = ntohs(lsa_header->length) - type_offset; + uint16_t len = ntohs(lsa_header->length) - type_offset; /* Checksum offset starts from "type" field, not the beginning of the lsa_header struct. The offset is 14, rather than 16. */ - int checksum_offset = (u_char *)&lsa_header->checksum - buffer; + int checksum_offset = (uint8_t *)&lsa_header->checksum - buffer; return (unsigned short)fletcher_checksum(buffer, len, checksum_offset); } int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsa_header) { - u_char *buffer = (u_char *)&lsa_header->type; - int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */ + uint8_t *buffer = (uint8_t *)&lsa_header->type; + int type_offset = + buffer - (uint8_t *)&lsa_header->age; /* should be 2 */ /* Skip the AGE field */ - u_int16_t len = ntohs(lsa_header->length) - type_offset; + uint16_t len = ntohs(lsa_header->length) - type_offset; return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0); @@ -874,7 +876,7 @@ DEFUN (no_debug_ospf6_lsa_type, { int idx_lsa = 4; int idx_type = 5; - u_int i; + unsigned int i; struct ospf6_lsa_handler *handler = NULL; for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { @@ -915,7 +917,7 @@ void install_element_ospf6_debug_lsa(void) int config_write_ospf6_debug_lsa(struct vty *vty) { - u_int i; + unsigned int i; const struct ospf6_lsa_handler *handler; for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 4bf56a8c1e..e88d10ad7e 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -78,13 +78,13 @@ /* LSA Header */ #define OSPF6_LSA_HEADER_SIZE 20U struct ospf6_lsa_header { - u_int16_t age; /* LS age */ - u_int16_t type; /* LS type */ - u_int32_t id; /* Link State ID */ - u_int32_t adv_router; /* Advertising Router */ - u_int32_t seqnum; /* LS sequence number */ - u_int16_t checksum; /* LS checksum */ - u_int16_t length; /* LSA length */ + uint16_t age; /* LS age */ + uint16_t type; /* LS type */ + uint32_t id; /* Link State ID */ + uint32_t adv_router; /* Advertising Router */ + uint32_t seqnum; /* LS sequence number */ + uint16_t checksum; /* LS checksum */ + uint16_t length; /* LSA length */ }; #define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header)) @@ -138,7 +138,7 @@ struct ospf6_lsa { struct ospf6_lsa_handler { const struct { - u_int16_t type; /* host byte order */ + uint16_t type; /* host byte order */ const char *name; const char *short_name; int (*show)(struct vty *, struct ospf6_lsa *); @@ -150,7 +150,7 @@ struct ospf6_lsa_handler { #define lh_short_name s.short_name #define lh_show s.show #define lh_get_prefix_str s.get_prefix_str - u_char debug; + uint8_t debug; #define lh_debug debug }; @@ -208,13 +208,13 @@ extern vector ospf6_lsa_handler_vector; /* Function Prototypes */ -extern const char *ospf6_lstype_name(u_int16_t type); -extern const char *ospf6_lstype_short_name(u_int16_t type); -extern u_char ospf6_lstype_debug(u_int16_t type); +extern const char *ospf6_lstype_name(uint16_t type); +extern const char *ospf6_lstype_short_name(uint16_t type); +extern uint8_t ospf6_lstype_debug(uint16_t type); extern int ospf6_lsa_is_differ(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); extern int ospf6_lsa_is_changed(struct ospf6_lsa *lsa1, struct ospf6_lsa *lsa2); -extern u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *); -extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa *, u_int32_t); +extern uint16_t ospf6_lsa_age_current(struct ospf6_lsa *); +extern void ospf6_lsa_age_update_to_send(struct ospf6_lsa *, uint32_t); extern void ospf6_lsa_premature_aging(struct ospf6_lsa *); extern int ospf6_lsa_compare(struct ospf6_lsa *, struct ospf6_lsa *); @@ -241,11 +241,11 @@ extern int ospf6_lsa_refresh(struct thread *); extern unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *); extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *); -extern int ospf6_lsa_prohibited_duration(u_int16_t type, u_int32_t id, - u_int32_t adv_router, void *scope); +extern int ospf6_lsa_prohibited_duration(uint16_t type, uint32_t id, + uint32_t adv_router, void *scope); extern void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler); -extern const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type); +extern const struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type); extern void ospf6_lsa_init(void); extern void ospf6_lsa_terminate(void); diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index f17b558e8b..5e02c0c917 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -173,8 +173,8 @@ void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) ospf6_lsdb_count_assert(lsdb); } -struct ospf6_lsa *ospf6_lsdb_lookup(u_int16_t type, u_int32_t id, - u_int32_t adv_router, +struct ospf6_lsa *ospf6_lsdb_lookup(uint16_t type, uint32_t id, + uint32_t adv_router, struct ospf6_lsdb *lsdb) { struct route_node *node; @@ -196,8 +196,8 @@ struct ospf6_lsa *ospf6_lsdb_lookup(u_int16_t type, u_int32_t id, return (struct ospf6_lsa *)node->info; } -struct ospf6_lsa *ospf6_lsdb_lookup_next(u_int16_t type, u_int32_t id, - u_int32_t adv_router, +struct ospf6_lsa *ospf6_lsdb_lookup_next(uint16_t type, uint32_t id, + uint32_t adv_router, struct ospf6_lsdb *lsdb) { struct route_node *node; @@ -355,7 +355,7 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb) } void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level, - u_int16_t *type, u_int32_t *id, u_int32_t *adv_router, + uint16_t *type, uint32_t *id, uint32_t *adv_router, struct ospf6_lsdb *lsdb) { struct ospf6_lsa *lsa; @@ -403,11 +403,11 @@ void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level, } } -u_int32_t ospf6_new_ls_id(u_int16_t type, u_int32_t adv_router, - struct ospf6_lsdb *lsdb) +uint32_t ospf6_new_ls_id(uint16_t type, uint32_t adv_router, + struct ospf6_lsdb *lsdb) { struct ospf6_lsa *lsa; - u_int32_t id = 1, tmp_id; + uint32_t id = 1, tmp_id; /* This routine is curently invoked only for Inter-Prefix LSAs for * non-summarized routes (no area/range). @@ -424,13 +424,13 @@ u_int32_t ospf6_new_ls_id(u_int16_t type, u_int32_t adv_router, id++; } - return ((u_int32_t)htonl(id)); + return ((uint32_t)htonl(id)); } /* Decide new LS sequence number to originate. note return value is network byte order */ -u_int32_t ospf6_new_ls_seqnum(u_int16_t type, u_int32_t id, - u_int32_t adv_router, struct ospf6_lsdb *lsdb) +uint32_t ospf6_new_ls_seqnum(uint16_t type, uint32_t id, uint32_t adv_router, + struct ospf6_lsdb *lsdb) { struct ospf6_lsa *lsa; signed long seqnum = 0; @@ -442,5 +442,5 @@ u_int32_t ospf6_new_ls_seqnum(u_int16_t type, u_int32_t id, else seqnum = (signed long)ntohl(lsa->header->seqnum) + 1; - return ((u_int32_t)htonl(seqnum)); + return ((uint32_t)htonl(seqnum)); } diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h index 41e54b5d80..3b32e3ecf6 100644 --- a/ospf6d/ospf6_lsdb.h +++ b/ospf6d/ospf6_lsdb.h @@ -28,7 +28,7 @@ struct ospf6_lsdb { void *data; /* data structure that holds this lsdb */ struct route_table *table; - u_int32_t count; + uint32_t count; void (*hook_add)(struct ospf6_lsa *); void (*hook_remove)(struct ospf6_lsa *); }; @@ -37,11 +37,11 @@ struct ospf6_lsdb { extern struct ospf6_lsdb *ospf6_lsdb_create(void *data); extern void ospf6_lsdb_delete(struct ospf6_lsdb *lsdb); -extern struct ospf6_lsa *ospf6_lsdb_lookup(u_int16_t type, u_int32_t id, - u_int32_t adv_router, +extern struct ospf6_lsa *ospf6_lsdb_lookup(uint16_t type, uint32_t id, + uint32_t adv_router, struct ospf6_lsdb *lsdb); -extern struct ospf6_lsa *ospf6_lsdb_lookup_next(u_int16_t type, u_int32_t id, - u_int32_t adv_router, +extern struct ospf6_lsa *ospf6_lsdb_lookup_next(uint16_t type, uint32_t id, + uint32_t adv_router, struct ospf6_lsdb *lsdb); extern void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb); @@ -83,14 +83,14 @@ enum ospf_lsdb_show_level { }; extern void ospf6_lsdb_show(struct vty *vty, enum ospf_lsdb_show_level level, - u_int16_t *type, u_int32_t *id, - u_int32_t *adv_router, struct ospf6_lsdb *lsdb); + uint16_t *type, uint32_t *id, uint32_t *adv_router, + struct ospf6_lsdb *lsdb); -extern u_int32_t ospf6_new_ls_id(u_int16_t type, u_int32_t adv_router, - struct ospf6_lsdb *lsdb); -extern u_int32_t ospf6_new_ls_seqnum(u_int16_t type, u_int32_t id, - u_int32_t adv_router, - struct ospf6_lsdb *lsdb); +extern uint32_t ospf6_new_ls_id(uint16_t type, uint32_t adv_router, + struct ospf6_lsdb *lsdb); +extern uint32_t ospf6_new_ls_seqnum(uint16_t type, uint32_t id, + uint32_t adv_router, + struct ospf6_lsdb *lsdb); extern int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb); #endif /* OSPF6_LSDB_H */ diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index f32cd6e7e3..c608a01102 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -59,7 +59,7 @@ static const struct message ospf6_message_type_str[] = { /* Minimum (besides the standard OSPF packet header) lengths for OSPF packets of particular types, offset is the "type" field. */ -const u_int16_t ospf6_packet_minlen[OSPF6_MESSAGE_TYPE_ALL] = { +const uint16_t ospf6_packet_minlen[OSPF6_MESSAGE_TYPE_ALL] = { 0, OSPF6_HELLO_MIN_SIZE, OSPF6_DB_DESC_MIN_SIZE, @@ -69,7 +69,7 @@ const u_int16_t ospf6_packet_minlen[OSPF6_MESSAGE_TYPE_ALL] = { /* Minimum (besides the standard LSA header) lengths for LSAs of particular types, offset is the "LSA function code" portion of "LSA type" field. */ -const u_int16_t ospf6_lsa_minlen[OSPF6_LSTYPE_SIZE] = { +const uint16_t ospf6_lsa_minlen[OSPF6_LSTYPE_SIZE] = { 0, /* 0x2001 */ OSPF6_ROUTER_LSA_MIN_SIZE, /* 0x2002 */ OSPF6_NETWORK_LSA_MIN_SIZE, @@ -113,15 +113,15 @@ void ospf6_hello_print(struct ospf6_header *oh) ospf6_options_printbuf(hello->options, options, sizeof(options)); zlog_debug(" I/F-Id:%ld Priority:%d Option:%s", - (u_long)ntohl(hello->interface_id), hello->priority, + (unsigned long)ntohl(hello->interface_id), hello->priority, options); zlog_debug(" HelloInterval:%hu DeadInterval:%hu", ntohs(hello->hello_interval), ntohs(hello->dead_interval)); zlog_debug(" DR:%s BDR:%s", drouter, bdrouter); for (p = (char *)((caddr_t)hello + sizeof(struct ospf6_hello)); - p + sizeof(u_int32_t) <= OSPF6_MESSAGE_END(oh); - p += sizeof(u_int32_t)) { + p + sizeof(uint32_t) <= OSPF6_MESSAGE_END(oh); + p += sizeof(uint32_t)) { inet_ntop(AF_INET, (void *)p, neighbor, sizeof(neighbor)); zlog_debug(" Neighbor: %s", neighbor); } @@ -149,7 +149,7 @@ void ospf6_dbdesc_print(struct ospf6_header *oh) (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_IBIT) ? "I" : "-"), (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MBIT) ? "M" : "-"), (CHECK_FLAG(dbdesc->bits, OSPF6_DBDESC_MSBIT) ? "m" : "s"), - (u_long)ntohl(dbdesc->seqnum)); + (unsigned long)ntohl(dbdesc->seqnum)); for (p = (char *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc)); p + sizeof(struct ospf6_lsa_header) <= OSPF6_MESSAGE_END(oh); @@ -184,7 +184,7 @@ void ospf6_lsreq_print(struct ospf6_header *oh) void ospf6_lsupdate_print(struct ospf6_header *oh) { struct ospf6_lsupdate *lsupdate; - u_long num; + unsigned long num; char *p; ospf6_header_print(oh); @@ -278,9 +278,9 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst, /* TwoWay check */ for (p = (char *)((caddr_t)hello + sizeof(struct ospf6_hello)); - p + sizeof(u_int32_t) <= OSPF6_MESSAGE_END(oh); - p += sizeof(u_int32_t)) { - u_int32_t *router_id = (u_int32_t *)p; + p + sizeof(uint32_t) <= OSPF6_MESSAGE_END(oh); + p += sizeof(uint32_t)) { + uint32_t *router_id = (uint32_t *)p; if (*router_id == oi->area->ospf6->router_id) twoway++; @@ -429,7 +429,7 @@ static void ospf6_dbdesc_recv_master(struct ospf6_header *oh, if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)) zlog_debug( "Sequence number mismatch (%#lx expected)", - (u_long)on->dbdesc_seqnum); + (unsigned long)on->dbdesc_seqnum); thread_add_event(master, seqnumber_mismatch, on, 0, NULL); return; @@ -647,7 +647,7 @@ static void ospf6_dbdesc_recv_slave(struct ospf6_header *oh, if (IS_OSPF6_DEBUG_MESSAGE(oh->type, RECV)) zlog_debug( "Sequence number mismatch (%#lx expected)", - (u_long)on->dbdesc_seqnum + 1); + (unsigned long)on->dbdesc_seqnum + 1); thread_add_event(master, seqnumber_mismatch, on, 0, NULL); return; @@ -873,12 +873,12 @@ static void ospf6_lsreq_recv(struct in6_addr *src, struct in6_addr *dst, static unsigned ospf6_prefixes_examin( struct ospf6_prefix *current, /* start of buffer */ unsigned length, - const u_int32_t req_num_pfxs /* always compared with the actual number + const uint32_t req_num_pfxs /* always compared with the actual number of prefixes */ - ) +) { - u_char requested_pfx_bytes; - u_int32_t real_num_pfxs = 0; + uint8_t requested_pfx_bytes; + uint32_t real_num_pfxs = 0; while (length) { if (length < OSPF6_PREFIX_MIN_SIZE) { @@ -929,15 +929,15 @@ static unsigned ospf6_prefixes_examin( LSA type in network byte order, uses in host byte order and passes to ospf6_lstype_name() in network byte order again. */ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah, - const u_int16_t lsalen, - const u_char headeronly) + const uint16_t lsalen, + const uint8_t headeronly) { struct ospf6_intra_prefix_lsa *intra_prefix_lsa; struct ospf6_as_external_lsa *as_external_lsa; struct ospf6_link_lsa *link_lsa; unsigned exp_length; - u_int8_t ltindex; - u_int16_t lsatype; + uint8_t ltindex; + uint16_t lsatype; /* In case an additional minimum length constraint is defined for current @@ -1103,16 +1103,16 @@ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah, of deeper-level checks. */ static unsigned ospf6_lsaseq_examin(struct ospf6_lsa_header *lsah, /* start of buffered data */ - size_t length, const u_char headeronly, + size_t length, const uint8_t headeronly, /* When declared_num_lsas is not 0, compare it to the real number of LSAs and treat the difference as an error. */ - const u_int32_t declared_num_lsas) + const uint32_t declared_num_lsas) { - u_int32_t counted_lsas = 0; + uint32_t counted_lsas = 0; while (length) { - u_int16_t lsalen; + uint16_t lsalen; if (length < OSPF6_LSA_HEADER_SIZE) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_UNKNOWN, RECV)) @@ -1490,13 +1490,13 @@ static void ospf6_lsack_recv(struct in6_addr *src, struct in6_addr *dst, assert(p == OSPF6_MESSAGE_END(oh)); } -static u_char *recvbuf = NULL; -static u_char *sendbuf = NULL; +static uint8_t *recvbuf = NULL; +static uint8_t *sendbuf = NULL; static unsigned int iobuflen = 0; int ospf6_iobuf_size(unsigned int size) { - u_char *recvnew, *sendnew; + uint8_t *recvnew, *sendnew; if (size <= iobuflen) return iobuflen; @@ -1728,7 +1728,7 @@ int ospf6_hello_send(struct thread *thread) struct ospf6_interface *oi; struct ospf6_header *oh; struct ospf6_hello *hello; - u_char *p; + uint8_t *p; struct listnode *node, *nnode; struct ospf6_neighbor *on; @@ -1767,13 +1767,13 @@ int ospf6_hello_send(struct thread *thread) hello->drouter = oi->drouter; hello->bdrouter = oi->bdrouter; - p = (u_char *)((caddr_t)hello + sizeof(struct ospf6_hello)); + p = (uint8_t *)((caddr_t)hello + sizeof(struct ospf6_hello)); for (ALL_LIST_ELEMENTS(oi->neighbor_list, node, nnode, on)) { if (on->state < OSPF6_NEIGHBOR_INIT) continue; - if (p - sendbuf + sizeof(u_int32_t) > ospf6_packet_max(oi)) { + if (p - sendbuf + sizeof(uint32_t) > ospf6_packet_max(oi)) { if (IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_HELLO, SEND)) zlog_debug( @@ -1781,8 +1781,8 @@ int ospf6_hello_send(struct thread *thread) break; } - memcpy(p, &on->router_id, sizeof(u_int32_t)); - p += sizeof(u_int32_t); + memcpy(p, &on->router_id, sizeof(uint32_t)); + p += sizeof(uint32_t); } oh->type = OSPF6_MESSAGE_TYPE_HELLO; @@ -1799,7 +1799,7 @@ int ospf6_dbdesc_send(struct thread *thread) struct ospf6_neighbor *on; struct ospf6_header *oh; struct ospf6_dbdesc *dbdesc; - u_char *p; + uint8_t *p; struct ospf6_lsa *lsa; struct in6_addr *dst; @@ -1839,7 +1839,7 @@ int ospf6_dbdesc_send(struct thread *thread) dbdesc->seqnum = htonl(on->dbdesc_seqnum); /* if this is not initial one, set LSA headers in dbdesc */ - p = (u_char *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc)); + p = (uint8_t *)((caddr_t)dbdesc + sizeof(struct ospf6_dbdesc)); if (!CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT)) { for (ALL_LSDB(on->dbdesc_list, lsa)) { ospf6_lsa_age_update_to_send(lsa, @@ -1915,7 +1915,7 @@ int ospf6_lsreq_send(struct thread *thread) struct ospf6_neighbor *on; struct ospf6_header *oh; struct ospf6_lsreq_entry *e; - u_char *p; + uint8_t *p; struct ospf6_lsa *lsa, *last_req; on = (struct ospf6_neighbor *)THREAD_ARG(thread); @@ -1942,7 +1942,7 @@ int ospf6_lsreq_send(struct thread *thread) last_req = NULL; /* set Request entries in lsreq */ - p = (u_char *)((caddr_t)oh + sizeof(struct ospf6_header)); + p = (uint8_t *)((caddr_t)oh + sizeof(struct ospf6_header)); for (ALL_LSDB(on->request_list, lsa)) { /* MTU check */ if (p - sendbuf + sizeof(struct ospf6_lsreq_entry) @@ -2026,7 +2026,7 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) struct ospf6_neighbor *on; struct ospf6_header *oh; struct ospf6_lsupdate *lsupdate; - u_char *p; + uint8_t *p; int lsa_cnt; struct ospf6_lsa *lsa; @@ -2048,7 +2048,7 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); lsa_cnt = 0; /* lsupdate_list lists those LSA which doesn't need to be @@ -2071,8 +2071,9 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate - + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + + sizeof(struct + ospf6_lsupdate)); lsa_cnt = 0; } } @@ -2101,7 +2102,7 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) oh = (struct ospf6_header *)sendbuf; lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); lsa_cnt = 0; for (ALL_LSDB(on->retrans_list, lsa)) { @@ -2130,8 +2131,9 @@ int ospf6_lsupdate_send_neighbor(struct thread *thread) *)((caddr_t)oh + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate - + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + + sizeof(struct + ospf6_lsupdate)); lsa_cnt = 0; } } @@ -2173,7 +2175,7 @@ int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on, { struct ospf6_header *oh; struct ospf6_lsupdate *lsupdate; - u_char *p; + uint8_t *p; int lsa_cnt = 0; memset(sendbuf, 0, iobuflen); @@ -2181,7 +2183,7 @@ int ospf6_lsupdate_send_neighbor_now(struct ospf6_neighbor *on, lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay); memcpy(p, lsa->header, OSPF6_LSA_SIZE(lsa->header)); p += OSPF6_LSA_SIZE(lsa->header); @@ -2207,7 +2209,7 @@ int ospf6_lsupdate_send_interface(struct thread *thread) struct ospf6_interface *oi; struct ospf6_header *oh; struct ospf6_lsupdate *lsupdate; - u_char *p; + uint8_t *p; int lsa_cnt; struct ospf6_lsa *lsa; @@ -2232,7 +2234,7 @@ int ospf6_lsupdate_send_interface(struct thread *thread) lsupdate = (struct ospf6_lsupdate *)((caddr_t)oh + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate)); lsa_cnt = 0; for (ALL_LSDB(oi->lsupdate_list, lsa)) { @@ -2258,8 +2260,9 @@ int ospf6_lsupdate_send_interface(struct thread *thread) + sizeof(struct ospf6_header)); - p = (u_char *)((caddr_t)lsupdate - + sizeof(struct ospf6_lsupdate)); + p = (uint8_t *)((caddr_t)lsupdate + + sizeof(struct + ospf6_lsupdate)); lsa_cnt = 0; } } @@ -2294,7 +2297,7 @@ int ospf6_lsack_send_neighbor(struct thread *thread) { struct ospf6_neighbor *on; struct ospf6_header *oh; - u_char *p; + uint8_t *p; struct ospf6_lsa *lsa; int lsa_cnt = 0; @@ -2316,7 +2319,7 @@ int ospf6_lsack_send_neighbor(struct thread *thread) memset(sendbuf, 0, iobuflen); oh = (struct ospf6_header *)sendbuf; - p = (u_char *)((caddr_t)oh + sizeof(struct ospf6_header)); + p = (uint8_t *)((caddr_t)oh + sizeof(struct ospf6_header)); for (ALL_LSDB(on->lsack_list, lsa)) { /* MTU check */ @@ -2336,8 +2339,8 @@ int ospf6_lsack_send_neighbor(struct thread *thread) memset(sendbuf, 0, iobuflen); oh = (struct ospf6_header *)sendbuf; - p = (u_char *)((caddr_t)oh - + sizeof(struct ospf6_header)); + p = (uint8_t *)((caddr_t)oh + + sizeof(struct ospf6_header)); lsa_cnt = 0; } } @@ -2372,7 +2375,7 @@ int ospf6_lsack_send_interface(struct thread *thread) { struct ospf6_interface *oi; struct ospf6_header *oh; - u_char *p; + uint8_t *p; struct ospf6_lsa *lsa; int lsa_cnt = 0; @@ -2395,7 +2398,7 @@ int ospf6_lsack_send_interface(struct thread *thread) memset(sendbuf, 0, iobuflen); oh = (struct ospf6_header *)sendbuf; - p = (u_char *)((caddr_t)oh + sizeof(struct ospf6_header)); + p = (uint8_t *)((caddr_t)oh + sizeof(struct ospf6_header)); for (ALL_LSDB(oi->lsack_list, lsa)) { /* MTU check */ diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h index d867bd0252..d24b7f8942 100644 --- a/ospf6d/ospf6_message.h +++ b/ospf6d/ospf6_message.h @@ -46,14 +46,14 @@ extern unsigned char conf_debug_ospf6_message[]; /* OSPFv3 packet header */ #define OSPF6_HEADER_SIZE 16U struct ospf6_header { - u_char version; - u_char type; - u_int16_t length; - u_int32_t router_id; - u_int32_t area_id; - u_int16_t checksum; - u_char instance_id; - u_char reserved; + uint8_t version; + uint8_t type; + uint16_t length; + uint32_t router_id; + uint32_t area_id; + uint16_t checksum; + uint8_t instance_id; + uint8_t reserved; }; #define OSPF6_MESSAGE_END(H) ((caddr_t) (H) + ntohs ((H)->length)) @@ -62,24 +62,24 @@ struct ospf6_header { #define OSPF6_HELLO_MIN_SIZE 20U struct ospf6_hello { ifindex_t interface_id; - u_char priority; - u_char options[3]; - u_int16_t hello_interval; - u_int16_t dead_interval; - u_int32_t drouter; - u_int32_t bdrouter; + uint8_t priority; + uint8_t options[3]; + uint16_t hello_interval; + uint16_t dead_interval; + uint32_t drouter; + uint32_t bdrouter; /* Followed by Router-IDs */ }; /* Database Description */ #define OSPF6_DB_DESC_MIN_SIZE 12U struct ospf6_dbdesc { - u_char reserved1; - u_char options[3]; - u_int16_t ifmtu; - u_char reserved2; - u_char bits; - u_int32_t seqnum; + uint8_t reserved1; + uint8_t options[3]; + uint16_t ifmtu; + uint8_t reserved2; + uint8_t bits; + uint32_t seqnum; /* Followed by LSA Headers */ }; @@ -92,16 +92,16 @@ struct ospf6_dbdesc { /* It is just a sequence of entries below */ #define OSPF6_LSREQ_LSDESC_FIX_SIZE 12U struct ospf6_lsreq_entry { - u_int16_t reserved; /* Must Be Zero */ - u_int16_t type; /* LS type */ - u_int32_t id; /* Link State ID */ - u_int32_t adv_router; /* Advertising Router */ + uint16_t reserved; /* Must Be Zero */ + uint16_t type; /* LS type */ + uint32_t id; /* Link State ID */ + uint32_t adv_router; /* Advertising Router */ }; /* Link State Update */ #define OSPF6_LS_UPD_MIN_SIZE 4U struct ospf6_lsupdate { - u_int32_t lsa_number; + uint32_t lsa_number; /* Followed by LSAs */ }; diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 16bf2fd8e7..6455f606bd 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -62,7 +62,7 @@ int ospf6_neighbor_cmp(void *va, void *vb) return (ntohl(ona->router_id) < ntohl(onb->router_id) ? -1 : 1); } -struct ospf6_neighbor *ospf6_neighbor_lookup(u_int32_t router_id, +struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t router_id, struct ospf6_interface *oi) { struct listnode *n; @@ -76,7 +76,7 @@ struct ospf6_neighbor *ospf6_neighbor_lookup(u_int32_t router_id, } /* create ospf6_neighbor */ -struct ospf6_neighbor *ospf6_neighbor_create(u_int32_t router_id, +struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, struct ospf6_interface *oi) { struct ospf6_neighbor *on; @@ -147,10 +147,10 @@ void ospf6_neighbor_delete(struct ospf6_neighbor *on) XFREE(MTYPE_OSPF6_NEIGHBOR, on); } -static void ospf6_neighbor_state_change(u_char next_state, +static void ospf6_neighbor_state_change(uint8_t next_state, struct ospf6_neighbor *on, int event) { - u_char prev_state; + uint8_t prev_state; prev_state = on->state; on->state = next_state; @@ -708,7 +708,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty, (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT) ? "More " : ""), (CHECK_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MSBIT) ? "Master" : "Slave"), - (u_long)ntohl(on->dbdesc_seqnum)); + (unsigned long)ntohl(on->dbdesc_seqnum)); vty_out(vty, " Summary-List: %d LSAs\n", on->summary_list->count); for (ALL_LSDB(on->summary_list, lsa)) @@ -826,7 +826,7 @@ DEFUN (show_ipv6_ospf6_neighbor_one, struct ospf6_area *oa; struct listnode *i, *j, *k; void (*showfunc)(struct vty *, struct ospf6_neighbor *); - u_int32_t router_id; + uint32_t router_id; OSPF6_CMD_CHECK_RUNNING(); showfunc = ospf6_neighbor_show_detail; @@ -909,7 +909,7 @@ DEFUN (no_debug_ospf6, DEBUG_STR OSPF6_STR) { - u_int i; + unsigned int i; struct ospf6_lsa_handler *handler = NULL; OSPF6_DEBUG_ABR_OFF(); diff --git a/ospf6d/ospf6_neighbor.h b/ospf6d/ospf6_neighbor.h index 529f586f1a..0c4926edbb 100644 --- a/ospf6d/ospf6_neighbor.h +++ b/ospf6d/ospf6_neighbor.h @@ -41,25 +41,25 @@ struct ospf6_neighbor { struct ospf6_interface *ospf6_if; /* Neighbor state */ - u_char state; + uint8_t state; /* timestamp of last changing state */ - u_int32_t state_change; + uint32_t state_change; struct timeval last_changed; /* Neighbor Router ID */ - u_int32_t router_id; + uint32_t router_id; /* Neighbor Interface ID */ ifindex_t ifindex; /* Router Priority of this neighbor */ - u_char priority; + uint8_t priority; - u_int32_t drouter; - u_int32_t bdrouter; - u_int32_t prev_drouter; - u_int32_t prev_bdrouter; + uint32_t drouter; + uint32_t bdrouter; + uint32_t prev_drouter; + uint32_t prev_bdrouter; /* Options field (Capability) */ char options[3]; @@ -68,8 +68,8 @@ struct ospf6_neighbor { struct in6_addr linklocal_addr; /* For Database Exchange */ - u_char dbdesc_bits; - u_int32_t dbdesc_seqnum; + uint8_t dbdesc_bits; + uint32_t dbdesc_seqnum; /* Last received Database Description packet */ struct ospf6_dbdesc dbdesc_last; @@ -145,9 +145,9 @@ extern const char *ospf6_neighbor_state_str[]; int ospf6_neighbor_cmp(void *va, void *vb); void ospf6_neighbor_dbex_init(struct ospf6_neighbor *on); -struct ospf6_neighbor *ospf6_neighbor_lookup(u_int32_t, +struct ospf6_neighbor *ospf6_neighbor_lookup(uint32_t, struct ospf6_interface *); -struct ospf6_neighbor *ospf6_neighbor_create(u_int32_t, +struct ospf6_neighbor *ospf6_neighbor_create(uint32_t, struct ospf6_interface *); void ospf6_neighbor_delete(struct ospf6_neighbor *); diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c index 9f81bb89fb..4790d8f01e 100644 --- a/ospf6d/ospf6_network.c +++ b/ospf6d/ospf6_network.c @@ -38,9 +38,9 @@ struct in6_addr alldrouters6; /* setsockopt MulticastLoop to off */ static void ospf6_reset_mcastloop(void) { - u_int off = 0; + unsigned int off = 0; if (setsockopt(ospf6_sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &off, - sizeof(u_int)) + sizeof(unsigned int)) < 0) zlog_warn("Network: reset IPV6_MULTICAST_LOOP failed: %s", safe_strerror(errno)); @@ -156,7 +156,7 @@ int ospf6_sendmsg(struct in6_addr *src, struct in6_addr *dst, struct cmsghdr *scmsgp; union { struct cmsghdr hdr; - u_char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; + uint8_t buf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; } cmsgbuf; struct in6_pktinfo *pktinfo; struct sockaddr_in6 dst_sin6; @@ -212,7 +212,7 @@ int ospf6_recvmsg(struct in6_addr *src, struct in6_addr *dst, int retval; struct msghdr rmsghdr; struct cmsghdr *rcmsgp; - u_char cmsgbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; + uint8_t cmsgbuf[CMSG_SPACE(sizeof(struct in6_pktinfo))]; struct in6_pktinfo *pktinfo; struct sockaddr_in6 src_sin6; diff --git a/ospf6d/ospf6_proto.c b/ospf6d/ospf6_proto.c index d0ab676551..4b56a64b7f 100644 --- a/ospf6d/ospf6_proto.c +++ b/ospf6d/ospf6_proto.c @@ -26,10 +26,10 @@ void ospf6_prefix_apply_mask(struct ospf6_prefix *op) { - u_char *pnt, mask; + uint8_t *pnt, mask; int index, offset; - pnt = (u_char *)((caddr_t)op + sizeof(struct ospf6_prefix)); + pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix)); index = op->prefix_length / 8; offset = op->prefix_length % 8; mask = 0xff << (8 - offset); @@ -48,7 +48,7 @@ void ospf6_prefix_apply_mask(struct ospf6_prefix *op) pnt[index++] = 0; } -void ospf6_prefix_options_printbuf(u_int8_t prefix_options, char *buf, int size) +void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size) { snprintf(buf, size, "xxx"); } @@ -63,7 +63,7 @@ void ospf6_capability_printbuf(char capability, char *buf, int size) snprintf(buf, size, "----%c%c%c%c", w, v, e, b); } -void ospf6_options_printbuf(u_char *options, char *buf, int size) +void ospf6_options_printbuf(uint8_t *options, char *buf, int size) { const char *dc, *r, *n, *mc, *e, *v6; dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--"); diff --git a/ospf6d/ospf6_proto.h b/ospf6d/ospf6_proto.h index 5919190854..ca2804c476 100644 --- a/ospf6d/ospf6_proto.h +++ b/ospf6d/ospf6_proto.h @@ -53,11 +53,11 @@ /* OSPF6 Prefix */ #define OSPF6_PREFIX_MIN_SIZE 4U /* .length == 0 */ struct ospf6_prefix { - u_int8_t prefix_length; - u_int8_t prefix_options; + uint8_t prefix_length; + uint8_t prefix_options; union { - u_int16_t _prefix_metric; - u_int16_t _prefix_referenced_lstype; + uint16_t _prefix_metric; + uint16_t _prefix_referenced_lstype; } u; #define prefix_metric u._prefix_metric #define prefix_refer_lstype u._prefix_referenced_lstype @@ -92,9 +92,9 @@ struct ospf6_prefix { } while (0) extern void ospf6_prefix_apply_mask(struct ospf6_prefix *op); -extern void ospf6_prefix_options_printbuf(u_int8_t prefix_options, char *buf, +extern void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size); extern void ospf6_capability_printbuf(char capability, char *buf, int size); -extern void ospf6_options_printbuf(u_char *options, char *buf, int size); +extern void ospf6_options_printbuf(uint8_t *options, char *buf, int size); #endif /* OSPF6_PROTO_H */ diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 87f3f6edca..8be00d9b41 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -122,7 +122,7 @@ static char *ospf6_route_table_name(struct ospf6_route_table *table) return name; } -void ospf6_linkstate_prefix(u_int32_t adv_router, u_int32_t id, +void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id, struct prefix *prefix) { memset(prefix, 0, sizeof(struct prefix)); @@ -134,7 +134,7 @@ void ospf6_linkstate_prefix(u_int32_t adv_router, u_int32_t id, void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf, int size) { - u_int32_t adv_router, id; + uint32_t adv_router, id; char adv_router_str[16], id_str[16]; memcpy(&adv_router, &prefix->u.prefix6.s6_addr[0], 4); memcpy(&id, &prefix->u.prefix6.s6_addr[4], 4); @@ -382,6 +382,20 @@ struct ospf6_path *ospf6_path_dup(struct ospf6_path *path) return new; } +void ospf6_copy_paths(struct list *dst, struct list *src) +{ + struct ospf6_path *path_new, *path; + struct listnode *node; + + if (dst && src) { + for (ALL_LIST_ELEMENTS_RO(src, node, path)) { + path_new = ospf6_path_dup(path); + ospf6_copy_nexthops(path_new->nh_list, path->nh_list); + listnode_add_sort(dst, path_new); + } + } +} + struct ospf6_route *ospf6_route_create(void) { struct ospf6_route *route; @@ -420,6 +434,7 @@ struct ospf6_route *ospf6_route_copy(struct ospf6_route *route) new->linkstate_id = route->linkstate_id; new->path = route->path; ospf6_copy_nexthops(new->nh_list, route->nh_list); + ospf6_copy_paths(new->paths, route->paths); new->rnode = NULL; new->prev = NULL; new->next = NULL; @@ -460,9 +475,6 @@ int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb) if (ra->type != rb->type) return (ra->type - rb->type); - if (ra->path.area_id != rb->path.area_id) - return (ntohl(ra->path.area_id) - ntohl(rb->path.area_id)); - if (ra->path.type != rb->path.type) return (ra->path.type - rb->path.type); @@ -476,6 +488,9 @@ int ospf6_route_cmp(struct ospf6_route *ra, struct ospf6_route *rb) return (ra->path.cost - rb->path.cost); } + if (ra->path.area_id != rb->path.area_id) + return (ntohl(ra->path.area_id) - ntohl(rb->path.area_id)); + return 0; } @@ -649,10 +664,11 @@ struct ospf6_route *ospf6_route_add(struct ospf6_route *route, if (IS_OSPF6_DEBUG_ROUTE(MEMORY)) zlog_debug( - "%s %p: route add %p cost %u: update of %p old cost %u", + "%s %p: route add %p cost %u nh %u: update of %p old cost %u nh %u", ospf6_route_table_name(table), (void *)table, - (void *)route, route->path.cost, (void *)old, - old->path.cost); + (void *)route, route->path.cost, + listcount(route->nh_list), (void *)old, + old->path.cost, listcount(old->nh_list)); else if (IS_OSPF6_DEBUG_ROUTE(TABLE)) zlog_debug("%s: route add: update", ospf6_route_table_name(table)); @@ -1245,7 +1261,7 @@ static void ospf6_route_show_table_match(struct vty *vty, int detail, } static void ospf6_route_show_table_type(struct vty *vty, int detail, - u_char type, + uint8_t type, struct ospf6_route_table *table) { struct ospf6_route *route; @@ -1288,7 +1304,7 @@ int ospf6_route_table_show(struct vty *vty, int argc_start, int argc, int isprefix = 0; int i, ret; struct prefix prefix; - u_char type = 0; + uint8_t type = 0; memset(&prefix, 0, sizeof(struct prefix)); @@ -1375,7 +1391,7 @@ static void ospf6_linkstate_show_header(struct vty *vty) static void ospf6_linkstate_show(struct vty *vty, struct ospf6_route *route) { - u_int32_t router, id; + uint32_t router, id; char routername[16], idname[16], rbits[16], options[16]; router = ospf6_linkstate_prefix_adv_router(&route->prefix); @@ -1501,7 +1517,7 @@ void ospf6_brouter_show_header(struct vty *vty) void ospf6_brouter_show(struct vty *vty, struct ospf6_route *route) { - u_int32_t adv_router; + uint32_t adv_router; char adv[16], rbits[16], options[16], area[16]; adv_router = ospf6_linkstate_prefix_adv_router(&route->prefix); diff --git a/ospf6d/ospf6_route.h b/ospf6d/ospf6_route.h index b759828c39..a69e9a920f 100644 --- a/ospf6d/ospf6_route.h +++ b/ospf6d/ospf6_route.h @@ -63,9 +63,9 @@ struct ospf6_nexthop { /* Path */ struct ospf6_ls_origin { - u_int16_t type; - u_int32_t id; - u_int32_t adv_router; + uint16_t type; + uint32_t id; + uint32_t adv_router; }; struct ospf6_path { @@ -73,29 +73,29 @@ struct ospf6_path { struct ospf6_ls_origin origin; /* Router bits */ - u_char router_bits; + uint8_t router_bits; /* Optional Capabilities */ - u_char options[3]; + uint8_t options[3]; /* Prefix Options */ - u_char prefix_options; + uint8_t prefix_options; /* Associated Area */ - u_int32_t area_id; + uint32_t area_id; /* Path-type */ - u_char type; - u_char subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */ + uint8_t type; + uint8_t subtype; /* only used for redistribute i.e ZEBRA_ROUTE_XXX */ /* Cost */ - u_int8_t metric_type; - u_int32_t cost; + uint8_t metric_type; + uint32_t cost; union { - u_int32_t cost_e2; - u_int32_t cost_config; + uint32_t cost_e2; + uint32_t cost_config; } u; - u_int32_t tag; + uint32_t tag; /* nh list for this path */ struct list *nh_list; @@ -126,7 +126,7 @@ struct ospf6_route { unsigned int lock; /* Destination Type */ - u_char type; + uint8_t type; /* XXX: It would likely be better to use separate struct in_addr's * for the advertising router-ID and prefix IDs, instead of stuffing @@ -141,13 +141,13 @@ struct ospf6_route { struct timeval changed; /* flag */ - u_char flag; + uint8_t flag; /* route option */ void *route_option; /* link state id for advertising */ - u_int32_t linkstate_id; + uint32_t linkstate_id; /* path */ struct ospf6_path path; @@ -184,7 +184,7 @@ struct ospf6_route_table { /* patricia tree */ struct route_table *table; - u_int32_t count; + uint32_t count; bitfield_t idspace; @@ -246,6 +246,7 @@ extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX]; ((ra)->type == (rb)->type \ && memcmp(&(ra)->prefix, &(rb)->prefix, sizeof(struct prefix)) == 0 \ && memcmp(&(ra)->path, &(rb)->path, sizeof(struct ospf6_path)) == 0 \ + && listcount(ra->paths) == listcount(rb->paths) \ && ospf6_route_cmp_nexthops(ra, rb) == 0) #define ospf6_route_is_best(r) (CHECK_FLAG ((r)->flag, OSPF6_ROUTE_BEST)) @@ -256,7 +257,7 @@ extern const char *ospf6_path_type_substr[OSPF6_PATH_TYPE_MAX]; #define ADV_ROUTER_IN_PREFIX(x) ((x)->u.lp.id.s_addr) /* Function prototype */ -extern void ospf6_linkstate_prefix(u_int32_t adv_router, u_int32_t id, +extern void ospf6_linkstate_prefix(uint32_t adv_router, uint32_t id, struct prefix *prefix); extern void ospf6_linkstate_prefix2str(struct prefix *prefix, char *buf, int size); @@ -340,5 +341,6 @@ extern void ospf6_route_init(void); extern void ospf6_clean(void); extern void ospf6_path_free(struct ospf6_path *op); extern struct ospf6_path *ospf6_path_dup(struct ospf6_path *path); +extern void ospf6_copy_paths(struct list *dst, struct list *src); #endif /* OSPF6_ROUTE_H */ diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index ed1d8bee7d..376950e84a 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -209,16 +209,16 @@ static oid ospfv3_oid[] = {OSPFv3MIB}; static oid ospfv3_trap_oid[] = {OSPFv3MIB, 0}; /* Hook functions. */ -static u_char *ospfv3GeneralGroup(struct variable *, oid *, size_t *, int, +static uint8_t *ospfv3GeneralGroup(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfv3AreaEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfv3WwLsdbEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfv3AreaEntry(struct variable *, oid *, size_t *, int, +static uint8_t *ospfv3NbrEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfv3WwLsdbEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *ospfv3NbrEntry(struct variable *, oid *, size_t *, int, size_t *, +static uint8_t *ospfv3IfEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfv3IfEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); static struct variable ospfv3_variables[] = { /* OSPF general variables */ @@ -631,12 +631,12 @@ static struct variable ospfv3_variables[] = { {1, 9, 1, 15}}, }; -static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfv3GeneralGroup(struct variable *v, oid *name, + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { - u_int16_t sum; - u_int32_t count; + uint16_t sum; + uint32_t count; struct ospf6_lsa *lsa = NULL; /* Check whether the instance identifier is valid */ @@ -728,15 +728,15 @@ static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf6_area *oa, *area = NULL; struct ospf6_lsa *lsa = NULL; - u_int32_t area_id = 0; - u_int32_t count; - u_int16_t sum; + uint32_t area_id = 0; + uint32_t count; + uint16_t sum; struct listnode *node; unsigned int len; char a[16]; @@ -758,7 +758,7 @@ static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length, inet_ntop(AF_INET, &area_id, a, sizeof(a)); zlog_debug("SNMP access by area: %s, exact=%d len=%d length=%lu", a, - exact, len, (u_long)*length); + exact, len, (unsigned long)*length); for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) { if (area == NULL) { @@ -779,7 +779,7 @@ static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length, inet_ntop(AF_INET, &area->area_id, a, sizeof(a)); zlog_debug("SNMP found area: %s, exact=%d len=%d length=%lu", a, exact, - len, (u_long)*length); + len, (unsigned long)*length); switch (v->magic) { case OSPFv3IMPORTASEXTERN: @@ -833,15 +833,15 @@ static int if_icmp_func(struct interface *ifp1, struct interface *ifp2) return (ifp1->ifindex - ifp2->ifindex); } -static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct ospf6_lsa *lsa = NULL; ifindex_t ifindex; uint32_t area_id, id, instid, adv_router; - u_int16_t type; + uint16_t type; int len; oid *offset; int offsetlen; @@ -1027,7 +1027,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, break; case OSPFv3WWLSDBADVERTISEMENT: *var_len = ntohs(lsa->header->length); - return (u_char *)lsa->header; + return (uint8_t *)lsa->header; break; case OSPFv3WWLSDBTYPEKNOWN: return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa->header->type) @@ -1038,9 +1038,9 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); ifindex_t ifindex = 0; @@ -1052,7 +1052,7 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, struct list *ifslist; oid *offset; int offsetlen, len; - u_int32_t sum; + uint32_t sum; if (smux_header_table(v, name, length, exact, var_len, write_method) == MATCH_FAILED) @@ -1191,9 +1191,9 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); ifindex_t ifindex = 0; @@ -1301,7 +1301,7 @@ static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length, return SNMP_INTEGER(2); /* IPv6 only */ case OSPFv3NBRADDRESS: *var_len = sizeof(struct in6_addr); - return (u_char *)&on->linklocal_addr; + return (uint8_t *)&on->linklocal_addr; case OSPFv3NBROPTIONS: return SNMP_INTEGER(on->options[2]); case OSPFv3NBRPRIORITY: diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 8d32f3505e..28c3459825 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -139,10 +139,10 @@ static struct ospf6_vertex *ospf6_vertex_create(struct ospf6_lsa *lsa) v->lsa = lsa; /* capability bits + options */ - v->capability = *(u_char *)(OSPF6_LSA_HEADER_END(lsa->header)); - v->options[0] = *(u_char *)(OSPF6_LSA_HEADER_END(lsa->header) + 1); - v->options[1] = *(u_char *)(OSPF6_LSA_HEADER_END(lsa->header) + 2); - v->options[2] = *(u_char *)(OSPF6_LSA_HEADER_END(lsa->header) + 3); + v->capability = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header)); + v->options[0] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 1); + v->options[1] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 2); + v->options[2] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 3); v->nh_list = list_new(); v->nh_list->cmp = (int (*)(void *, void *))ospf6_nexthop_cmp; @@ -166,8 +166,8 @@ static struct ospf6_lsa *ospf6_lsdesc_lsa(caddr_t lsdesc, struct ospf6_vertex *v) { struct ospf6_lsa *lsa = NULL; - u_int16_t type = 0; - u_int32_t id = 0, adv_router = 0; + uint16_t type = 0; + uint32_t id = 0, adv_router = 0; if (VERTEX_IS_TYPE(NETWORK, v)) { type = htons(OSPF6_LSTYPE_ROUTER); @@ -262,8 +262,8 @@ static void ospf6_nexthop_calc(struct ospf6_vertex *w, struct ospf6_vertex *v, int i; ifindex_t ifindex; struct ospf6_interface *oi; - u_int16_t type; - u_int32_t adv_router; + uint16_t type; + uint32_t adv_router; struct ospf6_lsa *lsa; struct ospf6_link_lsa *link_lsa; char buf[64]; @@ -456,7 +456,7 @@ void ospf6_spf_reason_string(unsigned int reason, char *buf, int size) /* RFC2328 16.1. Calculating the shortest-path tree for an area */ /* RFC2740 3.8.1. Calculating the shortest path tree for an area */ -void ospf6_spf_calculation(u_int32_t router_id, +void ospf6_spf_calculation(uint32_t router_id, struct ospf6_route_table *result_table, struct ospf6_area *oa) { @@ -966,7 +966,7 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, uint8_t *new_header = NULL; const struct route_node *end = NULL; uint16_t lsa_length, total_lsa_length = 0, num_lsa = 0; - u_int16_t type = 0; + uint16_t type = 0; char ifbuf[16]; uint32_t interface_id; caddr_t lsd; diff --git a/ospf6d/ospf6_spf.h b/ospf6d/ospf6_spf.h index f294b8d34f..da95ec80a3 100644 --- a/ospf6d/ospf6_spf.h +++ b/ospf6d/ospf6_spf.h @@ -36,7 +36,7 @@ extern unsigned char conf_debug_ospf6_spf; /* Transit Vertex */ struct ospf6_vertex { /* type of this vertex */ - u_int8_t type; + uint8_t type; /* Vertex Identifier */ struct prefix vertex_id; @@ -51,16 +51,16 @@ struct ospf6_vertex { struct ospf6_lsa *lsa; /* Distance from Root (i.e. Cost) */ - u_int32_t cost; + uint32_t cost; /* Router hops to this node */ - u_char hops; + uint8_t hops; /* capability bits */ - u_char capability; + uint8_t capability; /* Optional capabilities */ - u_char options[3]; + uint8_t options[3]; /* For tree display */ struct ospf6_vertex *parent; @@ -136,7 +136,7 @@ static inline unsigned int ospf6_lsremove_to_spf_reason(struct ospf6_lsa *lsa) } extern void ospf6_spf_table_finish(struct ospf6_route_table *result_table); -extern void ospf6_spf_calculation(u_int32_t router_id, +extern void ospf6_spf_calculation(uint32_t router_id, struct ospf6_route_table *result_table, struct ospf6_area *oa); extern void ospf6_spf_schedule(struct ospf6 *ospf, unsigned int reason); diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 630b717fb3..e4a4891526 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -365,7 +365,7 @@ DEFUN(ospf6_router_id, int idx = 0; int ret; const char *router_id_str; - u_int32_t router_id; + uint32_t router_id; struct ospf6_area *oa; struct listnode *node; @@ -422,13 +422,13 @@ DEFUN(no_ospf6_router_id, return CMD_SUCCESS; } -#if CONFDATE > 20180828 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180828 CPP_NOTICE("ospf6: `router-id A.B.C.D` deprecated 2017/08/28") #endif ALIAS_HIDDEN(ospf6_router_id, ospf6_router_id_hdn_cmd, "router-id A.B.C.D", "Configure OSPF6 Router-ID\n" V4NOTATION_STR) -#if CONFDATE > 20180828 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180828 CPP_NOTICE("ospf6: `no router-id A.B.C.D` deprecated 2017/08/28") #endif ALIAS_HIDDEN(no_ospf6_router_id, no_ospf6_router_id_hdn_cmd, @@ -663,7 +663,7 @@ DEFUN (ospf6_interface_area, struct ospf6_area *oa; struct ospf6_interface *oi; struct interface *ifp; - u_int32_t area_id; + uint32_t area_id; /* find/create ospf6 interface */ ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT, 0); @@ -722,7 +722,7 @@ DEFUN (no_ospf6_interface_area, struct ospf6_interface *oi; struct ospf6_area *oa; struct interface *ifp; - u_int32_t area_id; + uint32_t area_id; ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); if (ifp == NULL) { diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h index 3ffcad0564..381027dcff 100644 --- a/ospf6d/ospf6_top.h +++ b/ospf6d/ospf6_top.h @@ -32,10 +32,10 @@ struct ospf6_master { /* OSPFv3 top level data structure */ struct ospf6 { /* my router id */ - u_int32_t router_id; + uint32_t router_id; /* static router id */ - u_int32_t router_id_static; + uint32_t router_id_static; struct in_addr router_id_zebra; @@ -55,7 +55,7 @@ struct ospf6 { struct ospf6_route_table *external_table; struct route_table *external_id_table; - u_int32_t external_id; + uint32_t external_id; /* redistribute route-map */ struct { @@ -63,10 +63,10 @@ struct ospf6 { struct route_map *map; } rmap[ZEBRA_ROUTE_MAX]; - u_char flag; + uint8_t flag; /* Configured flags */ - u_char config_flags; + uint8_t config_flags; #define OSPF6_LOG_ADJACENCY_CHANGES (1 << 0) #define OSPF6_LOG_ADJACENCY_DETAIL (1 << 1) @@ -91,13 +91,13 @@ struct ospf6 { struct thread *maxage_remover; struct thread *t_distribute_update; /* Distirbute update timer. */ - u_int32_t ref_bandwidth; + uint32_t ref_bandwidth; /* Distance parameters */ - u_char distance_all; - u_char distance_intra; - u_char distance_inter; - u_char distance_external; + uint8_t distance_all; + uint8_t distance_intra; + uint8_t distance_inter; + uint8_t distance_external; struct route_table *distance_table; diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 0decc09a29..8c2e706d17 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -468,7 +468,7 @@ int ospf6_distance_set(struct vty *vty, struct ospf6 *o, { int ret; struct prefix_ipv6 p; - u_char distance; + uint8_t distance; struct route_node *rn; struct ospf6_distance *odistance; @@ -553,7 +553,7 @@ void ospf6_distance_reset(struct ospf6 *o) } } -u_char ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or) +uint8_t ospf6_distance_apply(struct prefix_ipv6 *p, struct ospf6_route * or) { struct ospf6 *o; diff --git a/ospf6d/ospf6_zebra.h b/ospf6d/ospf6_zebra.h index 8ab9993367..e2f778fa72 100644 --- a/ospf6d/ospf6_zebra.h +++ b/ospf6d/ospf6_zebra.h @@ -34,7 +34,7 @@ extern unsigned char conf_debug_ospf6_zebra; /* OSPF6 distance */ struct ospf6_distance { /* Distance value for the IP source prefix */ - u_char distance; + uint8_t distance; /* Name of the access-list to be matched */ char *access_list; @@ -55,7 +55,7 @@ extern void ospf6_zebra_delete_discard(struct ospf6_route *request); struct ospf6; extern void ospf6_distance_reset(struct ospf6 *); -extern u_char ospf6_distance_apply(struct prefix_ipv6 *, struct ospf6_route *); +extern uint8_t ospf6_distance_apply(struct prefix_ipv6 *, struct ospf6_route *); extern int ospf6_distance_set(struct vty *, struct ospf6 *, const char *, const char *, const char *); diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index 58a39156da..8d6d5b4a26 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -126,9 +126,9 @@ static int parse_show_level(int idx_level, int argc, struct cmd_token **argv) return level; } -static u_int16_t parse_type_spec(int idx_lsa, int argc, struct cmd_token **argv) +static uint16_t parse_type_spec(int idx_lsa, int argc, struct cmd_token **argv) { - u_int16_t type = 0; + uint16_t type = 0; if (argc > idx_lsa) { if (strmatch(argv[idx_lsa]->text, "router")) @@ -220,7 +220,7 @@ DEFUN (show_ipv6_ospf6_database_type, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; + uint16_t type = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -282,7 +282,7 @@ DEFUN (show_ipv6_ospf6_database_id, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int32_t id = 0; + uint32_t id = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -333,7 +333,7 @@ DEFUN (show_ipv6_ospf6_database_router, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int32_t adv_router = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); inet_pton(AF_INET, argv[idx_ipv4]->arg, &adv_router); @@ -434,8 +434,8 @@ DEFUN (show_ipv6_ospf6_database_type_id, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t id = 0; + uint16_t type = 0; + uint32_t id = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -508,8 +508,8 @@ DEFUN (show_ipv6_ospf6_database_type_router, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t adv_router = 0; + uint16_t type = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -575,8 +575,8 @@ DEFUN (show_ipv6_ospf6_database_id_router, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int32_t id = 0; - u_int32_t adv_router = 0; + uint32_t id = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); inet_pton(AF_INET, argv[idx_ls_id]->arg, &id); @@ -628,8 +628,8 @@ DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int32_t id = 0; - u_int32_t adv_router = 0; + uint32_t id = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); inet_pton(AF_INET, argv[idx_adv_rtr]->arg, &adv_router); @@ -687,9 +687,9 @@ DEFUN (show_ipv6_ospf6_database_type_id_router, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t id = 0; - u_int32_t adv_router = 0; + uint16_t type = 0; + uint32_t id = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -765,9 +765,9 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t id = 0; - u_int32_t adv_router = 0; + uint16_t type = 0; + uint32_t id = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -828,7 +828,7 @@ DEFUN (show_ipv6_ospf6_database_self_originated, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int32_t adv_router = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); level = parse_show_level(idx_level, argc, argv); @@ -884,8 +884,8 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t adv_router = 0; + uint16_t type = 0; + uint32_t adv_router = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -959,9 +959,9 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t adv_router = 0; - u_int32_t id = 0; + uint16_t type = 0; + uint32_t adv_router = 0; + uint32_t id = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -1034,9 +1034,9 @@ DEFUN (show_ipv6_ospf6_database_type_id_self_originated, struct ospf6 *o = ospf6; struct ospf6_area *oa; struct ospf6_interface *oi; - u_int16_t type = 0; - u_int32_t adv_router = 0; - u_int32_t id = 0; + uint16_t type = 0; + uint32_t adv_router = 0; + uint32_t id = 0; OSPF6_CMD_CHECK_RUNNING(); @@ -1090,7 +1090,7 @@ DEFUN (show_ipv6_ospf6_border_routers, "Show detailed output\n") { int idx_ipv4 = 4; - u_int32_t adv_router; + uint32_t adv_router; struct ospf6_route *ro; struct prefix prefix; diff --git a/ospfclient/ospf_apiclient.c b/ospfclient/ospf_apiclient.c index bdac0e49a5..5b46059d78 100644 --- a/ospfclient/ospf_apiclient.c +++ b/ospfclient/ospf_apiclient.c @@ -303,7 +303,7 @@ int ospf_apiclient_close(struct ospf_apiclient *oclient) static int ospf_apiclient_send_request(struct ospf_apiclient *oclient, struct msg *msg) { - u_int32_t reqseq; + uint32_t reqseq; struct msg_reply *msgreply; int rc; @@ -341,10 +341,10 @@ static int ospf_apiclient_send_request(struct ospf_apiclient *oclient, * ----------------------------------------------------------- */ -static u_int32_t ospf_apiclient_get_seqnr(void) +static uint32_t ospf_apiclient_get_seqnr(void) { - static u_int32_t seqnr = MIN_SEQ; - u_int32_t tmp; + static uint32_t seqnr = MIN_SEQ; + uint32_t tmp; tmp = seqnr; /* Increment sequence number */ @@ -364,8 +364,8 @@ static u_int32_t ospf_apiclient_get_seqnr(void) /* * Synchronous request to register opaque type. */ -int ospf_apiclient_register_opaque_type(struct ospf_apiclient *cl, u_char ltype, - u_char otype) +int ospf_apiclient_register_opaque_type(struct ospf_apiclient *cl, + uint8_t ltype, uint8_t otype) { struct msg *msg; int rc; @@ -424,15 +424,15 @@ out: int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, struct in_addr ifaddr, struct in_addr area_id, - u_char lsa_type, u_char opaque_type, - u_int32_t opaque_id, void *opaquedata, + uint8_t lsa_type, uint8_t opaque_type, + uint32_t opaque_id, void *opaquedata, int opaquelen) { struct msg *msg; int rc; - u_char buf[OSPF_MAX_LSA_SIZE]; + uint8_t buf[OSPF_MAX_LSA_SIZE]; struct lsa_header *lsah; - u_int32_t tmp; + uint32_t tmp; /* We can only originate opaque LSAs */ @@ -455,7 +455,7 @@ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, lsah->checksum = 0; lsah->length = htons(sizeof(struct lsa_header) + opaquelen); - memcpy(((u_char *)lsah) + sizeof(struct lsa_header), opaquedata, + memcpy(((uint8_t *)lsah) + sizeof(struct lsa_header), opaquedata, opaquelen); msg = new_msg_originate_request(ospf_apiclient_get_seqnr(), ifaddr, @@ -470,8 +470,8 @@ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, } int ospf_apiclient_lsa_delete(struct ospf_apiclient *oclient, - struct in_addr area_id, u_char lsa_type, - u_char opaque_type, u_int32_t opaque_id) + struct in_addr area_id, uint8_t lsa_type, + uint8_t opaque_type, uint32_t opaque_id) { struct msg *msg; int rc; @@ -655,18 +655,18 @@ static void ospf_apiclient_msghandle(struct ospf_apiclient *oclient, void ospf_apiclient_register_callback( struct ospf_apiclient *oclient, - void (*ready_notify)(u_char lsa_type, u_char opaque_type, + void (*ready_notify)(uint8_t lsa_type, uint8_t opaque_type, struct in_addr addr), void (*new_if)(struct in_addr ifaddr, struct in_addr area_id), void (*del_if)(struct in_addr ifaddr), void (*ism_change)(struct in_addr ifaddr, struct in_addr area_id, - u_char status), + uint8_t status), void (*nsm_change)(struct in_addr ifaddr, struct in_addr nbraddr, - struct in_addr router_id, u_char status), + struct in_addr router_id, uint8_t status), void (*update_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char self_origin, struct lsa_header *lsa), + uint8_t self_origin, struct lsa_header *lsa), void (*delete_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char self_origin, struct lsa_header *lsa)) + uint8_t self_origin, struct lsa_header *lsa)) { assert(oclient); assert(update_notify); diff --git a/ospfclient/ospf_apiclient.h b/ospfclient/ospf_apiclient.h index 916a2d8ed1..6d1eb7f64f 100644 --- a/ospfclient/ospf_apiclient.h +++ b/ospfclient/ospf_apiclient.h @@ -30,18 +30,18 @@ struct ospf_apiclient { int fd_async; /* Pointer to callback functions */ - void (*ready_notify)(u_char lsa_type, u_char opaque_type, + void (*ready_notify)(uint8_t lsa_type, uint8_t opaque_type, struct in_addr addr); void (*new_if)(struct in_addr ifaddr, struct in_addr area_id); void (*del_if)(struct in_addr ifaddr); void (*ism_change)(struct in_addr ifaddr, struct in_addr area_id, - u_char status); + uint8_t status); void (*nsm_change)(struct in_addr ifaddr, struct in_addr nbraddr, - struct in_addr router_id, u_char status); + struct in_addr router_id, uint8_t status); void (*update_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char self_origin, struct lsa_header *lsa); + uint8_t self_origin, struct lsa_header *lsa); void (*delete_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char self_origin, struct lsa_header *lsa); + uint8_t self_origin, struct lsa_header *lsa); }; @@ -58,27 +58,27 @@ int ospf_apiclient_close(struct ospf_apiclient *oclient); /* Synchronous request to register opaque type. */ int ospf_apiclient_register_opaque_type(struct ospf_apiclient *oclient, - u_char ltype, u_char otype); + uint8_t ltype, uint8_t otype); /* Synchronous request to register event mask. */ int ospf_apiclient_register_events(struct ospf_apiclient *oclient, - u_int32_t mask); + uint32_t mask); /* Register callback functions.*/ void ospf_apiclient_register_callback( struct ospf_apiclient *oclient, - void (*ready_notify)(u_char lsa_type, u_char opaque_type, + void (*ready_notify)(uint8_t lsa_type, uint8_t opaque_type, struct in_addr addr), void (*new_if)(struct in_addr ifaddr, struct in_addr area_id), void (*del_if)(struct in_addr ifaddr), void (*ism_change)(struct in_addr ifaddr, struct in_addr area_id, - u_char status), + uint8_t status), void (*nsm_change)(struct in_addr ifaddr, struct in_addr nbraddr, - struct in_addr router_id, u_char status), + struct in_addr router_id, uint8_t status), void (*update_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char selforig, struct lsa_header *lsa), + uint8_t selforig, struct lsa_header *lsa), void (*delete_notify)(struct in_addr ifaddr, struct in_addr area_id, - u_char selforig, struct lsa_header *lsa)); + uint8_t selforig, struct lsa_header *lsa)); /* Synchronous request to synchronize LSDB. */ int ospf_apiclient_sync_lsdb(struct ospf_apiclient *oclient); @@ -86,16 +86,16 @@ int ospf_apiclient_sync_lsdb(struct ospf_apiclient *oclient); /* Synchronous request to originate or update opaque LSA. */ int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient, struct in_addr ifaddr, struct in_addr area_id, - u_char lsa_type, u_char opaque_type, - u_int32_t opaque_id, void *opaquedata, + uint8_t lsa_type, uint8_t opaque_type, + uint32_t opaque_id, void *opaquedata, int opaquelen); /* Synchronous request to delete opaque LSA. Parameter opaque_id is in host byte order */ int ospf_apiclient_lsa_delete(struct ospf_apiclient *oclient, - struct in_addr area_id, u_char lsa_type, - u_char opaque_type, u_int32_t opaque_id); + struct in_addr area_id, uint8_t lsa_type, + uint8_t opaque_type, uint32_t opaque_id); /* Fetch async message and handle it */ int ospf_apiclient_handle_async(struct ospf_apiclient *oclient); diff --git a/ospfclient/ospfclient.c b/ospfclient/ospfclient.c index 03b543a786..f5f994517e 100644 --- a/ospfclient/ospfclient.c +++ b/ospfclient/ospfclient.c @@ -72,7 +72,7 @@ char **args; /* Our opaque LSAs have the following format. */ struct my_opaque_lsa { struct lsa_header hdr; /* include common LSA header */ - u_char data[4]; /* our own data format then follows here */ + uint8_t data[4]; /* our own data format then follows here */ }; @@ -109,13 +109,13 @@ static int lsa_inject(struct thread *t) struct ospf_apiclient *cl; struct in_addr ifaddr; struct in_addr area_id; - u_char lsa_type; - u_char opaque_type; - u_int32_t opaque_id; + uint8_t lsa_type; + uint8_t opaque_type; + uint32_t opaque_id; void *opaquedata; int opaquelen; - static u_int32_t counter = 1; /* Incremented each time invoked */ + static uint32_t counter = 1; /* Incremented each time invoked */ int rc; cl = THREAD_ARG(t); @@ -135,7 +135,7 @@ static int lsa_inject(struct thread *t) opaque_type = atoi(args[3]); opaque_id = atoi(args[4]); opaquedata = &counter; - opaquelen = sizeof(u_int32_t); + opaquelen = sizeof(uint32_t); printf("Originating/updating LSA with counter=%d... ", counter); rc = ospf_apiclient_lsa_originate(cl, ifaddr, area_id, lsa_type, @@ -182,7 +182,7 @@ static int lsa_read(struct thread *thread) */ static void lsa_update_callback(struct in_addr ifaddr, struct in_addr area_id, - u_char is_self_originated, + uint8_t is_self_originated, struct lsa_header *lsa) { printf("lsa_update_callback: "); @@ -198,7 +198,7 @@ static void lsa_update_callback(struct in_addr ifaddr, struct in_addr area_id, if (lsa->type == OSPF_ROUTER_LSA) { struct router_lsa *rl = (struct router_lsa) lsa; ... - u_int16_t links = rl->links; + uint16_t links = rl->links; ... } */ @@ -207,7 +207,7 @@ static void lsa_update_callback(struct in_addr ifaddr, struct in_addr area_id, } static void lsa_delete_callback(struct in_addr ifaddr, struct in_addr area_id, - u_char is_self_originated, + uint8_t is_self_originated, struct lsa_header *lsa) { printf("lsa_delete_callback: "); @@ -218,7 +218,7 @@ static void lsa_delete_callback(struct in_addr ifaddr, struct in_addr area_id, ospf_lsa_header_dump(lsa); } -static void ready_callback(u_char lsa_type, u_char opaque_type, +static void ready_callback(uint8_t lsa_type, uint8_t opaque_type, struct in_addr addr) { printf("ready_callback: lsa_type: %d opaque_type: %d addr=%s\n", @@ -246,7 +246,7 @@ static void del_if_callback(struct in_addr ifaddr) } static void ism_change_callback(struct in_addr ifaddr, struct in_addr area_id, - u_char state) + uint8_t state) { printf("ism_change: ifaddr: %s ", inet_ntoa(ifaddr)); printf("area_id: %s\n", inet_ntoa(area_id)); @@ -255,7 +255,7 @@ static void ism_change_callback(struct in_addr ifaddr, struct in_addr area_id, } static void nsm_change_callback(struct in_addr ifaddr, struct in_addr nbraddr, - struct in_addr router_id, u_char state) + struct in_addr router_id, uint8_t state) { printf("nsm_change: ifaddr: %s ", inet_ntoa(ifaddr)); printf("nbraddr: %s\n", inet_ntoa(nbraddr)); diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index b29f35d7ce..0ff9d0da51 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -215,7 +215,7 @@ int ospf_area_range_set(struct ospf *ospf, struct in_addr area_id, } int ospf_area_range_cost_set(struct ospf *ospf, struct in_addr area_id, - struct prefix_ipv4 *p, u_int32_t cost) + struct prefix_ipv4 *p, uint32_t cost) { struct ospf_area *area; struct ospf_area_range *range; @@ -379,7 +379,7 @@ static void ospf_abr_nssa_check_status(struct ospf *ospf) struct listnode *lnode, *nnode; for (ALL_LIST_ELEMENTS(ospf->areas, lnode, nnode, area)) { - u_char old_state = area->NSSATranslatorState; + uint8_t old_state = area->NSSATranslatorState; if (area->external_routing != OSPF_AREA_NSSA) continue; @@ -471,7 +471,7 @@ void ospf_check_abr_status(struct ospf *ospf) int bb_act_attached = 0; int areas_configured = 0; int areas_act_attached = 0; - u_char new_flags = ospf->flags; + uint8_t new_flags = ospf->flags; if (IS_DEBUG_OSPF_EVENT) zlog_debug("ospf_check_abr_status(): Start"); @@ -585,12 +585,12 @@ static void ospf_abr_update_aggregate(struct ospf_area_range *range, range->specifics++; } -static void set_metric(struct ospf_lsa *lsa, u_int32_t metric) +static void set_metric(struct ospf_lsa *lsa, uint32_t metric) { struct summary_lsa *header; - u_char *mp; + uint8_t *mp; metric = htonl(metric); - mp = (u_char *)&metric; + mp = (uint8_t *)&metric; mp++; header = (struct summary_lsa *)lsa->data; memcpy(header->metric, mp, 3); @@ -683,18 +683,18 @@ static int ospf_abr_translate_nssa(struct ospf_area *area, struct ospf_lsa *lsa) return 0; } -static void ospf_abr_translate_nssa_range(struct prefix_ipv4 *p, u_int32_t cost) +static void ospf_abr_translate_nssa_range(struct prefix_ipv4 *p, uint32_t cost) { /* The Type-7 is created from the aggregated prefix and forwarded for lsa installation and flooding... to be added... */ } -void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, u_int32_t cost, +void ospf_abr_announce_network_to_area(struct prefix_ipv4 *p, uint32_t cost, struct ospf_area *area) { struct ospf_lsa *lsa, *old = NULL; struct summary_lsa *sl = NULL; - u_int32_t full_cost; + uint32_t full_cost; if (IS_DEBUG_OSPF_EVENT) zlog_debug("ospf_abr_announce_network_to_area(): Start"); @@ -1089,7 +1089,7 @@ static void ospf_abr_process_network_rt(struct ospf *ospf, zlog_debug("ospf_abr_process_network_rt(): Stop"); } -static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4 *p, u_int32_t cost, +static void ospf_abr_announce_rtr_to_area(struct prefix_ipv4 *p, uint32_t cost, struct ospf_area *area) { struct ospf_lsa *lsa, *old = NULL; diff --git a/ospfd/ospf_abr.h b/ospfd/ospf_abr.h index 3792732130..b3007622c4 100644 --- a/ospfd/ospf_abr.h +++ b/ospfd/ospf_abr.h @@ -33,23 +33,23 @@ struct ospf_area_range { struct in_addr addr; /* Area range masklen. */ - u_char masklen; + uint8_t masklen; /* Flags. */ - u_char flags; + uint8_t flags; /* Number of more specific prefixes. */ int specifics; /* Addr and masklen to substitute. */ struct in_addr subst_addr; - u_char subst_masklen; + uint8_t subst_masklen; /* Range cost. */ - u_int32_t cost; + uint32_t cost; /* Configured range cost. */ - u_int32_t cost_config; + uint32_t cost_config; }; /* Prototypes. */ @@ -64,7 +64,7 @@ ospf_area_range_lookup_next(struct ospf_area *, struct in_addr *, int); extern int ospf_area_range_set(struct ospf *, struct in_addr, struct prefix_ipv4 *, int); extern int ospf_area_range_cost_set(struct ospf *, struct in_addr, - struct prefix_ipv4 *, u_int32_t); + struct prefix_ipv4 *, uint32_t); extern int ospf_area_range_unset(struct ospf *, struct in_addr, struct prefix_ipv4 *); extern int ospf_area_range_substitute_set(struct ospf *, struct in_addr, @@ -81,6 +81,6 @@ extern void ospf_check_abr_status(struct ospf *); extern void ospf_abr_task(struct ospf *); extern void ospf_schedule_abr_task(struct ospf *); -extern void ospf_abr_announce_network_to_area(struct prefix_ipv4 *, u_int32_t, +extern void ospf_abr_announce_network_to_area(struct prefix_ipv4 *, uint32_t, struct ospf_area *); #endif /* _ZEBRA_OSPF_ABR_H */ diff --git a/ospfd/ospf_api.c b/ospfd/ospf_api.c index f1a7433760..8369dde822 100644 --- a/ospfd/ospf_api.c +++ b/ospfd/ospf_api.c @@ -62,7 +62,7 @@ void api_opaque_lsa_print(struct lsa_header *data) { struct opaque_lsa { struct lsa_header header; - u_char mydata[]; + uint8_t mydata[]; }; struct opaque_lsa *olsa; @@ -87,8 +87,8 @@ void api_opaque_lsa_print(struct lsa_header *data) * ----------------------------------------------------------- */ -struct msg *msg_new(u_char msgtype, void *msgbody, u_int32_t seqnum, - u_int16_t msglen) +struct msg *msg_new(uint8_t msgtype, void *msgbody, uint32_t seqnum, + uint16_t msglen) { struct msg *new; @@ -282,14 +282,14 @@ void msg_free(struct msg *msg) /* Set sequence number of message */ -void msg_set_seq(struct msg *msg, u_int32_t seqnr) +void msg_set_seq(struct msg *msg, uint32_t seqnr) { assert(msg); msg->hdr.msgseq = htonl(seqnr); } /* Get sequence number of message */ -u_int32_t msg_get_seq(struct msg *msg) +uint32_t msg_get_seq(struct msg *msg) { assert(msg); return ntohl(msg->hdr.msgseq); @@ -368,12 +368,12 @@ struct msg *msg_read(int fd) { struct msg *msg; struct apimsghdr hdr; - u_char buf[OSPF_API_MAX_MSG_SIZE]; + uint8_t buf[OSPF_API_MAX_MSG_SIZE]; int bodylen; int rlen; /* Read message header */ - rlen = readn(fd, (u_char *)&hdr, sizeof(struct apimsghdr)); + rlen = readn(fd, (uint8_t *)&hdr, sizeof(struct apimsghdr)); if (rlen < 0) { zlog_warn("msg_read: readn %s", safe_strerror(errno)); @@ -418,7 +418,7 @@ struct msg *msg_read(int fd) int msg_write(int fd, struct msg *msg) { - u_char buf[OSPF_API_MAX_MSG_SIZE]; + uint8_t buf[OSPF_API_MAX_MSG_SIZE]; int l; int wlen; @@ -452,8 +452,8 @@ int msg_write(int fd, struct msg *msg) * ----------------------------------------------------------- */ -struct msg *new_msg_register_opaque_type(u_int32_t seqnum, u_char ltype, - u_char otype) +struct msg *new_msg_register_opaque_type(uint32_t seqnum, uint8_t ltype, + uint8_t otype) { struct msg_register_opaque_type rmsg; @@ -465,10 +465,10 @@ struct msg *new_msg_register_opaque_type(u_int32_t seqnum, u_char ltype, sizeof(struct msg_register_opaque_type)); } -struct msg *new_msg_register_event(u_int32_t seqnum, +struct msg *new_msg_register_event(uint32_t seqnum, struct lsa_filter_type *filter) { - u_char buf[OSPF_API_MAX_MSG_SIZE]; + uint8_t buf[OSPF_API_MAX_MSG_SIZE]; struct msg_register_event *emsg; unsigned int len; @@ -484,9 +484,9 @@ struct msg *new_msg_register_event(u_int32_t seqnum, return msg_new(MSG_REGISTER_EVENT, emsg, seqnum, len); } -struct msg *new_msg_sync_lsdb(u_int32_t seqnum, struct lsa_filter_type *filter) +struct msg *new_msg_sync_lsdb(uint32_t seqnum, struct lsa_filter_type *filter) { - u_char buf[OSPF_API_MAX_MSG_SIZE]; + uint8_t buf[OSPF_API_MAX_MSG_SIZE]; struct msg_sync_lsdb *smsg; unsigned int len; @@ -503,7 +503,7 @@ struct msg *new_msg_sync_lsdb(u_int32_t seqnum, struct lsa_filter_type *filter) } -struct msg *new_msg_originate_request(u_int32_t seqnum, struct in_addr ifaddr, +struct msg *new_msg_originate_request(uint32_t seqnum, struct in_addr ifaddr, struct in_addr area_id, struct lsa_header *data) { @@ -527,9 +527,9 @@ struct msg *new_msg_originate_request(u_int32_t seqnum, struct in_addr ifaddr, return msg_new(MSG_ORIGINATE_REQUEST, omsg, seqnum, omsglen); } -struct msg *new_msg_delete_request(u_int32_t seqnum, struct in_addr area_id, - u_char lsa_type, u_char opaque_type, - u_int32_t opaque_id) +struct msg *new_msg_delete_request(uint32_t seqnum, struct in_addr area_id, + uint8_t lsa_type, uint8_t opaque_type, + uint32_t opaque_id) { struct msg_delete_request dmsg; dmsg.area_id = area_id; @@ -543,7 +543,7 @@ struct msg *new_msg_delete_request(u_int32_t seqnum, struct in_addr area_id, } -struct msg *new_msg_reply(u_int32_t seqnr, u_char rc) +struct msg *new_msg_reply(uint32_t seqnr, uint8_t rc) { struct msg *msg; struct msg_reply rmsg; @@ -557,8 +557,8 @@ struct msg *new_msg_reply(u_int32_t seqnr, u_char rc) return msg; } -struct msg *new_msg_ready_notify(u_int32_t seqnr, u_char lsa_type, - u_char opaque_type, struct in_addr addr) +struct msg *new_msg_ready_notify(uint32_t seqnr, uint8_t lsa_type, + uint8_t opaque_type, struct in_addr addr) { struct msg_ready_notify rmsg; @@ -571,7 +571,7 @@ struct msg *new_msg_ready_notify(u_int32_t seqnr, u_char lsa_type, sizeof(struct msg_ready_notify)); } -struct msg *new_msg_new_if(u_int32_t seqnr, struct in_addr ifaddr, +struct msg *new_msg_new_if(uint32_t seqnr, struct in_addr ifaddr, struct in_addr area_id) { struct msg_new_if nmsg; @@ -582,7 +582,7 @@ struct msg *new_msg_new_if(u_int32_t seqnr, struct in_addr ifaddr, return msg_new(MSG_NEW_IF, &nmsg, seqnr, sizeof(struct msg_new_if)); } -struct msg *new_msg_del_if(u_int32_t seqnr, struct in_addr ifaddr) +struct msg *new_msg_del_if(uint32_t seqnr, struct in_addr ifaddr) { struct msg_del_if dmsg; @@ -591,8 +591,8 @@ struct msg *new_msg_del_if(u_int32_t seqnr, struct in_addr ifaddr) return msg_new(MSG_DEL_IF, &dmsg, seqnr, sizeof(struct msg_del_if)); } -struct msg *new_msg_ism_change(u_int32_t seqnr, struct in_addr ifaddr, - struct in_addr area_id, u_char status) +struct msg *new_msg_ism_change(uint32_t seqnr, struct in_addr ifaddr, + struct in_addr area_id, uint8_t status) { struct msg_ism_change imsg; @@ -605,9 +605,9 @@ struct msg *new_msg_ism_change(u_int32_t seqnr, struct in_addr ifaddr, sizeof(struct msg_ism_change)); } -struct msg *new_msg_nsm_change(u_int32_t seqnr, struct in_addr ifaddr, +struct msg *new_msg_nsm_change(uint32_t seqnr, struct in_addr ifaddr, struct in_addr nbraddr, struct in_addr router_id, - u_char status) + uint8_t status) { struct msg_nsm_change nmsg; @@ -621,13 +621,13 @@ struct msg *new_msg_nsm_change(u_int32_t seqnr, struct in_addr ifaddr, sizeof(struct msg_nsm_change)); } -struct msg *new_msg_lsa_change_notify(u_char msgtype, u_int32_t seqnum, +struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum, struct in_addr ifaddr, struct in_addr area_id, - u_char is_self_originated, + uint8_t is_self_originated, struct lsa_header *data) { - u_char buf[OSPF_API_MAX_MSG_SIZE]; + uint8_t buf[OSPF_API_MAX_MSG_SIZE]; struct msg_lsa_change_notify *nmsg; unsigned int len; diff --git a/ospfd/ospf_api.h b/ospfd/ospf_api.h index 7b055db12b..c99923e7b8 100644 --- a/ospfd/ospf_api.h +++ b/ospfd/ospf_api.h @@ -44,10 +44,10 @@ /* Message header structure, fields are in network byte order and aligned to four octets. */ struct apimsghdr { - u_char version; /* OSPF API protocol version */ - u_char msgtype; /* Type of message */ - u_int16_t msglen; /* Length of message w/o header */ - u_int32_t msgseq; /* Sequence number */ + uint8_t version; /* OSPF API protocol version */ + uint8_t msgtype; /* Type of message */ + uint16_t msglen; /* Length of message w/o header */ + uint32_t msgseq; /* Sequence number */ }; /* Message representation with header and body */ @@ -62,8 +62,8 @@ struct msg { }; /* Prototypes for generic messages. */ -extern struct msg *msg_new(u_char msgtype, void *msgbody, u_int32_t seqnum, - u_int16_t msglen); +extern struct msg *msg_new(uint8_t msgtype, void *msgbody, uint32_t seqnum, + uint16_t msglen); extern struct msg *msg_dup(struct msg *msg); extern void msg_print(struct msg *msg); /* XXX debug only */ extern void msg_free(struct msg *msg); @@ -76,8 +76,8 @@ extern int msg_write(int fd, struct msg *msg); #define MIN_SEQ 1 #define MAX_SEQ 2147483647 -extern void msg_set_seq(struct msg *msg, u_int32_t seqnr); -extern u_int32_t msg_get_seq(struct msg *msg); +extern void msg_set_seq(struct msg *msg, uint32_t seqnr); +extern uint32_t msg_get_seq(struct msg *msg); /* ----------------------------------------------------------- * Message fifo queues @@ -124,15 +124,15 @@ extern void msg_fifo_free(struct msg_fifo *fifo); #define MSG_NSM_CHANGE 17 struct msg_register_opaque_type { - u_char lsatype; - u_char opaquetype; - u_char pad[2]; /* padding */ + uint8_t lsatype; + uint8_t opaquetype; + uint8_t pad[2]; /* padding */ }; struct msg_unregister_opaque_type { - u_char lsatype; - u_char opaquetype; - u_char pad[2]; /* padding */ + uint8_t lsatype; + uint8_t opaquetype; + uint8_t pad[2]; /* padding */ }; /* Power2 is needed to convert LSA types into bit positions, @@ -141,25 +141,25 @@ struct msg_unregister_opaque_type { #ifdef ORIGINAL_CODING -static const u_int16_t Power2[] = {0x0, 0x1, 0x2, 0x4, 0x8, 0x10, - 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, - 0x800, 0x1000, 0x2000, 0x4000, 0x8000}; +static const uint16_t Power2[] = {0x0, 0x1, 0x2, 0x4, 0x8, 0x10, + 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, + 0x800, 0x1000, 0x2000, 0x4000, 0x8000}; #else -static const u_int16_t Power2[] = { +static const uint16_t Power2[] = { 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4), (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10), (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15)}; #endif /* ORIGINAL_CODING */ struct lsa_filter_type { - u_int16_t typemask; /* bitmask for selecting LSA types (1..16) */ - u_char origin; /* selects according to origin. */ + uint16_t typemask; /* bitmask for selecting LSA types (1..16) */ + uint8_t origin; /* selects according to origin. */ #define NON_SELF_ORIGINATED 0 #define SELF_ORIGINATED (OSPF_LSA_SELF) #define ANY_ORIGIN 2 - u_char num_areas; /* number of areas in the filter. */ - /* areas, if any, go here. */ + uint8_t num_areas; /* number of areas in the filter. */ + /* areas, if any, go here. */ }; struct msg_register_event { @@ -183,10 +183,10 @@ struct msg_originate_request { struct msg_delete_request { struct in_addr area_id; /* "0.0.0.0" for AS-external opaque LSAs */ - u_char lsa_type; - u_char opaque_type; - u_char pad[2]; /* padding */ - u_int32_t opaque_id; + uint8_t lsa_type; + uint8_t opaque_type; + uint8_t pad[2]; /* padding */ + uint32_t opaque_id; }; struct msg_reply { @@ -202,16 +202,16 @@ struct msg_reply { #define OSPF_API_NOMEMORY (-8) #define OSPF_API_ERROR (-9) #define OSPF_API_UNDEF (-10) - u_char pad[3]; /* padding to four byte alignment */ + uint8_t pad[3]; /* padding to four byte alignment */ }; /* Message to tell client application that it ospf daemon is * ready to accept opaque LSAs for a given interface or area. */ struct msg_ready_notify { - u_char lsa_type; - u_char opaque_type; - u_char pad[2]; /* padding */ + uint8_t lsa_type; + uint8_t opaque_type; + uint8_t pad[2]; /* padding */ struct in_addr addr; /* interface address or area address */ }; @@ -224,8 +224,8 @@ struct msg_lsa_change_notify { struct in_addr ifaddr; /* Area ID. Not valid for AS-External and Opaque11 LSAs. */ struct in_addr area_id; - u_char is_self_originated; /* 1 if self originated. */ - u_char pad[3]; + uint8_t is_self_originated; /* 1 if self originated. */ + uint8_t pad[3]; struct lsa_header data; }; @@ -241,16 +241,16 @@ struct msg_del_if { struct msg_ism_change { struct in_addr ifaddr; /* interface IP address */ struct in_addr area_id; /* area this interface belongs to */ - u_char status; /* interface status (up/down) */ - u_char pad[3]; /* not used */ + uint8_t status; /* interface status (up/down) */ + uint8_t pad[3]; /* not used */ }; struct msg_nsm_change { struct in_addr ifaddr; /* attached interface */ struct in_addr nbraddr; /* Neighbor interface address */ struct in_addr router_id; /* Router ID of neighbor */ - u_char status; /* NSM status */ - u_char pad[3]; + uint8_t status; /* NSM status */ + uint8_t pad[3]; }; /* We make use of a union to define a structure that covers all @@ -285,45 +285,45 @@ struct apimsg { extern void api_opaque_lsa_print(struct lsa_header *data); /* Messages sent by client */ -extern struct msg *new_msg_register_opaque_type(u_int32_t seqnum, u_char ltype, - u_char otype); -extern struct msg *new_msg_register_event(u_int32_t seqnum, +extern struct msg *new_msg_register_opaque_type(uint32_t seqnum, uint8_t ltype, + uint8_t otype); +extern struct msg *new_msg_register_event(uint32_t seqnum, struct lsa_filter_type *filter); -extern struct msg *new_msg_sync_lsdb(u_int32_t seqnum, +extern struct msg *new_msg_sync_lsdb(uint32_t seqnum, struct lsa_filter_type *filter); -extern struct msg *new_msg_originate_request(u_int32_t seqnum, +extern struct msg *new_msg_originate_request(uint32_t seqnum, struct in_addr ifaddr, struct in_addr area_id, struct lsa_header *data); -extern struct msg *new_msg_delete_request(u_int32_t seqnum, +extern struct msg *new_msg_delete_request(uint32_t seqnum, struct in_addr area_id, - u_char lsa_type, u_char opaque_type, - u_int32_t opaque_id); + uint8_t lsa_type, uint8_t opaque_type, + uint32_t opaque_id); /* Messages sent by OSPF daemon */ -extern struct msg *new_msg_reply(u_int32_t seqnum, u_char rc); +extern struct msg *new_msg_reply(uint32_t seqnum, uint8_t rc); -extern struct msg *new_msg_ready_notify(u_int32_t seqnr, u_char lsa_type, - u_char opaque_type, +extern struct msg *new_msg_ready_notify(uint32_t seqnr, uint8_t lsa_type, + uint8_t opaque_type, struct in_addr addr); -extern struct msg *new_msg_new_if(u_int32_t seqnr, struct in_addr ifaddr, +extern struct msg *new_msg_new_if(uint32_t seqnr, struct in_addr ifaddr, struct in_addr area); -extern struct msg *new_msg_del_if(u_int32_t seqnr, struct in_addr ifaddr); +extern struct msg *new_msg_del_if(uint32_t seqnr, struct in_addr ifaddr); -extern struct msg *new_msg_ism_change(u_int32_t seqnr, struct in_addr ifaddr, - struct in_addr area, u_char status); +extern struct msg *new_msg_ism_change(uint32_t seqnr, struct in_addr ifaddr, + struct in_addr area, uint8_t status); -extern struct msg *new_msg_nsm_change(u_int32_t seqnr, struct in_addr ifaddr, +extern struct msg *new_msg_nsm_change(uint32_t seqnr, struct in_addr ifaddr, struct in_addr nbraddr, - struct in_addr router_id, u_char status); + struct in_addr router_id, uint8_t status); /* msgtype is MSG_LSA_UPDATE_NOTIFY or MSG_LSA_DELETE_NOTIFY */ -extern struct msg *new_msg_lsa_change_notify(u_char msgtype, u_int32_t seqnum, +extern struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum, struct in_addr ifaddr, struct in_addr area_id, - u_char is_self_originated, + uint8_t is_self_originated, struct lsa_header *data); /* string printing functions */ diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 36bd49125b..37735e3611 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -186,8 +186,8 @@ void ospf_apiserver_term(void) /* XXX */ } -static struct ospf_apiserver *lookup_apiserver(u_char lsa_type, - u_char opaque_type) +static struct ospf_apiserver *lookup_apiserver(uint8_t lsa_type, + uint8_t opaque_type) { struct listnode *n1, *n2; struct registered_opaque_type *r; @@ -766,8 +766,8 @@ static int ospf_apiserver_send_msg(struct ospf_apiserver *apiserv, return 0; } -int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, u_int32_t seqnr, - u_char rc) +int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, uint32_t seqnr, + uint8_t rc) { struct msg *msg = new_msg_reply(seqnr, rc); int ret; @@ -831,7 +831,7 @@ int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv, struct msg *msg) */ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct registered_opaque_type *regtype; int (*originator_func)(void *arg); @@ -895,7 +895,7 @@ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, } int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct listnode *node, *nnode; struct registered_opaque_type *regtype; @@ -934,8 +934,8 @@ int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserv, static int apiserver_is_opaque_type_registered(struct ospf_apiserver *apiserv, - u_char lsa_type, - u_char opaque_type) + uint8_t lsa_type, + uint8_t opaque_type) { struct listnode *node, *nnode; struct registered_opaque_type *regtype; @@ -957,8 +957,8 @@ int ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver *apiserv, struct msg *msg) { struct msg_register_opaque_type *rmsg; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; int rc = 0; /* Extract parameters from register opaque type message */ @@ -1135,8 +1135,8 @@ int ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver *apiserv, struct msg *msg) { struct msg_unregister_opaque_type *umsg; - u_char ltype; - u_char otype; + uint8_t ltype; + uint8_t otype; int rc = 0; /* Extract parameters from unregister opaque type message */ @@ -1163,7 +1163,7 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv, { struct msg_register_event *rmsg; int rc; - u_int32_t seqnum; + uint32_t seqnum; rmsg = (struct msg_register_event *)STREAM_DATA(msg->s); @@ -1212,7 +1212,7 @@ static int apiserver_sync_callback(struct ospf_lsa *lsa, void *p_arg, param = (struct param_t *)p_arg; apiserv = param->apiserv; - seqnum = (u_int32_t)int_arg; + seqnum = (uint32_t)int_arg; /* Check origin in filter. */ if ((param->filter->origin == ANY_ORIGIN) @@ -1260,14 +1260,14 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, struct msg *msg) { struct listnode *node, *nnode; - u_int32_t seqnum; + uint32_t seqnum; int rc = 0; struct msg_sync_lsdb *smsg; struct ospf_apiserver_param_t { struct ospf_apiserver *apiserv; struct lsa_filter_type *filter; } param; - u_int16_t mask; + uint16_t mask; struct route_node *rn; struct ospf_lsa *lsa; struct ospf *ospf; @@ -1290,13 +1290,13 @@ int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, /* Iterate over all areas. */ for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) { int i; - u_int32_t *area_id = NULL; + uint32_t *area_id = NULL; /* Compare area_id with area_ids in sync request. */ if ((i = smsg->filter.num_areas) > 0) { /* Let area_id point to the list of area IDs, * which is at the end of smsg->filter. */ - area_id = (u_int32_t *)(&smsg->filter + 1); + area_id = (uint32_t *)(&smsg->filter + 1); while (i) { if (*area_id == area->area_id.s_addr) { break; @@ -1379,8 +1379,8 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct stream *s; struct lsa_header *newlsa; struct ospf_lsa *new = NULL; - u_char options = 0x0; - u_int16_t length; + uint8_t options = 0x0; + uint16_t length; struct ospf *ospf; @@ -1419,7 +1419,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, ospf->router_id); /* Set opaque-LSA body fields. */ - stream_put(s, ((u_char *)protolsa) + sizeof(struct lsa_header), + stream_put(s, ((uint8_t *)protolsa) + sizeof(struct lsa_header), ntohs(protolsa->length) - sizeof(struct lsa_header)); /* Determine length of LSA. */ @@ -1904,8 +1904,8 @@ static int apiserver_flush_opaque_type_callback(struct ospf_lsa *lsa, { struct param_t { struct ospf_apiserver *apiserv; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; } * param; /* Sanity check */ @@ -1927,12 +1927,12 @@ static int apiserver_flush_opaque_type_callback(struct ospf_lsa *lsa, type or a connection to an application closes and all those opaque LSAs need to be flushed the LSDB. */ void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct param_t { struct ospf_apiserver *apiserv; - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; } param; struct listnode *node, *nnode; struct ospf *ospf; @@ -2076,7 +2076,7 @@ void ospf_apiserver_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct opaque_lsa { struct lsa_header header; - u_char data[1]; /* opaque data have variable length. This is + uint8_t data[1]; /* opaque data have variable length. This is start address */ }; @@ -2355,7 +2355,7 @@ void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr) msg_free(msg); } -static void apiserver_clients_lsa_change_notify(u_char msgtype, +static void apiserver_clients_lsa_change_notify(uint8_t msgtype, struct ospf_lsa *lsa) { struct msg *msg; @@ -2390,8 +2390,8 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, /* Now send message to all clients with a matching filter */ for (ALL_LIST_ELEMENTS(apiserver_list, node, nnode, apiserv)) { struct lsa_filter_type *filter; - u_int16_t mask; - u_int32_t *area; + uint16_t mask; + uint32_t *area; int i; /* Check filter for this client. */ @@ -2408,7 +2408,7 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, } if (i > 0) { - area = (u_int32_t *)(filter + 1); + area = (uint32_t *)(filter + 1); while (i) { if (*area == area_id.s_addr) { break; @@ -2444,7 +2444,7 @@ static void apiserver_clients_lsa_change_notify(u_char msgtype, */ -static int apiserver_notify_clients_lsa(u_char msgtype, struct ospf_lsa *lsa) +static int apiserver_notify_clients_lsa(uint8_t msgtype, struct ospf_lsa *lsa) { struct msg *msg; /* default area for AS-External and Opaque11 LSAs */ diff --git a/ospfd/ospf_apiserver.h b/ospfd/ospf_apiserver.h index 59d18bfd68..89a9474972 100644 --- a/ospfd/ospf_apiserver.h +++ b/ospfd/ospf_apiserver.h @@ -28,8 +28,8 @@ /* List of opaque types that application registered */ struct registered_opaque_type { - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; }; @@ -96,7 +96,7 @@ 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 int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, - u_int32_t seqnr, u_char rc); + uint32_t seqnr, uint8_t rc); /* ----------------------------------------------------------- * Followings are message handler functions @@ -152,11 +152,11 @@ extern int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, */ extern int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserver, - u_char lsa_type, - u_char opaque_type); + uint8_t lsa_type, + uint8_t opaque_type); extern int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserver, - u_char lsa_type, u_char opaque_type); + uint8_t lsa_type, uint8_t opaque_type); extern struct ospf_lsa * ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct ospf_interface *oi, struct lsa_header *protolsa); @@ -186,8 +186,8 @@ extern void ospf_apiserver_show_info(struct vty *vty, struct ospf_lsa *lsa); extern int ospf_ospf_apiserver_lsa_originator(void *arg); extern struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa); extern void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, - u_char lsa_type, - u_char opaque_type); + uint8_t lsa_type, + uint8_t opaque_type); /* ----------------------------------------------------------- * Followings are hooks when LSAs are updated or deleted @@ -200,7 +200,7 @@ extern void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, extern int ospf_apiserver_lsa_update(struct ospf_lsa *lsa); extern int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa); -extern void ospf_apiserver_clients_lsa_change_notify(u_char msgtype, +extern void ospf_apiserver_clients_lsa_change_notify(uint8_t msgtype, struct ospf_lsa *lsa); #endif /* _OSPF_APISERVER_H */ diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c index b970c1183a..18c1077da0 100644 --- a/ospfd/ospf_asbr.c +++ b/ospfd/ospf_asbr.c @@ -94,7 +94,8 @@ struct ospf_route *ospf_external_route_lookup(struct ospf *ospf, /* Add an External info for AS-external-LSA. */ -struct external_info *ospf_external_info_new(u_char type, u_short instance) +struct external_info *ospf_external_info_new(uint8_t type, + unsigned short instance) { struct external_info *new; @@ -127,7 +128,7 @@ int ospf_route_map_set_compare(struct route_map_set_values *values1, /* Add an External info for AS-external-LSA. */ struct external_info * -ospf_external_info_add(struct ospf *ospf, u_char type, u_short instance, +ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance, struct prefix_ipv4 p, ifindex_t ifindex, struct in_addr nexthop, route_tag_t tag) { @@ -185,8 +186,8 @@ ospf_external_info_add(struct ospf *ospf, u_char type, u_short instance, return new; } -void ospf_external_info_delete(struct ospf *ospf, u_char type, u_short instance, - struct prefix_ipv4 p) +void ospf_external_info_delete(struct ospf *ospf, uint8_t type, + unsigned short instance, struct prefix_ipv4 p) { struct route_node *rn; struct ospf_external *ext; @@ -204,8 +205,8 @@ void ospf_external_info_delete(struct ospf *ospf, u_char type, u_short instance, } } -struct external_info *ospf_external_info_lookup(struct ospf *ospf, u_char type, - u_short instance, +struct external_info *ospf_external_info_lookup(struct ospf *ospf, uint8_t type, + unsigned short instance, struct prefix_ipv4 *p) { struct route_node *rn; @@ -255,7 +256,7 @@ struct ospf_lsa *ospf_external_info_find_lsa(struct ospf *ospf, /* Update ASBR status. */ -void ospf_asbr_status_update(struct ospf *ospf, u_char status) +void ospf_asbr_status_update(struct ospf *ospf, uint8_t status) { zlog_info("ASBR[Status:%d]: Update", status); @@ -281,8 +282,8 @@ void ospf_asbr_status_update(struct ospf *ospf, u_char status) ospf_router_lsa_update(ospf); } -void ospf_redistribute_withdraw(struct ospf *ospf, u_char type, - u_short instance) +void ospf_redistribute_withdraw(struct ospf *ospf, uint8_t type, + unsigned short instance) { struct route_node *rn; struct external_info *ei; diff --git a/ospfd/ospf_asbr.h b/ospfd/ospf_asbr.h index d437314c82..370c6787b4 100644 --- a/ospfd/ospf_asbr.h +++ b/ospfd/ospf_asbr.h @@ -30,9 +30,9 @@ struct route_map_set_values { /* Redistributed external information. */ struct external_info { /* Type of source protocol. */ - u_char type; + uint8_t type; - u_short instance; + unsigned short instance; /* Prefix. */ struct prefix_ipv4 p; @@ -54,23 +54,25 @@ struct external_info { #define OSPF_ASBR_CHECK_DELAY 30 extern void ospf_external_route_remove(struct ospf *, struct prefix_ipv4 *); -extern struct external_info *ospf_external_info_new(u_char, u_short); +extern struct external_info *ospf_external_info_new(uint8_t, unsigned short); extern void ospf_reset_route_map_set_values(struct route_map_set_values *); extern int ospf_route_map_set_compare(struct route_map_set_values *, struct route_map_set_values *); -extern struct external_info *ospf_external_info_add(struct ospf *, u_char, - u_short, struct prefix_ipv4, +extern struct external_info *ospf_external_info_add(struct ospf *, uint8_t, + unsigned short, + struct prefix_ipv4, ifindex_t, struct in_addr, route_tag_t); -extern void ospf_external_info_delete(struct ospf *, u_char, u_short, +extern void ospf_external_info_delete(struct ospf *, uint8_t, unsigned short, struct prefix_ipv4); -extern struct external_info * -ospf_external_info_lookup(struct ospf *, u_char, u_short, struct prefix_ipv4 *); +extern struct external_info *ospf_external_info_lookup(struct ospf *, uint8_t, + unsigned short, + struct prefix_ipv4 *); extern struct ospf_route *ospf_external_route_lookup(struct ospf *, struct prefix_ipv4 *); -extern void ospf_asbr_status_update(struct ospf *, u_char); +extern void ospf_asbr_status_update(struct ospf *, uint8_t); -extern void ospf_redistribute_withdraw(struct ospf *, u_char, u_short); +extern void ospf_redistribute_withdraw(struct ospf *, uint8_t, unsigned short); extern void ospf_asbr_check(void); extern void ospf_schedule_asbr_check(void); extern void ospf_asbr_route_install_lsa(struct ospf_lsa *); diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c index 0c2ddc9647..d425624862 100644 --- a/ospfd/ospf_ase.c +++ b/ospfd/ospf_ase.c @@ -241,7 +241,7 @@ ospf_ase_calculate_asbr_route (struct ospf *ospf, static struct ospf_route * ospf_ase_calculate_new_route(struct ospf_lsa *lsa, - struct ospf_route *asbr_route, u_int32_t metric) + struct ospf_route *asbr_route, uint32_t metric) { struct as_external_lsa *al; struct ospf_route *new; @@ -282,7 +282,7 @@ ospf_ase_calculate_new_route(struct ospf_lsa *lsa, int ospf_ase_calculate_route(struct ospf *ospf, struct ospf_lsa *lsa) { - u_int32_t metric; + uint32_t metric; struct as_external_lsa *al; struct ospf_route *asbr_route; struct prefix_ipv4 asbr, p; diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c index 9254e7d240..0f7fb50778 100644 --- a/ospfd/ospf_bfd.c +++ b/ospfd/ospf_bfd.c @@ -308,7 +308,7 @@ void ospf_bfd_write_config(struct vty *vty, struct ospf_if_params *params) * ospf_bfd_show_info - Show BFD info structure */ void ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj, - u_char use_json, int param_only) + uint8_t use_json, int param_only) { if (param_only) bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json, @@ -322,7 +322,7 @@ void ospf_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj, * ospf_bfd_interface_show - Show the interface BFD configuration. */ void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp, - json_object *json_interface_sub, u_char use_json) + json_object *json_interface_sub, uint8_t use_json) { struct ospf_if_params *params; @@ -336,8 +336,8 @@ void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp, * ospf_bfd_if_param_set - Set the configured BFD paramter values for * interface. */ -static void ospf_bfd_if_param_set(struct interface *ifp, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, +static void ospf_bfd_if_param_set(struct interface *ifp, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults) { struct ospf_if_params *params; @@ -387,9 +387,9 @@ DEFUN (ip_ospf_bfd_param, int idx_number = 3; int idx_number_2 = 4; int idx_number_3 = 5; - u_int32_t rx_val; - u_int32_t tx_val; - u_int8_t dm_val; + uint32_t rx_val; + uint32_t tx_val; + uint8_t dm_val; int ret; assert(ifp); diff --git a/ospfd/ospf_bfd.h b/ospfd/ospf_bfd.h index c940f31ebd..6d7caf4217 100644 --- a/ospfd/ospf_bfd.h +++ b/ospfd/ospf_bfd.h @@ -35,13 +35,13 @@ extern void ospf_bfd_trigger_event(struct ospf_neighbor *nbr, int old_state, extern void ospf_bfd_interface_show(struct vty *vty, struct interface *ifp, json_object *json_interface_sub, - u_char use_json); + uint8_t use_json); extern void ospf_bfd_info_nbr_create(struct ospf_interface *oi, struct ospf_neighbor *nbr); extern void ospf_bfd_show_info(struct vty *vty, void *bfd_info, - json_object *json_obj, u_char use_json, + json_object *json_obj, uint8_t use_json, int param_only); extern void ospf_bfd_info_free(void **bfd_info); diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index 66ab59b816..08bedadf41 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -66,7 +66,7 @@ unsigned long term_debug_ospf_te = 0; unsigned long term_debug_ospf_ext = 0; unsigned long term_debug_ospf_sr = 0; -const char *ospf_redist_string(u_int route_type) +const char *ospf_redist_string(unsigned int route_type) { return (route_type == ZEBRA_ROUTE_MAX) ? "Default" : zebra_route_string(route_type); @@ -76,7 +76,7 @@ const char *ospf_redist_string(u_int route_type) const char *ospf_area_name_string(struct ospf_area *area) { static char buf[OSPF_AREA_STRING_MAXLEN] = ""; - u_int32_t area_id; + uint32_t area_id; if (!area) return "-"; @@ -92,7 +92,7 @@ const char *ospf_area_name_string(struct ospf_area *area) const char *ospf_area_desc_string(struct ospf_area *area) { static char buf[OSPF_AREA_DESC_STRING_MAXLEN] = ""; - u_char type; + uint8_t type; if (!area) return "(incomplete)"; @@ -118,7 +118,7 @@ const char *ospf_area_desc_string(struct ospf_area *area) const char *ospf_if_name_string(struct ospf_interface *oi) { static char buf[OSPF_IF_STRING_MAXLEN] = ""; - u_int32_t ifaddr; + uint32_t ifaddr; if (!oi || !oi->address) return "inactive"; @@ -228,7 +228,7 @@ const char *ospf_timer_dump(struct thread *t, char *buf, size_t size) return ospf_timeval_dump(&result, buf, size); } -static void ospf_packet_hello_dump(struct stream *s, u_int16_t length) +static void ospf_packet_hello_dump(struct stream *s, uint16_t length) { struct ospf_hello *hello; int i; @@ -242,7 +242,7 @@ static void ospf_packet_hello_dump(struct stream *s, u_int16_t length) ospf_options_dump(hello->options)); zlog_debug(" RtrPriority %d", hello->priority); zlog_debug(" RtrDeadInterval %ld", - (u_long)ntohl(hello->dead_interval)); + (unsigned long)ntohl(hello->dead_interval)); zlog_debug(" DRouter %s", inet_ntoa(hello->d_router)); zlog_debug(" BDRouter %s", inet_ntoa(hello->bd_router)); @@ -252,7 +252,7 @@ static void ospf_packet_hello_dump(struct stream *s, u_int16_t length) zlog_debug(" Neighbor %s", inet_ntoa(hello->neighbors[i])); } -static char *ospf_dd_flags_dump(u_char flags, char *buf, size_t size) +static char *ospf_dd_flags_dump(uint8_t flags, char *buf, size_t size) { memset(buf, 0, size); @@ -263,7 +263,7 @@ static char *ospf_dd_flags_dump(u_char flags, char *buf, size_t size) return buf; } -static char *ospf_router_lsa_flags_dump(u_char flags, char *buf, size_t size) +static char *ospf_router_lsa_flags_dump(uint8_t flags, char *buf, size_t size) { memset(buf, 0, size); @@ -275,7 +275,7 @@ static char *ospf_router_lsa_flags_dump(u_char flags, char *buf, size_t size) return buf; } -static void ospf_router_lsa_dump(struct stream *s, u_int16_t length) +static void ospf_router_lsa_dump(struct stream *s, uint16_t length) { char buf[BUFSIZ]; struct router_lsa *rl; @@ -293,15 +293,15 @@ static void ospf_router_lsa_dump(struct stream *s, u_int16_t length) zlog_debug(" Link ID %s", inet_ntoa(rl->link[i].link_id)); zlog_debug(" Link Data %s", inet_ntoa(rl->link[i].link_data)); - zlog_debug(" Type %d", (u_char)rl->link[i].type); - zlog_debug(" TOS %d", (u_char)rl->link[i].tos); + zlog_debug(" Type %d", (uint8_t)rl->link[i].type); + zlog_debug(" TOS %d", (uint8_t)rl->link[i].tos); zlog_debug(" metric %d", ntohs(rl->link[i].metric)); len -= 12; } } -static void ospf_network_lsa_dump(struct stream *s, u_int16_t length) +static void ospf_network_lsa_dump(struct stream *s, uint16_t length) { struct network_lsa *nl; int i, cnt; @@ -322,7 +322,7 @@ static void ospf_network_lsa_dump(struct stream *s, u_int16_t length) inet_ntoa(nl->routers[i])); } -static void ospf_summary_lsa_dump(struct stream *s, u_int16_t length) +static void ospf_summary_lsa_dump(struct stream *s, uint16_t length) { struct summary_lsa *sl; int size; @@ -339,7 +339,7 @@ static void ospf_summary_lsa_dump(struct stream *s, u_int16_t length) GET_METRIC(sl->metric)); } -static void ospf_as_external_lsa_dump(struct stream *s, u_int16_t length) +static void ospf_as_external_lsa_dump(struct stream *s, uint16_t length) { struct as_external_lsa *al; int size; @@ -361,7 +361,7 @@ static void ospf_as_external_lsa_dump(struct stream *s, u_int16_t length) } } -static void ospf_lsa_header_list_dump(struct stream *s, u_int16_t length) +static void ospf_lsa_header_list_dump(struct stream *s, uint16_t length) { struct lsa_header *lsa; @@ -377,12 +377,12 @@ static void ospf_lsa_header_list_dump(struct stream *s, u_int16_t length) } } -static void ospf_packet_db_desc_dump(struct stream *s, u_int16_t length) +static void ospf_packet_db_desc_dump(struct stream *s, uint16_t length) { struct ospf_db_desc *dd; char dd_flags[8]; - u_int32_t gp; + uint32_t gp; gp = stream_get_getp(s); dd = (struct ospf_db_desc *)stream_pnt(s); @@ -393,7 +393,8 @@ static void ospf_packet_db_desc_dump(struct stream *s, u_int16_t length) ospf_options_dump(dd->options)); zlog_debug(" Flags %d (%s)", dd->flags, ospf_dd_flags_dump(dd->flags, dd_flags, sizeof dd_flags)); - zlog_debug(" Sequence Number 0x%08lx", (u_long)ntohl(dd->dd_seqnum)); + zlog_debug(" Sequence Number 0x%08lx", + (unsigned long)ntohl(dd->dd_seqnum)); length -= OSPF_HEADER_SIZE + OSPF_DB_DESC_MIN_SIZE; @@ -404,10 +405,10 @@ static void ospf_packet_db_desc_dump(struct stream *s, u_int16_t length) stream_set_getp(s, gp); } -static void ospf_packet_ls_req_dump(struct stream *s, u_int16_t length) +static void ospf_packet_ls_req_dump(struct stream *s, uint16_t length) { - u_int32_t sp; - u_int32_t ls_type; + uint32_t sp; + uint32_t ls_type; struct in_addr ls_id; struct in_addr adv_router; @@ -431,12 +432,12 @@ static void ospf_packet_ls_req_dump(struct stream *s, u_int16_t length) stream_set_getp(s, sp); } -static void ospf_packet_ls_upd_dump(struct stream *s, u_int16_t length) +static void ospf_packet_ls_upd_dump(struct stream *s, uint16_t length) { - u_int32_t sp; + uint32_t sp; struct lsa_header *lsa; int lsa_len; - u_int32_t count; + uint32_t count; length -= OSPF_HEADER_SIZE; @@ -493,9 +494,9 @@ static void ospf_packet_ls_upd_dump(struct stream *s, u_int16_t length) stream_set_getp(s, sp); } -static void ospf_packet_ls_ack_dump(struct stream *s, u_int16_t length) +static void ospf_packet_ls_ack_dump(struct stream *s, uint16_t length) { - u_int32_t sp; + uint32_t sp; length -= OSPF_HEADER_SIZE; sp = stream_get_getp(s); @@ -514,11 +515,11 @@ void ospf_ip_header_dump(struct ip *iph) zlog_debug("ip_hl %d", iph->ip_hl); zlog_debug("ip_tos %d", iph->ip_tos); zlog_debug("ip_len %d", iph->ip_len); - zlog_debug("ip_id %u", (u_int32_t)iph->ip_id); - zlog_debug("ip_off %u", (u_int32_t)iph->ip_off); + zlog_debug("ip_id %u", (uint32_t)iph->ip_id); + zlog_debug("ip_off %u", (uint32_t)iph->ip_off); zlog_debug("ip_ttl %d", iph->ip_ttl); zlog_debug("ip_p %d", iph->ip_p); - zlog_debug("ip_sum 0x%x", (u_int32_t)iph->ip_sum); + zlog_debug("ip_sum 0x%x", (uint32_t)iph->ip_sum); zlog_debug("ip_src %s", inet_ntoa(iph->ip_src)); zlog_debug("ip_dst %s", inet_ntoa(iph->ip_dst)); } @@ -526,7 +527,7 @@ void ospf_ip_header_dump(struct ip *iph) static void ospf_header_dump(struct ospf_header *ospfh) { char buf[9]; - u_int16_t auth_type = ntohs(ospfh->auth_type); + uint16_t auth_type = ntohs(ospfh->auth_type); zlog_debug("Header"); zlog_debug(" Version %d", ospfh->version); @@ -552,7 +553,7 @@ static void ospf_header_dump(struct ospf_header *ospfh) zlog_debug(" Key ID %d", ospfh->u.crypt.key_id); zlog_debug(" Auth Data Len %d", ospfh->u.crypt.auth_data_len); zlog_debug(" Sequence number %ld", - (u_long)ntohl(ospfh->u.crypt.crypt_seqnum)); + (unsigned long)ntohl(ospfh->u.crypt.crypt_seqnum)); break; default: zlog_debug("* This is not supported authentication type"); @@ -919,7 +920,7 @@ DEFUN (debug_ospf_instance_nsm, "NSM Timer Information\n") { int idx_number = 2; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -991,7 +992,7 @@ DEFUN (no_debug_ospf_instance_nsm, "NSM Timer Information\n") { int idx_number = 3; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1065,7 +1066,7 @@ DEFUN (debug_ospf_instance_lsa, "LSA Refresh\n") { int idx_number = 2; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1141,7 +1142,7 @@ DEFUN (no_debug_ospf_instance_lsa, "LSA Refres\n") { int idx_number = 3; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1203,7 +1204,7 @@ DEFUN (debug_ospf_instance_zebra, "Zebra redistribute\n") { int idx_number = 2; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1267,7 +1268,7 @@ DEFUN (no_debug_ospf_instance_zebra, "Zebra redistribute\n") { int idx_number = 3; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1313,7 +1314,7 @@ DEFUN (debug_ospf_instance_event, "OSPF event information\n") { int idx_number = 2; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1335,7 +1336,7 @@ DEFUN (no_debug_ospf_instance_event, "OSPF event information\n") { int idx_number = 3; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1383,7 +1384,7 @@ DEFUN (debug_ospf_instance_nssa, "OSPF nssa information\n") { int idx_number = 2; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1405,7 +1406,7 @@ DEFUN (no_debug_ospf_instance_nssa, "OSPF nssa information\n") { int idx_number = 3; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if (!ospf_lookup_instance(instance)) @@ -1654,7 +1655,7 @@ DEFUN_NOSH (show_debugging_ospf_instance, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); if ((ospf = ospf_lookup_instance(instance)) == NULL) diff --git a/ospfd/ospf_dump_api.c b/ospfd/ospf_dump_api.c index 3cfe3453aa..1196339c34 100644 --- a/ospfd/ospf_dump_api.c +++ b/ospfd/ospf_dump_api.c @@ -101,7 +101,7 @@ const struct message ospf_auth_type_str[] = { #define OSPF_OPTION_STR_MAXLEN 24 -char *ospf_options_dump(u_char options) +char *ospf_options_dump(uint8_t options) { static char buf[OSPF_OPTION_STR_MAXLEN]; @@ -130,7 +130,7 @@ void ospf_lsa_header_dump(struct lsa_header *lsah) zlog_debug(" Link State ID %s", inet_ntoa(lsah->id)); zlog_debug(" Advertising Router %s", inet_ntoa(lsah->adv_router)); zlog_debug(" LS sequence number 0x%lx", - (u_long)ntohl(lsah->ls_seqnum)); + (unsigned long)ntohl(lsah->ls_seqnum)); zlog_debug(" LS checksum 0x%x", ntohs(lsah->checksum)); zlog_debug(" length %d", ntohs(lsah->length)); } diff --git a/ospfd/ospf_dump_api.h b/ospfd/ospf_dump_api.h index 3595220610..98fef34b15 100644 --- a/ospfd/ospf_dump_api.h +++ b/ospfd/ospf_dump_api.h @@ -37,7 +37,7 @@ extern const int ospf_link_state_id_type_msg_max; extern const int ospf_network_type_msg_max; extern const size_t ospf_auth_type_str_max; -extern char *ospf_options_dump(u_char); +extern char *ospf_options_dump(uint8_t); extern void ospf_lsa_header_dump(struct lsa_header *); #endif /* _ZEBRA_OSPF_DUMP_API_H */ diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c index 10dd2f92c7..ac5df3eb4e 100644 --- a/ospfd/ospf_ext.c +++ b/ospfd/ospf_ext.c @@ -922,7 +922,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area, struct lsa_header *lsah; struct ospf_lsa *new = NULL; struct ospf *top; - u_char options, lsa_type; + uint8_t options, lsa_type; struct in_addr lsa_id; struct in_addr router_id; uint32_t tmp; @@ -1014,7 +1014,7 @@ static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area, struct stream *s; struct lsa_header *lsah; struct ospf_lsa *new = NULL; - u_char options, lsa_type; + uint8_t options, lsa_type; struct in_addr lsa_id; uint32_t tmp; uint16_t length; diff --git a/ospfd/ospf_ia.c b/ospfd/ospf_ia.c index 9b74cb8c0f..86d15480a3 100644 --- a/ospfd/ospf_ia.c +++ b/ospfd/ospf_ia.c @@ -196,7 +196,7 @@ static int process_summary_lsa(struct ospf_area *area, struct route_table *rt, struct ospf_route *abr_or, *new_or; struct summary_lsa *sl; struct prefix_ipv4 p, abr; - u_int32_t metric; + uint32_t metric; if (lsa == NULL) return 0; @@ -302,7 +302,7 @@ static void ospf_update_network_route(struct ospf *ospf, struct route_table *rt, struct route_node *rn; struct ospf_route * or, *abr_or, *new_or; struct prefix_ipv4 abr; - u_int32_t cost; + uint32_t cost; abr.family = AF_INET; abr.prefix = lsa->header.adv_router; @@ -427,7 +427,7 @@ static void ospf_update_router_route(struct ospf *ospf, { struct ospf_route * or, *abr_or, *new_or; struct prefix_ipv4 abr; - u_int32_t cost; + uint32_t cost; abr.family = AF_INET; abr.prefix = lsa->header.adv_router; @@ -523,7 +523,7 @@ static int process_transit_summary_lsa(struct ospf_area *area, struct ospf *ospf = area->ospf; struct summary_lsa *sl; struct prefix_ipv4 p; - u_int32_t metric; + uint32_t metric; if (lsa == NULL) return 0; diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 0305305b81..52b954d6a1 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -76,8 +76,8 @@ int ospf_interface_neighbor_count(struct ospf_interface *oi) int ospf_if_get_output_cost(struct ospf_interface *oi) { /* If all else fails, use default OSPF cost */ - u_int32_t cost; - u_int32_t bw, refbw; + uint32_t cost; + uint32_t bw, refbw; /* ifp speed and bw can be 0 in some platforms, use ospf default bw if bw is configured under interface it would be used. @@ -96,7 +96,7 @@ int ospf_if_get_output_cost(struct ospf_interface *oi) /* See if a cost can be calculated from the zebra processes interface bandwidth field. */ else { - cost = (u_int32_t)((double)refbw / (double)bw + (double)0.5); + cost = (uint32_t)((double)refbw / (double)bw + (double)0.5); if (cost < 1) cost = 1; else if (cost > 65535) @@ -108,7 +108,7 @@ int ospf_if_get_output_cost(struct ospf_interface *oi) void ospf_if_recalculate_output_cost(struct interface *ifp) { - u_int32_t newcost; + uint32_t newcost; struct route_node *rn; for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { @@ -825,7 +825,7 @@ void ospf_vl_data_free(struct ospf_vl_data *vl_data) XFREE(MTYPE_OSPF_VL_DATA, vl_data); } -u_int vlink_count = 0; +unsigned int vlink_count = 0; struct ospf_interface *ospf_vl_new(struct ospf *ospf, struct ospf_vl_data *vl_data) @@ -1174,7 +1174,7 @@ void ospf_crypt_key_add(struct list *crypt, struct crypt_key *ck) listnode_add(crypt, ck); } -struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, u_char key_id) +struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, uint8_t key_id) { struct listnode *node; struct crypt_key *ck; @@ -1186,7 +1186,7 @@ struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, u_char key_id) return NULL; } -int ospf_crypt_key_delete(struct list *auth_crypt, u_char key_id) +int ospf_crypt_key_delete(struct list *auth_crypt, uint8_t key_id) { struct listnode *node, *nnode; struct crypt_key *ck; @@ -1202,7 +1202,7 @@ int ospf_crypt_key_delete(struct list *auth_crypt, u_char key_id) return 0; } -u_char ospf_default_iftype(struct interface *ifp) +uint8_t ospf_default_iftype(struct interface *ifp) { if (if_is_pointopoint(ifp)) return OSPF_IFTYPE_POINTOPOINT; diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h index 85a24f0026..73ded208cf 100644 --- a/ospfd/ospf_interface.h +++ b/ospfd/ospf_interface.h @@ -47,28 +47,30 @@ ? (O)->params->P \ : IF_DEF_PARAMS((O)->ifp)->P) -#define DECLARE_IF_PARAM(T, P) T P; u_char P##__config:1 +#define DECLARE_IF_PARAM(T, P) \ + T P; \ + uint8_t P##__config : 1 #define UNSET_IF_PARAM(S, P) ((S)->P##__config) = 0 #define SET_IF_PARAM(S, P) ((S)->P##__config) = 1 struct ospf_if_params { - DECLARE_IF_PARAM(u_int32_t, + DECLARE_IF_PARAM(uint32_t, transmit_delay); /* Interface Transmisson Delay */ - DECLARE_IF_PARAM(u_int32_t, + DECLARE_IF_PARAM(uint32_t, output_cost_cmd); /* Command Interface Output Cost */ - DECLARE_IF_PARAM(u_int32_t, + DECLARE_IF_PARAM(uint32_t, retransmit_interval); /* Retransmission Interval */ - DECLARE_IF_PARAM(u_char, passive_interface); /* OSPF Interface is + DECLARE_IF_PARAM(uint8_t, passive_interface); /* OSPF Interface is passive: no sending or receiving (no need to join multicast groups) */ - DECLARE_IF_PARAM(u_char, priority); /* OSPF Interface priority */ + DECLARE_IF_PARAM(uint8_t, priority); /* OSPF Interface priority */ /* Enable OSPF on this interface with area if_area */ DECLARE_IF_PARAM(struct in_addr, if_area); - u_int32_t if_area_id_fmt; + uint32_t if_area_id_fmt; - DECLARE_IF_PARAM(u_char, type); /* type of interface */ + DECLARE_IF_PARAM(uint8_t, type); /* type of interface */ #define OSPF_IF_ACTIVE 0 #define OSPF_IF_PASSIVE 1 @@ -80,25 +82,25 @@ struct ospf_if_params { ? IF_DEF_PARAMS((O)->ifp)->passive_interface \ : (O)->ospf->passive_interface_default)) - DECLARE_IF_PARAM(u_int32_t, v_hello); /* Hello Interval */ - DECLARE_IF_PARAM(u_int32_t, v_wait); /* Router Dead Interval */ + DECLARE_IF_PARAM(uint32_t, v_hello); /* Hello Interval */ + DECLARE_IF_PARAM(uint32_t, v_wait); /* Router Dead Interval */ /* MTU mismatch check (see RFC2328, chap 10.6) */ - DECLARE_IF_PARAM(u_char, mtu_ignore); + DECLARE_IF_PARAM(uint8_t, mtu_ignore); /* Fast-Hellos */ - DECLARE_IF_PARAM(u_char, fast_hello); + DECLARE_IF_PARAM(uint8_t, fast_hello); /* Authentication data. */ - u_char auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */ - u_char auth_simple__config : 1; + uint8_t auth_simple[OSPF_AUTH_SIMPLE_SIZE + 1]; /* Simple password. */ + uint8_t auth_simple__config : 1; DECLARE_IF_PARAM(struct list *, auth_crypt); /* List of Auth cryptographic data. */ DECLARE_IF_PARAM(int, auth_type); /* OSPF authentication type */ /* Other, non-configuration state */ - u_int32_t network_lsa_seqnum; /* Network LSA seqnum */ + uint32_t network_lsa_seqnum; /* Network LSA seqnum */ /* BFD configuration */ struct bfd_info *bfd_info; @@ -126,7 +128,7 @@ struct ospf_vl_data { struct ospf_interface *vl_oi; /* Interface data structure */ struct vertex_nexthop nexthop; /* Nexthop router and oi to use */ struct in_addr peer_addr; /* Address used to reach the peer */ - u_char flags; + uint8_t flags; }; @@ -136,8 +138,8 @@ struct ospf_vl_data { #define OSPF_VL_FLAG_APPROVED 0x01 struct crypt_key { - u_char key_id; - u_char auth_key[OSPF_AUTH_MD5_SIZE + 1]; + uint8_t key_id; + uint8_t auth_key[OSPF_AUTH_MD5_SIZE + 1]; }; /* OSPF interface structure. */ @@ -160,13 +162,13 @@ struct ospf_interface { struct ospf_fifo *obuf; /* Output queue */ /* OSPF Network Type. */ - u_char type; + uint8_t type; /* State of Interface State Machine. */ - u_char state; + uint8_t state; /* To which multicast groups do we currently belong? */ - u_char multicast_memberships; + uint8_t multicast_memberships; #define OI_MEMBER_FLAG(M) (1 << (M)) #define OI_MEMBER_COUNT(O,M) (IF_OSPF_IF_INFO(oi->ifp)->membership_counts[(M)]) #define OI_MEMBER_CHECK(O, M) \ @@ -188,8 +190,8 @@ struct ospf_interface { /* Configured varables. */ struct ospf_if_params *params; - u_int32_t crypt_seqnum; /* Cryptographic Sequence Number */ - u_int32_t output_cost; /* Acutual Interface Output Cost */ + uint32_t crypt_seqnum; /* Cryptographic Sequence Number */ + uint32_t output_cost; /* Acutual Interface Output Cost */ /* Neighbor information. */ struct route_table *nbrs; /* OSPF Neighbor List */ @@ -216,7 +218,7 @@ struct ospf_interface { } ls_ack_direct; /* Timer values. */ - u_int32_t v_ls_ack; /* Delayed Link State Acknowledgment */ + uint32_t v_ls_ack; /* Delayed Link State Acknowledgment */ /* Threads. */ struct thread *t_hello; /* timer */ @@ -229,20 +231,20 @@ struct ospf_interface { int on_write_q; /* Statistics fields. */ - u_int32_t hello_in; /* Hello message input count. */ - u_int32_t hello_out; /* Hello message output count. */ - u_int32_t db_desc_in; /* database desc. message input count. */ - u_int32_t db_desc_out; /* database desc. message output count. */ - u_int32_t ls_req_in; /* LS request message input count. */ - u_int32_t ls_req_out; /* LS request message output count. */ - u_int32_t ls_upd_in; /* LS update message input count. */ - u_int32_t ls_upd_out; /* LS update message output count. */ - u_int32_t ls_ack_in; /* LS Ack message input count. */ - u_int32_t ls_ack_out; /* LS Ack message output count. */ - u_int32_t discarded; /* discarded input count by error. */ - u_int32_t state_change; /* Number of status change. */ - - u_int32_t full_nbrs; + uint32_t hello_in; /* Hello message input count. */ + uint32_t hello_out; /* Hello message output count. */ + uint32_t db_desc_in; /* database desc. message input count. */ + uint32_t db_desc_out; /* database desc. message output count. */ + uint32_t ls_req_in; /* LS request message input count. */ + uint32_t ls_req_out; /* LS request message output count. */ + uint32_t ls_upd_in; /* LS update message input count. */ + uint32_t ls_upd_out; /* LS update message output count. */ + uint32_t ls_ack_in; /* LS Ack message input count. */ + uint32_t ls_ack_out; /* LS Ack message output count. */ + uint32_t discarded; /* discarded input count by error. */ + uint32_t state_change; /* Number of status change. */ + + uint32_t full_nbrs; QOBJ_FIELDS }; @@ -308,11 +310,11 @@ extern void ospf_vl_shut_unapproved(struct ospf *); extern int ospf_full_virtual_nbrs(struct ospf_area *); extern int ospf_vls_in_area(struct ospf_area *); -extern struct crypt_key *ospf_crypt_key_lookup(struct list *, u_char); +extern struct crypt_key *ospf_crypt_key_lookup(struct list *, uint8_t); extern struct crypt_key *ospf_crypt_key_new(void); extern void ospf_crypt_key_add(struct list *, struct crypt_key *); -extern int ospf_crypt_key_delete(struct list *, u_char); -extern u_char ospf_default_iftype(struct interface *ifp); +extern int ospf_crypt_key_delete(struct list *, uint8_t); +extern uint8_t ospf_default_iftype(struct interface *ifp); extern int ospf_interface_neighbor_count(struct ospf_interface *oi); /* Set all multicast memberships appropriately based on the type and diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 588a8f6724..fd3da45f78 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -52,9 +52,9 @@ #include "ospfd/ospf_abr.h" -u_int32_t get_metric(u_char *metric) +uint32_t get_metric(uint8_t *metric) { - u_int32_t m; + uint32_t m; m = metric[0]; m = (m << 8) + metric[1]; m = (m << 8) + metric[2]; @@ -121,28 +121,28 @@ int get_age(struct ospf_lsa *lsa) /* All the offsets are zero-based. The offsets in the RFC1008 are one-based. */ -u_int16_t ospf_lsa_checksum(struct lsa_header *lsa) +uint16_t ospf_lsa_checksum(struct lsa_header *lsa) { - u_char *buffer = (u_char *)&lsa->options; - int options_offset = buffer - (u_char *)&lsa->ls_age; /* should be 2 */ + uint8_t *buffer = (uint8_t *)&lsa->options; + int options_offset = buffer - (uint8_t *)&lsa->ls_age; /* should be 2 */ /* Skip the AGE field */ - u_int16_t len = ntohs(lsa->length) - options_offset; + uint16_t len = ntohs(lsa->length) - options_offset; /* Checksum offset starts from "options" field, not the beginning of the lsa_header struct. The offset is 14, rather than 16. */ - int checksum_offset = (u_char *)&lsa->checksum - buffer; + int checksum_offset = (uint8_t *)&lsa->checksum - buffer; return fletcher_checksum(buffer, len, checksum_offset); } int ospf_lsa_checksum_valid(struct lsa_header *lsa) { - u_char *buffer = (u_char *)&lsa->options; - int options_offset = buffer - (u_char *)&lsa->ls_age; /* should be 2 */ + uint8_t *buffer = (uint8_t *)&lsa->options; + int options_offset = buffer - (uint8_t *)&lsa->ls_age; /* should be 2 */ /* Skip the AGE field */ - u_int16_t len = ntohs(lsa->length) - options_offset; + uint16_t len = ntohs(lsa->length) - options_offset; return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE) == 0); @@ -295,16 +295,16 @@ const char *dump_lsa_key(struct ospf_lsa *lsa) return buf; } -u_int32_t lsa_seqnum_increment(struct ospf_lsa *lsa) +uint32_t lsa_seqnum_increment(struct ospf_lsa *lsa) { - u_int32_t seqnum; + uint32_t seqnum; seqnum = ntohl(lsa->data->ls_seqnum) + 1; return htonl(seqnum); } -void lsa_header_set(struct stream *s, u_char options, u_char type, +void lsa_header_set(struct stream *s, uint8_t options, uint8_t type, struct in_addr id, struct in_addr router_id) { struct lsa_header *lsah; @@ -324,9 +324,9 @@ void lsa_header_set(struct stream *s, u_char options, u_char type, /* router-LSA related functions. */ /* Get router-LSA flags. */ -static u_char router_lsa_flags(struct ospf_area *area) +static uint8_t router_lsa_flags(struct ospf_area *area) { - u_char flags; + uint8_t flags; flags = area->ospf->flags; @@ -396,7 +396,7 @@ struct ospf_neighbor *ospf_nbr_lookup_ptop(struct ospf_interface *oi) /* Determine cost of link, taking RFC3137 stub-router support into * consideration */ -static u_int16_t ospf_link_cost(struct ospf_interface *oi) +static uint16_t ospf_link_cost(struct ospf_interface *oi) { /* RFC3137 stub router support */ if (!CHECK_FLAG(oi->area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) @@ -407,8 +407,8 @@ static u_int16_t ospf_link_cost(struct ospf_interface *oi) /* Set a link information. */ static char link_info_set(struct stream *s, struct in_addr id, - struct in_addr data, u_char type, u_char tos, - u_int16_t cost) + struct in_addr data, uint8_t type, uint8_t tos, + uint16_t cost) { /* LSA stream is initially allocated to OSPF_MAX_LSA_SIZE, suits * vast majority of cases. Some rare routers with lots of links need @@ -459,7 +459,7 @@ static int lsa_link_ptop_set(struct stream *s, struct ospf_interface *oi) int links = 0; struct ospf_neighbor *nbr; struct in_addr id, mask, data; - u_int16_t cost = ospf_link_cost(oi); + uint16_t cost = ospf_link_cost(oi); if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) zlog_debug("LSA[Type1]: Set link Point-to-Point"); @@ -504,7 +504,7 @@ static int lsa_link_broadcast_set(struct stream *s, struct ospf_interface *oi) { struct ospf_neighbor *dr; struct in_addr id, mask; - u_int16_t cost = ospf_link_cost(oi); + uint16_t cost = ospf_link_cost(oi); /* Describe Type 3 Link. */ if (oi->state == ISM_Waiting) { @@ -563,7 +563,7 @@ static int lsa_link_loopback_set(struct stream *s, struct ospf_interface *oi) static int lsa_link_virtuallink_set(struct stream *s, struct ospf_interface *oi) { struct ospf_neighbor *nbr; - u_int16_t cost = ospf_link_cost(oi); + uint16_t cost = ospf_link_cost(oi); if (oi->state == ISM_PointToPoint) if ((nbr = ospf_nbr_lookup_ptop(oi))) @@ -589,7 +589,7 @@ static int lsa_link_ptomp_set(struct stream *s, struct ospf_interface *oi) struct route_node *rn; struct ospf_neighbor *nbr = NULL; struct in_addr id, mask; - u_int16_t cost = ospf_link_cost(oi); + uint16_t cost = ospf_link_cost(oi); mask.s_addr = 0xffffffff; id.s_addr = oi->address->u.prefix4.s_addr; @@ -670,7 +670,7 @@ static int router_lsa_link_set(struct stream *s, struct ospf_area *area) static void ospf_router_lsa_body_set(struct stream *s, struct ospf_area *area) { unsigned long putp; - u_int16_t cnt; + uint16_t cnt; /* Set flags. */ stream_putc(s, router_lsa_flags(area)); @@ -1115,9 +1115,9 @@ static struct ospf_lsa *ospf_network_lsa_refresh(struct ospf_lsa *lsa) return new; } -static void stream_put_ospf_metric(struct stream *s, u_int32_t metric_value) +static void stream_put_ospf_metric(struct stream *s, uint32_t metric_value) { - u_int32_t metric; + uint32_t metric; char *mp; /* Put 0 metric. TOS metric is not supported. */ @@ -1129,7 +1129,7 @@ static void stream_put_ospf_metric(struct stream *s, u_int32_t metric_value) /* summary-LSA related functions. */ static void ospf_summary_lsa_body_set(struct stream *s, struct prefix *p, - u_int32_t metric) + uint32_t metric) { struct in_addr mask; @@ -1139,14 +1139,14 @@ static void ospf_summary_lsa_body_set(struct stream *s, struct prefix *p, stream_put_ipv4(s, mask.s_addr); /* Set # TOS. */ - stream_putc(s, (u_char)0); + stream_putc(s, (uint8_t)0); /* Set metric. */ stream_put_ospf_metric(s, metric); } static struct ospf_lsa *ospf_summary_lsa_new(struct ospf_area *area, - struct prefix *p, u_int32_t metric, + struct prefix *p, uint32_t metric, struct in_addr id) { struct stream *s; @@ -1196,7 +1196,7 @@ static struct ospf_lsa *ospf_summary_lsa_new(struct ospf_area *area, /* Originate Summary-LSA. */ struct ospf_lsa *ospf_summary_lsa_originate(struct prefix_ipv4 *p, - u_int32_t metric, + uint32_t metric, struct ospf_area *area) { struct ospf_lsa *new; @@ -1274,13 +1274,13 @@ static struct ospf_lsa *ospf_summary_lsa_refresh(struct ospf *ospf, /* summary-ASBR-LSA related functions. */ static void ospf_summary_asbr_lsa_body_set(struct stream *s, struct prefix *p, - u_int32_t metric) + uint32_t metric) { /* Put Network Mask. */ - stream_put_ipv4(s, (u_int32_t)0); + stream_put_ipv4(s, (uint32_t)0); /* Set # TOS. */ - stream_putc(s, (u_char)0); + stream_putc(s, (uint8_t)0); /* Set metric. */ stream_put_ospf_metric(s, metric); @@ -1288,7 +1288,7 @@ static void ospf_summary_asbr_lsa_body_set(struct stream *s, struct prefix *p, static struct ospf_lsa *ospf_summary_asbr_lsa_new(struct ospf_area *area, struct prefix *p, - u_int32_t metric, + uint32_t metric, struct in_addr id) { struct stream *s; @@ -1338,7 +1338,7 @@ static struct ospf_lsa *ospf_summary_asbr_lsa_new(struct ospf_area *area, /* Originate summary-ASBR-LSA. */ struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *p, - u_int32_t metric, + uint32_t metric, struct ospf_area *area) { struct ospf_lsa *new; @@ -1501,7 +1501,7 @@ struct in_addr ospf_get_nssa_ip(struct ospf_area *area) #define DEFAULT_METRIC_TYPE EXTERNAL_METRIC_TYPE_2 -int metric_type(struct ospf *ospf, u_char src, u_short instance) +int metric_type(struct ospf *ospf, uint8_t src, unsigned short instance) { struct ospf_redist *red; @@ -1511,7 +1511,7 @@ int metric_type(struct ospf *ospf, u_char src, u_short instance) : red->dmetric.type); } -int metric_value(struct ospf *ospf, u_char src, u_short instance) +int metric_value(struct ospf *ospf, uint8_t src, unsigned short instance) { struct ospf_redist *red; @@ -1538,10 +1538,10 @@ static void ospf_external_lsa_body_set(struct stream *s, { struct prefix_ipv4 *p = &ei->p; struct in_addr mask, fwd_addr; - u_int32_t mvalue; + uint32_t mvalue; int mtype; int type; - u_short instance; + unsigned short instance; /* Put Network Mask. */ masklen2ip(p->prefixlen, &mask); @@ -2153,7 +2153,7 @@ void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p) } /* Flush an AS-external-LSA from LSDB and routing domain. */ -void ospf_external_lsa_flush(struct ospf *ospf, u_char type, +void ospf_external_lsa_flush(struct ospf *ospf, uint8_t type, struct prefix_ipv4 *p, ifindex_t ifindex /*, struct in_addr nexthop */) { @@ -2238,8 +2238,8 @@ void ospf_external_lsa_refresh_default(struct ospf *ospf) } } -void ospf_external_lsa_refresh_type(struct ospf *ospf, u_char type, - u_short instance, int force) +void ospf_external_lsa_refresh_type(struct ospf *ospf, uint8_t type, + unsigned short instance, int force) { struct route_node *rn; struct external_info *ei; @@ -2818,7 +2818,7 @@ static int ospf_maxage_lsa_remover(struct thread *thread) "LSA[Type%d:%s]: LSA 0x%lx is self-originated: ", lsa->data->type, inet_ntoa(lsa->data->id), - (u_long)lsa); + (unsigned long)lsa); if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) zlog_debug( @@ -3033,7 +3033,7 @@ int ospf_lsa_maxage_walker(struct thread *thread) return 0; } -struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *lsdb, u_char type, +struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *lsdb, uint8_t type, struct prefix_ipv4 *p, struct in_addr router_id) { @@ -3063,7 +3063,7 @@ struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *lsdb, u_char type, } struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *area, - u_int32_t type, struct in_addr id, + uint32_t type, struct in_addr id, struct in_addr adv_router) { if (!ospf) @@ -3088,7 +3088,7 @@ struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *area, return NULL; } -struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *area, u_int32_t type, +struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *area, uint32_t type, struct in_addr id) { struct ospf_lsa *lsa; @@ -3236,7 +3236,7 @@ int ospf_lsa_different(struct ospf_lsa *l1, struct ospf_lsa *l2) void ospf_lsa_flush_self_originated(struct ospf_neighbor *nbr, struct ospf_lsa *self, struct ospf_lsa *new) { - u_int32_t seqnum; + uint32_t seqnum; /* Adjust LS Sequence Number. */ seqnum = ntohl(new->data->ls_seqnum) + 1; @@ -3421,7 +3421,7 @@ int ospf_lsa_is_self_originated(struct ospf *ospf, struct ospf_lsa *lsa) /* Get unique Link State ID. */ struct in_addr ospf_lsa_unique_id(struct ospf *ospf, struct ospf_lsdb *lsdb, - u_char type, struct prefix_ipv4 *p) + uint8_t type, struct prefix_ipv4 *p) { struct ospf_lsa *lsa; struct in_addr mask, id; @@ -3473,7 +3473,7 @@ struct in_addr ospf_lsa_unique_id(struct ospf *ospf, struct ospf_lsdb *lsdb, #define LSA_ACTION_FLUSH_AREA 2 struct lsa_action { - u_char action; + uint8_t action; struct ospf_area *area; struct ospf_lsa *lsa; }; @@ -3576,7 +3576,7 @@ struct ospf_lsa *ospf_lsa_refresh(struct ospf *ospf, struct ospf_lsa *lsa) void ospf_refresher_register_lsa(struct ospf *ospf, struct ospf_lsa *lsa) { - u_int16_t index, current_index; + uint16_t index, current_index; assert(lsa->lock > 0); assert(IS_LSA_SELF(lsa)); diff --git a/ospfd/ospf_lsa.h b/ospfd/ospf_lsa.h index 94a34d4a90..f8f7b28d4e 100644 --- a/ospfd/ospf_lsa.h +++ b/ospfd/ospf_lsa.h @@ -53,20 +53,20 @@ /* OSPF LSA header. */ struct lsa_header { - u_int16_t ls_age; - u_char options; - u_char type; + uint16_t ls_age; + uint8_t options; + uint8_t type; struct in_addr id; struct in_addr adv_router; - u_int32_t ls_seqnum; - u_int16_t checksum; - u_int16_t length; + uint32_t ls_seqnum; + uint16_t checksum; + uint16_t length; }; /* OSPF LSA. */ struct ospf_lsa { /* LSA origination flag. */ - u_char flags; + uint8_t flags; #define OSPF_LSA_SELF 0x01 #define OSPF_LSA_SELF_CHECKED 0x02 #define OSPF_LSA_RECEIVED 0x04 @@ -140,9 +140,9 @@ struct router_lsa_link { struct in_addr link_id; struct in_addr link_data; struct { - u_char type; - u_char tos_count; - u_int16_t metric; + uint8_t type; + uint8_t tos_count; + uint16_t metric; } m[1]; }; @@ -157,15 +157,15 @@ struct router_lsa_link { be replaced with the next revision having 1 descriptor block. */ struct router_lsa { struct lsa_header header; - u_char flags; - u_char zero; - u_int16_t links; + uint8_t flags; + uint8_t zero; + uint16_t links; struct { struct in_addr link_id; struct in_addr link_data; - u_char type; - u_char tos; - u_int16_t metric; + uint8_t type; + uint8_t tos; + uint16_t metric; } link[1]; }; @@ -182,8 +182,8 @@ struct network_lsa { struct summary_lsa { struct lsa_header header; struct in_addr mask; - u_char tos; - u_char metric[3]; + uint8_t tos; + uint8_t metric[3]; }; /* OSPF AS-external-LSAs structure. */ @@ -192,10 +192,10 @@ struct as_external_lsa { struct lsa_header header; struct in_addr mask; struct { - u_char tos; - u_char metric[3]; + uint8_t tos; + uint8_t metric[3]; struct in_addr fwd_addr; - u_int32_t route_tag; + uint32_t route_tag; } e[1]; }; @@ -222,13 +222,13 @@ extern struct timeval int2tv(int); extern struct timeval msec2tv(int); extern int get_age(struct ospf_lsa *); -extern u_int16_t ospf_lsa_checksum(struct lsa_header *); +extern uint16_t ospf_lsa_checksum(struct lsa_header *); extern int ospf_lsa_checksum_valid(struct lsa_header *); extern int ospf_lsa_refresh_delay(struct ospf_lsa *); extern const char *dump_lsa_key(struct ospf_lsa *); -extern u_int32_t lsa_seqnum_increment(struct ospf_lsa *); -extern void lsa_header_set(struct stream *, u_char, u_char, struct in_addr, +extern uint32_t lsa_seqnum_increment(struct ospf_lsa *); +extern void lsa_header_set(struct stream *, uint8_t, uint8_t, struct in_addr, struct in_addr); extern struct ospf_neighbor *ospf_nbr_lookup_ptop(struct ospf_interface *); extern int ospf_check_nbr_status(struct ospf *); @@ -252,16 +252,17 @@ extern int ospf_router_lsa_update_area(struct ospf_area *); extern void ospf_network_lsa_update(struct ospf_interface *); extern struct ospf_lsa * -ospf_summary_lsa_originate(struct prefix_ipv4 *, u_int32_t, struct ospf_area *); +ospf_summary_lsa_originate(struct prefix_ipv4 *, uint32_t, struct ospf_area *); extern struct ospf_lsa *ospf_summary_asbr_lsa_originate(struct prefix_ipv4 *, - u_int32_t, + uint32_t, struct ospf_area *); extern struct ospf_lsa *ospf_lsa_install(struct ospf *, struct ospf_interface *, struct ospf_lsa *); extern void ospf_nssa_lsa_flush(struct ospf *ospf, struct prefix_ipv4 *p); -extern void ospf_external_lsa_flush(struct ospf *, u_char, struct prefix_ipv4 *, +extern void ospf_external_lsa_flush(struct ospf *, uint8_t, + struct prefix_ipv4 *, ifindex_t /* , struct in_addr nexthop */); extern struct in_addr ospf_get_ip_from_ifp(struct ospf_interface *); @@ -271,9 +272,9 @@ extern struct ospf_lsa *ospf_external_lsa_originate(struct ospf *, extern int ospf_external_lsa_originate_timer(struct thread *); extern int ospf_default_originate_timer(struct thread *); extern struct ospf_lsa *ospf_lsa_lookup(struct ospf *ospf, struct ospf_area *, - u_int32_t, struct in_addr, + uint32_t, struct in_addr, struct in_addr); -extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, u_int32_t, +extern struct ospf_lsa *ospf_lsa_lookup_by_id(struct ospf_area *, uint32_t, struct in_addr); extern struct ospf_lsa *ospf_lsa_lookup_by_header(struct ospf_area *, struct lsa_header *); @@ -283,24 +284,25 @@ extern void ospf_flush_self_originated_lsas_now(struct ospf *); extern int ospf_lsa_is_self_originated(struct ospf *, struct ospf_lsa *); -extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, u_char, +extern struct ospf_lsa *ospf_lsa_lookup_by_prefix(struct ospf_lsdb *, uint8_t, struct prefix_ipv4 *, struct in_addr); extern void ospf_lsa_maxage(struct ospf *, struct ospf_lsa *); -extern u_int32_t get_metric(u_char *); +extern uint32_t get_metric(uint8_t *); extern int ospf_lsa_maxage_walker(struct thread *); extern struct ospf_lsa *ospf_lsa_refresh(struct ospf *, struct ospf_lsa *); extern void ospf_external_lsa_refresh_default(struct ospf *); -extern void ospf_external_lsa_refresh_type(struct ospf *, u_char, u_short, int); +extern void ospf_external_lsa_refresh_type(struct ospf *, uint8_t, + unsigned short, int); extern struct ospf_lsa *ospf_external_lsa_refresh(struct ospf *, struct ospf_lsa *, struct external_info *, int); extern struct in_addr ospf_lsa_unique_id(struct ospf *, struct ospf_lsdb *, - u_char, struct prefix_ipv4 *); + uint8_t, struct prefix_ipv4 *); extern void ospf_schedule_lsa_flood_area(struct ospf_area *, struct ospf_lsa *); extern void ospf_schedule_lsa_flush_area(struct ospf_area *, struct ospf_lsa *); @@ -314,8 +316,8 @@ extern void ospf_discard_from_db(struct ospf *, struct ospf_lsdb *, struct ospf_lsa *); extern int is_prefix_default(struct prefix_ipv4 *); -extern int metric_type(struct ospf *, u_char, u_short); -extern int metric_value(struct ospf *, u_char, u_short); +extern int metric_type(struct ospf *, uint8_t, unsigned short); +extern int metric_value(struct ospf *, uint8_t, unsigned short); extern struct in_addr ospf_get_nssa_ip(struct ospf_area *); extern int ospf_translated_nssa_compare(struct ospf_lsa *, struct ospf_lsa *); diff --git a/ospfd/ospf_lsdb.c b/ospfd/ospf_lsdb.c index a596d32860..ef965a5f91 100644 --- a/ospfd/ospf_lsdb.c +++ b/ospfd/ospf_lsdb.c @@ -213,7 +213,7 @@ struct ospf_lsa *ospf_lsdb_lookup(struct ospf_lsdb *lsdb, struct ospf_lsa *lsa) return NULL; } -struct ospf_lsa *ospf_lsdb_lookup_by_id(struct ospf_lsdb *lsdb, u_char type, +struct ospf_lsa *ospf_lsdb_lookup_by_id(struct ospf_lsdb *lsdb, uint8_t type, struct in_addr id, struct in_addr adv_router) { @@ -240,7 +240,7 @@ struct ospf_lsa *ospf_lsdb_lookup_by_id(struct ospf_lsdb *lsdb, u_char type, } struct ospf_lsa *ospf_lsdb_lookup_by_id_next(struct ospf_lsdb *lsdb, - u_char type, struct in_addr id, + uint8_t type, struct in_addr id, struct in_addr adv_router, int first) { diff --git a/ospfd/ospf_lsdb.h b/ospfd/ospf_lsdb.h index 4831071122..65c7e28fed 100644 --- a/ospfd/ospf_lsdb.h +++ b/ospfd/ospf_lsdb.h @@ -70,9 +70,9 @@ extern void ospf_lsdb_delete_all(struct ospf_lsdb *); /* Set all stats to -1 (LSA_SPF_NOT_EXPLORED). */ extern void ospf_lsdb_clean_stat(struct ospf_lsdb *lsdb); extern struct ospf_lsa *ospf_lsdb_lookup(struct ospf_lsdb *, struct ospf_lsa *); -extern struct ospf_lsa *ospf_lsdb_lookup_by_id(struct ospf_lsdb *, u_char, +extern struct ospf_lsa *ospf_lsdb_lookup_by_id(struct ospf_lsdb *, uint8_t, struct in_addr, struct in_addr); -extern struct ospf_lsa *ospf_lsdb_lookup_by_id_next(struct ospf_lsdb *, u_char, +extern struct ospf_lsa *ospf_lsdb_lookup_by_id_next(struct ospf_lsdb *, uint8_t, struct in_addr, struct in_addr, int); extern unsigned long ospf_lsdb_count_all(struct ospf_lsdb *); diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 364f51aa7f..5bf7ec1469 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -132,7 +132,7 @@ FRR_DAEMON_INFO(ospfd, OSPF, .vty_port = OSPF_VTY_PORT, /* OSPFd main routine. */ int main(int argc, char **argv) { - u_short instance = 0; + unsigned short instance = 0; #ifdef SUPPORT_OSPF_API /* OSPF apiserver is disabled by default. */ diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h index b19cf5b3ef..91dfc7a276 100644 --- a/ospfd/ospf_neighbor.h +++ b/ospfd/ospf_neighbor.h @@ -30,16 +30,16 @@ struct ospf_neighbor { struct ospf_interface *oi; /* OSPF neighbor Information */ - u_char state; /* NSM status. */ - u_char dd_flags; /* DD bit flags. */ - u_int32_t dd_seqnum; /* DD Sequence Number. */ + uint8_t state; /* NSM status. */ + uint8_t dd_flags; /* DD bit flags. */ + uint32_t dd_seqnum; /* DD Sequence Number. */ /* Neighbor Information from Hello. */ struct prefix address; /* Neighbor Interface Address. */ struct in_addr src; /* Src address. */ struct in_addr router_id; /* Router ID. */ - u_char options; /* Options. */ + uint8_t options; /* Options. */ int priority; /* Router Priority. */ struct in_addr d_router; /* Designated Router. */ struct in_addr bd_router; /* Backup Designated Router. */ @@ -51,9 +51,9 @@ struct ospf_neighbor { /* Last received Databse Description packet. */ struct { - u_char options; - u_char flags; - u_int32_t dd_seqnum; + uint8_t options; + uint8_t flags; + uint32_t dd_seqnum; } last_recv; /* LSA data. */ @@ -62,13 +62,13 @@ struct ospf_neighbor { struct ospf_lsdb ls_req; struct ospf_lsa *ls_req_last; - u_int32_t crypt_seqnum; /* Cryptographic Sequence Number. */ + uint32_t crypt_seqnum; /* Cryptographic Sequence Number. */ /* Timer values. */ - u_int32_t v_inactivity; - u_int32_t v_db_desc; - u_int32_t v_ls_req; - u_int32_t v_ls_upd; + uint32_t v_inactivity; + uint32_t v_db_desc; + uint32_t v_ls_req; + uint32_t v_ls_upd; /* Threads. */ struct thread *t_inactivity; @@ -84,7 +84,7 @@ struct ospf_neighbor { struct timeval ts_last_progress; /* last advance of NSM */ struct timeval ts_last_regress; /* last regressive NSM change */ const char *last_regress_str; /* Event which last regressed NSM */ - u_int32_t state_change; /* NSM state change counter */ + uint32_t state_change; /* NSM state change counter */ /* BFD information */ void *bfd_info; diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index 5e11245bc5..d7cca0f133 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -138,7 +138,7 @@ int ospf_if_drop_alldrouters(struct ospf *top, struct prefix *p, int ospf_if_ipmulticast(struct ospf *top, struct prefix *p, ifindex_t ifindex) { - u_char val; + uint8_t val; int ret, len; /* Prevent receiving self-origined multicast packets. */ diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index b83c9dec2c..1e72e3db63 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -614,7 +614,7 @@ static void nsm_change_state(struct ospf_neighbor *nbr, int state) { struct ospf_interface *oi = nbr->oi; struct ospf_area *vl_area = NULL; - u_char old_state; + uint8_t old_state; int x; int force = 1; diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index 6e9cf36a3d..1ae9a29a1b 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -208,7 +208,7 @@ void ospf_opaque_type11_lsa_term(struct ospf *top) return; } -static const char *ospf_opaque_type_name(u_char opaque_type) +static const char *ospf_opaque_type_name(uint8_t opaque_type) { const char *name = "Unknown"; @@ -241,7 +241,7 @@ static const char *ospf_opaque_type_name(u_char opaque_type) if (OPAQUE_TYPE_RANGE_UNASSIGNED(opaque_type)) name = "Unassigned"; else { - u_int32_t bigger_range = opaque_type; + uint32_t bigger_range = opaque_type; /* * Get around type-limits warning: comparison is always * true due to limited range of data type @@ -261,7 +261,7 @@ static const char *ospf_opaque_type_name(u_char opaque_type) struct opaque_info_per_type; /* Forward declaration. */ struct ospf_opaque_functab { - u_char opaque_type; + uint8_t opaque_type; struct opaque_info_per_type *oipt; int (*new_if_hook)(struct interface *ifp); @@ -326,7 +326,7 @@ static void ospf_opaque_funclist_term(void) return; } -static struct list *ospf_get_opaque_funclist(u_char lsa_type) +static struct list *ospf_get_opaque_funclist(uint8_t lsa_type) { struct list *funclist = NULL; @@ -361,7 +361,7 @@ static struct list *ospf_get_opaque_funclist(u_char lsa_type) /* XXX: such a huge argument list can /not/ be healthy... */ int ospf_register_opaque_functab( - u_char lsa_type, u_char opaque_type, + uint8_t lsa_type, uint8_t opaque_type, int (*new_if_hook)(struct interface *ifp), int (*del_if_hook)(struct interface *ifp), void (*ism_change_hook)(struct ospf_interface *oi, int old_status), @@ -429,7 +429,7 @@ out: return rc; } -void ospf_delete_opaque_functab(u_char lsa_type, u_char opaque_type) +void ospf_delete_opaque_functab(uint8_t lsa_type, uint8_t opaque_type) { struct list *funclist; struct listnode *node, *nnode; @@ -467,7 +467,7 @@ ospf_opaque_functab_lookup(struct ospf_lsa *lsa) struct list *funclist; struct listnode *node; struct ospf_opaque_functab *functab; - u_char key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)); + uint8_t key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)); if ((funclist = ospf_get_opaque_funclist(lsa->data->type)) != NULL) for (ALL_LIST_ELEMENTS_RO(funclist, node, functab)) @@ -487,8 +487,8 @@ ospf_opaque_functab_lookup(struct ospf_lsa *lsa) * identified by their opaque-id. */ struct opaque_info_per_type { - u_char lsa_type; - u_char opaque_type; + uint8_t lsa_type; + uint8_t opaque_type; enum { PROC_NORMAL, PROC_SUSPEND } status; @@ -521,7 +521,7 @@ struct opaque_info_per_type { /* Opaque-LSA control information per opaque-id. */ struct opaque_info_per_id { - u_int32_t opaque_id; + uint32_t opaque_id; /* Thread for refresh/flush scheduling for this opaque-type/id. */ struct thread *t_opaque_lsa_self; @@ -665,7 +665,7 @@ lookup_opaque_info_by_type(struct ospf_lsa *lsa) struct list *listtop = NULL; struct listnode *node, *nnode; struct opaque_info_per_type *oipt = NULL; - u_char key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)); + uint8_t key = GET_OPAQUE_TYPE(ntohl(lsa->data->id.s_addr)); switch (lsa->data->type) { case OSPF_OPAQUE_LINK_LSA: @@ -746,7 +746,7 @@ lookup_opaque_info_by_id(struct opaque_info_per_type *oipt, { struct listnode *node, *nnode; struct opaque_info_per_id *oipi; - u_int32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)); + uint32_t key = GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)); for (ALL_LIST_ELEMENTS(oipt->id_list, node, nnode, oipi)) if (oipi->opaque_id == key) @@ -1181,9 +1181,9 @@ void ospf_opaque_config_write_debug(struct vty *vty) void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa) { struct lsa_header *lsah = (struct lsa_header *)lsa->data; - u_int32_t lsid = ntohl(lsah->id.s_addr); - u_char opaque_type = GET_OPAQUE_TYPE(lsid); - u_int32_t opaque_id = GET_OPAQUE_ID(lsid); + uint32_t lsid = ntohl(lsah->id.s_addr); + uint8_t opaque_type = GET_OPAQUE_TYPE(lsid); + uint32_t opaque_id = GET_OPAQUE_ID(lsid); struct ospf_opaque_functab *functab; /* Switch output functionality by vty address. */ @@ -1214,7 +1214,7 @@ void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa) return; } -void ospf_opaque_lsa_dump(struct stream *s, u_int16_t length) +void ospf_opaque_lsa_dump(struct stream *s, uint16_t length) { struct ospf_lsa lsa; @@ -1660,15 +1660,15 @@ struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa) #define OSPF_OPAQUE_TIMER_ON(T,F,L,V) thread_add_timer_msec (master, (F), (L), (V), &(T)) static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi, - struct ospf_area *area, u_char lsa_type, - u_char opaque_type); + 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); void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent, - u_char lsa_type, u_char opaque_type) + uint8_t lsa_type, uint8_t opaque_type) { struct ospf *top = NULL; struct ospf_area dummy, *area = NULL; @@ -1827,12 +1827,12 @@ out: } static struct ospf_lsa *pseudo_lsa(struct ospf_interface *oi, - struct ospf_area *area, u_char lsa_type, - u_char opaque_type) + struct ospf_area *area, uint8_t lsa_type, + uint8_t opaque_type) { static struct ospf_lsa lsa = {0}; static struct lsa_header lsah = {0}; - u_int32_t tmp; + uint32_t tmp; lsa.oi = oi; lsa.area = area; diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h index 4fc5699a29..96155608b2 100644 --- a/ospfd/ospf_opaque.h +++ b/ospfd/ospf_opaque.h @@ -41,9 +41,9 @@ #define LSID_OPAQUE_TYPE_MASK 0xff000000 /* 8 bits */ #define LSID_OPAQUE_ID_MASK 0x00ffffff /* 24 bits */ -#define GET_OPAQUE_TYPE(lsid) (((u_int32_t)(lsid)&LSID_OPAQUE_TYPE_MASK) >> 24) +#define GET_OPAQUE_TYPE(lsid) (((uint32_t)(lsid)&LSID_OPAQUE_TYPE_MASK) >> 24) -#define GET_OPAQUE_ID(lsid) ((u_int32_t)(lsid)&LSID_OPAQUE_ID_MASK) +#define GET_OPAQUE_ID(lsid) ((uint32_t)(lsid)&LSID_OPAQUE_ID_MASK) #define SET_OPAQUE_LSID(type, id) \ ((((unsigned)(type) << 24) & LSID_OPAQUE_TYPE_MASK) \ @@ -78,20 +78,20 @@ #define VALID_OPAQUE_INFO_LEN(lsahdr) \ ((ntohs((lsahdr)->length) >= sizeof(struct lsa_header)) \ - && ((ntohs((lsahdr)->length) % sizeof(u_int32_t)) == 0)) + && ((ntohs((lsahdr)->length) % sizeof(uint32_t)) == 0)) /* * Following section defines generic TLV (type, length, value) macros, * used for various LSA opaque usage e.g. Traffic Engineering. */ struct tlv_header { - u_int16_t type; /* Type of Value */ - u_int16_t length; /* Length of Value portion only, in bytes */ + uint16_t type; /* Type of Value */ + uint16_t length; /* Length of Value portion only, in bytes */ }; #define TLV_HDR_SIZE (sizeof(struct tlv_header)) -#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(u_int32_t))) +#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t))) #define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) @@ -126,7 +126,7 @@ extern int ospf_opaque_type11_lsa_init(struct ospf *ospf); extern void ospf_opaque_type11_lsa_term(struct ospf *ospf); extern int ospf_register_opaque_functab( - u_char lsa_type, u_char opaque_type, + uint8_t lsa_type, uint8_t opaque_type, int (*new_if_hook)(struct interface *ifp), int (*del_if_hook)(struct interface *ifp), void (*ism_change_hook)(struct ospf_interface *oi, int old_status), @@ -139,7 +139,7 @@ extern int ospf_register_opaque_functab( struct ospf_lsa *(*lsa_refresher)(struct ospf_lsa *lsa), int (*new_lsa_hook)(struct ospf_lsa *lsa), int (*del_lsa_hook)(struct ospf_lsa *lsa)); -extern void ospf_delete_opaque_functab(u_char lsa_type, u_char opaque_type); +extern void ospf_delete_opaque_functab(uint8_t lsa_type, uint8_t opaque_type); extern int ospf_opaque_new_if(struct interface *ifp); extern int ospf_opaque_del_if(struct interface *ifp); @@ -149,7 +149,7 @@ extern void ospf_opaque_config_write_router(struct vty *vty, struct ospf *ospf); extern void ospf_opaque_config_write_if(struct vty *vty, struct interface *ifp); extern void ospf_opaque_config_write_debug(struct vty *vty); extern void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa); -extern void ospf_opaque_lsa_dump(struct stream *s, u_int16_t length); +extern void ospf_opaque_lsa_dump(struct stream *s, uint16_t length); extern void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *init_delay); @@ -158,8 +158,8 @@ extern struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *lsa, extern struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa); extern void ospf_opaque_lsa_reoriginate_schedule(void *lsa_type_dependent, - u_char lsa_type, - u_char opaque_type); + uint8_t lsa_type, + uint8_t opaque_type); extern void ospf_opaque_lsa_refresh_schedule(struct ospf_lsa *lsa); extern void ospf_opaque_lsa_flush_schedule(struct ospf_lsa *lsa); diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 7906794411..1f67c0d5ad 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -81,7 +81,7 @@ const struct message ospf_packet_type_str[] = { /* Minimum (besides OSPF_HEADER_SIZE) lengths for OSPF packets of particular types, offset is the "type" field of a packet. */ -static const u_int16_t ospf_packet_minlen[] = { +static const uint16_t ospf_packet_minlen[] = { 0, OSPF_HELLO_MIN_SIZE, OSPF_DB_DESC_MIN_SIZE, @@ -92,7 +92,7 @@ static const u_int16_t ospf_packet_minlen[] = { /* Minimum (besides OSPF_LSA_HEADER_SIZE) lengths for LSAs of particular types, offset is the "LSA type" field. */ -static const u_int16_t ospf_lsa_minlen[] = { +static const uint16_t ospf_lsa_minlen[] = { 0, OSPF_ROUTER_LSA_MIN_SIZE, OSPF_NETWORK_LSA_MIN_SIZE, @@ -292,7 +292,7 @@ struct ospf_packet *ospf_packet_dup(struct ospf_packet *op) /* XXX size_t */ zlog_warn( "ospf_packet_dup stream %lu ospf_packet %u size mismatch", - (u_long)STREAM_SIZE(op->s), op->length); + (unsigned long)STREAM_SIZE(op->s), op->length); /* Reserve space for MD5 authentication that may be added later. */ new = ospf_packet_new(stream_get_endp(op->s) + OSPF_AUTH_MD5_SIZE); @@ -334,7 +334,7 @@ static int ospf_check_md5_digest(struct ospf_interface *oi, unsigned char digest[OSPF_AUTH_MD5_SIZE]; struct crypt_key *ck; struct ospf_neighbor *nbr; - u_int16_t length = ntohs(ospfh->length); + uint16_t length = ntohs(ospfh->length); /* Get secret key. */ ck = ospf_crypt_key_lookup(OSPF_IF_PARAM(oi, auth_crypt), @@ -387,9 +387,9 @@ static int ospf_make_md5_digest(struct ospf_interface *oi, unsigned char digest[OSPF_AUTH_MD5_SIZE] = {0}; MD5_CTX ctx; void *ibuf; - u_int32_t t; + uint32_t t; struct crypt_key *ck; - const u_int8_t *auth_key; + const uint8_t *auth_key; ibuf = STREAM_DATA(op->s); ospfh = (struct ospf_header *)ibuf; @@ -411,7 +411,7 @@ static int ospf_make_md5_digest(struct ospf_interface *oi, /* Get MD5 Authentication key from auth_key list. */ if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) - auth_key = (const u_int8_t *)digest; + auth_key = (const uint8_t *)digest; else { ck = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); auth_key = ck->auth_key; @@ -434,7 +434,7 @@ static int ospf_make_md5_digest(struct ospf_interface *oi, /* XXX size_t */ zlog_warn( "ospf_make_md5_digest: length mismatch stream %lu ospf_packet %u", - (u_long)stream_get_endp(op->s), op->length); + (unsigned long)stream_get_endp(op->s), op->length); return OSPF_AUTH_MD5_SIZE; } @@ -549,10 +549,10 @@ int ospf_ls_ack_timer(struct thread *thread) #ifdef WANT_OSPF_WRITE_FRAGMENT static void ospf_write_frags(int fd, struct ospf_packet *op, struct ip *iph, struct msghdr *msg, unsigned int maxdatasize, - unsigned int mtu, int flags, u_char type) + unsigned int mtu, int flags, uint8_t type) { #define OSPF_WRITE_FRAG_SHIFT 3 - u_int16_t offset; + uint16_t offset; struct iovec *iovp; int ret; @@ -637,13 +637,13 @@ static int ospf_write(struct thread *thread) struct ip iph; struct msghdr msg; struct iovec iov[2]; - u_char type; + uint8_t type; int ret; int flags = 0; struct listnode *node; #ifdef WANT_OSPF_WRITE_FRAGMENT - static u_int16_t ipid = 0; - u_int16_t maxdatasize; + static uint16_t ipid = 0; + uint16_t maxdatasize; #endif /* WANT_OSPF_WRITE_FRAGMENT */ #define OSPF_WRITE_IPHL_SHIFT 2 int pkt_count = 0; @@ -1109,7 +1109,7 @@ static void ospf_db_desc_save_current(struct ospf_neighbor *nbr, /* Process rest of DD packet. */ static void ospf_db_desc_proc(struct stream *s, struct ospf_interface *oi, struct ospf_neighbor *nbr, - struct ospf_db_desc *dd, u_int16_t size) + struct ospf_db_desc *dd, uint16_t size) { struct ospf_lsa *new, *find; struct lsa_header *lsah; @@ -1258,7 +1258,7 @@ static int ospf_db_desc_is_dup(struct ospf_db_desc *dd, /* OSPF Database Description message read -- RFC2328 Section 10.6. */ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh, struct stream *s, struct ospf_interface *oi, - u_int16_t size) + uint16_t size) { struct ospf_db_desc *dd; struct ospf_neighbor *nbr; @@ -1549,10 +1549,10 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh, /* OSPF Link State Request Read -- RFC2328 Section 10.7. */ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh, struct stream *s, struct ospf_interface *oi, - u_int16_t size) + uint16_t size) { struct ospf_neighbor *nbr; - u_int32_t ls_type; + uint32_t ls_type; struct in_addr ls_id; struct in_addr adv_router; struct ospf_lsa *find; @@ -1651,8 +1651,8 @@ static struct list *ospf_ls_upd_list_lsa(struct ospf_neighbor *nbr, struct stream *s, struct ospf_interface *oi, size_t size) { - u_int16_t count, sum; - u_int32_t length; + uint16_t count, sum; + uint32_t length; struct lsa_header *lsah; struct ospf_lsa *lsa; struct list *lsas; @@ -1789,7 +1789,7 @@ static void ospf_upd_list_clean(struct list *lsas) /* OSPF Link State Update message read -- RFC2328 Section 13. */ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph, struct ospf_header *ospfh, struct stream *s, - struct ospf_interface *oi, u_int16_t size) + struct ospf_interface *oi, uint16_t size) { struct ospf_neighbor *nbr; struct list *lsas; @@ -2190,7 +2190,7 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph, /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */ static void ospf_ls_ack(struct ip *iph, struct ospf_header *ospfh, struct stream *s, struct ospf_interface *oi, - u_int16_t size) + uint16_t size) { struct ospf_neighbor *nbr; @@ -2254,7 +2254,7 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd, { int ret; struct ip *iph; - u_int16_t ip_len; + uint16_t ip_len; ifindex_t ifindex = 0; struct iovec iov; /* Header and data both require alignment. */ @@ -2277,7 +2277,7 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd, zlog_warn( "ospf_recv_packet: discarding runt packet of length %d " "(ip header size is %u)", - ret, (u_int)sizeof(iph)); + ret, (unsigned int)sizeof(iph)); return NULL; } @@ -2419,8 +2419,8 @@ static int ospf_check_network_mask(struct ospf_interface *oi, static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh) { struct crypt_key *ck; - u_int16_t iface_auth_type; - u_int16_t pkt_auth_type = ntohs(ospfh->auth_type); + uint16_t iface_auth_type; + uint16_t pkt_auth_type = ntohs(ospfh->auth_type); switch (pkt_auth_type) { case OSPF_AUTH_NULL: /* RFC2328 D.5.1 */ @@ -2513,15 +2513,15 @@ static int ospf_check_auth(struct ospf_interface *oi, struct ospf_header *ospfh) static int ospf_check_sum(struct ospf_header *ospfh) { - u_int32_t ret; - u_int16_t sum; + uint32_t ret; + uint16_t sum; /* clear auth_data for checksum. */ memset(ospfh->u.auth_data, 0, OSPF_AUTH_SIMPLE_SIZE); /* keep checksum and clear. */ sum = ospfh->checksum; - memset(&ospfh->checksum, 0, sizeof(u_int16_t)); + memset(&ospfh->checksum, 0, sizeof(uint16_t)); /* calculate checksum. */ ret = in_cksum(ospfh, ntohs(ospfh->length)); @@ -2538,8 +2538,8 @@ static int ospf_check_sum(struct ospf_header *ospfh) /* Verify, that given link/TOS records are properly sized/aligned and match Router-LSA "# links" and "# TOS" fields as specified in RFC2328 A.4.2. */ static unsigned ospf_router_lsa_links_examin(struct router_lsa_link *link, - u_int16_t linkbytes, - const u_int16_t num_links) + uint16_t linkbytes, + const uint16_t num_links) { unsigned counted_links = 0, thislinklen; @@ -2567,8 +2567,8 @@ static unsigned ospf_router_lsa_links_examin(struct router_lsa_link *link, /* Verify, that the given LSA is properly sized/aligned (including type-specific minimum length constraint). */ -static unsigned ospf_lsa_examin(struct lsa_header *lsah, const u_int16_t lsalen, - const u_char headeronly) +static unsigned ospf_lsa_examin(struct lsa_header *lsah, const uint16_t lsalen, + const uint8_t headeronly) { unsigned ret; struct router_lsa *rlsa; @@ -2651,16 +2651,16 @@ static unsigned ospf_lsa_examin(struct lsa_header *lsah, const u_int16_t lsalen, of deeper-level checks. */ static unsigned ospf_lsaseq_examin(struct lsa_header *lsah, /* start of buffered data */ - size_t length, const u_char headeronly, + size_t length, const uint8_t headeronly, /* When declared_num_lsas is not 0, compare it to the real number of LSAs and treat the difference as an error. */ - const u_int32_t declared_num_lsas) + const uint32_t declared_num_lsas) { - u_int32_t counted_lsas = 0; + uint32_t counted_lsas = 0; while (length) { - u_int16_t lsalen; + uint16_t lsalen; if (length < OSPF_LSA_HEADER_SIZE) { if (IS_DEBUG_OSPF_PACKET(0, RECV)) zlog_debug( @@ -2726,7 +2726,7 @@ ospf_lsaseq_examin(struct lsa_header *lsah, /* start of buffered data */ static unsigned ospf_packet_examin(struct ospf_header *oh, const unsigned bytesonwire) { - u_int16_t bytesdeclared, bytesauth; + uint16_t bytesdeclared, bytesauth; unsigned ret; struct ospf_ls_update *lsupd; @@ -2883,7 +2883,7 @@ int ospf_read(struct thread *thread) struct ospf_interface *oi; struct ip *iph; struct ospf_header *ospfh; - u_int16_t length; + uint16_t length; struct interface *ifp = NULL; struct connected *c; @@ -3114,8 +3114,8 @@ static void ospf_make_header(int type, struct ospf_interface *oi, ospfh = (struct ospf_header *)STREAM_DATA(s); - ospfh->version = (u_char)OSPF_VERSION; - ospfh->type = (u_char)type; + ospfh->version = (uint8_t)OSPF_VERSION; + ospfh->type = (uint8_t)type; ospfh->router_id = oi->ospf->router_id; @@ -3168,7 +3168,7 @@ static int ospf_make_auth(struct ospf_interface *oi, struct ospf_header *ospfh) /* Fill rest of OSPF header. */ static void ospf_fill_header(struct ospf_interface *oi, struct stream *s, - u_int16_t length) + uint16_t length) { struct ospf_header *ospfh; @@ -3191,7 +3191,7 @@ static int ospf_make_hello(struct ospf_interface *oi, struct stream *s) { struct ospf_neighbor *nbr; struct route_node *rn; - u_int16_t length = OSPF_HELLO_MIN_SIZE; + uint16_t length = OSPF_HELLO_MIN_SIZE; struct in_addr mask; unsigned long p; int flag = 0; @@ -3279,8 +3279,8 @@ static int ospf_make_db_desc(struct ospf_interface *oi, struct ospf_neighbor *nbr, struct stream *s) { struct ospf_lsa *lsa; - u_int16_t length = OSPF_DB_DESC_MIN_SIZE; - u_char options; + uint16_t length = OSPF_DB_DESC_MIN_SIZE; + uint8_t options; unsigned long pp; int i; struct ospf_lsdb *lsdb; @@ -3328,7 +3328,7 @@ static int ospf_make_db_desc(struct ospf_interface *oi, if (!CHECK_FLAG(lsa->flags, OSPF_LSA_DISCARD)) { struct lsa_header *lsah; - u_int16_t ls_age; + uint16_t ls_age; /* DD packet overflows interface MTU. */ if (length + OSPF_LSA_HEADER_SIZE @@ -3370,7 +3370,7 @@ static int ospf_make_db_desc(struct ospf_interface *oi, return length; } -static int ospf_make_ls_req_func(struct stream *s, u_int16_t *length, +static int ospf_make_ls_req_func(struct stream *s, uint16_t *length, unsigned long delta, struct ospf_neighbor *nbr, struct ospf_lsa *lsa) { @@ -3396,7 +3396,7 @@ static int ospf_make_ls_req_func(struct stream *s, u_int16_t *length, static int ospf_make_ls_req(struct ospf_neighbor *nbr, struct stream *s) { struct ospf_lsa *lsa; - u_int16_t length = OSPF_LS_REQ_MIN_SIZE; + uint16_t length = OSPF_LS_REQ_MIN_SIZE; unsigned long delta = stream_get_endp(s) + 12; struct route_table *table; struct route_node *rn; @@ -3433,7 +3433,7 @@ static int ospf_make_ls_upd(struct ospf_interface *oi, struct list *update, { struct ospf_lsa *lsa; struct listnode *node; - u_int16_t length = 0; + uint16_t length = 0; unsigned int size_noauth; unsigned long delta = stream_get_endp(s); unsigned long pp; @@ -3451,7 +3451,7 @@ static int ospf_make_ls_upd(struct ospf_interface *oi, struct list *update, while ((node = listhead(update)) != NULL) { struct lsa_header *lsah; - u_int16_t ls_age; + uint16_t ls_age; if (IS_DEBUG_OSPF_EVENT) zlog_debug("ospf_make_ls_upd: List Iteration %d", @@ -3498,7 +3498,7 @@ static int ospf_make_ls_ack(struct ospf_interface *oi, struct list *ack, struct stream *s) { struct listnode *node, *nnode; - u_int16_t length = OSPF_LS_ACK_MIN_SIZE; + uint16_t length = OSPF_LS_ACK_MIN_SIZE; unsigned long delta = stream_get_endp(s) + 24; struct ospf_lsa *lsa; @@ -3521,7 +3521,7 @@ static int ospf_make_ls_ack(struct ospf_interface *oi, struct list *ack, static void ospf_hello_send_sub(struct ospf_interface *oi, in_addr_t addr) { struct ospf_packet *op; - u_int16_t length = OSPF_HEADER_SIZE; + uint16_t length = OSPF_HEADER_SIZE; op = ospf_packet_new(oi->ifp->mtu); @@ -3695,7 +3695,7 @@ void ospf_db_desc_send(struct ospf_neighbor *nbr) { struct ospf_interface *oi; struct ospf_packet *op; - u_int16_t length = OSPF_HEADER_SIZE; + uint16_t length = OSPF_HEADER_SIZE; oi = nbr->oi; op = ospf_packet_new(oi->ifp->mtu); @@ -3751,7 +3751,7 @@ void ospf_ls_req_send(struct ospf_neighbor *nbr) { struct ospf_interface *oi; struct ospf_packet *op; - u_int16_t length = OSPF_HEADER_SIZE; + uint16_t length = OSPF_HEADER_SIZE; oi = nbr->oi; op = ospf_packet_new(oi->ifp->mtu); @@ -3890,7 +3890,7 @@ static void ospf_ls_upd_queue_send(struct ospf_interface *oi, int send_lsupd_now) { struct ospf_packet *op; - u_int16_t length = OSPF_HEADER_SIZE; + uint16_t length = OSPF_HEADER_SIZE; if (IS_DEBUG_OSPF_EVENT) zlog_debug("listcount = %d, [%s]dst %s", listcount(update), @@ -4058,7 +4058,7 @@ static void ospf_ls_ack_send_list(struct ospf_interface *oi, struct list *ack, struct in_addr dst) { struct ospf_packet *op; - u_int16_t length = OSPF_HEADER_SIZE; + uint16_t length = OSPF_HEADER_SIZE; op = ospf_packet_new(oi->ifp->mtu); diff --git a/ospfd/ospf_packet.h b/ospfd/ospf_packet.h index 78b2b81e50..a508727968 100644 --- a/ospfd/ospf_packet.h +++ b/ospfd/ospf_packet.h @@ -59,7 +59,7 @@ struct ospf_packet { struct in_addr dst; /* OSPF packet length. */ - u_int16_t length; + uint16_t length; }; /* OSPF packet queue structure. */ @@ -72,23 +72,23 @@ struct ospf_fifo { /* OSPF packet header structure. */ struct ospf_header { - u_char version; /* OSPF Version. */ - u_char type; /* Packet Type. */ - u_int16_t length; /* Packet Length. */ + uint8_t version; /* OSPF Version. */ + uint8_t type; /* Packet Type. */ + uint16_t length; /* Packet Length. */ struct in_addr router_id; /* Router ID. */ struct in_addr area_id; /* Area ID. */ - u_int16_t checksum; /* Check Sum. */ - u_int16_t auth_type; /* Authentication Type. */ + uint16_t checksum; /* Check Sum. */ + uint16_t auth_type; /* Authentication Type. */ /* Authentication Data. */ union { /* Simple Authentication. */ - u_char auth_data[OSPF_AUTH_SIMPLE_SIZE]; + uint8_t auth_data[OSPF_AUTH_SIMPLE_SIZE]; /* Cryptographic Authentication. */ struct { - u_int16_t zero; /* Should be 0. */ - u_char key_id; /* Key ID. */ - u_char auth_data_len; /* Auth Data Length. */ - u_int32_t crypt_seqnum; /* Cryptographic Sequence + uint16_t zero; /* Should be 0. */ + uint8_t key_id; /* Key ID. */ + uint8_t auth_data_len; /* Auth Data Length. */ + uint32_t crypt_seqnum; /* Cryptographic Sequence Number. */ } crypt; } u; @@ -97,10 +97,10 @@ struct ospf_header { /* OSPF Hello body format. */ struct ospf_hello { struct in_addr network_mask; - u_int16_t hello_interval; - u_char options; - u_char priority; - u_int32_t dead_interval; + uint16_t hello_interval; + uint8_t options; + uint8_t priority; + uint32_t dead_interval; struct in_addr d_router; struct in_addr bd_router; struct in_addr neighbors[1]; @@ -108,14 +108,14 @@ struct ospf_hello { /* OSPF Database Description body format. */ struct ospf_db_desc { - u_int16_t mtu; - u_char options; - u_char flags; - u_int32_t dd_seqnum; + uint16_t mtu; + uint8_t options; + uint8_t flags; + uint32_t dd_seqnum; }; struct ospf_ls_update { - u_int32_t num_lsas; + uint32_t num_lsas; }; /* Macros. */ diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index e1d3e925ce..786b199029 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -90,13 +90,13 @@ struct ospf_ri_sr_info { struct ospf_router_info { bool enabled; - u_int8_t registered; - u_int8_t scope; + uint8_t registered; + uint8_t scope; /* Flags to manage this router information. */ #define RIFLG_LSA_ENGAGED 0x1 #define RIFLG_LSA_FORCED_REFRESH 0x2 - u_int32_t flags; + uint32_t flags; /* area pointer if flooding is Type 10 Null if flooding is AS scope */ struct ospf_area *area; @@ -163,7 +163,7 @@ int ospf_router_info_init(void) return 0; } -static int ospf_router_info_register(u_int8_t scope) +static int ospf_router_info_register(uint8_t scope) { int rc = 0; @@ -260,7 +260,7 @@ struct scope_info ospf_router_info_get_flooding_scope(void) *------------------------------------------------------------------------*/ static void set_router_info_capabilities(struct ri_tlv_router_cap *ric, - u_int32_t cap) + uint32_t cap) { ric->header.type = htons(RI_TLV_CAPABILITIES); ric->header.length = htons(RI_TLV_LENGTH); @@ -270,7 +270,7 @@ static void set_router_info_capabilities(struct ri_tlv_router_cap *ric, static int set_pce_header(struct ospf_pce_info *pce) { - u_int16_t length = 0; + uint16_t length = 0; struct listnode *node; struct ri_pce_subtlv_domain *domain; struct ri_pce_subtlv_neighbor *neighbor; @@ -326,7 +326,7 @@ static void set_pce_address(struct in_addr ipv4, struct ospf_pce_info *pce) return; } -static void set_pce_path_scope(u_int32_t scope, struct ospf_pce_info *pce) +static void set_pce_path_scope(uint32_t scope, struct ospf_pce_info *pce) { /* Set PCE Scope */ @@ -337,7 +337,7 @@ static void set_pce_path_scope(u_int32_t scope, struct ospf_pce_info *pce) return; } -static void set_pce_domain(u_int16_t type, u_int32_t domain, +static void set_pce_domain(uint16_t type, uint32_t domain, struct ospf_pce_info *pce) { @@ -358,7 +358,7 @@ static void set_pce_domain(u_int16_t type, u_int32_t domain, return; } -static void unset_pce_domain(u_int16_t type, u_int32_t domain, +static void unset_pce_domain(uint16_t type, uint32_t domain, struct ospf_pce_info *pce) { struct listnode *node; @@ -387,7 +387,7 @@ static void unset_pce_domain(u_int16_t type, u_int32_t domain, } } -static void set_pce_neighbor(u_int16_t type, u_int32_t domain, +static void set_pce_neighbor(uint16_t type, uint32_t domain, struct ospf_pce_info *pce) { @@ -408,7 +408,7 @@ static void set_pce_neighbor(u_int16_t type, u_int32_t domain, return; } -static void unset_pce_neighbor(u_int16_t type, u_int32_t domain, +static void unset_pce_neighbor(uint16_t type, uint32_t domain, struct ospf_pce_info *pce) { struct listnode *node; @@ -438,7 +438,7 @@ static void unset_pce_neighbor(u_int16_t type, u_int32_t domain, } } -static void set_pce_cap_flag(u_int32_t cap, struct ospf_pce_info *pce) +static void set_pce_cap_flag(uint32_t cap, struct ospf_pce_info *pce) { /* Set PCE Capabilities flag */ @@ -529,7 +529,7 @@ static void unset_param(struct tlv_header *tlv) static void initialize_params(struct ospf_router_info *ori) { - u_int32_t cap = 0; + uint32_t cap = 0; struct ospf *top; /* @@ -735,10 +735,10 @@ static struct ospf_lsa *ospf_router_info_lsa_new() struct stream *s; struct lsa_header *lsah; struct ospf_lsa *new = NULL; - u_char options, lsa_type; + uint8_t options, lsa_type; struct in_addr lsa_id; - u_int32_t tmp; - u_int16_t length; + uint32_t tmp; + uint16_t length; /* Create a stream for LSA. */ if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { @@ -974,7 +974,7 @@ static void ospf_router_info_lsa_schedule(enum lsa_opcode opcode) struct ospf_lsa lsa; struct lsa_header lsah; struct ospf *top; - u_int32_t tmp; + uint32_t tmp; memset(&lsa, 0, sizeof(lsa)); memset(&lsah, 0, sizeof(lsah)); @@ -1075,7 +1075,7 @@ static int ospf_router_info_lsa_update(struct ospf_lsa *lsa) * Followings are vty session control functions. *------------------------------------------------------------------------*/ -static u_int16_t show_vty_router_cap(struct vty *vty, struct tlv_header *tlvh) +static uint16_t show_vty_router_cap(struct vty *vty, struct tlv_header *tlvh) { struct ri_tlv_router_cap *top = (struct ri_tlv_router_cap *)tlvh; @@ -1088,8 +1088,8 @@ static u_int16_t show_vty_router_cap(struct vty *vty, struct tlv_header *tlvh) return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_subtlv_address(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_pce_subtlv_address(struct vty *vty, + struct tlv_header *tlvh) { struct ri_pce_subtlv_address *top = (struct ri_pce_subtlv_address *)tlvh; @@ -1114,8 +1114,8 @@ static u_int16_t show_vty_pce_subtlv_address(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_subtlv_path_scope(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_pce_subtlv_path_scope(struct vty *vty, + struct tlv_header *tlvh) { struct ri_pce_subtlv_path_scope *top = (struct ri_pce_subtlv_path_scope *)tlvh; @@ -1128,8 +1128,8 @@ static u_int16_t show_vty_pce_subtlv_path_scope(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_subtlv_domain(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_pce_subtlv_domain(struct vty *vty, + struct tlv_header *tlvh) { struct ri_pce_subtlv_domain *top = (struct ri_pce_subtlv_domain *)tlvh; struct in_addr tmp; @@ -1150,8 +1150,8 @@ static u_int16_t show_vty_pce_subtlv_domain(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_subtlv_neighbor(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_pce_subtlv_neighbor(struct vty *vty, + struct tlv_header *tlvh) { struct ri_pce_subtlv_neighbor *top = @@ -1176,8 +1176,8 @@ static u_int16_t show_vty_pce_subtlv_neighbor(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_subtlv_cap_flag(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_pce_subtlv_cap_flag(struct vty *vty, + struct tlv_header *tlvh) { struct ri_pce_subtlv_cap_flag *top = (struct ri_pce_subtlv_cap_flag *)tlvh; @@ -1192,7 +1192,7 @@ static u_int16_t show_vty_pce_subtlv_cap_flag(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) +static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) { if (vty != NULL) vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n", @@ -1204,11 +1204,11 @@ static u_int16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_info(struct vty *vty, struct tlv_header *ri, - uint32_t total) +static uint16_t show_vty_pce_info(struct vty *vty, struct tlv_header *ri, + uint32_t total) { struct tlv_header *tlvh; - u_int16_t sum = 0; + uint16_t sum = 0; for (tlvh = ri; sum < total; tlvh = TLV_HDR_NEXT(tlvh)) { switch (ntohs(tlvh->type)) { @@ -1332,7 +1332,7 @@ static void ospf_router_info_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct lsa_header *lsah = (struct lsa_header *)lsa->data; struct tlv_header *tlvh; - u_int16_t length = 0, sum = 0; + uint16_t length = 0, sum = 0; /* Initialize TLV browsing */ length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE; @@ -1442,7 +1442,7 @@ DEFUN (router_info, int idx_ipv4 = 2; char *area = (argc == 3) ? argv[idx_ipv4]->arg : NULL; - u_int8_t scope; + uint8_t scope; if (OspfRI.enabled) return CMD_SUCCESS; diff --git a/ospfd/ospf_ri.h b/ospfd/ospf_ri.h index 39ebb72009..26bcc1b62a 100644 --- a/ospfd/ospf_ri.h +++ b/ospfd/ospf_ri.h @@ -78,7 +78,7 @@ struct ri_tlv_router_cap { struct tlv_header header; /* Value length is 4 bytes. */ - u_int32_t value; + uint32_t value; }; /* Capabilities bits are left align */ @@ -108,10 +108,10 @@ struct ri_pce_subtlv_address { #define PCE_ADDRESS_LENGTH_IPV4 8 #define PCE_ADDRESS_LENGTH_IPV6 20 struct { - u_int16_t type; /* Address type: 1 = IPv4, 2 = IPv6 */ + uint16_t type; /* Address type: 1 = IPv4, 2 = IPv6 */ #define PCE_ADDRESS_TYPE_IPV4 1 #define PCE_ADDRESS_TYPE_IPV6 2 - u_int16_t reserved; + uint16_t reserved; struct in_addr value; /* PCE address */ } address; }; @@ -124,7 +124,7 @@ struct ri_pce_subtlv_path_scope { * L, R, Rd, S, Sd, Y, PrefL, PrefR, PrefS and PrefY bits: * see RFC5088 page 9 */ - u_int32_t value; + uint32_t value; }; /* PCE Domain Sub-TLV */ /* Optional */ @@ -135,18 +135,18 @@ struct ri_pce_subtlv_path_scope { struct ri_pce_subtlv_domain { struct tlv_header header; /* Type = 3; Length = 8 bytes. */ - u_int16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ - u_int16_t reserved; - u_int32_t value; + uint16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ + uint16_t reserved; + uint32_t value; }; /* PCE Neighbor Sub-TLV */ /* Mandatory if R or S bit is set */ #define RI_PCE_SUBTLV_NEIGHBOR 4 struct ri_pce_subtlv_neighbor { struct tlv_header header; /* Type = 4; Length = 8 bytes. */ - u_int16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ - u_int16_t reserved; - u_int32_t value; + uint16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ + uint16_t reserved; + uint32_t value; }; /* PCE Capabilities Flags Sub-TLV */ /* Optional */ @@ -164,7 +164,7 @@ struct ri_pce_subtlv_neighbor { struct ri_pce_subtlv_cap_flag { struct tlv_header header; /* Type = 5; Length = n x 4 bytes. */ - u_int32_t value; + uint32_t value; }; /* Structure to share flooding scope info for Segment Routing */ diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index 60a2e2d3e8..b964bbab74 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -449,7 +449,7 @@ void ospf_intra_add_stub(struct route_table *rt, struct router_lsa_link *link, struct vertex *v, struct ospf_area *area, int parent_is_root, int lsa_pos) { - u_int32_t cost; + uint32_t cost; struct route_node *rn; struct ospf_route * or ; struct prefix_ipv4 p; @@ -676,7 +676,7 @@ void ospf_route_table_dump(struct route_table *rt) static int ospf_asbr_route_cmp(struct ospf *ospf, struct ospf_route *r1, struct ospf_route *r2) { - u_char r1_type, r2_type; + uint8_t r1_type, r2_type; r1_type = r1->path_type; r2_type = r2->path_type; diff --git a/ospfd/ospf_route.h b/ospfd/ospf_route.h index 76df54fb3f..8cb5d32a8a 100644 --- a/ospfd/ospf_route.h +++ b/ospfd/ospf_route.h @@ -64,10 +64,10 @@ struct route_standard { int external_routing; /* Optional Capability. */ - u_char options; /* Get from LSA header. */ + uint8_t options; /* Get from LSA header. */ /* */ - u_char flags; /* From router-LSA */ + uint8_t flags; /* From router-LSA */ }; struct route_external { @@ -75,10 +75,10 @@ struct route_external { struct ospf_lsa *origin; /* Link State Cost Type2. */ - u_int32_t type2_cost; + uint32_t type2_cost; /* Tag value. */ - u_int32_t tag; + uint32_t tag; /* ASBR route. */ struct ospf_route *asbr; @@ -86,7 +86,7 @@ struct route_external { struct ospf_route { /* Destination Type. */ - u_char type; + uint8_t type; /* Destination ID. */ /* i.e. Link State ID. */ struct in_addr id; @@ -95,13 +95,13 @@ struct ospf_route { struct in_addr mask; /* Only valid for networks. */ /* Path Type. */ - u_char path_type; + uint8_t path_type; /* List of Paths. */ struct list *paths; /* Link State Cost. */ - u_int32_t cost; /* i.e. metric. */ + uint32_t cost; /* i.e. metric. */ /* Route specific info. */ union { diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c index bec0ec039b..ca711aa42f 100644 --- a/ospfd/ospf_routemap.c +++ b/ospfd/ospf_routemap.c @@ -342,7 +342,7 @@ static struct route_map_rule_cmd route_match_tag_cmd = { struct ospf_metric { enum { metric_increment, metric_decrement, metric_absolute } type; bool used; - u_int32_t metric; + uint32_t metric; }; /* `set metric METRIC' */ @@ -382,7 +382,7 @@ static void *route_set_metric_compile(const char *arg) { struct ospf_metric *metric; - metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + metric = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); metric->used = false; if (all_digit(arg)) @@ -430,7 +430,7 @@ static route_map_result_t route_set_metric_type(void *rule, route_map_object_t type, void *object) { - u_int32_t *metric_type; + uint32_t *metric_type; struct external_info *ei; if (type == RMAP_OSPF) { @@ -447,9 +447,9 @@ static route_map_result_t route_set_metric_type(void *rule, /* set metric-type compilation. */ static void *route_set_metric_type_compile(const char *arg) { - u_int32_t *metric_type; + uint32_t *metric_type; - metric_type = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + metric_type = XCALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); if (strcmp(arg, "type-1") == 0) *metric_type = EXTERNAL_METRIC_TYPE_1; else if (strcmp(arg, "type-2") == 0) diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index 28826254e4..7464b14b1f 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -220,32 +220,32 @@ static oid ospf_trap_oid[] = {OSPF2MIB, 16, 2}; /* Not reverse mappable! */ static struct in_addr ospf_empty_addr = {.s_addr = 0}; /* Hook functions. */ -static u_char *ospfGeneralGroup(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *ospfAreaEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); -static u_char *ospfStubAreaEntry(struct variable *, oid *, size_t *, int, +static uint8_t *ospfGeneralGroup(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfLsdbEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); -static u_char *ospfAreaRangeEntry(struct variable *, oid *, size_t *, int, +static uint8_t *ospfAreaEntry(struct variable *, oid *, size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ospfStubAreaEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfHostEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); -static u_char *ospfIfEntry(struct variable *, oid *, size_t *, int, size_t *, - WriteMethod **); -static u_char *ospfIfMetricEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *ospfVirtIfEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *ospfNbrEntry(struct variable *, oid *, size_t *, int, size_t *, +static uint8_t *ospfLsdbEntry(struct variable *, oid *, size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ospfAreaRangeEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfHostEntry(struct variable *, oid *, size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ospfIfEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfVirtNbrEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); -static u_char *ospfExtLsdbEntry(struct variable *, oid *, size_t *, int, +static uint8_t *ospfIfMetricEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfVirtIfEntry(struct variable *, oid *, size_t *, int, size_t *, WriteMethod **); -static u_char *ospfAreaAggregateEntry(struct variable *, oid *, size_t *, int, - size_t *, WriteMethod **); +static uint8_t *ospfNbrEntry(struct variable *, oid *, size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ospfVirtNbrEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfExtLsdbEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); +static uint8_t *ospfAreaAggregateEntry(struct variable *, oid *, size_t *, int, + size_t *, WriteMethod **); static struct variable ospf_variables[] = { /* OSPF general variables */ @@ -526,9 +526,9 @@ static int ospf_admin_stat(struct ospf *ospf) return 0; } -static u_char *ospfGeneralGroup(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfGeneralGroup(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf *ospf; @@ -695,9 +695,9 @@ static struct ospf_area *ospfAreaLookup(struct variable *v, oid name[], return NULL; } -static u_char *ospfAreaEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfAreaEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_area *area; struct in_addr addr; @@ -834,9 +834,9 @@ static struct ospf_area *ospfStubAreaLookup(struct variable *v, oid name[], return NULL; } -static u_char *ospfStubAreaEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfStubAreaEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_area *area; struct in_addr addr; @@ -883,7 +883,7 @@ static u_char *ospfStubAreaEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static struct ospf_lsa *lsdb_lookup_next(struct ospf_area *area, u_char *type, +static struct ospf_lsa *lsdb_lookup_next(struct ospf_area *area, uint8_t *type, int type_next, struct in_addr *ls_id, int ls_id_next, struct in_addr *router_id, @@ -919,7 +919,7 @@ static struct ospf_lsa *lsdb_lookup_next(struct ospf_area *area, u_char *type, static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, size_t *length, struct in_addr *area_id, - u_char *type, struct in_addr *ls_id, + uint8_t *type, struct in_addr *ls_id, struct in_addr *router_id, int exact) { struct ospf *ospf; @@ -1057,14 +1057,14 @@ static struct ospf_lsa *ospfLsdbLookup(struct variable *v, oid *name, return NULL; } -static u_char *ospfLsdbEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfLsdbEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_lsa *lsa; struct lsa_header *lsah; struct in_addr area_id; - u_char type; + uint8_t type; struct in_addr ls_id; struct in_addr router_id; struct ospf *ospf; @@ -1118,7 +1118,7 @@ static u_char *ospfLsdbEntry(struct variable *v, oid *name, size_t *length, break; case OSPFLSDBADVERTISEMENT: /* 8 */ *var_len = ntohs(lsah->length); - return (u_char *)lsah; + return (uint8_t *)lsah; break; default: return NULL; @@ -1222,9 +1222,9 @@ static struct ospf_area_range *ospfAreaRangeLookup(struct variable *v, return NULL; } -static u_char *ospfAreaRangeEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfAreaRangeEntry(struct variable *v, oid *name, + size_t *length, int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_area_range *range; struct in_addr area_id; @@ -1329,9 +1329,9 @@ static struct ospf_nbr_nbma *ospfHostLookup(struct variable *v, oid *name, return NULL; } -static u_char *ospfHostEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfHostEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_nbr_nbma *nbr_nbma; struct ospf_interface *oi; @@ -1654,9 +1654,9 @@ static struct ospf_interface *ospfIfLookup(struct variable *v, oid *name, return NULL; } -static u_char *ospfIfEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfIfEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { ifindex_t ifindex; struct in_addr ifaddr; @@ -1734,7 +1734,7 @@ static u_char *ospfIfEntry(struct variable *v, oid *name, size_t *length, break; case OSPFIFAUTHKEY: /* 16 */ *var_len = 0; - return (u_char *)OSPF_IF_PARAM(oi, auth_simple); + return (uint8_t *)OSPF_IF_PARAM(oi, auth_simple); break; case OSPFIFSTATUS: /* 17 */ return SNMP_INTEGER(SNMP_VALID); @@ -1821,9 +1821,9 @@ static struct ospf_interface *ospfIfMetricLookup(struct variable *v, oid *name, return NULL; } -static u_char *ospfIfMetricEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfIfMetricEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { /* Currently we support metric 1 only. */ ifindex_t ifindex; @@ -2014,9 +2014,9 @@ ospfVirtIfLookup(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfVirtIfEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfVirtIfEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_vl_data *vl_data; struct ospf_interface *oi; @@ -2065,7 +2065,7 @@ static u_char *ospfVirtIfEntry(struct variable *v, oid *name, size_t *length, break; case OSPFVIRTIFAUTHKEY: *var_len = 0; - return (u_char *)OSPF_IF_PARAM(oi, auth_simple); + return (uint8_t *)OSPF_IF_PARAM(oi, auth_simple); break; case OSPFVIRTIFSTATUS: return SNMP_INTEGER(SNMP_VALID); @@ -2215,7 +2215,7 @@ ospfNbrState OBJECT-TYPE full (8) } */ -static int32_t ospf_snmp_neighbor_state(u_char nst) +static int32_t ospf_snmp_neighbor_state(uint8_t nst) { switch (nst) { case NSM_Attempt: @@ -2237,9 +2237,9 @@ static int32_t ospf_snmp_neighbor_state(u_char nst) } } -static u_char *ospfNbrEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfNbrEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct in_addr nbr_addr; ifindex_t ifindex; @@ -2302,9 +2302,9 @@ static u_char *ospfNbrEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfVirtNbrEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfVirtNbrEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_vl_data *vl_data; struct in_addr area_id; @@ -2330,28 +2330,28 @@ static u_char *ospfVirtNbrEntry(struct variable *v, oid *name, size_t *length, /* Return the current value of the variable */ switch (v->magic) { case OSPFVIRTNBRAREA: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBRRTRID: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBRIPADDR: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBROPTIONS: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBRSTATE: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBREVENTS: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBRLSRETRANSQLEN: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFVIRTNBRHELLOSUPPRESSED: - return (u_char *)NULL; + return (uint8_t *)NULL; break; default: return NULL; @@ -2361,14 +2361,14 @@ static u_char *ospfVirtNbrEntry(struct variable *v, oid *name, size_t *length, } static struct ospf_lsa *ospfExtLsdbLookup(struct variable *v, oid *name, - size_t *length, u_char *type, + size_t *length, uint8_t *type, struct in_addr *ls_id, struct in_addr *router_id, int exact) { int first; oid *offset; int offsetlen; - u_char lsa_type; + uint8_t lsa_type; unsigned int len; struct ospf_lsa *lsa; struct ospf *ospf; @@ -2450,13 +2450,13 @@ static struct ospf_lsa *ospfExtLsdbLookup(struct variable *v, oid *name, return NULL; } -static u_char *ospfExtLsdbEntry(struct variable *v, oid *name, size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfExtLsdbEntry(struct variable *v, oid *name, size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct ospf_lsa *lsa; struct lsa_header *lsah; - u_char type; + uint8_t type; struct in_addr ls_id; struct in_addr router_id; struct ospf *ospf; @@ -2503,7 +2503,7 @@ static u_char *ospfExtLsdbEntry(struct variable *v, oid *name, size_t *length, break; case OSPFEXTLSDBADVERTISEMENT: *var_len = ntohs(lsah->length); - return (u_char *)lsah; + return (uint8_t *)lsah; break; default: return NULL; @@ -2512,10 +2512,10 @@ static u_char *ospfExtLsdbEntry(struct variable *v, oid *name, size_t *length, return NULL; } -static u_char *ospfAreaAggregateEntry(struct variable *v, oid *name, - size_t *length, int exact, - size_t *var_len, - WriteMethod **write_method) +static uint8_t *ospfAreaAggregateEntry(struct variable *v, oid *name, + size_t *length, int exact, + size_t *var_len, + WriteMethod **write_method) { if (smux_header_table(v, name, length, exact, var_len, write_method) == MATCH_FAILED) @@ -2524,22 +2524,22 @@ static u_char *ospfAreaAggregateEntry(struct variable *v, oid *name, /* Return the current value of the variable */ switch (v->magic) { case OSPFAREAAGGREGATEAREAID: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFAREAAGGREGATELSDBTYPE: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFAREAAGGREGATENET: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFAREAAGGREGATEMASK: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFAREAAGGREGATESTATUS: - return (u_char *)NULL; + return (uint8_t *)NULL; break; case OSPFAREAAGGREGATEEFFECT: - return (u_char *)NULL; + return (uint8_t *)NULL; break; default: return NULL; diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index f81210ffc9..c6c16e7169 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -360,23 +360,23 @@ static struct router_lsa_link * ospf_get_next_link(struct vertex *v, struct vertex *w, struct router_lsa_link *prev_link) { - u_char *p; - u_char *lim; - u_char lsa_type = LSA_LINK_TYPE_TRANSIT; + uint8_t *p; + uint8_t *lim; + uint8_t lsa_type = LSA_LINK_TYPE_TRANSIT; struct router_lsa_link *l; if (w->type == OSPF_VERTEX_ROUTER) lsa_type = LSA_LINK_TYPE_POINTOPOINT; if (prev_link == NULL) - p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; + p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; else { - p = (u_char *)prev_link; + p = (uint8_t *)prev_link; p += (OSPF_ROUTER_LSA_LINK_SIZE + (prev_link->m[0].tos_count * OSPF_ROUTER_LSA_TOS_SIZE)); } - lim = ((u_char *)v->lsa) + ntohs(v->lsa->length); + lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length); while (p < lim) { l = (struct router_lsa_link *)p; @@ -784,8 +784,8 @@ static void ospf_spf_next(struct vertex *v, struct ospf *ospf, struct ospf_area *area, struct pqueue *candidate) { struct ospf_lsa *w_lsa = NULL; - u_char *p; - u_char *lim; + uint8_t *p; + uint8_t *lim; struct router_lsa_link *l = NULL; struct in_addr *r; int type = 0, lsa_pos = -1, lsa_pos_next = 0; @@ -802,8 +802,8 @@ static void ospf_spf_next(struct vertex *v, struct ospf *ospf, v->type == OSPF_VERTEX_ROUTER ? "Router" : "Network", inet_ntoa(v->lsa->id)); - p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; - lim = ((u_char *)v->lsa) + ntohs(v->lsa->length); + p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; + lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length); while (p < lim) { struct vertex *w; @@ -1017,8 +1017,8 @@ static void ospf_spf_process_stubs(struct ospf_area *area, struct vertex *v, zlog_debug("ospf_process_stub():processing stubs for area %s", inet_ntoa(area->area_id)); if (v->type == OSPF_VERTEX_ROUTER) { - u_char *p; - u_char *lim; + uint8_t *p; + uint8_t *lim; struct router_lsa_link *l; struct router_lsa *rlsa; int lsa_pos = 0; @@ -1034,8 +1034,8 @@ static void ospf_spf_process_stubs(struct ospf_area *area, struct vertex *v, zlog_debug( "ospf_process_stubs(): we have %d links to process", ntohs(rlsa->links)); - p = ((u_char *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; - lim = ((u_char *)v->lsa) + ntohs(v->lsa->length); + p = ((uint8_t *)v->lsa) + OSPF_LSA_HEADER_SIZE + 4; + lim = ((uint8_t *)v->lsa) + ntohs(v->lsa->length); while (p < lim) { l = (struct router_lsa_link *)p; diff --git a/ospfd/ospf_spf.h b/ospfd/ospf_spf.h index e23f5941ff..85f42bcd18 100644 --- a/ospfd/ospf_spf.h +++ b/ospfd/ospf_spf.h @@ -33,12 +33,12 @@ /* A router or network in an area */ struct vertex { - u_char flags; - u_char type; /* copied from LSA header */ + uint8_t flags; + uint8_t type; /* copied from LSA header */ struct in_addr id; /* copied from LSA header */ struct lsa_header *lsa; /* Router or Network LSA */ int *stat; /* Link to LSA status. */ - u_int32_t distance; /* from root to this vertex */ + uint32_t distance; /* from root to this vertex */ struct list *parents; /* list of parents in SPF tree */ struct list *children; /* list of children in SPF tree*/ }; diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index c7bc129a4b..e5fc3e2954 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -888,7 +888,7 @@ static inline int sr_prefix_cmp(struct sr_prefix *srp1, struct sr_prefix *srp2) /* Update Segment Link of given Segment Routing Node */ static void update_ext_link_sid(struct sr_node *srn, struct sr_link *srl, - u_char lsa_flags) + uint8_t lsa_flags) { struct listnode *node; struct sr_link *lk; @@ -2313,7 +2313,7 @@ DEFUN (show_ip_opsf_srdb, int idx = 0; struct in_addr rid; struct sr_node *srn; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); json_object *json = NULL, *json_node_array = NULL; if (!OspfSR.enabled) { diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 276a5765f8..05adc5aa4f 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -122,7 +122,7 @@ int ospf_mpls_te_init(void) static int ospf_mpls_te_register(enum inter_as_mode mode) { int rc = 0; - u_int8_t scope; + uint8_t scope; if (OspfMplsTE.inter_as != Off) return rc; @@ -149,7 +149,7 @@ static int ospf_mpls_te_register(enum inter_as_mode mode) static int ospf_mpls_te_unregister() { - u_int8_t scope; + uint8_t scope; if (OspfMplsTE.inter_as == Off) return 0; @@ -197,9 +197,9 @@ static void del_mpls_te_link(void *val) return; } -static u_int32_t get_mpls_te_instance_value(void) +static uint32_t get_mpls_te_instance_value(void) { - static u_int32_t seqno = 0; + static uint32_t seqno = 0; if (seqno < MAX_LEGAL_TE_INSTANCE_NUM) seqno += 1; @@ -284,7 +284,7 @@ static void set_mpls_te_router_addr(struct in_addr ipv4) static void set_linkparams_link_header(struct mpls_te_link *lp) { - u_int16_t length = 0; + uint16_t length = 0; /* TE_LINK_SUBTLV_LINK_TYPE */ if (ntohs(lp->link_type.header.type) != 0) @@ -465,7 +465,7 @@ static void set_linkparams_rmtif_ipaddr(struct mpls_te_link *lp, } static void set_linkparams_te_metric(struct mpls_te_link *lp, - u_int32_t te_metric) + uint32_t te_metric) { lp->te_metric.header.type = htons(TE_LINK_SUBTLV_TE_METRIC); lp->te_metric.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE); @@ -500,7 +500,7 @@ static void set_linkparams_unrsv_bw(struct mpls_te_link *lp, int priority, } static void set_linkparams_rsc_clsclr(struct mpls_te_link *lp, - u_int32_t classcolor) + uint32_t classcolor) { lp->rsc_clsclr.header.type = htons(TE_LINK_SUBTLV_RSC_CLSCLR); lp->rsc_clsclr.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE); @@ -509,7 +509,7 @@ static void set_linkparams_rsc_clsclr(struct mpls_te_link *lp, } static void set_linkparams_inter_as(struct mpls_te_link *lp, - struct in_addr addr, u_int32_t as) + struct in_addr addr, uint32_t as) { /* Set the Remote ASBR IP address and then the associated AS number */ @@ -535,8 +535,8 @@ static void unset_linkparams_inter_as(struct mpls_te_link *lp) lp->ras.value = htonl(0); } -void set_linkparams_llri(struct mpls_te_link *lp, u_int32_t local, - u_int32_t remote) +void set_linkparams_llri(struct mpls_te_link *lp, uint32_t local, + uint32_t remote) { lp->llri.header.type = htons(TE_LINK_SUBTLV_LLRI); @@ -555,10 +555,10 @@ void set_linkparams_lrrid(struct mpls_te_link *lp, struct in_addr local, lp->lrrid.remote.s_addr = remote.s_addr; } -static void set_linkparams_av_delay(struct mpls_te_link *lp, u_int32_t delay, - u_char anormal) +static void set_linkparams_av_delay(struct mpls_te_link *lp, uint32_t delay, + uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ lp->av_delay.header.type = htons(TE_LINK_SUBTLV_AV_DELAY); lp->av_delay.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE); @@ -569,10 +569,10 @@ static void set_linkparams_av_delay(struct mpls_te_link *lp, u_int32_t delay, return; } -static void set_linkparams_mm_delay(struct mpls_te_link *lp, u_int32_t low, - u_int32_t high, u_char anormal) +static void set_linkparams_mm_delay(struct mpls_te_link *lp, uint32_t low, + uint32_t high, uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ lp->mm_delay.header.type = htons(TE_LINK_SUBTLV_MM_DELAY); lp->mm_delay.header.length = htons(TE_LINK_SUBTLV_MM_DELAY_SIZE); @@ -584,7 +584,7 @@ static void set_linkparams_mm_delay(struct mpls_te_link *lp, u_int32_t low, return; } -static void set_linkparams_delay_var(struct mpls_te_link *lp, u_int32_t jitter) +static void set_linkparams_delay_var(struct mpls_te_link *lp, uint32_t jitter) { /* Note that TLV-length field is the size of array. */ lp->delay_var.header.type = htons(TE_LINK_SUBTLV_DELAY_VAR); @@ -593,10 +593,10 @@ static void set_linkparams_delay_var(struct mpls_te_link *lp, u_int32_t jitter) return; } -static void set_linkparams_pkt_loss(struct mpls_te_link *lp, u_int32_t loss, - u_char anormal) +static void set_linkparams_pkt_loss(struct mpls_te_link *lp, uint32_t loss, + uint8_t anormal) { - u_int32_t tmp; + uint32_t tmp; /* Note that TLV-length field is the size of array. */ lp->pkt_loss.header.type = htons(TE_LINK_SUBTLV_PKT_LOSS); lp->pkt_loss.header.length = htons(TE_LINK_SUBTLV_DEF_SIZE); @@ -1145,10 +1145,10 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf, struct stream *s; struct lsa_header *lsah; struct ospf_lsa *new = NULL; - u_char options, lsa_type = 0; + uint8_t options, lsa_type = 0; struct in_addr lsa_id; - u_int32_t tmp; - u_int16_t length; + uint32_t tmp; + uint16_t length; /* Create a stream for LSA. */ if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { @@ -1515,7 +1515,7 @@ void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, enum lsa_opcode opcode) struct ospf_lsa lsa; struct lsa_header lsah; struct ospf *top; - u_int32_t tmp; + uint32_t tmp; memset(&lsa, 0, sizeof(lsa)); memset(&lsah, 0, sizeof(lsah)); @@ -1598,7 +1598,7 @@ void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, enum lsa_opcode opcode) * Followings are vty session control functions. *------------------------------------------------------------------------*/ -static u_int16_t show_vty_router_addr(struct vty *vty, struct tlv_header *tlvh) +static uint16_t show_vty_router_addr(struct vty *vty, struct tlv_header *tlvh) { struct te_tlv_router_addr *top = (struct te_tlv_router_addr *)tlvh; @@ -1610,7 +1610,7 @@ static u_int16_t show_vty_router_addr(struct vty *vty, struct tlv_header *tlvh) return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_header(struct vty *vty, struct tlv_header *tlvh) +static uint16_t show_vty_link_header(struct vty *vty, struct tlv_header *tlvh) { struct te_tlv_link *top = (struct te_tlv_link *)tlvh; @@ -1624,8 +1624,8 @@ static u_int16_t show_vty_link_header(struct vty *vty, struct tlv_header *tlvh) return TLV_HDR_SIZE; /* Here is special, not "TLV_SIZE". */ } -static u_int16_t show_vty_link_subtlv_link_type(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_link_type(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_link_type *top; const char *cp = "Unknown"; @@ -1651,8 +1651,8 @@ static u_int16_t show_vty_link_subtlv_link_type(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_link_id(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_link_id(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_link_id *top; @@ -1665,8 +1665,8 @@ static u_int16_t show_vty_link_subtlv_link_id(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_lclif_ipaddr *top; int i, n; @@ -1690,8 +1690,8 @@ static u_int16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_rmtif_ipaddr *top; int i, n; @@ -1714,24 +1714,24 @@ static u_int16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_te_metric(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_te_metric(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_te_metric *top; top = (struct te_link_subtlv_te_metric *)tlvh; if (vty != NULL) vty_out(vty, " Traffic Engineering Metric: %u\n", - (u_int32_t)ntohl(top->value)); + (uint32_t)ntohl(top->value)); else zlog_debug(" Traffic Engineering Metric: %u", - (u_int32_t)ntohl(top->value)); + (uint32_t)ntohl(top->value)); return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_max_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_max_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_max_bw *top; float fval; @@ -1747,8 +1747,8 @@ static u_int16_t show_vty_link_subtlv_max_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_max_rsv_bw *top; float fval; @@ -1766,8 +1766,8 @@ static u_int16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_unrsv_bw *top; float fval1, fval2; @@ -1797,24 +1797,24 @@ static u_int16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_rsc_clsclr *top; top = (struct te_link_subtlv_rsc_clsclr *)tlvh; if (vty != NULL) vty_out(vty, " Resource class/color: 0x%x\n", - (u_int32_t)ntohl(top->value)); + (uint32_t)ntohl(top->value)); else zlog_debug(" Resource Class/Color: 0x%x", - (u_int32_t)ntohl(top->value)); + (uint32_t)ntohl(top->value)); return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_lrrid(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_lrrid(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_lrrid *top; @@ -1835,8 +1835,8 @@ static u_int16_t show_vty_link_subtlv_lrrid(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_llri(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_llri(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_llri *top; @@ -1844,21 +1844,21 @@ static u_int16_t show_vty_link_subtlv_llri(struct vty *vty, if (vty != NULL) { vty_out(vty, " Link Local ID: %d\n", - (u_int32_t)ntohl(top->local)); + (uint32_t)ntohl(top->local)); vty_out(vty, " Link Remote ID: %d\n", - (u_int32_t)ntohl(top->remote)); + (uint32_t)ntohl(top->remote)); } else { zlog_debug(" Link Local ID: %d", - (u_int32_t)ntohl(top->local)); + (uint32_t)ntohl(top->local)); zlog_debug(" Link Remote ID: %d", - (u_int32_t)ntohl(top->remote)); + (uint32_t)ntohl(top->remote)); } return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_rip(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_rip(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_rip *top; @@ -1874,8 +1874,8 @@ static u_int16_t show_vty_link_subtlv_rip(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_ras(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_ras(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_ras *top; @@ -1891,16 +1891,16 @@ static u_int16_t show_vty_link_subtlv_ras(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_av_delay(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_av_delay(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_av_delay *top; - u_int32_t delay; - u_int32_t anomalous; + uint32_t delay; + uint32_t anomalous; top = (struct te_link_subtlv_av_delay *)tlvh; - delay = (u_int32_t)ntohl(top->value) & TE_EXT_MASK; - anomalous = (u_int32_t)ntohl(top->value) & TE_EXT_ANORMAL; + delay = (uint32_t)ntohl(top->value) & TE_EXT_MASK; + anomalous = (uint32_t)ntohl(top->value) & TE_EXT_ANORMAL; if (vty != NULL) vty_out(vty, " %s Average Link Delay: %d (micro-sec)\n", @@ -1912,17 +1912,17 @@ static u_int16_t show_vty_link_subtlv_av_delay(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_mm_delay(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_mm_delay(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_mm_delay *top; - u_int32_t low, high; - u_int32_t anomalous; + uint32_t low, high; + uint32_t anomalous; top = (struct te_link_subtlv_mm_delay *)tlvh; - low = (u_int32_t)ntohl(top->low) & TE_EXT_MASK; - anomalous = (u_int32_t)ntohl(top->low) & TE_EXT_ANORMAL; - high = (u_int32_t)ntohl(top->high); + low = (uint32_t)ntohl(top->low) & TE_EXT_MASK; + anomalous = (uint32_t)ntohl(top->low) & TE_EXT_ANORMAL; + high = (uint32_t)ntohl(top->high); if (vty != NULL) vty_out(vty, " %s Min/Max Link Delay: %d/%d (micro-sec)\n", @@ -1934,14 +1934,14 @@ static u_int16_t show_vty_link_subtlv_mm_delay(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_delay_var(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_delay_var(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_delay_var *top; - u_int32_t jitter; + uint32_t jitter; top = (struct te_link_subtlv_delay_var *)tlvh; - jitter = (u_int32_t)ntohl(top->value) & TE_EXT_MASK; + jitter = (uint32_t)ntohl(top->value) & TE_EXT_MASK; if (vty != NULL) vty_out(vty, " Delay Variation: %d (micro-sec)\n", jitter); @@ -1951,18 +1951,18 @@ static u_int16_t show_vty_link_subtlv_delay_var(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_pkt_loss(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_pkt_loss(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_pkt_loss *top; - u_int32_t loss; - u_int32_t anomalous; + uint32_t loss; + uint32_t anomalous; float fval; top = (struct te_link_subtlv_pkt_loss *)tlvh; - loss = (u_int32_t)ntohl(top->value) & TE_EXT_MASK; + loss = (uint32_t)ntohl(top->value) & TE_EXT_MASK; fval = (float)(loss * LOSS_PRECISION); - anomalous = (u_int32_t)ntohl(top->value) & TE_EXT_ANORMAL; + anomalous = (uint32_t)ntohl(top->value) & TE_EXT_ANORMAL; if (vty != NULL) vty_out(vty, " %s Link Loss: %g (%%)\n", @@ -1974,8 +1974,8 @@ static u_int16_t show_vty_link_subtlv_pkt_loss(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_res_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_res_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_res_bw *top; float fval; @@ -1995,8 +1995,8 @@ static u_int16_t show_vty_link_subtlv_res_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_ava_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_ava_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_ava_bw *top; float fval; @@ -2016,8 +2016,8 @@ static u_int16_t show_vty_link_subtlv_ava_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_link_subtlv_use_bw(struct vty *vty, - struct tlv_header *tlvh) +static uint16_t show_vty_link_subtlv_use_bw(struct vty *vty, + struct tlv_header *tlvh) { struct te_link_subtlv_use_bw *top; float fval; @@ -2037,7 +2037,7 @@ static u_int16_t show_vty_link_subtlv_use_bw(struct vty *vty, return TLV_SIZE(tlvh); } -static u_int16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) +static uint16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) { if (vty != NULL) vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n", @@ -2049,13 +2049,12 @@ static u_int16_t show_vty_unknown_tlv(struct vty *vty, struct tlv_header *tlvh) return TLV_SIZE(tlvh); } -static u_int16_t ospf_mpls_te_show_link_subtlv(struct vty *vty, - struct tlv_header *tlvh0, - u_int16_t subtotal, - u_int16_t total) +static uint16_t ospf_mpls_te_show_link_subtlv(struct vty *vty, + struct tlv_header *tlvh0, + uint16_t subtotal, uint16_t total) { struct tlv_header *tlvh, *next; - u_int16_t sum = subtotal; + uint16_t sum = subtotal; for (tlvh = tlvh0; sum < total; tlvh = (next ? next : TLV_HDR_NEXT(tlvh))) { @@ -2133,9 +2132,9 @@ static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct lsa_header *lsah = (struct lsa_header *)lsa->data; struct tlv_header *tlvh, *next; - u_int16_t sum, total; - u_int16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh, - u_int16_t subtotal, u_int16_t total) = NULL; + uint16_t sum, total; + uint16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh, + uint16_t subtotal, uint16_t total) = NULL; sum = 0; total = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE; diff --git a/ospfd/ospf_te.h b/ospfd/ospf_te.h index ff93974986..06c17f07fe 100644 --- a/ospfd/ospf_te.h +++ b/ospfd/ospf_te.h @@ -123,8 +123,8 @@ struct te_link_subtlv_link_type { struct { #define LINK_TYPE_SUBTLV_VALUE_PTP 1 #define LINK_TYPE_SUBTLV_VALUE_MA 2 - u_char value; - u_char padding[3]; + uint8_t value; + uint8_t padding[3]; } link_type; }; @@ -153,7 +153,7 @@ struct te_link_subtlv_rmtif_ipaddr { #define TE_LINK_SUBTLV_TE_METRIC 5 struct te_link_subtlv_te_metric { struct tlv_header header; /* Value length is 4 octets. */ - u_int32_t value; /* Link metric for TE purpose. */ + uint32_t value; /* Link metric for TE purpose. */ }; /* Link Sub-TLV: Maximum Bandwidth */ /* Optional */ @@ -182,7 +182,7 @@ struct te_link_subtlv_unrsv_bw { #define TE_LINK_SUBTLV_RSC_CLSCLR 9 struct te_link_subtlv_rsc_clsclr { struct tlv_header header; /* Value length is 4 octets. */ - u_int32_t value; /* Admin. group membership. */ + uint32_t value; /* Admin. group membership. */ }; /* For RFC6827 */ @@ -200,8 +200,8 @@ struct te_link_subtlv_lrrid { #define TE_LINK_SUBTLV_LLRI_SIZE 8 struct te_link_subtlv_llri { struct tlv_header header; /* Value length is 8 octets. */ - u_int32_t local; /* Link Local Identifier */ - u_int32_t remote; /* Link Remote Identifier */ + uint32_t local; /* Link Local Identifier */ + uint32_t remote; /* Link Remote Identifier */ }; /* Inter-RA Export Upward sub-TLV (12) and Inter-RA Export Downward sub-TLV (13) @@ -215,7 +215,7 @@ struct te_link_subtlv_llri { #define TE_LINK_SUBTLV_RAS 21 struct te_link_subtlv_ras { struct tlv_header header; /* Value length is 4 octets. */ - u_int32_t value; /* Remote AS number */ + uint32_t value; /* Remote AS number */ }; /* IPv4 Remote ASBR ID Sub-TLV */ @@ -240,7 +240,7 @@ struct te_link_subtlv_av_delay { * delay in micro-seconds only 24 bits => 0 ... 16777215 * with Anomalous Bit as Upper most bit */ - u_int32_t value; + uint32_t value; }; /* Link Sub-TLV: Low/High Link Delay */ @@ -252,9 +252,9 @@ struct te_link_subtlv_mm_delay { * low delay in micro-seconds only 24 bits => 0 ... 16777215 * with Anomalous Bit (A) as Upper most bit */ - u_int32_t low; + uint32_t low; /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */ - u_int32_t high; + uint32_t high; }; /* Link Sub-TLV: Link Delay Variation i.e. Jitter */ @@ -262,7 +262,7 @@ struct te_link_subtlv_mm_delay { struct te_link_subtlv_delay_var { struct tlv_header header; /* Value length is 4 bytes. */ /* interval in micro-seconds only 24 bits => 0 ... 16777215 */ - u_int32_t value; + uint32_t value; }; /* Link Sub-TLV: Routine Unidirectional Link Packet Loss */ @@ -273,7 +273,7 @@ struct te_link_subtlv_pkt_loss { * in percentage of total traffic only 24 bits (2^24 - 2) * with Anomalous Bit as Upper most bit */ - u_int32_t value; + uint32_t value; }; /* Link Sub-TLV: Unidirectional Residual Bandwidth */ /* Optional */ @@ -311,23 +311,23 @@ enum inter_as_mode { Off, AS, Area }; struct te_link_subtlv { struct tlv_header header; union { - u_int32_t link_type; + uint32_t link_type; struct in_addr link_id; struct in_addr lclif; struct in_addr rmtif; - u_int32_t te_metric; + uint32_t te_metric; float max_bw; float max_rsv_bw; float unrsv[8]; - u_int32_t rsc_clsclr; - u_int32_t llri[2]; - u_int32_t ras; + uint32_t rsc_clsclr; + uint32_t llri[2]; + uint32_t ras; struct in_addr rip; struct in_addr lrrid[2]; - u_int32_t av_delay; - u_int32_t mm_delay; - u_int32_t delay_var; - u_int32_t pkt_loss; + uint32_t av_delay; + uint32_t mm_delay; + uint32_t delay_var; + uint32_t pkt_loss; float res_bw; float ava_bw; float use_bw; @@ -357,7 +357,7 @@ struct mpls_te_link { * is subdivided into 8-bit "unused" field and 16-bit "instance" field. * In this implementation, each Link-TLV has its own instance. */ - u_int32_t instance; + uint32_t instance; /* Reference pointer to a Zebra-interface. */ struct interface *ifp; @@ -366,10 +366,10 @@ struct mpls_te_link { struct ospf_area *area; /* Flags to manage this link parameters. */ - u_int32_t flags; + uint32_t flags; /* Type of MPLS-TE link: RFC3630, RFC5392, RFC5392 emulated, RFC6827 */ - u_int8_t type; + uint8_t type; /* Store Link-TLV in network byte order. */ /* RFC3630 & RFC6827 / RFC 6827 */ @@ -410,7 +410,7 @@ extern void ospf_mpls_te_finish(void); extern struct ospf_mpls_te *get_ospf_mpls_te(void); extern void ospf_mpls_te_update_if(struct interface *); extern void ospf_mpls_te_lsa_schedule(struct mpls_te_link *, enum lsa_opcode); -extern void set_linkparams_llri(struct mpls_te_link *, u_int32_t, u_int32_t); +extern void set_linkparams_llri(struct mpls_te_link *, uint32_t, uint32_t); extern void set_linkparams_lrrid(struct mpls_te_link *, struct in_addr, struct in_addr); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index ee53497af1..21567c6ce6 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -135,7 +135,7 @@ int ospf_oi_count(struct interface *ifp) static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, struct cmd_token *argv[], const int argc, uint32_t enable, - u_short *instance) + unsigned short *instance) { struct ospf *ospf = NULL; int idx_vrf = 0, idx_inst = 0; @@ -165,7 +165,7 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, } static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, - json_object *json, u_char use_vrf) + json_object *json, uint8_t use_vrf) { if (use_vrf) { if (json) { @@ -199,7 +199,7 @@ DEFUN_NOSH (router_ospf, { struct ospf *ospf = NULL; int ret = CMD_SUCCESS; - u_short instance = 0; + unsigned short instance = 0; struct vrf *vrf = NULL; struct route_node *rn; struct interface *ifp; @@ -266,7 +266,7 @@ DEFUN (no_router_ospf, VRF_CMD_HELP_STR) { struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); if (ospf == NULL) { @@ -377,7 +377,7 @@ DEFPY (no_ospf_router_id, } -static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) +static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) { struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct listnode *ln; @@ -402,10 +402,10 @@ static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) static void ospf_passive_interface_update_addr(struct ospf *ospf, struct interface *ifp, struct ospf_if_params *params, - u_char value, + uint8_t value, struct in_addr addr) { - u_char dflt; + uint8_t dflt; params->passive_interface = value; if (params != IF_DEF_PARAMS(ifp)) { @@ -428,7 +428,7 @@ static void ospf_passive_interface_update_addr(struct ospf *ospf, static void ospf_passive_interface_update(struct ospf *ospf, struct interface *ifp, struct ospf_if_params *params, - u_char value) + uint8_t value) { params->passive_interface = value; if (params == IF_DEF_PARAMS(ifp)) { @@ -680,7 +680,7 @@ DEFUN (ospf_area_range, struct prefix_ipv4 p; struct in_addr area_id; int format; - u_int32_t cost; + uint32_t cost; VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); @@ -712,7 +712,7 @@ DEFUN (ospf_area_range_cost, struct prefix_ipv4 p; struct in_addr area_id; int format; - u_int32_t cost; + uint32_t cost; VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); @@ -912,7 +912,7 @@ ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) : "stub"); else vty_out(vty, "Area %ld is %s\n", - (u_long)ntohl(area_id.s_addr), + (unsigned long)ntohl(area_id.s_addr), area->external_routing == OSPF_AREA_NSSA ? "nssa" : "stub"); @@ -1678,7 +1678,7 @@ DEFUN (ospf_area_default_cost, int idx_number = 3; struct ospf_area *area; struct in_addr area_id; - u_int32_t cost; + uint32_t cost; int format; struct prefix_ipv4 p; @@ -2054,7 +2054,7 @@ DEFUN (ospf_abr_type, { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_vendor = 2; - u_char abr_type = OSPF_ABR_UNKNOWN; + uint8_t abr_type = OSPF_ABR_UNKNOWN; if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) abr_type = OSPF_ABR_CISCO; @@ -2089,7 +2089,7 @@ DEFUN (no_ospf_abr_type, { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_vendor = 3; - u_char abr_type = OSPF_ABR_UNKNOWN; + uint8_t abr_type = OSPF_ABR_UNKNOWN; if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) abr_type = OSPF_ABR_CISCO; @@ -2338,7 +2338,7 @@ DEFUN (no_ospf_timers_lsa_min_arrival, return CMD_SUCCESS; } -#if CONFDATE > 20180708 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708 CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08") #endif ALIAS_HIDDEN(ospf_timers_lsa_min_arrival, ospf_timers_lsa_arrival_cmd, @@ -2348,7 +2348,7 @@ ALIAS_HIDDEN(ospf_timers_lsa_min_arrival, ospf_timers_lsa_arrival_cmd, "ospf minimum arrival interval delay\n" "delay (msec) between accepted lsas\n"); -#if CONFDATE > 20180708 +#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708 CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08") #endif ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival, no_ospf_timers_lsa_arrival_cmd, @@ -2542,7 +2542,7 @@ DEFUN (ospf_auto_cost_reference_bandwidth, VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); int idx_number = 2; - u_int32_t refbw; + uint32_t refbw; struct interface *ifp; refbw = strtol(argv[idx_number]->arg, NULL, 10); @@ -2597,7 +2597,7 @@ DEFUN (ospf_write_multiplier, { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_number; - u_int32_t write_oi_count; + uint32_t write_oi_count; if (argc == 3) idx_number = 2; @@ -2644,7 +2644,7 @@ const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)", const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"}; static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, - json_object *json_areas, u_char use_json) + json_object *json_areas, uint8_t use_json) { json_object *json_area = NULL; @@ -2950,7 +2950,7 @@ static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, } static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, - json_object *json, u_char use_vrf) + json_object *json, uint8_t use_vrf) { struct listnode *node, *nnode; struct ospf_area *area; @@ -3264,7 +3264,7 @@ DEFUN (show_ip_ospf, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; @@ -3272,7 +3272,7 @@ DEFUN (show_ip_ospf, int inst = 0; int idx_vrf = 0; json_object *json = NULL; - u_char use_vrf = 0; + uint8_t use_vrf = 0; if (listcount(om->ospf) == 0) return CMD_SUCCESS; @@ -3341,8 +3341,8 @@ DEFUN (show_ip_ospf_instance, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); int ret = CMD_SUCCESS; json_object *json = NULL; @@ -3371,7 +3371,7 @@ DEFUN (show_ip_ospf_instance, static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, struct interface *ifp, json_object *json_interface_sub, - u_char use_json) + uint8_t use_json) { int is_up; struct ospf_neighbor *nbr; @@ -3687,8 +3687,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, - char *intf_name, u_char use_vrf, - json_object *json, u_char use_json) + char *intf_name, uint8_t use_vrf, + json_object *json, uint8_t use_json) { struct interface *ifp; struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); @@ -3781,7 +3781,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, static void show_ip_ospf_interface_traffic_sub(struct vty *vty, struct ospf_interface *oi, json_object *json_interface_sub, - u_char use_json) + uint8_t use_json) { if (use_json) { json_object_int_add(json_interface_sub, "ifIndex", @@ -3819,7 +3819,7 @@ static void show_ip_ospf_interface_traffic_sub(struct vty *vty, /* OSPFv2 Packet Counters */ static int show_ip_ospf_interface_traffic_common( struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, - int display_once, u_char use_vrf, u_char use_json) + int display_once, uint8_t use_vrf, uint8_t use_json) { struct vrf *vrf = NULL; struct interface *ifp = NULL; @@ -3937,14 +3937,14 @@ DEFUN (show_ip_ospf_interface, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL, *intf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0, idx_intf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -4020,8 +4020,8 @@ DEFUN (show_ip_ospf_instance_interface, int idx_number = 3; int idx_intf = 0; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); char *intf_name = NULL; int ret = CMD_SUCCESS; json_object *json = NULL; @@ -4070,11 +4070,11 @@ DEFUN (show_ip_ospf_interface_traffic, bool all_vrf = FALSE; int inst = 0; int idx_vrf = 0, idx_intf = 0; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); json_object *json = NULL; int ret = CMD_SUCCESS; int display_once = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -4146,7 +4146,7 @@ static void show_ip_ospf_neighbour_header(struct vty *vty) static void show_ip_ospf_neighbor_sub(struct vty *vty, struct ospf_interface *oi, - json_object *json, u_char use_json) + json_object *json, uint8_t use_json) { struct route_node *rn; struct ospf_neighbor *nbr, *prev_nbr = NULL; @@ -4257,8 +4257,8 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, } static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, - json_object *json, u_char use_json, - u_char use_vrf) + json_object *json, uint8_t use_json, + uint8_t use_vrf) { struct ospf_interface *oi; struct listnode *node; @@ -4319,14 +4319,14 @@ DEFUN (show_ip_ospf_neighbor, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -4401,8 +4401,8 @@ DEFUN (show_ip_ospf_instance_neighbor, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); json_object *json = NULL; int ret = CMD_SUCCESS; @@ -4429,8 +4429,8 @@ DEFUN (show_ip_ospf_instance_neighbor, } static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, - json_object *json, u_char use_json, - u_char use_vrf) + json_object *json, uint8_t use_json, + uint8_t use_vrf) { struct listnode *node; struct ospf_interface *oi; @@ -4532,14 +4532,14 @@ DEFUN (show_ip_ospf_neighbor_all, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -4613,8 +4613,8 @@ DEFUN (show_ip_ospf_instance_neighbor_all, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); json_object *json = NULL; int ret = CMD_SUCCESS; @@ -4642,7 +4642,7 @@ DEFUN (show_ip_ospf_instance_neighbor_all, static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, int arg_base, struct cmd_token **argv, - u_char use_json, u_char use_vrf) + uint8_t use_json, uint8_t use_vrf) { struct interface *ifp; struct route_node *rn; @@ -4701,7 +4701,7 @@ DEFUN (show_ip_ospf_neighbor_int, { struct ospf *ospf; int idx_ifname = 4; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; int ret = CMD_SUCCESS; struct interface *ifp = NULL; @@ -4736,8 +4736,8 @@ DEFUN (show_ip_ospf_instance_neighbor_int, int idx_number = 3; int idx_ifname = 5; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); if (!uj) show_ip_ospf_neighbour_header(vty); @@ -4760,7 +4760,8 @@ DEFUN (show_ip_ospf_instance_neighbor_int, static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, struct ospf_interface *oi, struct ospf_nbr_nbma *nbr_nbma, - u_char use_json, json_object *json) + uint8_t use_json, + json_object *json) { char timebuf[OSPF_TIME_DUMP_SIZE]; json_object *json_sub = NULL; @@ -4837,7 +4838,8 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, struct ospf_interface *oi, struct ospf_neighbor *nbr, - json_object *json, u_char use_json) + json_object *json, + uint8_t use_json) { char timebuf[OSPF_TIME_DUMP_SIZE]; json_object *json_sub = NULL; @@ -5053,7 +5055,7 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, int arg_base, struct cmd_token **argv, - u_char use_json, u_char use_vrf) + uint8_t use_json, uint8_t use_vrf) { struct listnode *node; struct ospf_neighbor *nbr; @@ -5114,7 +5116,7 @@ DEFUN (show_ip_ospf_neighbor_id, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; int ret = CMD_SUCCESS; @@ -5142,8 +5144,8 @@ DEFUN (show_ip_ospf_instance_neighbor_id, int idx_number = 3; int idx_router_id = 5; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -5160,7 +5162,8 @@ DEFUN (show_ip_ospf_instance_neighbor_id, static int show_ip_ospf_neighbor_detail_common(struct vty *vty, struct ospf *ospf, json_object *json, - u_char use_json, u_char use_vrf) + uint8_t use_json, + uint8_t use_vrf) { struct ospf_interface *oi; struct listnode *node; @@ -5227,14 +5230,14 @@ DEFUN (show_ip_ospf_neighbor_detail, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -5306,8 +5309,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); json_object *json = NULL; int ret = CMD_SUCCESS; @@ -5336,8 +5339,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail, static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, struct ospf *ospf, json_object *json, - u_char use_json, - u_char use_vrf) + uint8_t use_json, + uint8_t use_vrf) { struct listnode *node; struct ospf_interface *oi; @@ -5416,14 +5419,14 @@ DEFUN (show_ip_ospf_neighbor_detail_all, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -5497,8 +5500,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); json_object *json = NULL; int ret = CMD_SUCCESS; @@ -5528,7 +5531,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, struct ospf *ospf, int arg_base, struct cmd_token **argv, - u_char use_json) + uint8_t use_json) { struct ospf_interface *oi; struct interface *ifp; @@ -5596,7 +5599,7 @@ DEFUN (show_ip_ospf_neighbor_int_detail, JSON_STR) { struct ospf *ospf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct listnode *node = NULL; int ret = CMD_SUCCESS; @@ -5625,8 +5628,8 @@ DEFUN (show_ip_ospf_instance_neighbor_int_detail, int idx_number = 3; int idx_ifname = 5; struct ospf *ospf; - u_short instance = 0; - u_char uj = use_json(argc, argv); + unsigned short instance = 0; + uint8_t uj = use_json(argc, argv); instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -5655,7 +5658,7 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), - (u_long)ntohl(lsa->data->ls_seqnum), + (unsigned long)ntohl(lsa->data->ls_seqnum), ntohs(lsa->data->checksum)); /* LSA specific part show. */ switch (lsa->data->type) { @@ -5688,7 +5691,8 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) ? "E2" : "E1", inet_ntoa(p.prefix), p.prefixlen, - (u_long)ntohl(asel->e[0].route_tag)); + (unsigned long)ntohl( + asel->e[0].route_tag)); break; case OSPF_NETWORK_LSA: case OSPF_ASBR_SUMMARY_LSA: @@ -5766,7 +5770,7 @@ static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) vty_out(vty, " Advertising Router: %s\n", inet_ntoa(lsa->data->adv_router)); vty_out(vty, " LS Seq Number: %08lx\n", - (u_long)ntohl(lsa->data->ls_seqnum)); + (unsigned long)ntohl(lsa->data->ls_seqnum)); vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); } @@ -6209,7 +6213,8 @@ static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, int arg_base, int argc, - struct cmd_token **argv, u_char use_vrf) + struct cmd_token **argv, + uint8_t use_vrf) { int idx_type = 4; int type, ret; @@ -6304,7 +6309,7 @@ DEFUN (show_ip_ospf_database_max, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -6354,14 +6359,14 @@ DEFUN (show_ip_ospf_instance_database, "Advertising Router (as an IP address)\n") { struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; if (argv_find(argv, argc, "(1-65535)", &idx)) { instance = strtoul(argv[idx]->arg, NULL, 10); @@ -6420,7 +6425,7 @@ DEFUN (show_ip_ospf_instance_database_max, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); @@ -6439,7 +6444,7 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, struct ospf *ospf, int arg_base, int argc, struct cmd_token **argv, - u_char use_vrf) + uint8_t use_vrf) { int idx_type = 4; int type, ret; @@ -6504,14 +6509,14 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, "Self-originated link states\n") { struct ospf *ospf = NULL; - u_short instance = 0; + unsigned short instance = 0; struct listnode *node = NULL; char *vrf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; int idx = 0, idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; if (argv_find(argv, argc, "(1-65535)", &idx)) { instance = strtoul(argv[idx]->arg, NULL, 10); @@ -6905,7 +6910,7 @@ DEFUN (ip_ospf_message_digest_key, { VTY_DECLVAR_CONTEXT(interface, ifp); struct crypt_key *ck; - u_char key_id; + uint8_t key_id; struct in_addr addr; struct ospf_if_params *params; @@ -6935,7 +6940,7 @@ DEFUN (ip_ospf_message_digest_key, } ck = ospf_crypt_key_new(); - ck->key_id = (u_char)key_id; + ck->key_id = (uint8_t)key_id; memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE); @@ -7035,7 +7040,7 @@ DEFUN (ip_ospf_cost, { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; - u_int32_t cost = OSPF_OUTPUT_COST_DEFAULT; + uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; struct in_addr addr; struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); @@ -7158,8 +7163,8 @@ static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, const char *fast_hello_str) { VTY_DECLVAR_CONTEXT(interface, ifp); - u_int32_t seconds; - u_char hellomult; + uint32_t seconds; + uint8_t hellomult; struct in_addr addr; int ret; struct ospf_if_params *params; @@ -7366,7 +7371,7 @@ DEFUN (ip_ospf_hello_interval, struct in_addr addr; struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); - u_int32_t seconds = 0; + uint32_t seconds = 0; argv_find(argv, argc, "(1-65535)", &idx); seconds = strtol(argv[idx]->arg, NULL, 10); @@ -7705,7 +7710,7 @@ DEFUN (ip_ospf_retransmit_interval, { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; - u_int32_t seconds; + uint32_t seconds; struct in_addr addr; struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); @@ -7804,7 +7809,7 @@ DEFUN (ip_ospf_transmit_delay, { VTY_DECLVAR_CONTEXT(interface, ifp); int idx = 0; - u_int32_t seconds; + uint32_t seconds; struct in_addr addr; struct ospf_if_params *params; @@ -7912,7 +7917,7 @@ DEFUN (ip_ospf_area, struct ospf_if_params *params = NULL; struct route_node *rn; struct ospf *ospf = NULL; - u_short instance = 0; + unsigned short instance = 0; char *areaid; if (argv_find(argv, argc, "(1-65535)", &idx)) @@ -8013,7 +8018,7 @@ DEFUN (no_ip_ospf_area, int idx = 0; struct ospf *ospf; struct ospf_if_params *params; - u_short instance = 0; + unsigned short instance = 0; struct in_addr addr; if (argv_find(argv, argc, "(1-65535)", &idx)) @@ -8161,7 +8166,7 @@ DEFUN (ospf_redistribute_instance_source, int source; int type = -1; int metric = -1; - u_short instance; + unsigned short instance; struct ospf_redist *red; if (!ospf) @@ -8225,7 +8230,7 @@ DEFUN (no_ospf_redistribute_instance_source, VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); int idx_ospf_table = 2; int idx_number = 3; - u_int instance; + unsigned int instance; struct ospf_redist *red; int source; @@ -9257,7 +9262,8 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, } static int show_ip_ospf_border_routers_common(struct vty *vty, - struct ospf *ospf, u_char use_vrf) + struct ospf *ospf, + uint8_t use_vrf) { if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); @@ -9297,7 +9303,7 @@ DEFUN (show_ip_ospf_border_routers, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; + uint8_t use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); @@ -9341,7 +9347,7 @@ DEFUN (show_ip_ospf_instance_border_routers, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -9355,7 +9361,7 @@ DEFUN (show_ip_ospf_instance_border_routers, } static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, - json_object *json, u_char use_vrf) + json_object *json, uint8_t use_vrf) { json_object *json_vrf = NULL; @@ -9423,8 +9429,8 @@ DEFUN (show_ip_ospf_route, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; - u_char use_vrf = 0; - u_char uj = use_json(argc, argv); + uint8_t use_vrf = 0; + uint8_t uj = use_json(argc, argv); json_object *json = NULL; if (uj) @@ -9492,7 +9498,7 @@ DEFUN (show_ip_ospf_instance_route, { int idx_number = 3; struct ospf *ospf; - u_short instance = 0; + unsigned short instance = 0; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -9515,7 +9521,7 @@ DEFUN (show_ip_ospf_vrfs, "Show OSPF VRFs \n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); json_object *json = NULL; json_object *json_vrfs = NULL; struct ospf *ospf = NULL; @@ -9853,7 +9859,7 @@ static int config_write_interface(struct vty *vty) static int config_write_network_area(struct vty *vty, struct ospf *ospf) { struct route_node *rn; - u_char buf[INET_ADDRSTRLEN]; + uint8_t buf[INET_ADDRSTRLEN]; /* `network area' print. */ for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) @@ -9884,7 +9890,7 @@ static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) { struct listnode *node; struct ospf_area *area; - u_char buf[INET_ADDRSTRLEN]; + uint8_t buf[INET_ADDRSTRLEN]; /* Area configuration print. */ for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index e322f60509..23d00633d4 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -384,7 +384,7 @@ void ospf_zebra_add(struct ospf *ospf, struct prefix_ipv4 *p, { struct zapi_route api; struct zapi_nexthop *api_nh; - u_char distance; + uint8_t distance; struct ospf_path *path; struct listnode *node; int count = 0; @@ -522,8 +522,8 @@ void ospf_zebra_delete_discard(struct ospf *ospf, struct prefix_ipv4 *p) inet_ntoa(p->prefix), p->prefixlen); } -struct ospf_external *ospf_external_lookup(struct ospf *ospf, u_char type, - u_short instance) +struct ospf_external *ospf_external_lookup(struct ospf *ospf, uint8_t type, + unsigned short instance) { struct list *ext_list; struct listnode *node; @@ -540,8 +540,8 @@ struct ospf_external *ospf_external_lookup(struct ospf *ospf, u_char type, return NULL; } -struct ospf_external *ospf_external_add(struct ospf *ospf, u_char type, - u_short instance) +struct ospf_external *ospf_external_add(struct ospf *ospf, uint8_t type, + unsigned short instance) { struct list *ext_list; struct ospf_external *ext; @@ -564,7 +564,7 @@ struct ospf_external *ospf_external_add(struct ospf *ospf, u_char type, return ext; } -void ospf_external_del(struct ospf *ospf, u_char type, u_short instance) +void ospf_external_del(struct ospf *ospf, uint8_t type, unsigned short instance) { struct ospf_external *ext; @@ -583,8 +583,8 @@ void ospf_external_del(struct ospf *ospf, u_char type, u_short instance) } } -struct ospf_redist *ospf_redist_lookup(struct ospf *ospf, u_char type, - u_short instance) +struct ospf_redist *ospf_redist_lookup(struct ospf *ospf, uint8_t type, + unsigned short instance) { struct list *red_list; struct listnode *node; @@ -601,8 +601,8 @@ struct ospf_redist *ospf_redist_lookup(struct ospf *ospf, u_char type, return NULL; } -struct ospf_redist *ospf_redist_add(struct ospf *ospf, u_char type, - u_short instance) +struct ospf_redist *ospf_redist_add(struct ospf *ospf, uint8_t type, + unsigned short instance) { struct list *red_list; struct ospf_redist *red; @@ -626,7 +626,7 @@ struct ospf_redist *ospf_redist_add(struct ospf *ospf, u_char type, return red; } -void ospf_redist_del(struct ospf *ospf, u_char type, u_short instance) +void ospf_redist_del(struct ospf *ospf, uint8_t type, unsigned short instance) { struct ospf_redist *red; @@ -643,7 +643,8 @@ void ospf_redist_del(struct ospf *ospf, u_char type, u_short instance) } -int ospf_is_type_redistributed(struct ospf *ospf, int type, u_short instance) +int ospf_is_type_redistributed(struct ospf *ospf, int type, + unsigned short instance) { return (DEFAULT_ROUTE_TYPE(type) ? vrf_bitmap_check(zclient->default_information, @@ -658,7 +659,7 @@ int ospf_is_type_redistributed(struct ospf *ospf, int type, u_short instance) ospf->vrf_id)))); } -int ospf_redistribute_set(struct ospf *ospf, int type, u_short instance, +int ospf_redistribute_set(struct ospf *ospf, int type, unsigned short instance, int mtype, int mvalue) { int force = 0; @@ -707,7 +708,8 @@ int ospf_redistribute_set(struct ospf *ospf, int type, u_short instance, return CMD_SUCCESS; } -int ospf_redistribute_unset(struct ospf *ospf, int type, u_short instance) +int ospf_redistribute_unset(struct ospf *ospf, int type, + unsigned short instance) { if (type == zclient->redist_default && instance == zclient->instance) return CMD_SUCCESS; @@ -846,8 +848,8 @@ int ospf_redistribute_check(struct ospf *ospf, struct external_info *ei, struct route_map_set_values save_values; struct prefix_ipv4 *p = &ei->p; struct ospf_redist *red; - u_char type = is_prefix_default(&ei->p) ? DEFAULT_ROUTE : ei->type; - u_short instance = is_prefix_default(&ei->p) ? 0 : ei->instance; + uint8_t type = is_prefix_default(&ei->p) ? DEFAULT_ROUTE : ei->type; + unsigned short instance = is_prefix_default(&ei->p) ? 0 : ei->instance; if (changed) *changed = 0; @@ -1136,7 +1138,8 @@ static int ospf_distribute_list_update_timer(struct thread *thread) } /* Update distribute-list and set timer to apply access-list. */ -void ospf_distribute_list_update(struct ospf *ospf, int type, u_short instance) +void ospf_distribute_list_update(struct ospf *ospf, int type, + unsigned short instance) { struct route_table *rt; struct ospf_external *ext; @@ -1341,7 +1344,7 @@ int ospf_distance_set(struct vty *vty, struct ospf *ospf, { int ret; struct prefix_ipv4 p; - u_char distance; + uint8_t distance; struct route_node *rn; struct ospf_distance *odistance; @@ -1426,8 +1429,8 @@ void ospf_distance_reset(struct ospf *ospf) } } -u_char ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *p, - struct ospf_route * or) +uint8_t ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *p, + struct ospf_route * or) { if (ospf == NULL) @@ -1491,7 +1494,7 @@ static void ospf_zebra_connected(struct zclient *zclient) zclient_send_reg_requests(zclient, VRF_DEFAULT); } -void ospf_zebra_init(struct thread_master *master, u_short instance) +void ospf_zebra_init(struct thread_master *master, unsigned short instance) { /* Allocate zebra structure. */ zclient = zclient_new_notify(master, &zclient_options_default); diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h index 236f5a2631..6737306532 100644 --- a/ospfd/ospf_zebra.h +++ b/ospfd/ospf_zebra.h @@ -34,7 +34,7 @@ /* OSPF distance. */ struct ospf_distance { /* Distance value for the IP source prefix. */ - u_char distance; + uint8_t distance; /* Name of the access-list to be matched. */ char *access_list; @@ -53,23 +53,26 @@ extern int ospf_redistribute_check(struct ospf *, struct external_info *, int *); extern int ospf_distribute_check_connected(struct ospf *, struct external_info *); -extern void ospf_distribute_list_update(struct ospf *, int, u_short); +extern void ospf_distribute_list_update(struct ospf *, int, unsigned short); -extern int ospf_is_type_redistributed(struct ospf *, int, u_short); +extern int ospf_is_type_redistributed(struct ospf *, int, unsigned short); extern void ospf_distance_reset(struct ospf *); -extern u_char ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *, - struct ospf_route *); -extern struct ospf_external *ospf_external_lookup(struct ospf *, u_char, - u_short); -extern struct ospf_external *ospf_external_add(struct ospf *, u_char, u_short); -extern void ospf_external_del(struct ospf *, u_char, u_short); -extern struct ospf_redist *ospf_redist_lookup(struct ospf *, u_char, u_short); -extern struct ospf_redist *ospf_redist_add(struct ospf *, u_char, u_short); -extern void ospf_redist_del(struct ospf *, u_char, u_short); +extern uint8_t ospf_distance_apply(struct ospf *ospf, struct prefix_ipv4 *, + struct ospf_route *); +extern struct ospf_external *ospf_external_lookup(struct ospf *, uint8_t, + unsigned short); +extern struct ospf_external *ospf_external_add(struct ospf *, uint8_t, + unsigned short); +extern void ospf_external_del(struct ospf *, uint8_t, unsigned short); +extern struct ospf_redist *ospf_redist_lookup(struct ospf *, uint8_t, + unsigned short); +extern struct ospf_redist *ospf_redist_add(struct ospf *, uint8_t, + unsigned short); +extern void ospf_redist_del(struct ospf *, uint8_t, unsigned short); -extern int ospf_redistribute_set(struct ospf *, int, u_short, int, int); -extern int ospf_redistribute_unset(struct ospf *, int, u_short); +extern int ospf_redistribute_set(struct ospf *, int, unsigned short, int, int); +extern int ospf_redistribute_unset(struct ospf *, int, unsigned short); extern int ospf_redistribute_default_set(struct ospf *, int, int, int); extern int ospf_redistribute_default_unset(struct ospf *); extern int ospf_distribute_list_out_set(struct ospf *, int, const char *); @@ -80,7 +83,7 @@ extern int ospf_distance_set(struct vty *, struct ospf *, const char *, const char *, const char *); extern int ospf_distance_unset(struct vty *, struct ospf *, const char *, const char *, const char *); -extern void ospf_zebra_init(struct thread_master *, u_short); +extern void ospf_zebra_init(struct thread_master *, unsigned short); extern void ospf_zebra_vrf_register(struct ospf *ospf); extern void ospf_zebra_vrf_deregister(struct ospf *ospf); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 26bbc5ee11..4cf38439c6 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -223,7 +223,7 @@ static int ospf_area_id_cmp(struct ospf_area *a1, struct ospf_area *a2) } /* Allocate new ospf structure. */ -static struct ospf *ospf_new(u_short instance, const char *name) +static struct ospf *ospf_new(unsigned short instance, const char *name) { int i; struct vrf *vrf = NULL; @@ -338,7 +338,7 @@ static struct ospf *ospf_new(u_short instance, const char *name) return new; } -struct ospf *ospf_lookup_instance(u_short instance) +struct ospf *ospf_lookup_instance(unsigned short instance) { struct ospf *ospf; struct listnode *node, *nnode; @@ -374,7 +374,7 @@ static void ospf_delete(struct ospf *ospf) listnode_delete(om->ospf, ospf); } -struct ospf *ospf_lookup_by_inst_name(u_short instance, const char *name) +struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name) { struct ospf *ospf = NULL; struct listnode *node, *nnode; @@ -389,7 +389,7 @@ struct ospf *ospf_lookup_by_inst_name(u_short instance, const char *name) return NULL; } -struct ospf *ospf_get(u_short instance, const char *name) +struct ospf *ospf_get(unsigned short instance, const char *name) { struct ospf *ospf; @@ -413,7 +413,7 @@ struct ospf *ospf_get(u_short instance, const char *name) return ospf; } -struct ospf *ospf_get_instance(u_short instance) +struct ospf *ospf_get_instance(unsigned short instance) { struct ospf *ospf; @@ -608,7 +608,7 @@ static void ospf_finish_final(struct ospf *ospf) struct ospf_vl_data *vl_data; struct listnode *node, *nnode; int i; - u_short instance = 0; + unsigned short instance = 0; QOBJ_UNREG(ospf); @@ -1941,7 +1941,7 @@ int ospf_nbr_nbma_unset(struct ospf *ospf, struct in_addr nbr_addr) } int ospf_nbr_nbma_priority_set(struct ospf *ospf, struct in_addr nbr_addr, - u_char priority) + uint8_t priority) { struct ospf_nbr_nbma *nbr_nbma; diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index bed446085e..bc9c68d570 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -81,7 +81,7 @@ #define OSPF_LS_REFRESH_JITTER 60 struct ospf_external { - u_short instance; + unsigned short instance; struct route_table *external_info; }; @@ -94,12 +94,12 @@ struct ospf_master { struct thread_master *master; /* Various OSPF global configuration. */ - u_char options; + uint8_t options; #define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */ }; struct ospf_redist { - u_short instance; + unsigned short instance; /* Redistribute metric info. */ struct { @@ -121,10 +121,10 @@ struct ospf_redist { struct ospf { /* OSPF's running state based on the '[no] router ospf [<instance>]' * config. */ - u_char oi_running; + uint8_t oi_running; /* OSPF instance ID */ - u_short instance; + unsigned short instance; /* OSPF Router ID. */ struct in_addr router_id; /* Configured automatically. */ @@ -135,12 +135,12 @@ struct ospf { char *name; /* VRF name */ /* ABR/ASBR internal flags. */ - u_char flags; + uint8_t flags; #define OSPF_FLAG_ABR 0x0001 #define OSPF_FLAG_ASBR 0x0002 /* ABR type. */ - u_char abr_type; + uint8_t abr_type; #define OSPF_ABR_UNKNOWN 0 #define OSPF_ABR_STAND 1 #define OSPF_ABR_IBM 2 @@ -149,24 +149,24 @@ struct ospf { #define OSPF_ABR_DEFAULT OSPF_ABR_CISCO /* NSSA ABR */ - u_char anyNSSA; /* Bump for every NSSA attached. */ + uint8_t anyNSSA; /* Bump for every NSSA attached. */ /* Configured variables. */ - u_char config; + uint8_t config; #define OSPF_RFC1583_COMPATIBLE (1 << 0) #define OSPF_OPAQUE_CAPABLE (1 << 2) #define OSPF_LOG_ADJACENCY_CHANGES (1 << 3) #define OSPF_LOG_ADJACENCY_DETAIL (1 << 4) /* Opaque-LSA administrative flags. */ - u_char opaque; + uint8_t opaque; #define OPAQUE_OPERATION_READY_BIT (1 << 0) /* RFC3137 stub router. Configured time to stay stub / max-metric */ unsigned int stub_router_startup_time; /* seconds */ unsigned int stub_router_shutdown_time; /* seconds */ #define OSPF_STUB_ROUTER_UNCONFIGURED 0 - u_char stub_router_admin_set; + uint8_t stub_router_admin_set; #define OSPF_STUB_ROUTER_ADMINISTRATIVE_SET 1 #define OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET 0 @@ -188,7 +188,7 @@ struct ospf { #define DEFAULT_ORIGINATE_NONE 0 #define DEFAULT_ORIGINATE_ZEBRA 1 #define DEFAULT_ORIGINATE_ALWAYS 2 - u_int32_t ref_bandwidth; /* Reference Bandwidth (Kbps). */ + uint32_t ref_bandwidth; /* Reference Bandwidth (Kbps). */ struct route_table *networks; /* OSPF config networks. */ struct list *vlinks; /* Configured Virtual-Links. */ struct list *areas; /* OSPF areas. */ @@ -196,7 +196,7 @@ struct ospf { struct ospf_area *backbone; /* Pointer to the Backbone Area. */ struct list *oiflist; /* ospf interfaces */ - u_char passive_interface_default; /* passive-interface default */ + uint8_t passive_interface_default; /* passive-interface default */ /* LSDB of AS-external-LSAs. */ struct ospf_lsdb *lsdb; @@ -276,31 +276,31 @@ struct ospf { / OSPF_LSA_REFRESHER_GRANULARITY \ + 1) struct { - u_int16_t index; + uint16_t index; struct list *qs[OSPF_LSA_REFRESHER_SLOTS]; } lsa_refresh_queue; struct thread *t_lsa_refresher; time_t lsa_refresher_started; #define OSPF_LSA_REFRESH_INTERVAL_DEFAULT 10 - u_int16_t lsa_refresh_interval; + uint16_t lsa_refresh_interval; /* Distance parameter. */ - u_char distance_all; - u_char distance_intra; - u_char distance_inter; - u_char distance_external; + uint8_t distance_all; + uint8_t distance_intra; + uint8_t distance_inter; + uint8_t distance_external; /* Statistics for LSA origination. */ - u_int32_t lsa_originate_count; + uint32_t lsa_originate_count; /* Statistics for LSA used for new instantiation. */ - u_int32_t rx_lsa_count; + uint32_t rx_lsa_count; /* Counter of "ip ospf area x.x.x.x" used * for multual exclusion of network command under * router ospf or ip ospf area x under interface. */ - u_int32_t if_ospf_cli_count; + uint32_t if_ospf_cli_count; struct route_table *distance_table; @@ -343,26 +343,26 @@ struct ospf_area { #define OSPF_SHORTCUT_ENABLE 1 #define OSPF_SHORTCUT_DISABLE 2 int shortcut_capability; /* Other ABRs agree on S-bit */ - u_int32_t default_cost; /* StubDefaultCost. */ + uint32_t default_cost; /* StubDefaultCost. */ int auth_type; /* Authentication type. */ - u_char NSSATranslatorRole; /* NSSA configured role */ + uint8_t NSSATranslatorRole; /* NSSA configured role */ #define OSPF_NSSA_ROLE_NEVER 0 #define OSPF_NSSA_ROLE_CANDIDATE 1 #define OSPF_NSSA_ROLE_ALWAYS 2 - u_char NSSATranslatorState; /* NSSA operational role */ + uint8_t NSSATranslatorState; /* NSSA operational role */ #define OSPF_NSSA_TRANSLATE_DISABLED 0 #define OSPF_NSSA_TRANSLATE_ENABLED 1 int NSSATranslatorStabilityInterval; - u_char transit; /* TransitCapability. */ + uint8_t transit; /* TransitCapability. */ #define OSPF_TRANSIT_FALSE 0 #define OSPF_TRANSIT_TRUE 1 struct route_table *ranges; /* Configured Area Ranges. */ /* RFC3137 stub router state flags for area */ - u_char stub_router_state; + uint8_t stub_router_state; #define OSPF_AREA_ADMIN_STUB_ROUTED (1 << 0) /* admin stub-router set */ #define OSPF_AREA_IS_STUB_ROUTED (1 << 1) /* stub-router active */ #define OSPF_AREA_WAS_START_STUB_ROUTED (1 << 2) /* startup SR was done */ @@ -412,19 +412,19 @@ struct ospf_area { struct thread *t_opaque_lsa_self; /* Type-10 Opaque-LSAs origin. */ /* Statistics field. */ - u_int32_t spf_calculation; /* SPF Calculation Count. */ + uint32_t spf_calculation; /* SPF Calculation Count. */ /* Time stamps. */ struct timeval ts_spf; /* SPF calculation time stamp. */ /* Router count. */ - u_int32_t abr_count; /* ABR router in this area. */ - u_int32_t asbr_count; /* ASBR router in this area. */ + uint32_t abr_count; /* ABR router in this area. */ + uint32_t asbr_count; /* ASBR router in this area. */ /* Counters. */ - u_int32_t act_ints; /* Active interfaces. */ - u_int32_t full_nbrs; /* Fully adjacent neighbors. */ - u_int32_t full_vls; /* Fully adjacent virtual neighbors. */ + uint32_t act_ints; /* Active interfaces. */ + uint32_t full_nbrs; /* Fully adjacent neighbors. */ + uint32_t full_vls; /* Fully adjacent virtual neighbors. */ }; /* OSPF config network structure. */ @@ -446,16 +446,16 @@ struct ospf_nbr_nbma { struct ospf_neighbor *nbr; /* Neighbor priority. */ - u_char priority; + uint8_t priority; /* Poll timer value. */ - u_int32_t v_poll; + uint32_t v_poll; /* Poll timer thread. */ struct thread *t_poll; /* State change. */ - u_int32_t state_change; + uint32_t state_change; }; /* Macro. */ @@ -500,11 +500,11 @@ extern int ospf_zlog; extern struct zebra_privs_t ospfd_privs; /* Prototypes. */ -extern const char *ospf_redist_string(u_int route_type); -extern struct ospf *ospf_lookup_instance(u_short); -extern struct ospf *ospf_get(u_short instance, const char *name); -extern struct ospf *ospf_get_instance(u_short); -extern struct ospf *ospf_lookup_by_inst_name(u_short instance, +extern const char *ospf_redist_string(unsigned int route_type); +extern struct ospf *ospf_lookup_instance(unsigned short); +extern struct ospf *ospf_get(unsigned short instance, const char *name); +extern struct ospf *ospf_get_instance(unsigned short); +extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name); extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id); extern void ospf_finish(struct ospf *); @@ -535,7 +535,7 @@ extern int ospf_timers_refresh_set(struct ospf *, int); extern int ospf_timers_refresh_unset(struct ospf *); extern int ospf_nbr_nbma_set(struct ospf *, struct in_addr); extern int ospf_nbr_nbma_unset(struct ospf *, struct in_addr); -extern int ospf_nbr_nbma_priority_set(struct ospf *, struct in_addr, u_char); +extern int ospf_nbr_nbma_priority_set(struct ospf *, struct in_addr, uint8_t); extern int ospf_nbr_nbma_priority_unset(struct ospf *, struct in_addr); extern int ospf_nbr_nbma_poll_interval_set(struct ospf *, struct in_addr, unsigned int); diff --git a/pimd/mtracebis.c b/pimd/mtracebis.c index 5c8229175a..ce83b420b4 100644 --- a/pimd/mtracebis.c +++ b/pimd/mtracebis.c @@ -251,7 +251,7 @@ static int recv_response(int fd, int *hops, struct igmp_mtrace *mtracer) struct igmp_mtrace *mtrace; int mtrace_len; int responses; - u_short sum; + unsigned short sum; recvd = recvfrom(fd, mtrace_buf, IP_AND_MTRACE_BUF_LEN, 0, NULL, 0); diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 29ff337d96..f5772174ba 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -62,7 +62,7 @@ void pim_bfd_write_config(struct vty *vty, struct interface *ifp) * pim_bfd_show_info - Show BFD info structure */ void pim_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj, - u_char use_json, int param_only) + uint8_t use_json, int param_only) { if (param_only) bfd_show_param(vty, (struct bfd_info *)bfd_info, 1, 0, use_json, @@ -179,8 +179,8 @@ void pim_bfd_trigger_event(struct pim_interface *pim_ifp, * pim_bfd_if_param_set - Set the configured BFD paramter values for * interface. */ -void pim_bfd_if_param_set(struct interface *ifp, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, int defaults) +void pim_bfd_if_param_set(struct interface *ifp, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults) { struct pim_interface *pim_ifp = ifp->info; int command = 0; diff --git a/pimd/pim_bfd.h b/pimd/pim_bfd.h index 316d3c1e2f..0dfd80839f 100644 --- a/pimd/pim_bfd.h +++ b/pimd/pim_bfd.h @@ -28,9 +28,9 @@ void pim_bfd_init(void); void pim_bfd_write_config(struct vty *vty, struct interface *ifp); void pim_bfd_show_info(struct vty *vty, void *bfd_info, json_object *json_obj, - u_char use_json, int param_only); -void pim_bfd_if_param_set(struct interface *ifp, u_int32_t min_rx, - u_int32_t min_tx, u_int8_t detect_mult, int defaults); + uint8_t use_json, int param_only); +void pim_bfd_if_param_set(struct interface *ifp, uint32_t min_rx, + uint32_t min_tx, uint8_t detect_mult, int defaults); int pim_bfd_reg_dereg_all_nbr(struct interface *ifp, int command); void pim_bfd_trigger_event(struct pim_interface *pim_ifp, struct pim_neighbor *nbr, uint8_t nbr_up); diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 803e7bb013..35514a85da 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -432,7 +432,7 @@ static void pim_show_membership_helper(struct vty *vty, json_object_object_add(json_iface, ch_grp_str, json_row); } static void pim_show_membership(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; @@ -549,7 +549,7 @@ static void pim_print_ifp_flags(struct vty *vty, struct interface *ifp, } static void igmp_show_interfaces(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct interface *ifp; time_t now; @@ -634,7 +634,7 @@ static void igmp_show_interfaces(struct pim_instance *pim, struct vty *vty, static void igmp_show_interfaces_single(struct pim_instance *pim, struct vty *vty, const char *ifname, - u_char uj) + uint8_t uj) { struct igmp_sock *igmp; struct interface *ifp; @@ -894,7 +894,7 @@ static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty) static void pim_show_interfaces_single(struct pim_instance *pim, struct vty *vty, const char *ifname, - u_char uj) + uint8_t uj) { struct in_addr ifaddr; struct interface *ifp; @@ -1295,7 +1295,7 @@ static void pim_show_interfaces_single(struct pim_instance *pim, } static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct interface *ifp; struct listnode *upnode; @@ -1388,7 +1388,7 @@ static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, } static void pim_show_interface_traffic(struct pim_instance *pim, - struct vty *vty, u_char uj) + struct vty *vty, uint8_t uj) { struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; @@ -1468,7 +1468,7 @@ static void pim_show_interface_traffic(struct pim_instance *pim, static void pim_show_interface_traffic_single(struct pim_instance *pim, struct vty *vty, - const char *ifname, u_char uj) + const char *ifname, uint8_t uj) { struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; @@ -1557,7 +1557,7 @@ static void pim_show_interface_traffic_single(struct pim_instance *pim, static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp, struct pim_ifchannel *ch, json_object *json, - time_t now, u_char uj) + time_t now, uint8_t uj) { char ch_src_str[INET_ADDRSTRLEN]; char ch_grp_str[INET_ADDRSTRLEN]; @@ -1620,7 +1620,7 @@ static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp, } } -static void pim_show_join(struct pim_instance *pim, struct vty *vty, u_char uj) +static void pim_show_join(struct pim_instance *pim, struct vty *vty, uint8_t uj) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; @@ -1654,7 +1654,7 @@ static void pim_show_join(struct pim_instance *pim, struct vty *vty, u_char uj) } static void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, - const char *neighbor, u_char uj) + const char *neighbor, uint8_t uj) { struct listnode *neighnode; struct interface *ifp; @@ -1864,7 +1864,7 @@ static void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, static void pim_show_state(struct pim_instance *pim, struct vty *vty, const char *src_or_group, const char *group, - u_char uj) + uint8_t uj) { struct channel_oil *c_oil; struct listnode *node; @@ -2065,7 +2065,7 @@ static void pim_show_state(struct pim_instance *pim, struct vty *vty, } static void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *neighnode; struct interface *ifp; @@ -2261,7 +2261,7 @@ static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state, } static void pim_show_upstream(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *upnode; struct pim_upstream *up; @@ -2406,7 +2406,7 @@ static void pim_show_join_desired_helper(struct pim_instance *pim, struct vty *vty, struct pim_interface *pim_ifp, struct pim_ifchannel *ch, - json_object *json, u_char uj) + json_object *json, uint8_t uj) { struct pim_upstream *up = ch->upstream; json_object *json_group = NULL; @@ -2462,7 +2462,7 @@ static void pim_show_join_desired_helper(struct pim_instance *pim, } static void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; @@ -2498,7 +2498,7 @@ static void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, } static void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *upnode; struct pim_upstream *up; @@ -2566,30 +2566,30 @@ static void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty, } } -static void show_rpf_refresh_stats(struct vty *vty, time_t now, - json_object *json) +static void show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim, + time_t now, json_object *json) { char refresh_uptime[10]; pim_time_uptime_begin(refresh_uptime, sizeof(refresh_uptime), now, - qpim_rpf_cache_refresh_last); + pim->rpf_cache_refresh_last); if (json) { json_object_int_add(json, "rpfCacheRefreshDelayMsecs", qpim_rpf_cache_refresh_delay_msec); json_object_int_add( json, "rpfCacheRefreshTimer", - pim_time_timer_remain_msec(qpim_rpf_cache_refresher)); + pim_time_timer_remain_msec(pim->rpf_cache_refresher)); json_object_int_add(json, "rpfCacheRefreshRequests", - qpim_rpf_cache_refresh_requests); + pim->rpf_cache_refresh_requests); json_object_int_add(json, "rpfCacheRefreshEvents", - qpim_rpf_cache_refresh_events); + pim->rpf_cache_refresh_events); json_object_string_add(json, "rpfCacheRefreshLast", refresh_uptime); json_object_int_add(json, "nexthopLookups", - qpim_nexthop_lookups); + pim->nexthop_lookups); json_object_int_add(json, "nexthopLookupsAvoided", - nexthop_lookups_avoided); + pim->nexthop_lookups_avoided); } else { vty_out(vty, "RPF Cache Refresh Delay: %ld msecs\n" @@ -2600,11 +2600,11 @@ static void show_rpf_refresh_stats(struct vty *vty, time_t now, "Nexthop Lookups: %lld\n" "Nexthop Lookups Avoided: %lld\n", qpim_rpf_cache_refresh_delay_msec, - pim_time_timer_remain_msec(qpim_rpf_cache_refresher), - (long long)qpim_rpf_cache_refresh_requests, - (long long)qpim_rpf_cache_refresh_events, - refresh_uptime, (long long)qpim_nexthop_lookups, - (long long)nexthop_lookups_avoided); + pim_time_timer_remain_msec(pim->rpf_cache_refresher), + (long long)pim->rpf_cache_refresh_requests, + (long long)pim->rpf_cache_refresh_events, + refresh_uptime, (long long)pim->nexthop_lookups, + (long long)pim->nexthop_lookups_avoided); } } @@ -2616,7 +2616,7 @@ static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty, char uptime_mroute_del[10]; pim_time_uptime_begin(uptime_scan_oil, sizeof(uptime_scan_oil), now, - qpim_scan_oil_last); + pim->scan_oil_last); pim_time_uptime_begin(uptime_mroute_add, sizeof(uptime_mroute_add), now, pim->mroute_add_last); pim_time_uptime_begin(uptime_mroute_del, sizeof(uptime_mroute_del), now, @@ -2626,12 +2626,12 @@ static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty, "Scan OIL - Last: %s Events: %lld\n" "MFC Add - Last: %s Events: %lld\n" "MFC Del - Last: %s Events: %lld\n", - uptime_scan_oil, (long long)qpim_scan_oil_events, + uptime_scan_oil, (long long)pim->scan_oil_events, uptime_mroute_add, (long long)pim->mroute_add_events, uptime_mroute_del, (long long)pim->mroute_del_events); } -static void pim_show_rpf(struct pim_instance *pim, struct vty *vty, u_char uj) +static void pim_show_rpf(struct pim_instance *pim, struct vty *vty, uint8_t uj) { struct listnode *up_node; struct pim_upstream *up; @@ -2642,9 +2642,9 @@ static void pim_show_rpf(struct pim_instance *pim, struct vty *vty, u_char uj) if (uj) { json = json_object_new_object(); - show_rpf_refresh_stats(vty, now, json); + show_rpf_refresh_stats(vty, pim, now, json); } else { - show_rpf_refresh_stats(vty, now, json); + show_rpf_refresh_stats(vty, pim, now, json); vty_out(vty, "\n"); vty_out(vty, "Source Group RpfIface RpfAddress RibNextHop Metric Pref\n"); @@ -2755,7 +2755,7 @@ static void pim_show_nexthop(struct pim_instance *pim, struct vty *vty) } static void igmp_show_groups(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct interface *ifp; time_t now; @@ -3306,7 +3306,7 @@ DEFUN (show_ip_igmp_interface, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3333,7 +3333,7 @@ DEFUN (show_ip_igmp_interface_vrf_all, JSON_STR) { int idx = 2; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3389,7 +3389,7 @@ DEFUN (show_ip_igmp_join_vrf_all, VRF_CMD_HELP_STR "IGMP static join information\n") { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3423,7 +3423,7 @@ DEFUN (show_ip_igmp_groups, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3443,7 +3443,7 @@ DEFUN (show_ip_igmp_groups_vrf_all, IGMP_GROUP_STR JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3621,7 +3621,7 @@ DEFUN (show_ip_pim_interface, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3648,7 +3648,7 @@ DEFUN (show_ip_pim_interface_vrf_all, JSON_STR) { int idx = 6; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3687,7 +3687,7 @@ DEFUN (show_ip_pim_join, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3707,7 +3707,7 @@ DEFUN (show_ip_pim_join_vrf_all, "PIM interface join information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3741,7 +3741,7 @@ DEFUN (show_ip_pim_local_membership, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3765,7 +3765,7 @@ DEFUN (show_ip_pim_neighbor, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3792,7 +3792,7 @@ DEFUN (show_ip_pim_neighbor_vrf_all, JSON_STR) { int idx = 2; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3855,7 +3855,7 @@ DEFUN (show_ip_pim_state, const char *group = NULL; int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3889,7 +3889,7 @@ DEFUN (show_ip_pim_state_vrf_all, const char *src_or_group = NULL; const char *group = NULL; int idx = 2; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3932,7 +3932,7 @@ DEFUN (show_ip_pim_upstream, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -3952,7 +3952,7 @@ DEFUN (show_ip_pim_upstream_vrf_all, "PIM upstream information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -3984,7 +3984,7 @@ DEFUN (show_ip_pim_upstream_join_desired, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -4006,7 +4006,7 @@ DEFUN (show_ip_pim_upstream_rpf, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -4028,7 +4028,7 @@ DEFUN (show_ip_pim_rp, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -4048,7 +4048,7 @@ DEFUN (show_ip_pim_rp_vrf_all, "PIM RP information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -4082,7 +4082,7 @@ DEFUN (show_ip_pim_rpf, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -4102,7 +4102,7 @@ DEFUN (show_ip_pim_rpf_vrf_all, "PIM cached source rpf information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -4249,7 +4249,7 @@ DEFUN (show_ip_pim_interface_traffic, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -4337,7 +4337,7 @@ static void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim, vty_out(vty, "\n"); - show_rpf_refresh_stats(vty, now, NULL); + show_rpf_refresh_stats(vty, pim, now, NULL); vty_out(vty, "\n"); @@ -4373,7 +4373,7 @@ DEFUN (show_ip_multicast_vrf_all, VRF_CMD_HELP_STR "Multicast global information\n") { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -4396,7 +4396,7 @@ DEFUN (show_ip_multicast_vrf_all, } static void show_mroute(struct pim_instance *pim, struct vty *vty, bool fill, - u_char uj) + uint8_t uj) { struct listnode *node; struct channel_oil *c_oil; @@ -4730,7 +4730,7 @@ DEFUN (show_ip_mroute, "Fill in Assumed data\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); bool fill = false; int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); @@ -4755,7 +4755,7 @@ DEFUN (show_ip_mroute_vrf_all, "Fill in Assumed data\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 4; struct vrf *vrf; bool first = true; @@ -4863,7 +4863,7 @@ DEFUN (show_ip_mroute_count_vrf_all, VRF_CMD_HELP_STR "Route and packet count data\n") { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -5454,7 +5454,7 @@ DEFUN (no_ip_pim_ssm_prefix_list_name, } static void ip_pim_ssm_show_group_range(struct pim_instance *pim, - struct vty *vty, u_char uj) + struct vty *vty, uint8_t uj) { struct pim_ssm *ssm = pim->ssm_info; const char *range_str = @@ -5483,7 +5483,7 @@ DEFUN (show_ip_pim_ssm_range, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -5494,7 +5494,7 @@ DEFUN (show_ip_pim_ssm_range, } static void ip_pim_ssm_show_group_type(struct pim_instance *pim, - struct vty *vty, u_char uj, + struct vty *vty, uint8_t uj, const char *group) { struct in_addr group_addr; @@ -5536,7 +5536,7 @@ DEFUN (show_ip_pim_group_type, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!vrf) return CMD_WARNING; @@ -7226,8 +7226,13 @@ DEFUN (no_debug_msdp, return CMD_SUCCESS; } -ALIAS(no_debug_msdp, undebug_msdp_cmd, "undebug msdp", - UNDEBUG_STR DEBUG_MSDP_STR) +#if CONFDATE > 20190402 +CPP_NOTICE("bgpd: time to remove undebug commands") +#endif +ALIAS_HIDDEN (no_debug_msdp, + undebug_msdp_cmd, + "undebug msdp", + UNDEBUG_STR DEBUG_MSDP_STR) DEFUN (debug_msdp_events, debug_msdp_events_cmd, @@ -7252,8 +7257,15 @@ DEFUN (no_debug_msdp_events, return CMD_SUCCESS; } -ALIAS(no_debug_msdp_events, undebug_msdp_events_cmd, "undebug msdp events", - UNDEBUG_STR DEBUG_MSDP_STR DEBUG_MSDP_EVENTS_STR) +#if CONFDATE > 20190402 +CPP_NOTICE("bgpd: time to remove undebug commands") +#endif +ALIAS_HIDDEN (no_debug_msdp_events, + undebug_msdp_events_cmd, + "undebug msdp events", + UNDEBUG_STR + DEBUG_MSDP_STR + DEBUG_MSDP_EVENTS_STR) DEFUN (debug_msdp_packets, debug_msdp_packets_cmd, @@ -7278,8 +7290,15 @@ DEFUN (no_debug_msdp_packets, return CMD_SUCCESS; } -ALIAS(no_debug_msdp_packets, undebug_msdp_packets_cmd, "undebug msdp packets", - UNDEBUG_STR DEBUG_MSDP_STR DEBUG_MSDP_PACKETS_STR) +#if CONFDATE > 20190402 +CPP_NOTICE("bgpd: time to remove undebug commands") +#endif +ALIAS_HIDDEN (no_debug_msdp_packets, + undebug_msdp_packets_cmd, + "undebug msdp packets", + UNDEBUG_STR + DEBUG_MSDP_STR + DEBUG_MSDP_PACKETS_STR) DEFUN (debug_mtrace, debug_mtrace_cmd, @@ -7439,9 +7458,9 @@ DEFUN (ip_pim_bfd_param, int idx_number = 3; int idx_number_2 = 4; int idx_number_3 = 5; - u_int32_t rx_val; - u_int32_t tx_val; - u_int8_t dm_val; + uint32_t rx_val; + uint32_t tx_val; + uint8_t dm_val; int ret; struct pim_interface *pim_ifp = ifp->info; @@ -7787,7 +7806,7 @@ static void print_empty_json_obj(struct vty *vty) } static void ip_msdp_show_mesh_group(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *mbrnode; struct pim_msdp_mg_mbr *mbr; @@ -7864,7 +7883,7 @@ DEFUN (show_ip_msdp_mesh_group, "MSDP mesh-group information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); @@ -7886,7 +7905,7 @@ DEFUN (show_ip_msdp_mesh_group_vrf_all, "MSDP mesh-group information\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -7909,7 +7928,7 @@ DEFUN (show_ip_msdp_mesh_group_vrf_all, } static void ip_msdp_show_peers(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *mpnode; struct pim_msdp_peer *mp; @@ -7963,7 +7982,7 @@ static void ip_msdp_show_peers(struct pim_instance *pim, struct vty *vty, } static void ip_msdp_show_peers_detail(struct pim_instance *pim, struct vty *vty, - const char *peer, u_char uj) + const char *peer, uint8_t uj) { struct listnode *mpnode; struct pim_msdp_peer *mp; @@ -8079,7 +8098,7 @@ DEFUN (show_ip_msdp_peer_detail, "peer ip address\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); @@ -8114,7 +8133,7 @@ DEFUN (show_ip_msdp_peer_detail_vrf_all, JSON_STR) { int idx = 2; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -8142,7 +8161,7 @@ DEFUN (show_ip_msdp_peer_detail_vrf_all, } static void ip_msdp_show_sa(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *sanode; struct pim_msdp_sa *sa; @@ -8219,7 +8238,7 @@ static void ip_msdp_show_sa(struct pim_instance *pim, struct vty *vty, static void ip_msdp_show_sa_entry_detail(struct pim_msdp_sa *sa, const char *src_str, const char *grp_str, struct vty *vty, - u_char uj, json_object *json) + uint8_t uj, json_object *json) { char rp_str[INET_ADDRSTRLEN]; char peer_str[INET_ADDRSTRLEN]; @@ -8283,7 +8302,7 @@ static void ip_msdp_show_sa_entry_detail(struct pim_msdp_sa *sa, } static void ip_msdp_show_sa_detail(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct listnode *sanode; struct pim_msdp_sa *sa; @@ -8320,7 +8339,7 @@ DEFUN (show_ip_msdp_sa_detail, "Detailed output\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); @@ -8343,7 +8362,7 @@ DEFUN (show_ip_msdp_sa_detail_vrf_all, "Detailed output\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; @@ -8366,7 +8385,7 @@ DEFUN (show_ip_msdp_sa_detail_vrf_all, } static void ip_msdp_show_sa_addr(struct pim_instance *pim, struct vty *vty, - const char *addr, u_char uj) + const char *addr, uint8_t uj) { struct listnode *sanode; struct pim_msdp_sa *sa; @@ -8395,7 +8414,7 @@ static void ip_msdp_show_sa_addr(struct pim_instance *pim, struct vty *vty, } static void ip_msdp_show_sa_sg(struct pim_instance *pim, struct vty *vty, - const char *src, const char *grp, u_char uj) + const char *src, const char *grp, uint8_t uj) { struct listnode *sanode; struct pim_msdp_sa *sa; @@ -8435,7 +8454,7 @@ DEFUN (show_ip_msdp_sa_sg, "group ip\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; int idx = 2; @@ -8472,7 +8491,7 @@ DEFUN (show_ip_msdp_sa_sg_vrf_all, "group ip\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); struct vrf *vrf; bool first = true; int idx = 2; diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c index b183492e3e..8274d08a26 100644 --- a/pimd/pim_igmp_mtrace.c +++ b/pimd/pim_igmp_mtrace.c @@ -174,7 +174,7 @@ static int mtrace_send_packet(struct interface *ifp, int fd; char if_str[INET_ADDRSTRLEN]; char rsp_str[INET_ADDRSTRLEN]; - u_char ttl; + uint8_t ttl; memset(&to, 0, sizeof(to)); to.sin_family = AF_INET; diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 60a3308a00..ab4ffc26ae 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -119,6 +119,7 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) pim_upstream_init(pim); + pim->last_route_change_time = -1; return pim; } diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index 5422e8fe0d..75f011513f 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -94,6 +94,18 @@ struct pim_instance { unsigned int keep_alive_time; unsigned int rp_keep_alive_time; + + /* If we need to rescan all our upstreams */ + struct thread *rpf_cache_refresher; + int64_t rpf_cache_refresh_requests; + int64_t rpf_cache_refresh_events; + int64_t rpf_cache_refresh_last; + int64_t scan_oil_events; + int64_t scan_oil_last; + + int64_t nexthop_lookups; + int64_t nexthop_lookups_avoided; + int64_t last_route_change_time; }; void pim_vrf_init(void); diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index dd77e2b084..20a942b4fd 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -477,17 +477,6 @@ struct pim_neighbor *pim_neighbor_find_if(struct interface *ifp) return listnode_head(pim_ifp->pim_neighbor_list); } -/* rpf info associated with an upstream entry needs to be re-evaluated - * when an RPF neighbor comes or goes */ -static void pim_neighbor_rpf_update(void) -{ - /* XXX: for the time being piggyback on the timer used on rib changes - * to scan and update the rpf nexthop. This is expensive processing - * and we should be able to optimize neighbor changes differently than - * nexthop changes. */ - sched_rpf_cache_refresh(); -} - struct pim_neighbor * pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, pim_hello_options hello_options, uint16_t holdtime, @@ -556,7 +545,7 @@ pim_neighbor_add(struct interface *ifp, struct in_addr source_addr, pim_rp_setup(pim_ifp->pim); - pim_neighbor_rpf_update(); + sched_rpf_cache_refresh(pim_ifp->pim); return neigh; } @@ -678,7 +667,7 @@ void pim_neighbor_delete(struct interface *ifp, struct pim_neighbor *neigh, pim_neighbor_free(neigh); - pim_neighbor_rpf_update(); + sched_rpf_cache_refresh(pim_ifp->pim); } void pim_neighbor_delete_all(struct interface *ifp, const char *delete_message) diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 94f19bea77..94cb32bc23 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -759,7 +759,7 @@ int pim_parse_nexthop_update(int command, struct zclient *zclient, pnc->upstream_hash->count, listcount(pnc->rp_list)); } - pim_rpf_set_refresh_time(); + pim_rpf_set_refresh_time(pim); if (listcount(pnc->rp_list)) pim_update_rp_nh(pim, pnc); diff --git a/pimd/pim_nht.h b/pimd/pim_nht.h index 72ed777bf7..77e25dcd70 100644 --- a/pimd/pim_nht.h +++ b/pimd/pim_nht.h @@ -33,13 +33,13 @@ struct pim_nexthop_cache { struct pim_rpf rpf; /* IGP route's metric. */ - u_int32_t metric; + uint32_t metric; uint32_t distance; /* Nexthop number and nexthop linked list. */ - u_char nexthop_num; + uint8_t nexthop_num; struct nexthop *nexthop; int64_t last_update; - u_int16_t flags; + uint16_t flags; #define PIM_NEXTHOP_VALID (1 << 0) struct list *rp_list; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 2395361180..45d3452d71 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -868,7 +868,7 @@ struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group) "%s: Nexthop cache not found for RP %s grp %s register with Zebra", __PRETTY_FUNCTION__, buf, buf1); } - pim_rpf_set_refresh_time(); + pim_rpf_set_refresh_time(pim); pim_nexthop_lookup(pim, &rp_info->rp.source_nexthop, rp_info->rp.rpf_addr.u.prefix4, 1); } @@ -976,7 +976,7 @@ int pim_rp_check_is_my_ip_address(struct pim_instance *pim, } void pim_rp_show_information(struct pim_instance *pim, struct vty *vty, - u_char uj) + uint8_t uj) { struct rp_info *rp_info; struct rp_info *prev_rp_info = NULL; diff --git a/pimd/pim_rp.h b/pimd/pim_rp.h index e07d65137f..e0631b27be 100644 --- a/pimd/pim_rp.h +++ b/pimd/pim_rp.h @@ -68,7 +68,7 @@ struct pim_rpf *pim_rp_g(struct pim_instance *pim, struct in_addr group); #define RP(P, G) pim_rp_g ((P), (G)) void pim_rp_show_information(struct pim_instance *pim, struct vty *vty, - u_char uj); + uint8_t uj); void pim_resolve_rp_nh(struct pim_instance *pim); int pim_rp_list_cmp(void *v1, void *v2); #endif diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index b5d5f006f2..221c1ee4af 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -37,17 +37,15 @@ #include "pim_nht.h" #include "pim_oil.h" -static long long last_route_change_time = -1; -long long nexthop_lookups_avoided = 0; - static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up); -void pim_rpf_set_refresh_time(void) +void pim_rpf_set_refresh_time(struct pim_instance *pim) { - last_route_change_time = pim_time_monotonic_usec(); + pim->last_route_change_time = pim_time_monotonic_usec(); if (PIM_DEBUG_TRACE) - zlog_debug("%s: New last route change time: %lld", - __PRETTY_FUNCTION__, last_route_change_time); + zlog_debug("%s: vrf(%s) New last route change time: %" PRId64, + __PRETTY_FUNCTION__, pim->vrf->name, + pim->last_route_change_time); } int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, @@ -70,7 +68,7 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, return -1; if ((nexthop->last_lookup.s_addr == addr.s_addr) - && (nexthop->last_lookup_time > last_route_change_time)) { + && (nexthop->last_lookup_time > pim->last_route_change_time)) { if (PIM_DEBUG_TRACE) { char addr_str[INET_ADDRSTRLEN]; pim_inet4_dump("<addr?>", addr, addr_str, @@ -79,12 +77,12 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, pim_addr_dump("<nexthop?>", &nexthop->mrib_nexthop_addr, nexthop_str, sizeof(nexthop_str)); zlog_debug( - "%s: Using last lookup for %s at %lld, %lld addr%s", + "%s: Using last lookup for %s at %lld, %" PRId64 " addr%s", __PRETTY_FUNCTION__, addr_str, nexthop->last_lookup_time, - last_route_change_time, nexthop_str); + pim->last_route_change_time, nexthop_str); } - nexthop_lookups_avoided++; + pim->nexthop_lookups_avoided++; return 0; } else { if (PIM_DEBUG_TRACE) { @@ -92,10 +90,10 @@ int pim_nexthop_lookup(struct pim_instance *pim, struct pim_nexthop *nexthop, pim_inet4_dump("<addr?>", addr, addr_str, sizeof(addr_str)); zlog_debug( - "%s: Looking up: %s, last lookup time: %lld, %lld", + "%s: Looking up: %s, last lookup time: %lld, %" PRId64, __PRETTY_FUNCTION__, addr_str, nexthop->last_lookup_time, - last_route_change_time); + pim->last_route_change_time); } } diff --git a/pimd/pim_rpf.h b/pimd/pim_rpf.h index 86032f1c29..78bbfc7ed9 100644 --- a/pimd/pim_rpf.h +++ b/pimd/pim_rpf.h @@ -56,8 +56,6 @@ enum pim_rpf_result { PIM_RPF_OK = 0, PIM_RPF_CHANGED, PIM_RPF_FAILURE }; struct pim_upstream; -extern long long nexthop_lookups_avoided; - unsigned int pim_rpf_hash_key(void *arg); int pim_rpf_equal(const void *arg1, const void *arg2); @@ -71,5 +69,5 @@ 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); -void pim_rpf_set_refresh_time(void); +void pim_rpf_set_refresh_time(struct pim_instance *pim); #endif /* PIM_RPF_H */ diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index a5a842ceee..8f311391e1 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -107,7 +107,7 @@ int pim_socket_bind(int fd, struct interface *ifp) } int pim_socket_mcast(int protocol, struct in_addr ifaddr, struct interface *ifp, - u_char loop) + uint8_t loop) { int rcvbuf = 1024 * 1024 * 8; #ifdef HAVE_STRUCT_IP_MREQN_IMR_IFINDEX diff --git a/pimd/pim_sock.h b/pimd/pim_sock.h index 358dd39a44..98db6fecd7 100644 --- a/pimd/pim_sock.h +++ b/pimd/pim_sock.h @@ -39,7 +39,7 @@ int pim_socket_bind(int fd, struct interface *ifp); void pim_socket_ip_hdr(int fd); int pim_socket_raw(int protocol); int pim_socket_mcast(int protocol, struct in_addr ifaddr, struct interface *ifp, - u_char loop); + uint8_t loop); int pim_socket_join(int fd, struct in_addr group, struct in_addr ifaddr, ifindex_t ifindex); int pim_socket_join_source(int fd, ifindex_t ifindex, struct in_addr group_addr, diff --git a/pimd/pim_ssm.c b/pimd/pim_ssm.c index 71bb6f2abd..d35f5cff7e 100644 --- a/pimd/pim_ssm.c +++ b/pimd/pim_ssm.c @@ -48,7 +48,7 @@ static void pim_ssm_range_reevaluate(struct pim_instance *pim) * disappear in time for SSM groups. */ pim_upstream_register_reevaluate(pim); - igmp_source_forward_reevaluate_all(); + igmp_source_forward_reevaluate_all(pim); } void pim_ssm_prefix_list_update(struct pim_instance *pim, diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 81c0cb6efb..6cce697202 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -394,133 +394,105 @@ static int pim_zebra_if_address_del(int command, struct zclient *client, return 0; } -static void scan_upstream_rpf_cache() +static void scan_upstream_rpf_cache(struct pim_instance *pim) { struct listnode *up_node; struct listnode *up_nextnode; struct listnode *node; struct pim_upstream *up; struct interface *ifp; - struct vrf *vrf; - struct pim_instance *pim; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - pim = vrf->info; - if (!pim) - continue; - for (ALL_LIST_ELEMENTS(pim->upstream_list, up_node, up_nextnode, - up)) { - enum pim_rpf_result rpf_result; - struct pim_rpf old; - struct prefix nht_p; + for (ALL_LIST_ELEMENTS(pim->upstream_list, up_node, up_nextnode, up)) { + enum pim_rpf_result rpf_result; + struct pim_rpf old; + struct prefix nht_p; - nht_p.family = AF_INET; - nht_p.prefixlen = IPV4_MAX_BITLEN; - nht_p.u.prefix4.s_addr = up->upstream_addr.s_addr; - pim_resolve_upstream_nh(pim, &nht_p); + nht_p.family = AF_INET; + nht_p.prefixlen = IPV4_MAX_BITLEN; + nht_p.u.prefix4.s_addr = up->upstream_addr.s_addr; + pim_resolve_upstream_nh(pim, &nht_p); - old.source_nexthop.interface = - up->rpf.source_nexthop.interface; - old.source_nexthop.nbr = up->rpf.source_nexthop.nbr; - rpf_result = pim_rpf_update(pim, up, &old, 0); + old.source_nexthop.interface = up->rpf.source_nexthop.interface; + old.source_nexthop.nbr = up->rpf.source_nexthop.nbr; + rpf_result = pim_rpf_update(pim, up, &old, 0); - if (rpf_result == PIM_RPF_FAILURE) - continue; + if (rpf_result == PIM_RPF_FAILURE) + continue; - if (rpf_result == PIM_RPF_CHANGED) { - struct pim_neighbor *nbr; + if (rpf_result == PIM_RPF_CHANGED) { + struct pim_neighbor *nbr; + + nbr = pim_neighbor_find(old.source_nexthop.interface, + old.rpf_addr.u.prefix4); + if (nbr) + pim_jp_agg_remove_group(nbr->upstream_jp_agg, + up); + + /* + * We have detected a case where we might need + * to rescan + * the inherited o_list so do it. + */ + if (up->channel_oil->oil_inherited_rescan) { + pim_upstream_inherited_olist_decide(pim, up); + up->channel_oil->oil_inherited_rescan = 0; + } - nbr = pim_neighbor_find( - old.source_nexthop.interface, - old.rpf_addr.u.prefix4); - if (nbr) - pim_jp_agg_remove_group( - nbr->upstream_jp_agg, up); + if (up->join_state == PIM_UPSTREAM_JOINED) { + /* + * If we come up real fast we can be here + * where the mroute has not been installed + * so install it. + */ + if (!up->channel_oil->installed) + pim_mroute_add(up->channel_oil, + __PRETTY_FUNCTION__); /* - * We have detected a case where we might need - * to rescan - * the inherited o_list so do it. + * RFC 4601: 4.5.7. Sending (S,G) + * Join/Prune Messages + * + * Transitions from Joined State + * + * RPF'(S,G) changes not due to an Assert + * + * The upstream (S,G) state machine remains + * in Joined state. Send Join(S,G) to the new + * upstream neighbor, which is the new value + * of RPF'(S,G). Send Prune(S,G) to the old + * upstream neighbor, which is the old value + * of RPF'(S,G). Set the Join Timer (JT) to + * expire after t_periodic seconds. */ - if (up->channel_oil->oil_inherited_rescan) { - pim_upstream_inherited_olist_decide(pim, - up); - up->channel_oil->oil_inherited_rescan = - 0; - } + pim_jp_agg_switch_interface(&old, &up->rpf, up); - if (up->join_state == PIM_UPSTREAM_JOINED) { - /* - * If we come up real fast we can be - * here - * where the mroute has not been - * installed - * so install it. - */ - if (!up->channel_oil->installed) - pim_mroute_add( - up->channel_oil, - __PRETTY_FUNCTION__); - - /* - * RFC 4601: 4.5.7. Sending (S,G) - * Join/Prune Messages - * - * Transitions from Joined State - * - * RPF'(S,G) changes not due to an - * Assert - * - * The upstream (S,G) state machine - * remains in Joined - * state. Send Join(S,G) to the new - * upstream neighbor, which is - * the new value of RPF'(S,G). Send - * Prune(S,G) to the old - * upstream neighbor, which is the old - * value of RPF'(S,G). Set - * the Join Timer (JT) to expire after - * t_periodic seconds. - */ - pim_jp_agg_switch_interface( - &old, &up->rpf, up); - - pim_upstream_join_timer_restart(up, - &old); - } /* up->join_state == PIM_UPSTREAM_JOINED */ - - /* FIXME can join_desired actually be changed by - pim_rpf_update() - returning PIM_RPF_CHANGED ? */ - pim_upstream_update_join_desired(pim, up); - - } /* PIM_RPF_CHANGED */ - - } /* for (qpim_upstream_list) */ - } + pim_upstream_join_timer_restart(up, &old); + } /* up->join_state == PIM_UPSTREAM_JOINED */ - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - pim = vrf->info; - if (!pim) - continue; + /* FIXME can join_desired actually be changed by + pim_rpf_update() + returning PIM_RPF_CHANGED ? */ + pim_upstream_update_join_desired(pim, up); - FOR_ALL_INTERFACES (pim->vrf, ifp) - if (ifp->info) { - struct pim_interface *pim_ifp = ifp->info; - struct pim_iface_upstream_switch *us; + } /* PIM_RPF_CHANGED */ - for (ALL_LIST_ELEMENTS_RO( - pim_ifp->upstream_switch_list, - node, us)) { - struct pim_rpf rpf; - rpf.source_nexthop.interface = ifp; - rpf.rpf_addr.u.prefix4 = us->address; - pim_joinprune_send(&rpf, us->us); - pim_jp_agg_clear_group(us->us); - } + } /* for (qpim_upstream_list) */ + + FOR_ALL_INTERFACES (pim->vrf, ifp) + if (ifp->info) { + struct pim_interface *pim_ifp = ifp->info; + struct pim_iface_upstream_switch *us; + + for (ALL_LIST_ELEMENTS_RO(pim_ifp->upstream_switch_list, + node, us)) { + struct pim_rpf rpf; + + rpf.source_nexthop.interface = ifp; + rpf.rpf_addr.u.prefix4 = us->address; + pim_joinprune_send(&rpf, us->us); + pim_jp_agg_clear_group(us->us); } - } + } } void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index) @@ -657,69 +629,57 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index) } } -void pim_scan_oil(struct pim_instance *pim_matcher) +void pim_scan_oil(struct pim_instance *pim) { struct listnode *node; struct listnode *nextnode; struct channel_oil *c_oil; ifindex_t ifindex; int vif_index = 0; - struct vrf *vrf; - struct pim_instance *pim; - - qpim_scan_oil_last = pim_time_monotonic_sec(); - ++qpim_scan_oil_events; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - pim = vrf->info; - if (!pim) - continue; - - if (pim_matcher && pim != pim_matcher) - continue; - - for (ALL_LIST_ELEMENTS(pim->channel_oil_list, node, nextnode, - c_oil)) { - if (c_oil->up - && c_oil->up->rpf.source_nexthop.interface) { - ifindex = c_oil->up->rpf.source_nexthop - .interface->ifindex; - vif_index = pim_if_find_vifindex_by_ifindex( - pim, ifindex); - /* Pass Current selected NH vif index to mroute - * download */ - if (vif_index) - pim_scan_individual_oil(c_oil, - vif_index); - } else - pim_scan_individual_oil(c_oil, 0); - } + pim->scan_oil_last = pim_time_monotonic_sec(); + ++pim->scan_oil_events; + + for (ALL_LIST_ELEMENTS(pim->channel_oil_list, node, nextnode, c_oil)) { + if (c_oil->up && c_oil->up->rpf.source_nexthop.interface) { + ifindex = c_oil->up->rpf.source_nexthop + .interface->ifindex; + vif_index = + pim_if_find_vifindex_by_ifindex(pim, ifindex); + /* Pass Current selected NH vif index to mroute + * download */ + if (vif_index) + pim_scan_individual_oil(c_oil, vif_index); + } else + pim_scan_individual_oil(c_oil, 0); } } static int on_rpf_cache_refresh(struct thread *t) { + struct pim_instance *pim = THREAD_ARG(t); + /* update PIM protocol state */ - scan_upstream_rpf_cache(); + scan_upstream_rpf_cache(pim); /* update kernel multicast forwarding cache (MFC) */ - pim_scan_oil(NULL); + pim_scan_oil(pim); - qpim_rpf_cache_refresh_last = pim_time_monotonic_sec(); - ++qpim_rpf_cache_refresh_events; + pim->rpf_cache_refresh_last = pim_time_monotonic_sec(); + ++pim->rpf_cache_refresh_events; // It is called as part of pim_neighbor_add // pim_rp_setup (); return 0; } -void sched_rpf_cache_refresh(void) +void sched_rpf_cache_refresh(struct pim_instance *pim) { - ++qpim_rpf_cache_refresh_requests; + ++pim->rpf_cache_refresh_requests; - pim_rpf_set_refresh_time(); + pim_rpf_set_refresh_time(pim); - if (qpim_rpf_cache_refresher) { + if (pim->rpf_cache_refresher) { /* Refresh timer is already running */ return; } @@ -731,9 +691,9 @@ void sched_rpf_cache_refresh(void) qpim_rpf_cache_refresh_delay_msec); } - thread_add_timer_msec(master, on_rpf_cache_refresh, 0, + thread_add_timer_msec(master, on_rpf_cache_refresh, pim, qpim_rpf_cache_refresh_delay_msec, - &qpim_rpf_cache_refresher); + &pim->rpf_cache_refresher); } static void pim_zebra_connected(struct zclient *zclient) @@ -864,48 +824,40 @@ static void igmp_source_forward_reevaluate_one(struct pim_instance *pim, } } -void igmp_source_forward_reevaluate_all(void) +void igmp_source_forward_reevaluate_all(struct pim_instance *pim) { struct interface *ifp; - struct vrf *vrf; - struct pim_instance *pim; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - pim = vrf->info; - if (!pim) + FOR_ALL_INTERFACES (pim->vrf, ifp) { + struct pim_interface *pim_ifp = ifp->info; + struct listnode *sock_node; + struct igmp_sock *igmp; + + if (!pim_ifp) continue; - FOR_ALL_INTERFACES (pim->vrf, ifp) { - struct pim_interface *pim_ifp = ifp->info; - struct listnode *sock_node; - struct igmp_sock *igmp; - - if (!pim_ifp) - continue; - - /* scan igmp sockets */ - for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, - sock_node, igmp)) { - struct listnode *grpnode; - struct igmp_group *grp; - - /* scan igmp groups */ - for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, - grpnode, grp)) { - struct listnode *srcnode; - struct igmp_source *src; - - /* scan group sources */ - for (ALL_LIST_ELEMENTS_RO( - grp->group_source_list, - srcnode, src)) { - igmp_source_forward_reevaluate_one( - pim, src); - } /* scan group sources */ - } /* scan igmp groups */ - } /* scan igmp sockets */ - } /* scan interfaces */ - } + /* scan igmp sockets */ + for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, + igmp)) { + struct listnode *grpnode; + struct igmp_group *grp; + + /* scan igmp groups */ + for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, + grpnode, grp)) { + struct listnode *srcnode; + struct igmp_source *src; + + /* scan group sources */ + for (ALL_LIST_ELEMENTS_RO( + grp->group_source_list, srcnode, + src)) { + igmp_source_forward_reevaluate_one(pim, + src); + } /* scan group sources */ + } /* scan igmp groups */ + } /* scan igmp sockets */ + } /* scan interfaces */ } void igmp_source_forward_start(struct pim_instance *pim, diff --git a/pimd/pim_zebra.h b/pimd/pim_zebra.h index d9b17cb82d..dd46fd40f9 100644 --- a/pimd/pim_zebra.h +++ b/pimd/pim_zebra.h @@ -39,11 +39,11 @@ void igmp_anysource_forward_stop(struct igmp_group *group); void igmp_source_forward_start(struct pim_instance *pim, struct igmp_source *source); void igmp_source_forward_stop(struct igmp_source *source); -void igmp_source_forward_reevaluate_all(void); +void igmp_source_forward_reevaluate_all(struct pim_instance *pim); void pim_forward_start(struct pim_ifchannel *ch); void pim_forward_stop(struct pim_ifchannel *ch, bool install_it); -void sched_rpf_cache_refresh(void); +void sched_rpf_cache_refresh(struct pim_instance *pim); struct zclient *pim_zebra_zclient_get(void); #endif /* PIM_ZEBRA_H */ diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index 8006148f93..37e2bfbbfd 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -144,8 +144,8 @@ static int zclient_read_nexthop(struct pim_instance *pim, int num_ifindex = 0; struct stream *s; uint16_t length; - u_char marker; - u_char version; + uint8_t marker; + uint8_t version; vrf_id_t vrf_id; uint16_t command = 0; struct in_addr raddr; @@ -352,7 +352,7 @@ int zclient_lookup_nexthop(struct pim_instance *pim, uint32_t route_metric = 0xFFFFFFFF; uint8_t protocol_distance = 0xFF; - qpim_nexthop_lookups++; + pim->nexthop_lookups++; for (lookup = 0; lookup < max_lookup; ++lookup) { int num_ifindex; @@ -515,8 +515,8 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) int err; uint16_t length = 0; vrf_id_t vrf_id; - u_char marker; - u_char version; + uint8_t marker; + uint8_t version; stream_reset(s); err = zclient_read_header(s, zlookup->sock, &length, &marker, diff --git a/pimd/pimd.c b/pimd/pimd.c index 52e0920f1f..551f6047d7 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -52,13 +52,6 @@ int qpim_t_periodic = PIM_DEFAULT_T_PERIODIC; /* Period between Join/Prune Messages */ struct pim_assert_metric qpim_infinite_assert_metric; long qpim_rpf_cache_refresh_delay_msec = 50; -struct thread *qpim_rpf_cache_refresher = NULL; -int64_t qpim_rpf_cache_refresh_requests = 0; -int64_t qpim_rpf_cache_refresh_events = 0; -int64_t qpim_rpf_cache_refresh_last = 0; -int64_t qpim_scan_oil_events = 0; -int64_t qpim_scan_oil_last = 0; -int64_t qpim_nexthop_lookups = 0; int qpim_packet_process = PIM_DEFAULT_PACKET_PROCESS; uint8_t qpim_ecmp_enable = 0; uint8_t qpim_ecmp_rebalance_enable = 0; diff --git a/pimd/pimd.h b/pimd/pimd.h index de7f259319..840e0d7e34 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -140,13 +140,6 @@ struct in_addr qpim_all_pim_routers_addr; int qpim_t_periodic; /* Period between Join/Prune Messages */ struct pim_assert_metric qpim_infinite_assert_metric; long qpim_rpf_cache_refresh_delay_msec; -struct thread *qpim_rpf_cache_refresher; -int64_t qpim_rpf_cache_refresh_requests; -int64_t qpim_rpf_cache_refresh_events; -int64_t qpim_rpf_cache_refresh_last; -int64_t qpim_scan_oil_events; -int64_t qpim_scan_oil_last; -int64_t qpim_nexthop_lookups; extern int qpim_packet_process; extern uint8_t qpim_ecmp_enable; extern uint8_t qpim_ecmp_rebalance_enable; @@ -40,7 +40,7 @@ */ #define qpb_address_family_set qpb__address_family__set static inline int qpb__address_family__set(Qpb__AddressFamily *pb_family, - u_char family) + uint8_t family) { switch (family) { case AF_INET: @@ -63,7 +63,7 @@ static inline int qpb__address_family__set(Qpb__AddressFamily *pb_family, */ #define qpb_address_family_get qpb__address_family__get static inline int qpb__address_family__get(Qpb__AddressFamily pb_family, - u_char *family) + uint8_t *family) { switch (pb_family) { @@ -115,7 +115,7 @@ static inline Qpb__L3Prefix *qpb__l3_prefix__create(qpb_allocator_t *allocator, */ #define qpb_l3_prefix_get qpb__l3_prefix__get static inline int qpb__l3_prefix__get(const Qpb__L3Prefix *pb_prefix, - u_char family, struct prefix *prefix) + uint8_t family, struct prefix *prefix) { switch (family) { @@ -262,7 +262,7 @@ static inline int qpb__ipv6_address__get(const Qpb__Ipv6Address *v6, #define qpb_l3_address_create qpb__l3_address__create static inline Qpb__L3Address * qpb__l3_address__create(qpb_allocator_t *allocator, union g_addr *addr, - u_char family) + uint8_t family) { Qpb__L3Address *l3_addr; @@ -298,7 +298,7 @@ qpb__l3_address__create(qpb_allocator_t *allocator, union g_addr *addr, */ #define qpb_l3_address_get qpb__l3_address__get static inline int qpb__l3_address__get(const Qpb__L3Address *l3_addr, - u_char *family, union g_addr *addr) + uint8_t *family, union g_addr *addr) { if (l3_addr->v4) { qpb__ipv4_address__get(l3_addr->v4, &addr->ipv4); diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 3a773f2451..5a3f341205 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -133,7 +133,7 @@ void rip_interface_multicast_set(int sock, struct connected *connected) } /* Send RIP request packet to specified interface. */ -static void rip_request_interface_send(struct interface *ifp, u_char version) +static void rip_request_interface_send(struct interface *ifp, uint8_t version) { struct sockaddr_in to; diff --git a/ripd/rip_offset.c b/ripd/rip_offset.c index 0e0230c9d2..ab14c3176d 100644 --- a/ripd/rip_offset.c +++ b/ripd/rip_offset.c @@ -185,7 +185,7 @@ static int rip_offset_list_unset(struct vty *vty, const char *alist, /* If metric is modifed return 1. */ int rip_offset_list_apply_in(struct prefix_ipv4 *p, struct interface *ifp, - u_int32_t *metric) + uint32_t *metric) { struct rip_offset_list *offset; struct access_list *alist; @@ -221,7 +221,7 @@ int rip_offset_list_apply_in(struct prefix_ipv4 *p, struct interface *ifp, /* If metric is modifed return 1. */ int rip_offset_list_apply_out(struct prefix_ipv4 *p, struct interface *ifp, - u_int32_t *metric) + uint32_t *metric) { struct rip_offset_list *offset; struct access_list *alist; diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 0a6337bf76..ae62835a74 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -105,7 +105,7 @@ static struct rip_peer *rip_peer_get(struct in_addr *addr) return peer; } -void rip_peer_update(struct sockaddr_in *from, u_char version) +void rip_peer_update(struct sockaddr_in *from, uint8_t version) { struct rip_peer *peer; peer = rip_peer_get(&from->sin_addr); diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c index 40e7ed915b..2c02324876 100644 --- a/ripd/rip_routemap.c +++ b/ripd/rip_routemap.c @@ -37,7 +37,7 @@ struct rip_metric_modifier { enum { metric_increment, metric_decrement, metric_absolute } type; bool used; - u_int8_t metric; + uint8_t metric; }; /* Hook function for updating route_map assignment. */ @@ -62,8 +62,8 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_int32_t *metric; - u_int32_t check; + uint32_t *metric; + uint32_t check; struct rip_info *rinfo; if (type == RMAP_RIP) { @@ -85,9 +85,9 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, /* Route map `match metric' match statement. `arg' is METRIC value */ static void *route_match_metric_compile(const char *arg) { - u_int32_t *metric; + uint32_t *metric; - metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); *metric = atoi(arg); if (*metric > 0) diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 45bb2e377a..917e532e0a 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -88,14 +88,14 @@ static oid rip_oid[] = {RIPV2MIB}; static struct route_table *rip_ifaddr_table; /* Hook functions. */ -static u_char *rip2Globals(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); -static u_char *rip2IfStatEntry(struct variable *, oid[], size_t *, int, - size_t *, WriteMethod **); -static u_char *rip2IfConfAddress(struct variable *, oid[], size_t *, int, - size_t *, WriteMethod **); -static u_char *rip2PeerTable(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); +static uint8_t *rip2Globals(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *rip2IfStatEntry(struct variable *, oid[], size_t *, int, + size_t *, WriteMethod **); +static uint8_t *rip2IfConfAddress(struct variable *, oid[], size_t *, int, + size_t *, WriteMethod **); +static uint8_t *rip2PeerTable(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); static struct variable rip_variables[] = { /* RIP Global Counters. */ @@ -152,9 +152,9 @@ static struct variable rip_variables[] = { extern struct thread_master *master; -static u_char *rip2Globals(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *rip2Globals(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { if (smux_header_generic(v, name, length, exact, var_len, write_method) == MATCH_FAILED) @@ -336,9 +336,9 @@ static struct rip_peer *rip2PeerLookup(struct variable *v, oid name[], return NULL; } -static u_char *rip2IfStatEntry(struct variable *v, oid name[], size_t *length, - int exact, size_t *var_len, - WriteMethod **write_method) +static uint8_t *rip2IfStatEntry(struct variable *v, oid name[], size_t *length, + int exact, size_t *var_len, + WriteMethod **write_method) { struct interface *ifp; struct rip_interface *ri; @@ -365,20 +365,20 @@ static u_char *rip2IfStatEntry(struct variable *v, oid name[], size_t *length, break; case RIP2IFSTATRCVBADPACKETS: *var_len = sizeof(long); - return (u_char *)&ri->recv_badpackets; + return (uint8_t *)&ri->recv_badpackets; case RIP2IFSTATRCVBADROUTES: *var_len = sizeof(long); - return (u_char *)&ri->recv_badroutes; + return (uint8_t *)&ri->recv_badroutes; case RIP2IFSTATSENTUPDATES: *var_len = sizeof(long); - return (u_char *)&ri->sent_updates; + return (uint8_t *)&ri->sent_updates; case RIP2IFSTATSTATUS: *var_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&valid; + return (uint8_t *)&valid; default: return NULL; @@ -435,15 +435,15 @@ static long rip2IfConfReceive(struct rip_interface *ri) return doNotReceive; } -static u_char *rip2IfConfAddress(struct variable *v, oid name[], size_t *length, - int exact, size_t *val_len, - WriteMethod **write_method) +static uint8_t *rip2IfConfAddress(struct variable *v, oid name[], + size_t *length, int exact, size_t *val_len, + WriteMethod **write_method) { static struct in_addr addr; static long valid = SNMP_INVALID; static long domain = 0; static long config = 0; - static u_int auth = 0; + static unsigned int auth = 0; struct interface *ifp; struct rip_interface *ri; @@ -464,43 +464,43 @@ static u_char *rip2IfConfAddress(struct variable *v, oid name[], size_t *length, switch (v->magic) { case RIP2IFCONFADDRESS: *val_len = sizeof(struct in_addr); - return (u_char *)&addr; + return (uint8_t *)&addr; case RIP2IFCONFDOMAIN: *val_len = 2; - return (u_char *)&domain; + return (uint8_t *)&domain; case RIP2IFCONFAUTHTYPE: auth = ri->auth_type; *val_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&auth; + return (uint8_t *)&auth; case RIP2IFCONFAUTHKEY: *val_len = 0; - return (u_char *)&domain; + return (uint8_t *)&domain; case RIP2IFCONFSEND: config = rip2IfConfSend(ri); *val_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&config; + return (uint8_t *)&config; case RIP2IFCONFRECEIVE: config = rip2IfConfReceive(ri); *val_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&config; + return (uint8_t *)&config; case RIP2IFCONFDEFAULTMETRIC: *val_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&ifp->metric; + return (uint8_t *)&ifp->metric; case RIP2IFCONFSTATUS: *val_len = sizeof(long); v->type = ASN_INTEGER; - return (u_char *)&valid; + return (uint8_t *)&valid; case RIP2IFCONFSRCADDRESS: *val_len = sizeof(struct in_addr); - return (u_char *)&addr; + return (uint8_t *)&addr; default: return NULL; @@ -508,9 +508,9 @@ static u_char *rip2IfConfAddress(struct variable *v, oid name[], size_t *length, return NULL; } -static u_char *rip2PeerTable(struct variable *v, oid name[], size_t *length, - int exact, size_t *val_len, - WriteMethod **write_method) +static uint8_t *rip2PeerTable(struct variable *v, oid name[], size_t *length, + int exact, size_t *val_len, + WriteMethod **write_method) { static struct in_addr addr; static int domain = 0; @@ -533,11 +533,11 @@ static u_char *rip2PeerTable(struct variable *v, oid name[], size_t *length, switch (v->magic) { case RIP2PEERADDRESS: *val_len = sizeof(struct in_addr); - return (u_char *)&peer->addr; + return (uint8_t *)&peer->addr; case RIP2PEERDOMAIN: *val_len = 2; - return (u_char *)&domain; + return (uint8_t *)&domain; case RIP2PEERLASTUPDATE: #if 0 @@ -548,23 +548,23 @@ static u_char *rip2PeerTable(struct variable *v, oid name[], size_t *length, */ *val_len = sizeof (time_t); uptime = peer->uptime; /* now - snmp_agent_startup - peer->uptime */ - return (u_char *) &uptime; + return (uint8_t *) &uptime; #else - return (u_char *)NULL; + return (uint8_t *)NULL; #endif case RIP2PEERVERSION: *val_len = sizeof(int); version = peer->version; - return (u_char *)&version; + return (uint8_t *)&version; case RIP2PEERRCVBADPACKETS: *val_len = sizeof(int); - return (u_char *)&peer->recv_badpackets; + return (uint8_t *)&peer->recv_badpackets; case RIP2PEERRCVBADROUTES: *val_len = sizeof(int); - return (u_char *)&peer->recv_badroutes; + return (uint8_t *)&peer->recv_badroutes; default: return NULL; diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c index dc972981b0..29b2f88172 100644 --- a/ripd/rip_zebra.c +++ b/ripd/rip_zebra.c @@ -37,7 +37,7 @@ struct zclient *zclient = NULL; /* Send ECMP routes to zebra. */ -static void rip_zebra_ipv4_send(struct route_node *rp, u_char cmd) +static void rip_zebra_ipv4_send(struct route_node *rp, uint8_t cmd) { struct list *list = (struct list *)rp->info; struct zapi_route api; diff --git a/ripd/ripd.c b/ripd/ripd.c index 86c0348b94..ecc4027008 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -64,7 +64,7 @@ long rip_global_queries = 0; /* Prototypes. */ static void rip_event(enum rip_event, int); static void rip_output_process(struct connected *, struct sockaddr_in *, int, - u_char); + uint8_t); static int rip_triggered_update(struct thread *); static int rip_update_jitter(unsigned long); @@ -675,8 +675,8 @@ static void rip_packet_dump(struct rip_packet *packet, int size, struct rte *rte; const char *command_str; char pbuf[BUFSIZ], nbuf[BUFSIZ]; - u_char netmask = 0; - u_char *p; + uint8_t netmask = 0; + uint8_t *p; /* Set command string. */ if (packet->command > 0 && packet->command < RIP_COMMAND_MAX) @@ -698,7 +698,7 @@ static void rip_packet_dump(struct rip_packet *packet, int size, if (rte->family == htons(RIP_FAMILY_AUTH)) { if (rte->tag == htons(RIP_AUTH_SIMPLE_PASSWORD)) { - p = (u_char *)&rte->prefix; + p = (uint8_t *)&rte->prefix; zlog_debug( " family 0x%X type %d auth string: %s", @@ -719,11 +719,11 @@ static void rip_packet_dump(struct rip_packet *packet, int size, " Auth Data len %d", ntohs(md5->packet_len), md5->keyid, md5->auth_len); - zlog_debug( - " Sequence Number %ld", - (u_long)ntohl(md5->sequence)); + zlog_debug(" Sequence Number %ld", + (unsigned long)ntohl( + md5->sequence)); } else if (rte->tag == htons(RIP_AUTH_DATA)) { - p = (u_char *)&rte->prefix; + p = (uint8_t *)&rte->prefix; zlog_debug( " family 0x%X type %d (MD5 data)", @@ -753,7 +753,7 @@ static void rip_packet_dump(struct rip_packet *packet, int size, BUFSIZ), ntohs(rte->family), (route_tag_t)ntohs(rte->tag), - (u_long)ntohl(rte->metric)); + (unsigned long)ntohl(rte->metric)); } else { zlog_debug( " %s family %d tag %" ROUTE_TAG_PRI @@ -761,7 +761,7 @@ static void rip_packet_dump(struct rip_packet *packet, int size, inet_ntop(AF_INET, &rte->prefix, pbuf, BUFSIZ), ntohs(rte->family), (route_tag_t)ntohs(rte->tag), - (u_long)ntohl(rte->metric)); + (unsigned long)ntohl(rte->metric)); } } } @@ -771,7 +771,7 @@ static void rip_packet_dump(struct rip_packet *packet, int size, check net 0 because we accept default route. */ static int rip_destination_check(struct in_addr addr) { - u_int32_t destination; + uint32_t destination; /* Convert to host byte order. */ destination = ntohl(addr.s_addr); @@ -848,8 +848,8 @@ static int rip_auth_md5(struct rip_packet *packet, struct sockaddr_in *from, struct keychain *keychain; struct key *key; MD5_CTX ctx; - u_char digest[RIP_AUTH_MD5_SIZE]; - u_int16_t packet_len; + uint8_t digest[RIP_AUTH_MD5_SIZE]; + uint16_t packet_len; char auth_str[RIP_AUTH_MD5_SIZE]; if (IS_RIP_DEBUG_EVENT) @@ -892,7 +892,7 @@ static int rip_auth_md5(struct rip_packet *packet, struct sockaddr_in *from, } /* retrieve authentication data */ - md5data = (struct rip_md5_data *)(((u_char *)packet) + packet_len); + md5data = (struct rip_md5_data *)(((uint8_t *)packet) + packet_len); memset(auth_str, 0, RIP_AUTH_MD5_SIZE); @@ -1179,7 +1179,7 @@ static void rip_response_process(struct rip_packet *packet, int size, the received Next Hop is not directly reachable, it should be treated as 0.0.0.0. */ if (packet->version == RIPv2 && rte->nexthop.s_addr != 0) { - u_int32_t addrval; + uint32_t addrval; /* Multicast address check. */ addrval = ntohl(rte->nexthop.s_addr); @@ -1245,7 +1245,7 @@ static void rip_response_process(struct rip_packet *packet, int size, || (packet->version == RIPv2 && (rte->prefix.s_addr != 0 && rte->mask.s_addr == 0))) { - u_int32_t destination; + uint32_t destination; if (subnetted == -1) { memcpy(&ifaddr, ifc->address, @@ -1382,7 +1382,7 @@ static int rip_create_socket(void) * by connected argument. NULL to argument denotes destination should be * should be RIP multicast group */ -static int rip_send_packet(u_char *buf, int size, struct sockaddr_in *to, +static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to, struct connected *ifc) { int ret; @@ -1641,7 +1641,7 @@ static void rip_request_process(struct rip_packet *packet, int size, } packet->command = RIP_RESPONSE; - rip_send_packet((u_char *)packet, size, from, ifc); + rip_send_packet((uint8_t *)packet, size, from, ifc); } rip_global_queries++; } @@ -1661,7 +1661,7 @@ static int setsockopt_pktinfo(int sock) } /* Read RIP packet by recvmsg function. */ -int rip_recvmsg(int sock, u_char *buf, int size, struct sockaddr_in *from, +int rip_recvmsg(int sock, uint8_t *buf, int size, struct sockaddr_in *from, ifindex_t *ifindex) { int ret; @@ -2009,7 +2009,7 @@ static int rip_read(struct thread *t) /* Write routing table entry to the stream and return next index of the routing table entry in the stream. */ static int rip_write_rte(int num, struct stream *s, struct prefix_ipv4 *p, - u_char version, struct rip_info *rinfo) + uint8_t version, struct rip_info *rinfo) { struct in_addr mask; @@ -2037,7 +2037,7 @@ static int rip_write_rte(int num, struct stream *s, struct prefix_ipv4 *p, /* Send update to the ifp or spcified neighbor. */ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, - int route_type, u_char version) + int route_type, uint8_t version) { int ret; struct stream *s; @@ -2400,7 +2400,7 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to, } /* Send RIP packet to the interface. */ -static void rip_update_interface(struct connected *ifc, u_char version, +static void rip_update_interface(struct connected *ifc, uint8_t version, int route_type) { struct interface *ifp = ifc->ifp; @@ -2702,7 +2702,7 @@ static int rip_create(void) /* Sned RIP request to the destination. */ int rip_request_send(struct sockaddr_in *to, struct interface *ifp, - u_char version, struct connected *connected) + uint8_t version, struct connected *connected) { struct rte *rte; struct rip_packet rip_packet; @@ -2721,7 +2721,7 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp, * interface does not support multicast. Caller loops * over each connected address for this case. */ - if (rip_send_packet((u_char *)&rip_packet, sizeof(rip_packet), + if (rip_send_packet((uint8_t *)&rip_packet, sizeof(rip_packet), to, connected) != sizeof(rip_packet)) return -1; @@ -2738,7 +2738,7 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp, if (p->family != AF_INET) continue; - if (rip_send_packet((u_char *)&rip_packet, sizeof(rip_packet), + if (rip_send_packet((uint8_t *)&rip_packet, sizeof(rip_packet), to, connected) != sizeof(rip_packet)) return -1; @@ -3060,7 +3060,7 @@ struct route_table *rip_distance_table; struct rip_distance { /* Distance value for the IP source prefix. */ - u_char distance; + uint8_t distance; /* Name of the access-list to be matched. */ char *access_list; @@ -3081,7 +3081,7 @@ static int rip_distance_set(struct vty *vty, const char *distance_str, { int ret; struct prefix_ipv4 p; - u_char distance; + uint8_t distance; struct route_node *rn; struct rip_distance *rdistance; @@ -3166,7 +3166,7 @@ static void rip_distance_reset(void) } /* Apply RIP information to distance method. */ -u_char rip_distance_apply(struct rip_info *rinfo) +uint8_t rip_distance_apply(struct rip_info *rinfo) { struct route_node *rn; struct prefix_ipv4 p; diff --git a/ripd/ripd.h b/ripd/ripd.h index abbc3a79e7..784b064606 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -139,11 +139,11 @@ struct rip { int default_metric; /* RIP default-information originate. */ - u_char default_information; + uint8_t default_information; char *default_information_route_map; /* RIP default distance. */ - u_char distance; + uint8_t distance; struct route_table *distance_table; /* RIP ECMP flag */ @@ -154,7 +154,7 @@ struct rip { char *name; struct route_map *map; int metric_config; - u_int32_t metric; + uint32_t metric; } route_map[ZEBRA_ROUTE_MAX]; QOBJ_FIELDS @@ -163,12 +163,12 @@ DECLARE_QOBJ_TYPE(rip) /* RIP routing table entry which belong to rip_packet. */ struct rte { - u_int16_t family; /* Address family of this route. */ - u_int16_t tag; /* Route Tag which included in RIP2 packet. */ + uint16_t family; /* Address family of this route. */ + uint16_t tag; /* Route Tag which included in RIP2 packet. */ struct in_addr prefix; /* Prefix of rip route. */ struct in_addr mask; /* Netmask of rip route. */ struct in_addr nexthop; /* Next hop of rip route. */ - u_int32_t metric; /* Metric value of rip route. */ + uint32_t metric; /* Metric value of rip route. */ }; /* RIP packet structure. */ @@ -199,19 +199,19 @@ struct rip_info { struct in_addr from; /* Metric of this route. */ - u_int32_t metric; + uint32_t metric; /* External metric of this route. if learnt from an externalm proto */ - u_int32_t external_metric; + uint32_t external_metric; /* Tag information of this route. */ - u_int16_t tag; + uint16_t tag; /* Flags of RIP route. */ #define RIP_RTF_FIB 1 #define RIP_RTF_CHANGED 2 - u_char flags; + uint8_t flags; /* Garbage collect timer. */ struct thread *t_timeout; @@ -219,14 +219,14 @@ struct rip_info { /* Route-map futures - this variables can be changed. */ struct in_addr nexthop_out; - u_char metric_set; - u_int32_t metric_out; - u_int16_t tag_out; + uint8_t metric_set; + uint32_t metric_out; + uint16_t tag_out; ifindex_t ifindex_out; struct route_node *rp; - u_char distance; + uint8_t distance; #ifdef NEW_RIP_TABLE struct rip_info *next; @@ -266,7 +266,7 @@ struct rip_interface { char *key_chain; /* value to use for md5->auth_len */ - u_int8_t md5_auth_len; + uint8_t md5_auth_len; /* Split horizon flag. */ split_horizon_policy_t split_horizon; @@ -310,7 +310,7 @@ struct rip_peer { time_t uptime; /* Peer RIP version. */ - u_char version; + uint8_t version; /* Statistics. */ int recv_badpackets; @@ -321,20 +321,20 @@ struct rip_peer { }; struct rip_md5_info { - u_int16_t family; - u_int16_t type; - u_int16_t packet_len; - u_char keyid; - u_char auth_len; - u_int32_t sequence; - u_int32_t reserv1; - u_int32_t reserv2; + uint16_t family; + uint16_t type; + uint16_t packet_len; + uint8_t keyid; + uint8_t auth_len; + uint32_t sequence; + uint32_t reserv1; + uint32_t reserv2; }; struct rip_md5_data { - u_int16_t family; - u_int16_t type; - u_char digest[16]; + uint16_t family; + uint16_t type; + uint8_t digest[16]; }; /* RIP accepet/announce methods. */ @@ -380,7 +380,7 @@ extern void rip_zclient_reset(void); extern void rip_offset_init(void); extern int if_check_address(struct in_addr addr); -extern int rip_request_send(struct sockaddr_in *, struct interface *, u_char, +extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t, struct connected *); extern int rip_neighbor_lookup(struct sockaddr_in *); @@ -401,7 +401,7 @@ extern int config_write_rip_offset_list(struct vty *); extern int config_write_rip_redistribute(struct vty *, int); extern void rip_peer_init(void); -extern void rip_peer_update(struct sockaddr_in *, u_char); +extern void rip_peer_update(struct sockaddr_in *, uint8_t); extern void rip_peer_bad_route(struct sockaddr_in *); extern void rip_peer_bad_packet(struct sockaddr_in *); extern void rip_peer_display(struct vty *); @@ -409,13 +409,13 @@ extern struct rip_peer *rip_peer_lookup(struct in_addr *); extern struct rip_peer *rip_peer_lookup_next(struct in_addr *); extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *, - u_int32_t *); + uint32_t *); extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *, - u_int32_t *); + uint32_t *); extern void rip_offset_clean(void); extern void rip_info_free(struct rip_info *); -extern u_char rip_distance_apply(struct rip_info *); +extern uint8_t rip_distance_apply(struct rip_info *); extern void rip_redistribute_clean(void); extern struct rip_info *rip_ecmp_add(struct rip_info *); diff --git a/ripngd/ripng_offset.c b/ripngd/ripng_offset.c index 82f8a7aa66..f8d73250b4 100644 --- a/ripngd/ripng_offset.c +++ b/ripngd/ripng_offset.c @@ -194,7 +194,7 @@ static int ripng_offset_list_unset(struct vty *vty, const char *alist, /* If metric is modifed return 1. */ int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp, - u_char *metric) + uint8_t *metric) { struct ripng_offset_list *offset; struct access_list *alist; @@ -232,7 +232,7 @@ int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp, /* If metric is modifed return 1. */ int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp, - u_char *metric) + uint8_t *metric) { struct ripng_offset_list *offset; struct access_list *alist; diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index cd46d97402..2f75898482 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -113,7 +113,7 @@ static struct ripng_peer *ripng_peer_get(struct in6_addr *addr) return peer; } -void ripng_peer_update(struct sockaddr_in6 *from, u_char version) +void ripng_peer_update(struct sockaddr_in6 *from, uint8_t version) { struct ripng_peer *peer; peer = ripng_peer_get(&from->sin6_addr); diff --git a/ripngd/ripng_route.h b/ripngd/ripng_route.h index 3db1279b5c..dc7d422d1e 100644 --- a/ripngd/ripng_route.h +++ b/ripngd/ripng_route.h @@ -30,16 +30,16 @@ struct ripng_aggregate { unsigned int suppress; /* Metric of this route. */ - u_char metric; + uint8_t metric; /* Tag field of RIPng packet.*/ - u_int16_t tag; + uint16_t tag; /* Route-map futures - this variables can be changed. */ struct in6_addr nexthop_out; - u_char metric_set; - u_char metric_out; - u_int16_t tag_out; + uint8_t metric_set; + uint8_t metric_out; + uint16_t tag_out; }; extern void ripng_aggregate_increment(struct route_node *rp, diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c index e518585c74..e9a38d137b 100644 --- a/ripngd/ripng_routemap.c +++ b/ripngd/ripng_routemap.c @@ -33,7 +33,7 @@ struct rip_metric_modifier { enum { metric_increment, metric_decrement, metric_absolute } type; bool used; - u_int8_t metric; + uint8_t metric; }; /* `match metric METRIC' */ @@ -42,7 +42,7 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_int32_t *metric; + uint32_t *metric; struct ripng_info *rinfo; if (type == RMAP_RIPNG) { @@ -60,9 +60,9 @@ static route_map_result_t route_match_metric(void *rule, struct prefix *prefix, /* Route map `match metric' match statement. `arg' is METRIC value */ static void *route_match_metric_compile(const char *arg) { - u_int32_t *metric; + uint32_t *metric; - metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + metric = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); *metric = atoi(arg); if (*metric > 0) diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index 6c9d911a6a..6830e0e926 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -37,7 +37,7 @@ struct zclient *zclient = NULL; /* Send ECMP routes to zebra. */ -static void ripng_zebra_ipv6_send(struct route_node *rp, u_char cmd) +static void ripng_zebra_ipv6_send(struct route_node *rp, uint8_t cmd) { struct list *list = (struct list *)rp->info; struct zapi_route api; diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 673f0637c7..840157516f 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -214,7 +214,7 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to, } /* Receive UDP RIPng packet from socket. */ -static int ripng_recv_packet(int sock, u_char *buf, int bufsize, +static int ripng_recv_packet(int sock, uint8_t *buf, int bufsize, struct sockaddr_in6 *from, ifindex_t *ifindex, int *hoplimit) { @@ -1506,7 +1506,7 @@ int ripng_triggered_update(struct thread *t) /* Write routing table entry to the stream and return next index of the routing table entry in the stream. */ int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p, - struct in6_addr *nexthop, u_int16_t tag, u_char metric) + struct in6_addr *nexthop, uint16_t tag, uint8_t metric) { /* RIPng packet header. */ if (num == 0) { @@ -1517,9 +1517,9 @@ int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p, /* Write routing table entry. */ if (!nexthop) - stream_write(s, (u_char *)&p->prefix, sizeof(struct in6_addr)); + stream_write(s, (uint8_t *)&p->prefix, sizeof(struct in6_addr)); else - stream_write(s, (u_char *)nexthop, sizeof(struct in6_addr)); + stream_write(s, (uint8_t *)nexthop, sizeof(struct in6_addr)); stream_putw(s, tag); if (p) stream_putc(s, p->prefixlen); diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h index 25a5b46c02..534905d895 100644 --- a/ripngd/ripngd.h +++ b/ripngd/ripngd.h @@ -95,8 +95,8 @@ struct ripng { int sock; /* RIPng Parameters.*/ - u_char command; - u_char version; + uint8_t command; + uint8_t version; unsigned long update_time; unsigned long timeout_time; unsigned long garbage_time; @@ -137,35 +137,35 @@ struct ripng { char *name; struct route_map *map; int metric_config; - u_int32_t metric; + uint32_t metric; } route_map[ZEBRA_ROUTE_MAX]; }; /* Routing table entry. */ struct rte { struct in6_addr addr; /* RIPng destination prefix */ - u_int16_t tag; /* RIPng tag */ - u_char prefixlen; /* Length of the RIPng prefix */ - u_char metric; /* Metric of the RIPng route */ + uint16_t tag; /* RIPng tag */ + uint8_t prefixlen; /* Length of the RIPng prefix */ + uint8_t metric; /* Metric of the RIPng route */ /* The nexthop is stored by the structure * ripng_nexthop within ripngd.c */ }; /* RIPNG send packet. */ struct ripng_packet { - u_char command; - u_char version; - u_int16_t zero; + uint8_t command; + uint8_t version; + uint16_t zero; struct rte rte[1]; }; /* Each route's information. */ struct ripng_info { /* This route's type. Static, ripng or aggregate. */ - u_char type; + uint8_t type; /* Sub type for static route. */ - u_char sub_type; + uint8_t sub_type; /* RIPng specific information */ struct in6_addr nexthop; @@ -175,10 +175,10 @@ struct ripng_info { ifindex_t ifindex; /* Metric of this route. */ - u_char metric; + uint8_t metric; /* Tag field of RIPng packet.*/ - u_int16_t tag; + uint16_t tag; /* For aggregation. */ unsigned int suppress; @@ -186,7 +186,7 @@ struct ripng_info { /* Flags of RIPng route. */ #define RIPNG_RTF_FIB 1 #define RIPNG_RTF_CHANGED 2 - u_char flags; + uint8_t flags; /* Garbage collect timer. */ struct thread *t_timeout; @@ -194,9 +194,9 @@ struct ripng_info { /* Route-map features - this variables can be changed. */ struct in6_addr nexthop_out; - u_char metric_set; - u_char metric_out; - u_int16_t tag_out; + uint8_t metric_set; + uint8_t metric_out; + uint16_t tag_out; struct route_node *rp; }; @@ -207,10 +207,10 @@ struct ripng_info { struct ripng_tag { /* Tag value. */ - u_int16_t tag; + uint16_t tag; /* Port. */ - u_int16_t port; + uint16_t port; /* Multicast group. */ struct in6_addr maddr; @@ -222,10 +222,10 @@ struct ripng_tag int distance; /* Split horizon. */ - u_char split_horizon; + uint8_t split_horizon; /* Poison reverse. */ - u_char poison_reverse; + uint8_t poison_reverse; }; #endif /* 0 */ #endif /* not yet */ @@ -271,10 +271,10 @@ struct ripng_interface { #endif /* notyet */ /* Default information originate. */ - u_char default_originate; + uint8_t default_originate; /* Default information only. */ - u_char default_only; + uint8_t default_only; /* Wake up thread. */ struct thread *t_wakeup; @@ -295,7 +295,7 @@ struct ripng_peer { time_t uptime; /* Peer RIP version. */ - u_char version; + uint8_t version; /* Statistics. */ int recv_badpackets; @@ -351,7 +351,7 @@ extern void ripng_offset_init(void); extern int config_write_ripng_offset_list(struct vty *); extern void ripng_peer_init(void); -extern void ripng_peer_update(struct sockaddr_in6 *, u_char); +extern void ripng_peer_update(struct sockaddr_in6 *, uint8_t); extern void ripng_peer_bad_route(struct sockaddr_in6 *); extern void ripng_peer_bad_packet(struct sockaddr_in6 *); extern void ripng_peer_display(struct vty *); @@ -359,9 +359,9 @@ extern struct ripng_peer *ripng_peer_lookup(struct in6_addr *); extern struct ripng_peer *ripng_peer_lookup_next(struct in6_addr *); extern int ripng_offset_list_apply_in(struct prefix_ipv6 *, struct interface *, - u_char *); + uint8_t *); extern int ripng_offset_list_apply_out(struct prefix_ipv6 *, struct interface *, - u_char *); + uint8_t *); extern void ripng_offset_clean(void); extern struct ripng_info *ripng_info_new(void); @@ -385,8 +385,8 @@ extern int ripng_redistribute_check(int); extern void ripng_redistribute_write(struct vty *, int); extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p, - struct in6_addr *nexthop, u_int16_t tag, - u_char metric); + struct in6_addr *nexthop, uint16_t tag, + uint8_t metric); extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to, struct interface *ifp); diff --git a/tests/bgpd/test_aspath.c b/tests/bgpd/test_aspath.c index 9e5cb7fe54..247591580a 100644 --- a/tests/bgpd/test_aspath.c +++ b/tests/bgpd/test_aspath.c @@ -67,7 +67,7 @@ struct test_spec { static struct test_segment { const char *name; const char *desc; - const u_char asdata[1024]; + const uint8_t asdata[1024]; int len; struct test_spec sp; } test_segments[] = { @@ -917,7 +917,7 @@ struct compare_tests { }; /* make an aspath from a data stream */ -static struct aspath *make_aspath(const u_char *data, size_t len, int use32bit) +static struct aspath *make_aspath(const uint8_t *data, size_t len, int use32bit) { struct stream *s = NULL; struct aspath *as; @@ -934,7 +934,7 @@ static struct aspath *make_aspath(const u_char *data, size_t len, int use32bit) return as; } -static void printbytes(const u_char *bytes, int len) +static void printbytes(const uint8_t *bytes, int len) { int i = 0; while (i < len) { @@ -952,7 +952,7 @@ static int validate(struct aspath *as, const struct test_spec *sp) { size_t bytes, bytes4; int fails = 0; - const u_char *out; + const uint8_t *out; static struct stream *s; struct aspath *asinout, *asconfeddel, *asstr, *as4; diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index 69f5afb992..c75a699a16 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -54,7 +54,7 @@ static int tty = 0; static struct test_segment { const char *name; const char *desc; - const u_char data[1024]; + const uint8_t data[1024]; int len; #define SHOULD_PARSE 0 #define SHOULD_ERR -1 diff --git a/tests/bgpd/test_ecommunity.c b/tests/bgpd/test_ecommunity.c index 3de8a9fc72..dc6d8268b1 100644 --- a/tests/bgpd/test_ecommunity.c +++ b/tests/bgpd/test_ecommunity.c @@ -45,7 +45,7 @@ struct test_spec { static struct test_segment { const char *name; const char *desc; - const u_int8_t data[1024]; + const uint8_t data[1024]; int len; struct test_spec sp; } test_segments[] = {{/* 0 */ @@ -121,7 +121,7 @@ static void parse_test(struct test_segment *t) printf("%s: %s\n", t->name, t->desc); - ecom = ecommunity_parse((u_int8_t *)t->data, t->len); + ecom = ecommunity_parse((uint8_t *)t->data, t->len); printf("ecom: %s\nvalidating...:\n", ecommunity_str(ecom)); diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index 8acb280ed3..34c35cfcc5 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -58,7 +58,7 @@ static int tty = 0; static struct test_segment { const char *name; const char *desc; - const u_char data[1024]; + const uint8_t data[1024]; int len; #define SHOULD_PARSE 0 #define SHOULD_ERR -1 @@ -809,7 +809,26 @@ static struct test_segment { 37, SHOULD_ERR, }, - + { + .name = "IPv4", + .desc = "IPV4 MP Reach, flowspec, 1 NLRI", + .data = { + /* AFI / SAFI */ 0x0, + AFI_IP, + IANA_SAFI_FLOWSPEC, + 0x00, /* no NH */ + 0x00, + 0x06, /* FS Length */ + 0x01, /* FS dest prefix ID */ + 0x1e, /* IP */ + 0x1e, + 0x28, + 0x28, + 0x0 + }, + .len = 12, + .parses = SHOULD_PARSE, + }, {NULL, NULL, {0}, 0, 0}}; /* MP_UNREACH_NLRI tests */ @@ -906,6 +925,24 @@ static struct test_segment mp_unreach_segments[] = { (3 + (1 + 3 + 8 + 2) + (1 + 3 + 8 + 3)), SHOULD_PARSE, }, + { + .name = "IPv4", + .desc = "IPV4 MP Unreach, flowspec, 1 NLRI", + .data = { + /* AFI / SAFI */ 0x0, + AFI_IP, + IANA_SAFI_FLOWSPEC, + 0x06, /* FS Length */ + 0x01, /* FS dest prefix ID */ + 0x1e, /* IP */ + 0x1e, + 0x28, + 0x28, + 0x0 + }, + .len = 10, + .parses = SHOULD_PARSE, + }, {NULL, NULL, {0}, 0, 0}}; /* nlri_parse indicates 0 on successful parse, and -1 otherwise. @@ -1002,9 +1039,11 @@ int main(void) conf_bgp_debug_neighbor_events = -1UL; conf_bgp_debug_packet = -1UL; conf_bgp_debug_as4 = -1UL; + conf_bgp_debug_flowspec = -1UL; term_bgp_debug_neighbor_events = -1UL; term_bgp_debug_packet = -1UL; term_bgp_debug_as4 = -1UL; + term_bgp_debug_flowspec = -1UL; qobj_init(); cmd_init(0); diff --git a/tests/bgpd/test_mpath.c b/tests/bgpd/test_mpath.c index 247fcf7da0..2168bd5b74 100644 --- a/tests/bgpd/test_mpath.c +++ b/tests/bgpd/test_mpath.c @@ -105,9 +105,10 @@ static struct bgp *bgp_create_fake(as_t *as, const char *name) for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) { - bgp->route[afi][safi] = bgp_table_init(afi, safi); - bgp->aggregate[afi][safi] = bgp_table_init(afi, safi); - bgp->rib[afi][safi] = bgp_table_init(afi, safi); + bgp->route[afi][safi] = bgp_table_init(bgp, afi, safi); + bgp->aggregate[afi][safi] = bgp_table_init( + bgp, afi, safi); + bgp->rib[afi][safi] = bgp_table_init(bgp, afi, safi); bgp->maxpaths[afi][safi].maxpaths_ebgp = MULTIPATH_NUM; bgp->maxpaths[afi][safi].maxpaths_ibgp = MULTIPATH_NUM; } diff --git a/tests/lib/test_checksum.c b/tests/lib/test_checksum.c index c265e164eb..3972f76763 100644 --- a/tests/lib/test_checksum.c +++ b/tests/lib/test_checksum.c @@ -48,8 +48,8 @@ typedef uint16_t testoff_t; /* The final reduction phase. * This one should be the original ospfd version */ -static u_int16_t reduce_ospfd(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_ospfd(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y @@ -73,8 +73,8 @@ static u_int16_t reduce_ospfd(struct csum_vals *vals, testsz_t len, } /* slightly different concatenation */ -static u_int16_t reduce_ospfd1(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_ospfd1(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y @@ -97,14 +97,14 @@ static u_int16_t reduce_ospfd1(struct csum_vals *vals, testsz_t len, } /* original isisd version */ -static u_int16_t reduce_isisd(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_isisd(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y #define c0 vals->a.c0 #define c1 vals->a.c1 - u_int32_t mul; + uint32_t mul; mul = (len - off) * (c0); x = mul - c0 - c1; @@ -132,14 +132,14 @@ static u_int16_t reduce_isisd(struct csum_vals *vals, testsz_t len, } /* Is the -1 in y wrong perhaps? */ -static u_int16_t reduce_isisd_yfix(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_isisd_yfix(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y #define c0 vals->a.c0 #define c1 vals->a.c1 - u_int32_t mul; + uint32_t mul; mul = (len - off) * (c0); x = mul - c0 - c1; @@ -167,14 +167,14 @@ static u_int16_t reduce_isisd_yfix(struct csum_vals *vals, testsz_t len, } /* Move the mods yp */ -static u_int16_t reduce_isisd_mod(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_isisd_mod(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y #define c0 vals->a.c0 #define c1 vals->a.c1 - u_int32_t mul; + uint32_t mul; mul = (len - off) * (c0); x = mul - c1 - c0; @@ -202,14 +202,14 @@ static u_int16_t reduce_isisd_mod(struct csum_vals *vals, testsz_t len, } /* Move the mods up + fix y */ -static u_int16_t reduce_isisd_mody(struct csum_vals *vals, testsz_t len, - testoff_t off) +static uint16_t reduce_isisd_mody(struct csum_vals *vals, testsz_t len, + testoff_t off) { #define x vals->x #define y vals->y #define c0 vals->a.c0 #define c1 vals->a.c1 - u_int32_t mul; + uint32_t mul; mul = (len - off) * (c0); x = mul - c0 - c1; @@ -238,7 +238,7 @@ static u_int16_t reduce_isisd_mody(struct csum_vals *vals, testsz_t len, struct reductions_t { const char *name; - u_int16_t (*f)(struct csum_vals *, testsz_t, testoff_t); + uint16_t (*f)(struct csum_vals *, testsz_t, testoff_t); } reducts[] = { {.name = "ospfd", .f = reduce_ospfd}, {.name = "ospfd-1", .f = reduce_ospfd1}, @@ -250,14 +250,14 @@ struct reductions_t { }; /* The original ospfd checksum */ -static u_int16_t ospfd_checksum(u_char *buffer, testsz_t len, testoff_t off) +static uint16_t ospfd_checksum(uint8_t *buffer, testsz_t len, testoff_t off) { - u_char *sp, *ep, *p, *q; + uint8_t *sp, *ep, *p, *q; int c0 = 0, c1 = 0; int x, y; - u_int16_t checksum, *csum; + uint16_t checksum, *csum; - csum = (u_int16_t *)(buffer + off); + csum = (uint16_t *)(buffer + off); *(csum) = 0; sp = buffer; @@ -301,21 +301,21 @@ static u_int16_t ospfd_checksum(u_char *buffer, testsz_t len, testoff_t off) } /* the original, broken isisd checksum */ -static u_int16_t iso_csum_create(u_char *buffer, testsz_t len, testoff_t off) +static uint16_t iso_csum_create(uint8_t *buffer, testsz_t len, testoff_t off) { - u_int8_t *p; + uint8_t *p; int x; int y; - u_int32_t mul; - u_int32_t c0; - u_int32_t c1; - u_int16_t checksum, *csum; + uint32_t mul; + uint32_t c0; + uint32_t c1; + uint16_t checksum, *csum; int i, init_len, partial_len; checksum = 0; - csum = (u_int16_t *)(buffer + off); + csum = (uint16_t *)(buffer + off); *(csum) = checksum; p = buffer; @@ -369,11 +369,11 @@ static u_int16_t iso_csum_create(u_char *buffer, testsz_t len, testoff_t off) return checksum; } -static int verify(u_char *buffer, testsz_t len) +static int verify(uint8_t *buffer, testsz_t len) { - u_int8_t *p; - u_int32_t c0; - u_int32_t c1; + uint8_t *p; + uint32_t c0; + uint32_t c1; int i, partial_len; p = buffer; @@ -403,9 +403,9 @@ static int verify(u_char *buffer, testsz_t len) static int /* return checksum in low-order 16 bits */ in_cksum_optimized(void *parg, int nbytes) { - u_short *ptr = parg; + unsigned short *ptr = parg; register long sum; /* assumes long == 32 bits */ - register u_short answer; /* assumes u_short == 16 bits */ + register unsigned short answer; /* assumes unsigned short == 16 bits */ register int count; /* * Our algorithm is simple, using a 32-bit accumulator (sum), @@ -419,7 +419,7 @@ static int /* return checksum in low-order 16 bits */ sum += *++ptr; if (nbytes & 1) /* Odd */ - sum += *(u_char *)(++ptr); /* one byte only */ + sum += *(uint8_t *)(++ptr); /* one byte only */ /* * Add back carry outs from top 16 bits to low 16 bits. @@ -436,7 +436,7 @@ static int /* return checksum in low-order 16 bits */ in_cksum_rfc(void *parg, int count) /* from RFC 1071 */ { - u_short *addr = parg; + unsigned short *addr = parg; /* Compute Internet Checksum for "count" bytes * beginning at location "addr". */ @@ -449,7 +449,7 @@ static int /* return checksum in low-order 16 bits */ } /* Add left-over byte, if any */ if (count > 0) { - sum += *(u_char *)addr; + sum += *(uint8_t *)addr; } /* Fold 32-bit sum to 16 bits */ @@ -463,14 +463,14 @@ int main(int argc, char **argv) { /* 60017 65629 702179 */ #define MAXDATALEN 60017 -#define BUFSIZE MAXDATALEN + sizeof(u_int16_t) - u_char buffer[BUFSIZE]; +#define BUFSIZE MAXDATALEN + sizeof(uint16_t) + uint8_t buffer[BUFSIZE]; int exercise = 0; #define EXERCISESTEP 257 srandom(time(NULL)); while (1) { - u_int16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc; + uint16_t ospfd, isisd, lib, in_csum, in_csum_res, in_csum_rfc; int i, j; exercise += EXERCISESTEP; @@ -492,17 +492,17 @@ int main(int argc, char **argv) "in_csum_rfc %x, len:%d\n", in_csum, in_csum_res, in_csum_rfc, exercise); - ospfd = ospfd_checksum(buffer, exercise + sizeof(u_int16_t), + ospfd = ospfd_checksum(buffer, exercise + sizeof(uint16_t), exercise); - if (verify(buffer, exercise + sizeof(u_int16_t))) + if (verify(buffer, exercise + sizeof(uint16_t))) printf("verify: ospfd failed\n"); - isisd = iso_csum_create(buffer, exercise + sizeof(u_int16_t), + isisd = iso_csum_create(buffer, exercise + sizeof(uint16_t), exercise); - if (verify(buffer, exercise + sizeof(u_int16_t))) + if (verify(buffer, exercise + sizeof(uint16_t))) printf("verify: isisd failed\n"); - lib = fletcher_checksum(buffer, exercise + sizeof(u_int16_t), + lib = fletcher_checksum(buffer, exercise + sizeof(uint16_t), exercise); - if (verify(buffer, exercise + sizeof(u_int16_t))) + if (verify(buffer, exercise + sizeof(uint16_t))) printf("verify: lib failed\n"); if (ospfd != lib) { @@ -522,7 +522,7 @@ int main(int argc, char **argv) for (i = 0; reducts[i].name != NULL; i++) { ospfd = reducts[i].f( &ospfd_vals, - exercise + sizeof(u_int16_t), + exercise + sizeof(uint16_t), exercise); printf("%20s: x: %02x, y %02x, checksum 0x%04x\n", reducts[i].name, @@ -531,7 +531,7 @@ int main(int argc, char **argv) } } - printf("\n u_char testdata [] = {\n "); + printf("\n uint8_t testdata [] = {\n "); for (i = 0; i < exercise; i++) { printf("0x%02x,%s", buffer[i], (i + 1) % 8 ? " " : "\n "); diff --git a/tests/test_lblmgr.c b/tests/test_lblmgr.c index b08f63b70f..c751c0b12d 100644 --- a/tests/test_lblmgr.c +++ b/tests/test_lblmgr.c @@ -29,7 +29,7 @@ #define CHUNK_SIZE 32 struct zclient *zclient; -u_short instance = 1; +unsigned short instance = 1; const char *sequence = "GGRGGGRRG"; diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl index a85d811c96..c1fab1029a 100755 --- a/tools/checkpatch.pl +++ b/tools/checkpatch.pl @@ -5629,49 +5629,52 @@ sub process { } } +# +# Kernel macros unnused for FRR +# # Check for __attribute__ packed, prefer __packed - if ($realfile !~ m@\binclude/uapi/@ && - $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { - WARN("PREFER_PACKED", - "__packed is preferred over __attribute__((packed))\n" . $herecurr); - } +# if ($realfile !~ m@\binclude/uapi/@ && +# $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { +# WARN("PREFER_PACKED", +# "__packed is preferred over __attribute__((packed))\n" . $herecurr); +# } # Check for __attribute__ aligned, prefer __aligned - if ($realfile !~ m@\binclude/uapi/@ && - $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { - WARN("PREFER_ALIGNED", - "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); - } +# if ($realfile !~ m@\binclude/uapi/@ && +# $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { +# WARN("PREFER_ALIGNED", +# "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); +# } # Check for __attribute__ format(printf, prefer __printf - if ($realfile !~ m@\binclude/uapi/@ && - $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { - if (WARN("PREFER_PRINTF", - "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; +# if ($realfile !~ m@\binclude/uapi/@ && +# $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { +# if (WARN("PREFER_PRINTF", +# "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && +# $fix) { +# $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; - } - } +# } +# } # Check for __attribute__ format(scanf, prefer __scanf - if ($realfile !~ m@\binclude/uapi/@ && - $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { - if (WARN("PREFER_SCANF", - "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && - $fix) { - $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; - } - } +# if ($realfile !~ m@\binclude/uapi/@ && +# $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { +# if (WARN("PREFER_SCANF", +# "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && +# $fix) { +# $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; +# } +# } # Check for __attribute__ weak, or __weak declarations (may have link issues) - if ($^V && $^V ge 5.10.0 && - $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && - ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || - $line =~ /\b__weak\b/)) { - ERROR("WEAK_DECLARATION", - "Using weak declarations can have unintended link defects\n" . $herecurr); - } +# if ($^V && $^V ge 5.10.0 && +# $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && +# ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || +# $line =~ /\b__weak\b/)) { +# ERROR("WEAK_DECLARATION", +# "Using weak declarations can have unintended link defects\n" . $herecurr); +# } # check for c99 types like uint8_t used outside of uapi/ and tools/ if ($realfile !~ m@\binclude/uapi/@ && @@ -6357,6 +6360,19 @@ sub process { "unknown module license " . $extracted_string . "\n" . $herecurr); } } + +# check for usage of nonstandard fixed-width integral types + if ($line =~ /u_int8_t/ || + $line =~ /u_int32_t/ || + $line =~ /u_int16_t/ || + $line =~ /u_int64_t/ || + $line =~ /[^a-z_]u_char[^a-z_]/ || + $line =~ /[^a-z_]u_short[^a-z_]/ || + $line =~ /[^a-z_]u_int[^a-z_]/ || + $line =~ /[^a-z_]u_long[^a-z_]/) { + ERROR("NONSTANDARD_INTEGRAL_TYPES", + "Please, no nonstandard integer types in new code.\n" . $herecurr) + } } # If we have no input at all, then there is nothing to report on diff --git a/tools/convert-fixedwidth.sh b/tools/convert-fixedwidth.sh new file mode 100755 index 0000000000..bb6011edd4 --- /dev/null +++ b/tools/convert-fixedwidth.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# This script converts nonstandard fixed-width integer types found in FRR to +# C99 standard types. +USAGE="./$(basename "$0")" +USAGE+=$' <src-path> -- convert nonstandard fixed-width integer types found in FRR to C99 standard types\n' +USAGE+=$'<src-path> - a directory containing C source, or a C source file\n' +if [ $# -eq 0 ]; then + printf "%s" "$USAGE" + exit 1 +fi + +FRRTREE=$1 + +if [[ -d $FRRTREE ]]; then + SOURCES=$(find $FRRTREE -type f -name '*.[ch]') +elif [[ -f $FRRTREE ]]; then + SOURCES="$FRRTREE" + SOURCES+=$'\n' +else + printf "%s" "$USAGE" + exit 1 +fi + +printf "%s" "$SOURCES" | while read line ; do + printf "Processing $line " + sed -i -e 's/u_int\([0-9]\{1,3\}\)_t/uint\1_t/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_char\([^a-z_]\|$\)/\1uint8_t\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_short\([^a-z_]\|$\)/\1unsigned short\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_int\([^a-z_]\|$\)/\1unsigned int\2/g' $line + printf "." + sed -i -e 's/\([^a-z_]\)u_long\([^a-z_]\|$\)/\1unsigned long\2/g' $line + printf "." + sed -i -e 's/^u_char /uint8_t /g' $line + printf "." + sed -i -e 's/^u_short /unsigned short /g' $line + printf "." + sed -i -e 's/^u_int /unsigned int /g' $line + printf "." + sed -i -e 's/^u_long /unsigned long /g' $line + printf ".\n" +done diff --git a/tools/fixup-deprecated.py b/tools/fixup-deprecated.py new file mode 100755 index 0000000000..38958480a8 --- /dev/null +++ b/tools/fixup-deprecated.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Script used to replace deprecated quagga/frr mactors/types/etc. +# +# loosly based on indent.py, 2017 by David Lamparter +# 2018 by Lou Berger, placed in public domain + +import sys, re, subprocess, os + +class replaceEntry: + compiled = None #compiled regex + repl = None #regex + def __init__(self, c, r): + self.compiled = c + self.repl = r + +rList = [ + # old #define VNL, VTYNL, VTY_NEWLINE + replaceEntry(re.compile(r'(VNL|VTYNL|VTY_NEWLINE)'), + r'"\\n"'), + # old #define VTY_GET_INTEGER(desc, v, str) + # old #define VTY_GET_INTEGER_RANGE(desc, v, str, min, max) + # old #define VTY_GET_ULONG(desc, v, str) + replaceEntry(re.compile(r'(VTY_GET_INTEGER(_RANGE|)|VTY_GET_ULONG)[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), + r'(\4) = strtoul((\5), NULL, 10);\t/* \3 */'), + # old #define VTY_GET_ULL(desc, v, str) + replaceEntry(re.compile(r'VTY_GET_ULL[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), + r'(\2) = strtoull((\3), NULL, 10);\t/* \1 */'), + # old #define VTY_GET_IPV4_ADDRESS(desc, v, str) + replaceEntry(re.compile(r'VTY_GET_IPV4_ADDRESS[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), + r'inet_aton((\3), &(\2));\t/* \1 */'), + # old #define VTY_GET_IPV4_PREFIX(desc, v, str) + replaceEntry(re.compile(r'VTY_GET_IPV4_PREFIX[\s\(]*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)(\s*|)(\)|,).*?;', re.M | re.S), + r'str2prefix_ipv4((\3), &(\2));\t/* \1 */'), + # old #define vty_outln(vty, str, ...) + replaceEntry(re.compile(r'vty_outln[\s\(]*(.*?)\s*,\s*(".*?"|.*?)\s*(\)|,)', re.M | re.S), + r'vty_out(\1, \2 "\\n"\3'), + ] + +def fixup_file(fn): + with open(fn, 'r') as fd: + text = fd.read() + + for re in rList: + text = re.compiled.sub(re.repl,text) + + tmpname = fn + '.fixup' + with open(tmpname, 'w') as ofd: + ofd.write(text) + os.rename(tmpname, fn) + +if __name__ == '__main__': + for fn in sys.argv[1:]: + fixup_file(fn) @@ -187,7 +187,7 @@ stop() else PIDFILE=`pidfile $inst` PID=`cat $PIDFILE 2>/dev/null` - ${SSD} --stop --quiet --retry=TERM/30/KILL/5 --oknodo --pidfile "$PIDFILE" --exec "$D_PATH/$1" + kill -2 $PID 2>/dev/null # # Now we have to wait until $DAEMON has _really_ stopped. # diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 1308e1218b..c7f45ce4fc 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -141,21 +141,22 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, bufvalid += nread; + /* + * We expect string output from daemons, so instead of looking + * for the full 3 null bytes of the terminator, we check for + * just one instead and assume it is the first byte of the + * terminator. The presence of the full terminator is checked + * later. + */ if (bufvalid - buf >= 4) - end = memmem(bufvalid - 4, 4, terminator, - sizeof(terminator)); - - if (end && end + sizeof(terminator) + 1 > bufvalid) - /* found \0\0\0 but return code hasn't been read yet */ - end = NULL; - if (end) - ret = end[sizeof(terminator)]; + end = memmem(bufvalid - 4, 4, "\0", 1); /* * calculate # bytes we have, up to & not including the * terminator if present */ size_t textlen = (end ? end : bufvalid) - buf; + bool b = false; /* feed line processing callback if present */ while (callback && bufvalid > buf && (end > buf || !end)) { @@ -165,16 +166,38 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, /* line break */ *eol++ = '\0'; else if (end == buf) - /* no line break, end of input, no text left - * before end - * => don't insert an empty line at the end */ - break; + /* + * no line break, end of input, no text left + * before end; nothing to write + */ + b = true; else if (end) - /* no line break, end of input, but some text - * left */ + /* no nl, end of input, but some text left */ eol = end; - else - /* continue reading */ + else if (bufvalid == buf + bufsz) { + /* + * no nl, no end of input, no buffer space; + * realloc + */ + char *new; + + bufsz *= 2; + if (buf == stackbuf) { + new = XMALLOC(MTYPE_TMP, bufsz); + memcpy(new, stackbuf, sizeof(stackbuf)); + } else + new = XREALLOC(MTYPE_TMP, buf, bufsz); + + bufvalid = bufvalid - buf + new; + buf = new; + /* if end != NULL, we won't be reading more + * data... */ + assert(end == NULL); + b = true; + } else + b = true; + + if (b) break; /* eol is at line end now, either \n => \0 or \0\0\0 */ @@ -187,10 +210,7 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, if (callback) callback(cbarg, buf); - if (eol == end) - /* \n\0\0\0 */ - break; - + /* shift back data and adjust bufvalid */ memmove(buf, eol, bufvalid - eol); bufvalid -= eol - buf; if (end) @@ -203,23 +223,28 @@ static int vtysh_client_run(struct vtysh_client *vclient, const char *line, fwrite(buf, 1, textlen, fp); memmove(buf, buf + textlen, bufvalid - buf - textlen); bufvalid -= textlen; + if (end) + end -= textlen; + + /* + * ---------------------------------------------------- + * At this point `buf` should be in one of two states: + * - Empty (i.e. buf == bufvalid) + * - Contains up to 4 bytes of the terminator + * ---------------------------------------------------- + */ + assert(((buf == bufvalid) + || (bufvalid - buf <= 4 && buf[0] == 0x00))); } - if (bufvalid == buf + bufsz) { - char *new; - bufsz *= 2; - if (buf == stackbuf) { - new = XMALLOC(MTYPE_TMP, bufsz); - memcpy(new, stackbuf, sizeof(stackbuf)); - } else - new = XREALLOC(MTYPE_TMP, buf, bufsz); - - bufvalid = bufvalid - buf + new; - buf = new; - /* if end != NULL, we won't be reading more data... */ - assert(end == NULL); + /* if we have the terminator, break */ + if (end && bufvalid - buf == 4) { + assert(!memcmp(buf, terminator, 3)); + ret = buf[3]; + break; } - } while (!end); + + } while (true); goto out; out_err: @@ -298,7 +323,7 @@ void vtysh_pager_init(void) static int vtysh_execute_func(const char *line, int pager) { int ret, cmd_stat; - u_int i; + unsigned int i; vector vline; const struct cmd_element *cmd; FILE *fp = NULL; @@ -312,6 +337,13 @@ static int vtysh_execute_func(const char *line, int pager) if (vline == NULL) return CMD_SUCCESS; + if (user_mode) { + if (strncmp("en", vector_slot(vline, 0), 2) == 0) { + fprintf(stdout, "%% Command not allowed: enable\n"); + return CMD_WARNING; + } + } + saved_ret = ret = cmd_execute_command(vline, vty, &cmd, 1); saved_node = vty->node; @@ -339,6 +371,8 @@ static int vtysh_execute_func(const char *line, int pager) || saved_node == BGP_VPNV6_NODE || saved_node == BGP_IPV4_NODE || saved_node == BGP_IPV6_NODE + || saved_node == BGP_FLOWSPECV4_NODE + || saved_node == BGP_FLOWSPECV6_NODE || saved_node == BGP_IPV4M_NODE || saved_node == BGP_IPV4L_NODE || saved_node == BGP_IPV6L_NODE @@ -357,6 +391,8 @@ static int vtysh_execute_func(const char *line, int pager) || saved_node == BGP_VNC_L2_GROUP_NODE) && (tried == 1)) { vtysh_execute("exit-vnc"); + } else if (saved_node == VRF_NODE && (tried == 1)) { + vtysh_execute("exit-vrf"); } else if ((saved_node == KEYCHAIN_KEY_NODE || saved_node == LDP_PSEUDOWIRE_NODE || saved_node == LDP_IPV4_IFACE_NODE @@ -385,13 +421,13 @@ static int vtysh_execute_func(const char *line, int pager) fprintf(stdout, "Warning...\n"); break; case CMD_ERR_AMBIGUOUS: - fprintf(stdout, "%% Ambiguous command.\n"); + fprintf(stdout, "%% Ambiguous command: %s\n", line); break; case CMD_ERR_NO_MATCH: - fprintf(stdout, "%% Unknown command.\n"); + fprintf(stdout, "%% Unknown command: %s\n", line); break; case CMD_ERR_INCOMPLETE: - fprintf(stdout, "%% Command incomplete.\n"); + fprintf(stdout, "%% Command incomplete: %s\n", line); break; case CMD_SUCCESS_DAEMON: { /* @@ -622,6 +658,8 @@ int vtysh_mark_file(const char *filename) || prev_node == BGP_VPNV6_NODE || prev_node == BGP_IPV4_NODE || prev_node == BGP_IPV6_NODE + || prev_node == BGP_FLOWSPECV4_NODE + || prev_node == BGP_FLOWSPECV6_NODE || prev_node == BGP_IPV4L_NODE || prev_node == BGP_IPV6L_NODE || prev_node == BGP_IPV4M_NODE @@ -632,6 +670,8 @@ int vtysh_mark_file(const char *filename) } else if ((prev_node == BGP_EVPN_VNI_NODE) && (tried == 1)) { fprintf(outputfile, "exit-vni\n"); + } else if (prev_node == VRF_NODE) { + fprintf(outputfile, "exit-vrf\n"); } else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1)) { fprintf(outputfile, "exit\n"); @@ -683,7 +723,7 @@ int vtysh_mark_file(const char *filename) fprintf(stdout, "%s", vty->buf); break; case CMD_SUCCESS_DAEMON: { - u_int i; + unsigned int i; int cmd_stat = CMD_SUCCESS; fprintf(outputfile, "%s", vty->buf); @@ -760,7 +800,7 @@ int vtysh_config_from_file(struct vty *vty, FILE *fp) that */ break; case CMD_SUCCESS_DAEMON: { - u_int i; + unsigned int i; int cmd_stat = CMD_SUCCESS; for (i = 0; i < array_size(vtysh_client); i++) { @@ -992,6 +1032,12 @@ static struct cmd_node bgp_vpnv4_node = {BGP_VPNV4_NODE, static struct cmd_node bgp_vpnv6_node = {BGP_VPNV6_NODE, "%s(config-router-af)# "}; +static struct cmd_node bgp_flowspecv4_node = {BGP_FLOWSPECV4_NODE, + "%s(config-router-af)# "}; + +static struct cmd_node bgp_flowspecv6_node = {BGP_FLOWSPECV6_NODE, + "%s(config-router-af)# "}; + static struct cmd_node bgp_ipv4_node = {BGP_IPV4_NODE, "%s(config-router-af)# "}; @@ -1132,6 +1178,26 @@ DEFUNSH(VTYSH_BGPD, address_family_ipv4, address_family_ipv4_cmd, return CMD_SUCCESS; } +DEFUNSH(VTYSH_BGPD, address_family_flowspecv4, address_family_flowspecv4_cmd, + "address-family ipv4 flowspec", + "Enter Address Family command mode\n" + "Address Family\n" + "Address Family Modifier\n") +{ + vty->node = BGP_FLOWSPECV4_NODE; + return CMD_SUCCESS; +} + +DEFUNSH(VTYSH_BGPD, address_family_flowspecv6, address_family_flowspecv6_cmd, + "address-family ipv6 flowspec", + "Enter Address Family command mode\n" + "Address Family\n" + "Address Family Modifier\n") +{ + vty->node = BGP_FLOWSPECV6_NODE; + return CMD_SUCCESS; +} + DEFUNSH(VTYSH_BGPD, address_family_ipv4_multicast, address_family_ipv4_multicast_cmd, "address-family ipv4 multicast", "Enter Address Family command mode\n" @@ -1521,7 +1587,6 @@ static int vtysh_exit(struct vty *vty) case LDP_NODE: case LDP_L2VPN_NODE: case ISIS_NODE: - case MASC_NODE: case RMAP_NODE: case VTY_NODE: case KEYCHAIN_NODE: @@ -1537,6 +1602,8 @@ static int vtysh_exit(struct vty *vty) case BGP_IPV6_NODE: case BGP_IPV6M_NODE: case BGP_IPV6L_NODE: + case BGP_FLOWSPECV4_NODE: + case BGP_FLOWSPECV6_NODE: case BGP_VRF_POLICY_NODE: case BGP_EVPN_NODE: case BGP_VNC_DEFAULTS_NODE: @@ -1591,7 +1658,9 @@ DEFUNSH(VTYSH_BGPD, exit_address_family, exit_address_family_cmd, || vty->node == BGP_IPV4L_NODE || vty->node == BGP_VPNV4_NODE || vty->node == BGP_VPNV6_NODE || vty->node == BGP_IPV6_NODE || vty->node == BGP_IPV6L_NODE || vty->node == BGP_IPV6M_NODE - || vty->node == BGP_EVPN_NODE) + || vty->node == BGP_EVPN_NODE + || vty->node == BGP_FLOWSPECV4_NODE + || vty->node == BGP_FLOWSPECV6_NODE) vty->node = BGP_NODE; return CMD_SUCCESS; } @@ -1613,8 +1682,16 @@ DEFUNSH(VTYSH_BGPD, exit_vnc_config, exit_vnc_config_cmd, "exit-vnc", return CMD_SUCCESS; } +DEFUNSH(VTYSH_PIMD|VTYSH_ZEBRA, exit_vrf_config, exit_vrf_config_cmd, "exit-vrf", + "Exit from VRF configuration mode\n") +{ + if (vty->node == VRF_NODE) + vty->node = CONFIG_NODE; + return CMD_SUCCESS; +} + DEFUNSH(VTYSH_BGPD, exit_vrf_policy, exit_vrf_policy_cmd, "exit-vrf-policy", - "Exit from VRF configuration mode\n") + "Exit from VRF policy configuration mode\n") { if (vty->node == BGP_VRF_POLICY_NODE) vty->node = BGP_NODE; @@ -2259,7 +2336,7 @@ DEFUN (vtysh_write_terminal, "For the isis daemon\n" "For the pim daemon\n") { - u_int i; + unsigned int i; char line[] = "do write terminal\n"; FILE *fp = outputfile; @@ -2353,7 +2430,7 @@ static void backup_config_file(const char *fbackup) int vtysh_write_config_integrated(void) { - u_int i; + unsigned int i; char line[] = "do write terminal\n"; FILE *fp; int fd; @@ -2461,7 +2538,7 @@ DEFUN (vtysh_write_memory, { int ret = CMD_SUCCESS; char line[] = "do write memory\n"; - u_int i; + unsigned int i; fprintf(outputfile, "Note: this version of vtysh never writes vtysh.conf\n"); @@ -2562,7 +2639,7 @@ DEFUN (vtysh_show_daemons, SHOW_STR "Show list of running daemons\n") { - u_int i; + unsigned int i; for (i = 0; i < array_size(vtysh_client); i++) if (vtysh_client[i].fd >= 0) @@ -2975,7 +3052,7 @@ static int vtysh_connect_all_instances(struct vtysh_client *head_client) int vtysh_connect_all(const char *daemon_name) { - u_int i; + unsigned int i; int rc = 0; int matches = 0; @@ -3082,6 +3159,8 @@ void vtysh_init_vty(void) install_node(&zebra_node, NULL); install_node(&bgp_vpnv4_node, NULL); install_node(&bgp_vpnv6_node, NULL); + install_node(&bgp_flowspecv4_node, NULL); + install_node(&bgp_flowspecv6_node, NULL); install_node(&bgp_ipv4_node, NULL); install_node(&bgp_ipv4m_node, NULL); install_node(&bgp_ipv4l_node, NULL); @@ -3167,6 +3246,10 @@ void vtysh_init_vty(void) install_element(BGP_VPNV4_NODE, &vtysh_quit_bgpd_cmd); install_element(BGP_VPNV6_NODE, &vtysh_exit_bgpd_cmd); install_element(BGP_VPNV6_NODE, &vtysh_quit_bgpd_cmd); + install_element(BGP_FLOWSPECV4_NODE, &vtysh_exit_bgpd_cmd); + install_element(BGP_FLOWSPECV4_NODE, &vtysh_quit_bgpd_cmd); + install_element(BGP_FLOWSPECV6_NODE, &vtysh_exit_bgpd_cmd); + install_element(BGP_FLOWSPECV6_NODE, &vtysh_quit_bgpd_cmd); install_element(BGP_IPV4_NODE, &vtysh_exit_bgpd_cmd); install_element(BGP_IPV4_NODE, &vtysh_quit_bgpd_cmd); install_element(BGP_IPV4M_NODE, &vtysh_exit_bgpd_cmd); @@ -3226,6 +3309,8 @@ void vtysh_init_vty(void) install_element(BGP_IPV4L_NODE, &vtysh_end_all_cmd); install_element(BGP_VPNV4_NODE, &vtysh_end_all_cmd); install_element(BGP_VPNV6_NODE, &vtysh_end_all_cmd); + install_element(BGP_FLOWSPECV4_NODE, &vtysh_end_all_cmd); + install_element(BGP_FLOWSPECV6_NODE, &vtysh_end_all_cmd); install_element(BGP_IPV6_NODE, &vtysh_end_all_cmd); install_element(BGP_IPV6M_NODE, &vtysh_end_all_cmd); install_element(BGP_IPV6L_NODE, &vtysh_end_all_cmd); @@ -3299,6 +3384,8 @@ void vtysh_init_vty(void) install_element(BGP_NODE, &address_family_ipv6_vpn_cmd); install_element(BGP_NODE, &address_family_ipv6_labeled_unicast_cmd); install_element(BGP_NODE, &address_family_evpn_cmd); + install_element(BGP_NODE, &address_family_flowspecv4_cmd); + install_element(BGP_NODE, &address_family_flowspecv6_cmd); #if defined(HAVE_CUMULUS) install_element(BGP_NODE, &address_family_evpn2_cmd); #endif @@ -3311,6 +3398,8 @@ void vtysh_init_vty(void) install_element(BGP_IPV6M_NODE, &exit_address_family_cmd); install_element(BGP_EVPN_NODE, &exit_address_family_cmd); install_element(BGP_IPV6L_NODE, &exit_address_family_cmd); + install_element(BGP_FLOWSPECV4_NODE, &exit_address_family_cmd); + install_element(BGP_FLOWSPECV6_NODE, &exit_address_family_cmd); #if defined(HAVE_RPKI) install_element(CONFIG_NODE, &rpki_cmd); @@ -3342,6 +3431,8 @@ void vtysh_init_vty(void) install_element(ENABLE_NODE, &vtysh_show_running_config_cmd); install_element(ENABLE_NODE, &vtysh_copy_running_config_cmd); + install_element(VRF_NODE, &exit_vrf_config_cmd); + install_element(CONFIG_NODE, &vtysh_vrf_cmd); install_element(CONFIG_NODE, &vtysh_no_vrf_cmd); @@ -3379,7 +3470,7 @@ void vtysh_init_vty(void) /* debugging */ install_element(VIEW_NODE, &vtysh_show_debugging_cmd); install_element(VIEW_NODE, &vtysh_show_debugging_hashtable_cmd); - install_element(VIEW_NODE, &vtysh_debug_all_cmd); + install_element(ENABLE_NODE, &vtysh_debug_all_cmd); install_element(CONFIG_NODE, &vtysh_debug_all_cmd); /* misc lib show commands */ diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 52a1a46105..9b21c3376a 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -100,4 +100,6 @@ extern int execute_flag; extern struct vty *vty; +extern int user_mode; + #endif /* VTYSH_H */ diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index e3431fac59..e94bd139e5 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -44,7 +44,7 @@ struct config { struct config *config; /* Index of this config. */ - u_int32_t index; + uint32_t index; }; struct list *config_top; @@ -201,7 +201,7 @@ void vtysh_config_parse_line(void *arg, const char *line) config = config_get(INTERFACE_NODE, line); else if (strncmp(line, "pseudowire", strlen("pseudowire")) == 0) config = config_get(PW_NODE, line); - else if (strncmp(line, "logical-router", strlen("ns")) == 0) + else if (strncmp(line, "logical-router", strlen("logical-router")) == 0) config = config_get(LOGICALROUTER_NODE, line); else if (strncmp(line, "vrf", strlen("vrf")) == 0) config = config_get(VRF_NODE, line); @@ -283,8 +283,6 @@ void vtysh_config_parse_line(void *arg, const char *line) strlen("ip forwarding")) == 0)) config = config_get(FORWARDING_NODE, line); - else if (strncmp(line, "service", strlen("service")) == 0) - config = config_get(SERVICE_NODE, line); else if (strncmp(line, "debug vrf", strlen("debug vrf")) == 0) config = config_get(VRF_DEBUG_NODE, line); else if (strncmp(line, "debug", strlen("debug")) == 0) @@ -328,9 +326,9 @@ void vtysh_config_parse_line(void *arg, const char *line) ((I) == ACCESS_NODE || (I) == PREFIX_NODE || (I) == IP_NODE \ || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE \ || (I) == ACCESS_IPV6_NODE || (I) == ACCESS_MAC_NODE \ - || (I) == PREFIX_IPV6_NODE || (I) == SERVICE_NODE \ - || (I) == FORWARDING_NODE || (I) == DEBUG_NODE || (I) == AAA_NODE \ - || (I) == VRF_DEBUG_NODE || (I) == MPLS_NODE) + || (I) == PREFIX_IPV6_NODE || (I) == FORWARDING_NODE \ + || (I) == DEBUG_NODE || (I) == AAA_NODE || (I) == VRF_DEBUG_NODE \ + || (I) == MPLS_NODE) /* Display configuration to file pointer. */ void vtysh_config_dump(FILE *fp) diff --git a/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index a3d2f95ec1..4de671b7fa 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -60,6 +60,9 @@ static char history_file[MAXPATHLEN]; /* Flag for indicate executing child command. */ int execute_flag = 0; +/* Flag to indicate if in user/unprivileged mode. */ +int user_mode; + /* For sigsetjmp() & siglongjmp(). */ static sigjmp_buf jmpbuf; @@ -150,6 +153,7 @@ static void usage(int status) " --vty_socket Override vty socket path\n" " --config_dir Override config directory path\n" "-N --pathspace Insert prefix into config & socket paths\n" + "-u --user Run as an unprivileged user\n" "-w, --writeconfig Write integrated config (frr.conf) and exit\n" "-h, --help Display this help and exit\n\n" "Note that multiple commands may be executed from the command\n" @@ -180,6 +184,7 @@ struct option longopts[] = { {"mark", no_argument, NULL, 'm'}, {"writeconfig", no_argument, NULL, 'w'}, {"pathspace", required_argument, NULL, 'N'}, + {"user", no_argument, NULL, 'u'}, {0}}; /* Read a string, and return a pointer to it. Returns NULL on EOF. */ @@ -310,6 +315,8 @@ int main(int argc, char **argv, char **env) realgid = getgid(); suid_off(); + user_mode = 0; /* may be set in options processing */ + /* Preserve name of myself. */ progname = ((p = strrchr(argv[0], '/')) ? ++p : argv[0]); @@ -318,7 +325,8 @@ int main(int argc, char **argv, char **env) /* Option handling. */ while (1) { - opt = getopt_long(argc, argv, "be:c:d:nf:mEhCwN:", longopts, 0); + opt = getopt_long(argc, argv, "be:c:d:nf:mEhCwN:u", + longopts, 0); if (opt == EOF) break; @@ -375,6 +383,9 @@ int main(int argc, char **argv, char **env) case 'C': dryrun = 1; break; + case 'u': + user_mode = 1; + break; case 'w': writeconfig = 1; break; @@ -425,11 +436,13 @@ int main(int argc, char **argv, char **env) vty_init_vtysh(); - /* Read vtysh configuration file before connecting to daemons. - * (file may not be readable to calling user in SUID mode) */ - suid_on(); - vtysh_read_config(vtysh_config); - suid_off(); + if (!user_mode) { + /* Read vtysh configuration file before connecting to daemons. + * (file may not be readable to calling user in SUID mode) */ + suid_on(); + vtysh_read_config(vtysh_config); + suid_off(); + } if (markfile) { if (!inputfile) { diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index 88af18d829..e575b71549 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -100,7 +100,7 @@ static int vtysh_pam(const char *user) struct vtysh_user { char *name; - u_char nopassword; + uint8_t nopassword; }; struct list *userlist; diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 264882e21f..ca388d807b 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -138,7 +138,7 @@ struct daemon { daemon_state_t state; int fd; struct timeval echo_sent; - u_int connect_tries; + unsigned int connect_tries; struct thread *t_wakeup; struct thread *t_read; struct thread *t_write; @@ -552,7 +552,7 @@ static int handle_read(struct thread *t_read) snprintf(why, sizeof(why), "read returned bad echo response of %d bytes " "(expecting %u): %.*s", - (int)rc, (u_int)sizeof(resp), (int)rc, buf); + (int)rc, (unsigned int)sizeof(resp), (int)rc, buf); daemon_down(dmn, why); return 0; } @@ -888,7 +888,7 @@ static int wakeup_send_echo(struct thread *t_wakeup) char why[100 + sizeof(echocmd)]; snprintf(why, sizeof(why), "write '%s' returned %d instead of %u", echocmd, - (int)rc, (u_int)sizeof(echocmd)); + (int)rc, (unsigned int)sizeof(echocmd)); daemon_down(dmn, why); } else { gettimeofday(&dmn->echo_sent, NULL); @@ -1174,7 +1174,7 @@ int main(int argc, char **argv) if (!(dmn = (struct daemon *)calloc(1, sizeof(*dmn)))) { fprintf(stderr, "calloc(1,%u) failed: %s\n", - (u_int)sizeof(*dmn), + (unsigned int)sizeof(*dmn), safe_strerror(errno)); return 1; } diff --git a/zebra/client_main.c b/zebra/client_main.c index 9b82e48261..4035e53f7c 100644 --- a/zebra/client_main.c +++ b/zebra/client_main.c @@ -39,7 +39,7 @@ int sock; /* IPv4 route add and delete test. */ void zebra_test_ipv4(int command, int type, char *prefix, char *gateway, - u_char distance) + uint8_t distance) { struct zapi_ipv4 api; struct prefix_ipv4 p; @@ -119,7 +119,7 @@ void zebra_sim(FILE *fp) { char buf[BUFSIZ]; char distance_str[BUFSIZ]; - u_char distance; + uint8_t distance; while (fgets(buf, sizeof buf, fp)) { int i; diff --git a/zebra/connected.c b/zebra/connected.c index 94b56c8971..2198ddf5ea 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -273,7 +273,7 @@ void connected_up(struct interface *ifp, struct connected *ifc) /* Add connected IPv4 route to the interface. */ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr, - u_char prefixlen, struct in_addr *broad, + uint8_t prefixlen, struct in_addr *broad, const char *label) { struct prefix_ipv4 *p; @@ -469,7 +469,7 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p) /* Delete connected IPv4 route to the interface. */ void connected_delete_ipv4(struct interface *ifp, int flags, - struct in_addr *addr, u_char prefixlen, + struct in_addr *addr, uint8_t prefixlen, struct in_addr *broad) { struct prefix p, d; @@ -495,7 +495,7 @@ void connected_delete_ipv4(struct interface *ifp, int flags, /* Add connected IPv6 route to the interface. */ void connected_add_ipv6(struct interface *ifp, int flags, struct in6_addr *addr, - u_char prefixlen, const char *label) + uint8_t prefixlen, const char *label) { struct prefix_ipv6 *p; struct connected *ifc; @@ -536,7 +536,7 @@ void connected_add_ipv6(struct interface *ifp, int flags, struct in6_addr *addr, } void connected_delete_ipv6(struct interface *ifp, struct in6_addr *address, - u_char prefixlen) + uint8_t prefixlen) { struct prefix p; struct connected *ifc; diff --git a/zebra/connected.h b/zebra/connected.h index d10a092984..9b69a3f246 100644 --- a/zebra/connected.h +++ b/zebra/connected.h @@ -29,11 +29,11 @@ extern struct connected *connected_check_ptp(struct interface *ifp, union prefixconstptr d); extern void connected_add_ipv4(struct interface *ifp, int flags, - struct in_addr *addr, u_char prefixlen, + struct in_addr *addr, uint8_t prefixlen, struct in_addr *broad, const char *label); extern void connected_delete_ipv4(struct interface *ifp, int flags, - struct in_addr *addr, u_char prefixlen, + struct in_addr *addr, uint8_t prefixlen, struct in_addr *broad); extern void connected_delete_ipv4_unnumbered(struct connected *ifc); @@ -42,10 +42,10 @@ extern void connected_up(struct interface *ifp, struct connected *ifc); extern void connected_down(struct interface *ifp, struct connected *ifc); extern void connected_add_ipv6(struct interface *ifp, int flags, - struct in6_addr *address, u_char prefixlen, + struct in6_addr *address, uint8_t prefixlen, const char *label); extern void connected_delete_ipv6(struct interface *ifp, - struct in6_addr *address, u_char prefixlen); + struct in6_addr *address, uint8_t prefixlen); extern int connected_is_unnumbered(struct interface *); diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 09fc085018..b506315ebf 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -242,7 +242,7 @@ static int if_getaddrs(void) #if defined(KAME) if (IN6_IS_ADDR_LINKLOCAL(&addr->sin6_addr)) { addr->sin6_scope_id = - ntohs(*(u_int16_t *)&addr->sin6_addr + ntohs(*(uint16_t *)&addr->sin6_addr .s6_addr[2]); addr->sin6_addr.s6_addr[2] = addr->sin6_addr.s6_addr[3] = 0; diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c index 94738664b3..e9182304dd 100644 --- a/zebra/if_ioctl_solaris.c +++ b/zebra/if_ioctl_solaris.c @@ -252,7 +252,7 @@ static int if_get_addr(struct interface *ifp, struct sockaddr *addr, struct lifreq lifreq; struct sockaddr_storage mask, dest; char *dest_pnt = NULL; - u_char prefixlen = 0; + uint8_t prefixlen = 0; afi_t af; int flags = 0; diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index a37d74416b..4a37c14b92 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -271,7 +271,7 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, struct rtattr *attr[IFLA_VRF_MAX + 1]; struct vrf *vrf; struct zebra_vrf *zvrf; - u_int32_t nl_table_id; + uint32_t nl_table_id; ifi = NLMSG_DATA(h); @@ -296,7 +296,7 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, return; } - nl_table_id = *(u_int32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]); + nl_table_id = *(uint32_t *)RTA_DATA(attr[IFLA_VRF_TABLE]); if (h->nlmsg_type == RTM_NEWLINK) { if (IS_ZEBRA_DEBUG_KERNEL) @@ -314,21 +314,28 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, return; } - /* Enable the created VRF. */ - if (!vrf_enable(vrf)) { - zlog_err("Failed to enable VRF %s id %u", name, - ifi->ifi_index); - return; - } - /* * This is the only place that we get the actual kernel table_id * being used. We need it to set the table_id of the routes * we are passing to the kernel.... And to throw some totally * awesome parties. that too. + * + * At this point we *must* have a zvrf because the vrf_create + * callback creates one. We *must* set the table id + * before the vrf_enable because of( at the very least ) + * static routes being delayed for installation until + * during the vrf_enable callbacks. */ zvrf = (struct zebra_vrf *)vrf->info; zvrf->table_id = nl_table_id; + + /* Enable the created VRF. */ + if (!vrf_enable(vrf)) { + zlog_err("Failed to enable VRF %s id %u", name, + ifi->ifi_index); + return; + } + } else // h->nlmsg_type == RTM_DELLINK { if (IS_ZEBRA_DEBUG_KERNEL) @@ -409,7 +416,7 @@ static int netlink_extract_bridge_info(struct rtattr *link_data, parse_rtattr_nested(attr, IFLA_BR_MAX, link_data); if (attr[IFLA_BR_VLAN_FILTERING]) bridge_info->vlan_aware = - *(u_char *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]); + *(uint8_t *)RTA_DATA(attr[IFLA_BR_VLAN_FILTERING]); return 0; } @@ -503,8 +510,8 @@ static int netlink_bridge_interface(struct nlmsghdr *h, int len, ns_id_t ns_id, struct interface *ifp; struct rtattr *aftb[IFLA_BRIDGE_MAX + 1]; struct { - u_int16_t flags; - u_int16_t vid; + uint16_t flags; + uint16_t vid; } * vinfo; vlanid_t access_vlan; @@ -631,7 +638,7 @@ static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h, if (slave_kind && (strcmp(slave_kind, "vrf") == 0) && !vrf_is_backend_netns()) { zif_slave_type = ZEBRA_IF_SLAVE_VRF; - vrf_id = *(u_int32_t *)RTA_DATA(tb[IFLA_MASTER]); + vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]); } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) { zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE; bridge_ifindex = @@ -683,7 +690,7 @@ static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h, /* Request for specific interface or address information from the kernel */ static int netlink_request_intf_addr(struct zebra_ns *zns, int family, int type, - u_int32_t filter_mask) + uint32_t filter_mask) { struct { struct nlmsghdr n; @@ -876,7 +883,7 @@ int netlink_interface_addr(struct sockaddr_nl *snl, struct nlmsghdr *h, struct interface *ifp; void *addr; void *broad; - u_char flags = 0; + uint8_t flags = 0; char *label = NULL; struct zebra_ns *zns; @@ -1008,6 +1015,54 @@ int netlink_interface_addr(struct sockaddr_nl *snl, struct nlmsghdr *h, return 0; } +/* helper function called by if_netlink_change + * to delete interfaces in case the interface moved + * to an other netns + */ +static void if_netlink_check_ifp_instance_consistency(uint16_t cmd, + struct interface *ifp, + ns_id_t ns_id) +{ + struct interface *old_ifp; + + /* + * look if interface name is also found on other netns + * - only if vrf backend is netns + * - do not concern lo interface + * - then remove previous one + * - for new link case, check found interface is not active + */ + if (!vrf_is_backend_netns() || + !strcmp(ifp->name, "lo")) + return; + old_ifp = if_lookup_by_name_not_ns(ns_id, ifp->name); + if (!old_ifp) + return; + if ((cmd == RTM_NEWLINK) + && (CHECK_FLAG(old_ifp->status, ZEBRA_INTERFACE_ACTIVE))) + return; + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("%s %s(%u) %s VRF %u", + cmd == RTM_DELLINK ? + "RTM_DELLINK replaced by" : + "RTM_NEWLINK replaces", + ifp->name, + old_ifp->ifindex, + cmd == RTM_DELLINK ? + "in" : "from", + old_ifp->vrf_id); + /* the found interface replaces the current one + * remove it + */ + if (cmd == RTM_DELLINK) + if_delete(ifp); + else + if_delete(old_ifp); + /* the found interface is replaced by the current one + * suppress it + */ +} + int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, ns_id_t ns_id, int startup) { @@ -1109,8 +1164,7 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if (slave_kind && (strcmp(slave_kind, "vrf") == 0) && !vrf_is_backend_netns()) { zif_slave_type = ZEBRA_IF_SLAVE_VRF; - vrf_id = - *(u_int32_t *)RTA_DATA(tb[IFLA_MASTER]); + vrf_id = *(uint32_t *)RTA_DATA(tb[IFLA_MASTER]); } else if (slave_kind && (strcmp(slave_kind, "bridge") == 0)) { zif_slave_type = ZEBRA_IF_SLAVE_BRIDGE; @@ -1169,6 +1223,8 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp)) zebra_l2if_update_bridge_slave(ifp, bridge_ifindex); + if_netlink_check_ifp_instance_consistency(RTM_NEWLINK, + ifp, ns_id); } else if (ifp->vrf_id != vrf_id) { /* VRF change for an interface. */ if (IS_ZEBRA_DEBUG_KERNEL) @@ -1236,6 +1292,8 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if (IS_ZEBRA_IF_BRIDGE_SLAVE(ifp) || was_bridge_slave) zebra_l2if_update_bridge_slave(ifp, bridge_ifindex); + if_netlink_check_ifp_instance_consistency(RTM_NEWLINK, + ifp, ns_id); } } else { /* Delete interface notification from kernel */ @@ -1259,6 +1317,8 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if (!IS_ZEBRA_IF_VRF(ifp)) if_delete_update(ifp); + if_netlink_check_ifp_instance_consistency(RTM_DELLINK, + ifp, ns_id); } return 0; diff --git a/zebra/interface.c b/zebra/interface.c index 7795d34d0b..6f59a2d399 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -181,7 +181,7 @@ static int if_zebra_delete_hook(struct interface *ifp) } /* Build the table key */ -static void if_build_key(u_int32_t ifindex, struct prefix *p) +static void if_build_key(uint32_t ifindex, struct prefix *p) { p->family = AF_INET; p->prefixlen = IPV4_MAX_BITLEN; @@ -221,7 +221,7 @@ void if_unlink_per_ns(struct interface *ifp) /* Look up an interface by identifier within a NS */ struct interface *if_lookup_by_index_per_ns(struct zebra_ns *ns, - u_int32_t ifindex) + uint32_t ifindex) { struct prefix p; struct route_node *rn; @@ -252,6 +252,30 @@ struct interface *if_lookup_by_name_per_ns(struct zebra_ns *ns, return NULL; } +/* this function must be used only if the vrf backend + * is a netns backend + */ +struct interface *if_lookup_by_name_not_ns(ns_id_t ns_id, + const char *ifname) +{ + struct interface *ifp; + struct ns *ns; + + RB_FOREACH (ns, ns_head, &ns_tree) { + if (ns->ns_id == ns_id) + continue; + /* if_delete_update has removed interface + * from zns->if_table + * so to look for interface, use the vrf list + */ + ifp = if_lookup_by_name(ifname, (vrf_id_t)ns->ns_id); + if (!ifp) + continue; + return ifp; + } + return NULL; +} + const char *ifindex2ifname_per_ns(struct zebra_ns *zns, unsigned int ifindex) { struct interface *ifp; @@ -787,7 +811,7 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); } -static void ipv6_ll_address_to_mac(struct in6_addr *address, u_char *mac) +static void ipv6_ll_address_to_mac(struct in6_addr *address, uint8_t *mac) { mac[0] = address->s6_addr[8] ^ 0x02; mac[1] = address->s6_addr[9]; @@ -801,6 +825,7 @@ void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp, struct in6_addr *address, int add) { struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_if *zif = ifp->info; char buf[16] = "169.254.0.1"; struct in_addr ipv4_ll; char mac[6]; @@ -808,7 +833,7 @@ void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp, inet_pton(AF_INET, buf, &ipv4_ll); - ipv6_ll_address_to_mac(address, (u_char *)mac); + ipv6_ll_address_to_mac(address, (uint8_t *)mac); ns_id = zvrf->zns->ns_id; /* @@ -821,6 +846,16 @@ void if_nbr_ipv6ll_to_ipv4ll_neigh_update(struct interface *ifp, /* Add arp record */ kernel_neigh_update(add, ifp->ifindex, ipv4_ll.s_addr, mac, 6, ns_id); + + /* + * We need to note whether or not we originated a v6 + * neighbor entry for this interface. So that when + * someone unwisely accidently deletes this entry + * we can shove it back in. + */ + zif->v6_2_v4_ll_neigh_entry = !!add; + memcpy(&zif->v6_2_v4_ll_addr6, address, sizeof(*address)); + zvrf->neigh_updates++; } @@ -1857,7 +1892,7 @@ DEFUN (link_params_metric, int idx_number = 1; VTY_DECLVAR_CONTEXT(interface, ifp); struct if_link_params *iflp = if_link_params_get(ifp); - u_int32_t metric; + uint32_t metric; metric = strtoul(argv[idx_number]->arg, NULL, 10); @@ -2045,7 +2080,7 @@ DEFUN (link_params_inter_as, VTY_DECLVAR_CONTEXT(interface, ifp); struct if_link_params *iflp = if_link_params_get(ifp); struct in_addr addr; - u_int32_t as; + uint32_t as; if (!inet_aton(argv[idx_ipv4]->arg, &addr)) { vty_out(vty, "Please specify Router-Addr by A.B.C.D\n"); @@ -2104,7 +2139,7 @@ DEFUN (link_params_delay, "Maximum delay in micro-second as decimal (0...16777215)\n") { /* Get and Check new delay values */ - u_int32_t delay = 0, low = 0, high = 0; + uint32_t delay = 0, low = 0, high = 0; delay = strtoul(argv[1]->arg, NULL, 10); if (argc == 6) { low = strtoul(argv[3]->arg, NULL, 10); @@ -2113,7 +2148,7 @@ DEFUN (link_params_delay, VTY_DECLVAR_CONTEXT(interface, ifp); struct if_link_params *iflp = if_link_params_get(ifp); - u_int8_t update = 0; + uint8_t update = 0; if (argc == 2) { /* Check new delay value against old Min and Max delays if set @@ -2199,7 +2234,7 @@ DEFUN (link_params_delay_var, int idx_number = 1; VTY_DECLVAR_CONTEXT(interface, ifp); struct if_link_params *iflp = if_link_params_get(ifp); - u_int32_t value; + uint32_t value; value = strtoul(argv[idx_number]->arg, NULL, 10); diff --git a/zebra/interface.h b/zebra/interface.h index 9f109fc05f..9634bfdb3f 100644 --- a/zebra/interface.h +++ b/zebra/interface.h @@ -93,7 +93,7 @@ struct rtadvconf { milliseconds (1 hour). Default: 0 */ - u_int32_t AdvReachableTime; + uint32_t AdvReachableTime; #define RTADV_MAX_REACHABLE_TIME 3600000 /* The value to be placed in the Retrans Timer field in the Router @@ -167,10 +167,10 @@ struct rtadvconf { int DefaultPreference; #define RTADV_PREF_MEDIUM 0x0 /* Per RFC4191. */ - u_char inFastRexmit; /* True if we're rexmits faster than usual */ + uint8_t inFastRexmit; /* True if we're rexmits faster than usual */ /* Track if RA was configured by BGP or by the Operator or both */ - u_char ra_configured; /* Was RA configured? */ + uint8_t ra_configured; /* Was RA configured? */ #define BGP_RA_CONFIGURED (1<<0) /* BGP configured RA? */ #define VTY_RA_CONFIGURED (1<<1) /* Operator configured RA? */ #define VTY_RA_INTERVAL_CONFIGURED (1<<2) /* Operator configured RA interval */ @@ -206,13 +206,13 @@ struct irdp_interface; /* `zebra' daemon local interface structure. */ struct zebra_if { /* Shutdown configuration. */ - u_char shutdown; + uint8_t shutdown; /* Multicast configuration. */ - u_char multicast; + uint8_t multicast; /* Router advertise configuration. */ - u_char rtadv_enable; + uint8_t rtadv_enable; /* Installed addresses chains tree. */ struct route_table *ipv4_subnets; @@ -248,11 +248,11 @@ struct zebra_if { * down (but primary still plumbed) and primary having gone * ~IFF_UP, and all addresses gone. */ - u_char primary_state; + uint8_t primary_state; #endif /* SUNOS_5 */ /* ptm enable configuration */ - u_char ptm_enable; + uint8_t ptm_enable; /* Zebra interface and "slave" interface type */ zebra_iftype_t zif_type; @@ -272,6 +272,13 @@ struct zebra_if { struct interface *link; struct thread *speed_update; + + /* + * Does this interface have a v6 to v4 ll neighbor entry + * for bgp unnumbered? + */ + bool v6_2_v4_ll_neigh_entry; + struct in6_addr v6_2_v4_ll_addr6; }; DECLARE_HOOK(zebra_if_extra_info, (struct vty * vty, struct interface *ifp), @@ -314,10 +321,11 @@ static inline void zebra_if_set_ziftype(struct interface *ifp, extern void zebra_if_init(void); -extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, - u_int32_t); +extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t); extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *, const char *); +extern struct interface *if_lookup_by_name_not_ns(ns_id_t ns_id, + const char *ifname); extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *); extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int); diff --git a/zebra/ioctl.c b/zebra/ioctl.c index a95d5d4e1b..a577b008d5 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -48,7 +48,7 @@ void ifreq_set_name(struct ifreq *ifreq, struct interface *ifp) } /* call ioctl system call */ -int if_ioctl(u_long request, caddr_t buffer) +int if_ioctl(unsigned long request, caddr_t buffer) { int sock; int ret; @@ -80,7 +80,7 @@ int if_ioctl(u_long request, caddr_t buffer) } /* call ioctl system call */ -int vrf_if_ioctl(u_long request, caddr_t buffer, vrf_id_t vrf_id) +int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id) { int sock; int ret; @@ -113,7 +113,7 @@ int vrf_if_ioctl(u_long request, caddr_t buffer, vrf_id_t vrf_id) } #ifndef HAVE_NETLINK -static int if_ioctl_ipv6(u_long request, caddr_t buffer) +static int if_ioctl_ipv6(unsigned long request, caddr_t buffer) { int sock; int ret; @@ -493,7 +493,7 @@ int if_unset_flags(struct interface *ifp, uint64_t flags) /* linux/include/net/ipv6.h */ struct in6_ifreq { struct in6_addr ifr6_addr; - u_int32_t ifr6_prefixlen; + uint32_t ifr6_prefixlen; int ifr6_ifindex; }; #endif /* _LINUX_IN6_H */ diff --git a/zebra/ioctl.h b/zebra/ioctl.h index 1a6e14ed4d..2a8ea77909 100644 --- a/zebra/ioctl.h +++ b/zebra/ioctl.h @@ -24,8 +24,8 @@ /* Prototypes. */ extern void ifreq_set_name(struct ifreq *, struct interface *); -extern int if_ioctl(u_long, caddr_t); -extern int vrf_if_ioctl(u_long request, caddr_t buffer, vrf_id_t vrf_id); +extern int if_ioctl(unsigned long, caddr_t); +extern int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id); extern int if_set_flags(struct interface *, uint64_t); extern int if_unset_flags(struct interface *, uint64_t); @@ -41,7 +41,7 @@ extern int if_prefix_add_ipv6(struct interface *, struct connected *); extern int if_prefix_delete_ipv6(struct interface *, struct connected *); #ifdef SOLARIS_IPV6 -extern int if_ioctl_ipv6(u_long, caddr_t); +extern int if_ioctl_ipv6(unsigned long, caddr_t); extern struct connected *if_lookup_linklocal(struct interface *); #define AF_IOCTL(af, request, buffer) \ diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c index f429c42440..eb68451f7c 100644 --- a/zebra/ioctl_solaris.c +++ b/zebra/ioctl_solaris.c @@ -45,13 +45,13 @@ void lifreq_set_name(struct lifreq *lifreq, const char *ifname) strncpy(lifreq->lifr_name, ifname, IFNAMSIZ); } -int vrf_if_ioctl(u_long request, caddr_t buffer, vrf_id_t vrf_id) +int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id) { return if_ioctl(request, buffer); } /* call ioctl system call */ -int if_ioctl(u_long request, caddr_t buffer) +int if_ioctl(unsigned long request, caddr_t buffer) { int sock; int ret; @@ -86,7 +86,7 @@ int if_ioctl(u_long request, caddr_t buffer) } -int if_ioctl_ipv6(u_long request, caddr_t buffer) +int if_ioctl_ipv6(unsigned long request, caddr_t buffer) { int sock; int ret; @@ -155,7 +155,7 @@ void if_get_mtu(struct interface *ifp) { struct lifreq lifreq; int ret; - u_char changed = 0; + uint8_t changed = 0; if (ifp->flags & IFF_IPV4) { lifreq_set_name(&lifreq, ifp->name); diff --git a/zebra/irdp.h b/zebra/irdp.h index 8aa9f3e4b3..4800e75be3 100644 --- a/zebra/irdp.h +++ b/zebra/irdp.h @@ -117,7 +117,7 @@ struct irdp_interface { unsigned long MinAdvertInterval; unsigned long Preference; - u_int32_t flags; + uint32_t flags; #define IF_ACTIVE (1<<0) /* ICMP Active */ #define IF_BROADCAST (1<<1) /* 255.255.255.255 */ @@ -130,7 +130,7 @@ struct irdp_interface { struct interface *ifp; struct thread *t_advertise; unsigned long irdp_sent; - u_int16_t Lifetime; + uint16_t Lifetime; struct list *AdvPrefList; }; @@ -147,8 +147,8 @@ extern int 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 send_packet(struct interface *ifp, struct stream *s, u_int32_t dst, - struct prefix *p, u_int32_t ttl); +extern void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, + struct prefix *p, uint32_t ttl); #endif /* _IRDP_H */ diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 2c10ce86a0..ca78404797 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -97,7 +97,7 @@ static int irdp_if_delete(struct interface *ifp) return 0; } -static const char *inet_2a(u_int32_t a, char *b) +static const char *inet_2a(uint32_t a, char *b) { sprintf(b, "%u.%u.%u.%u", (a)&0xFF, (a >> 8) & 0xFF, (a >> 16) & 0xFF, (a >> 24) & 0xFF); @@ -118,7 +118,7 @@ static struct prefix *irdp_get_prefix(struct interface *ifp) } /* Join to the add/leave multicast group. */ -static int if_group(struct interface *ifp, int sock, u_int32_t group, +static int if_group(struct interface *ifp, int sock, uint32_t group, int add_leave) { struct ip_mreq m; @@ -216,7 +216,7 @@ static void irdp_if_start(struct interface *ifp, int multicast, struct irdp_interface *irdp = zi->irdp; struct listnode *node; struct connected *ifc; - u_int32_t timer, seed; + uint32_t timer, seed; assert(irdp); diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 39e04480c6..c2411d083f 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -146,7 +146,7 @@ static int make_advertisement_packet(struct interface *ifp, struct prefix *p, struct irdp_interface *irdp = zi->irdp; int size; int pref; - u_int16_t checksum; + uint16_t checksum; pref = get_pref(irdp, p); @@ -177,8 +177,8 @@ static void irdp_send(struct interface *ifp, struct prefix *p, struct stream *s) struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; char buf[PREFIX_STRLEN]; - u_int32_t dst; - u_int32_t ttl = 1; + uint32_t dst; + uint32_t ttl = 1; if (!irdp) return; @@ -210,7 +210,7 @@ static void irdp_advertisement(struct interface *ifp, struct prefix *p) int irdp_send_thread(struct thread *t_advert) { - u_int32_t timer, tmp; + uint32_t timer, tmp; struct interface *ifp = THREAD_ARG(t_advert); struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; @@ -288,7 +288,7 @@ void process_solicit(struct interface *ifp) { struct zebra_if *zi = ifp->info; struct irdp_interface *irdp = zi->irdp; - u_int32_t timer; + uint32_t timer; if (!irdp) return; diff --git a/zebra/irdp_packet.c b/zebra/irdp_packet.c index 11bc9b0440..b0dde96cce 100644 --- a/zebra/irdp_packet.c +++ b/zebra/irdp_packet.c @@ -175,7 +175,7 @@ static void parse_irdp_packet(char *p, int len, struct interface *ifp) } } -static int irdp_recvmsg(int sock, u_char *buf, int size, int *ifindex) +static int irdp_recvmsg(int sock, uint8_t *buf, int size, int *ifindex) { struct msghdr msg; struct iovec iov; @@ -226,7 +226,7 @@ int irdp_read_raw(struct thread *r) thread_add_read(zebrad.master, irdp_read_raw, NULL, irdp_sock, &t_irdp_raw); - ret = irdp_recvmsg(irdp_sock, (u_char *)buf, IRDP_RX_BUF, &ifindex); + ret = irdp_recvmsg(irdp_sock, (uint8_t *)buf, IRDP_RX_BUF, &ifindex); if (ret < 0) zlog_warn("IRDP: RX Error length = %d", ret); @@ -263,8 +263,8 @@ int irdp_read_raw(struct thread *r) return ret; } -void send_packet(struct interface *ifp, struct stream *s, u_int32_t dst, - struct prefix *p, u_int32_t ttl) +void send_packet(struct interface *ifp, struct stream *s, uint32_t dst, + struct prefix *p, uint32_t ttl) { static struct sockaddr_in sockdst = {AF_INET}; struct ip *ip; @@ -275,8 +275,8 @@ void send_packet(struct interface *ifp, struct stream *s, u_int32_t dst, char msgbuf[256]; char buf[256]; struct in_pktinfo *pktinfo; - u_long src; - u_char on; + unsigned long src; + uint8_t on; if (!(ifp->flags & IFF_UP)) return; diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 52b2692090..db4f19460a 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -58,12 +58,13 @@ #ifndef NLMSG_TAIL #define NLMSG_TAIL(nmsg) \ - ((struct rtattr *)(((u_char *)(nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) + ((struct rtattr *)(((uint8_t *)(nmsg)) \ + + NLMSG_ALIGN((nmsg)->nlmsg_len))) #endif #ifndef RTA_TAIL #define RTA_TAIL(rta) \ - ((struct rtattr *)(((u_char *)(rta)) + RTA_ALIGN((rta)->rta_len))) + ((struct rtattr *)(((uint8_t *)(rta)) + RTA_ALIGN((rta)->rta_len))) #endif #ifndef RTNL_FAMILY_IP6MR @@ -123,7 +124,7 @@ static const struct message rttype_str[] = {{RTN_UNICAST, "unicast"}, {0}}; extern struct thread_master *master; -extern u_int32_t nl_rcvbufsize; +extern uint32_t nl_rcvbufsize; extern struct zebra_privs_t zserv_privs; @@ -137,7 +138,7 @@ int netlink_talk_filter(struct sockaddr_nl *snl, struct nlmsghdr *h, static int netlink_recvbuf(struct nlsock *nl, uint32_t newsize) { - u_int32_t oldsize; + uint32_t oldsize; socklen_t newlen = sizeof(newsize); socklen_t oldlen = sizeof(oldsize); int ret; @@ -380,14 +381,14 @@ int rta_addattr_l(struct rtattr *rta, unsigned int maxlen, int type, void *data, return 0; } -int addattr16(struct nlmsghdr *n, unsigned int maxlen, int type, u_int16_t data) +int addattr16(struct nlmsghdr *n, unsigned int maxlen, int type, uint16_t data) { - return addattr_l(n, maxlen, type, &data, sizeof(u_int16_t)); + return addattr_l(n, maxlen, type, &data, sizeof(uint16_t)); } int addattr32(struct nlmsghdr *n, unsigned int maxlen, int type, int data) { - return addattr_l(n, maxlen, type, &data, sizeof(u_int32_t)); + return addattr_l(n, maxlen, type, &data, sizeof(uint32_t)); } struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type) @@ -400,7 +401,7 @@ struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type) int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest) { - nest->rta_len = (u_char *)NLMSG_TAIL(n) - (u_char *)nest; + nest->rta_len = (uint8_t *)NLMSG_TAIL(n) - (uint8_t *)nest; return n->nlmsg_len; } @@ -414,7 +415,7 @@ struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type) int rta_nest_end(struct rtattr *rta, struct rtattr *nest) { - nest->rta_len = (u_char *)RTA_TAIL(rta) - (u_char *)nest; + nest->rta_len = (uint8_t *)RTA_TAIL(rta) - (uint8_t *)nest; return rta->rta_len; } @@ -423,17 +424,17 @@ const char *nl_msg_type_to_str(uint16_t msg_type) return lookup_msg(nlmsg_str, msg_type, ""); } -const char *nl_rtproto_to_str(u_char rtproto) +const char *nl_rtproto_to_str(uint8_t rtproto) { return lookup_msg(rtproto_str, rtproto, ""); } -const char *nl_family_to_str(u_char family) +const char *nl_family_to_str(uint8_t family) { return lookup_msg(family_str, family, ""); } -const char *nl_rttype_to_str(u_char rttype) +const char *nl_rttype_to_str(uint8_t rttype) { return lookup_msg(rttype_str, rttype, ""); } diff --git a/zebra/kernel_netlink.h b/zebra/kernel_netlink.h index e5a079af5b..8441eeac76 100644 --- a/zebra/kernel_netlink.h +++ b/zebra/kernel_netlink.h @@ -32,7 +32,7 @@ extern int addattr_l(struct nlmsghdr *n, unsigned int maxlen, int type, extern int rta_addattr_l(struct rtattr *rta, unsigned int maxlen, int type, void *data, unsigned int alen); extern int addattr16(struct nlmsghdr *n, unsigned int maxlen, int type, - u_int16_t data); + uint16_t data); extern int addattr32(struct nlmsghdr *n, unsigned int maxlen, int type, int data); extern struct rtattr *addattr_nest(struct nlmsghdr *n, int maxlen, int type); @@ -40,9 +40,9 @@ extern int addattr_nest_end(struct nlmsghdr *n, struct rtattr *nest); extern struct rtattr *rta_nest(struct rtattr *rta, int maxlen, int type); extern int rta_nest_end(struct rtattr *rta, struct rtattr *nest); extern const char *nl_msg_type_to_str(uint16_t msg_type); -extern const char *nl_rtproto_to_str(u_char rtproto); -extern const char *nl_family_to_str(u_char family); -extern const char *nl_rttype_to_str(u_char rttype); +extern const char *nl_rtproto_to_str(uint8_t rtproto); +extern const char *nl_family_to_str(uint8_t family); +extern const char *nl_rttype_to_str(uint8_t rttype); extern int netlink_parse_info(int (*filter)(struct sockaddr_nl *, struct nlmsghdr *, ns_id_t, int), diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index eba4270efe..4ac3bed4b4 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -168,7 +168,7 @@ static inline void rta_copy(union sockunion *dest, caddr_t src) #define RTA_NAME_GET(DEST, RTA, RTMADDRS, PNT, LEN) \ if ((RTMADDRS) & (RTA)) { \ - u_char *pdest = (u_char *)(DEST); \ + uint8_t *pdest = (uint8_t *)(DEST); \ int len = SAROUNDUP((PNT)); \ struct sockaddr_dl *sdl = (struct sockaddr_dl *)(PNT); \ if (IS_ZEBRA_DEBUG_KERNEL) \ @@ -864,7 +864,7 @@ static int rtm_read_mesg(struct rt_msghdr *rtm, union sockunion *dest, void rtm_read(struct rt_msghdr *rtm) { int flags; - u_char zebra_flags; + uint8_t zebra_flags; union sockunion dest, mask, gate; char ifname[INTERFACE_NAMSIZ + 1]; short ifnlen = 0; diff --git a/zebra/label_manager.c b/zebra/label_manager.c index b58f0c9ff8..38869e80ec 100644 --- a/zebra/label_manager.c +++ b/zebra/label_manager.c @@ -64,11 +64,11 @@ static int relay_response_back(struct zserv *zserv) { int ret = 0; struct stream *src, *dst; - u_int16_t size = 0; - u_char marker; - u_char version; + uint16_t size = 0; + uint8_t marker; + uint8_t version; vrf_id_t vrf_id; - u_int16_t resp_cmd; + uint16_t resp_cmd; src = zclient->ibuf; dst = obuf; @@ -269,8 +269,9 @@ void label_manager_init(char *lm_zserv_path) * @para size Size of the label chunk * @return Pointer to the assigned label chunk */ -struct label_manager_chunk *assign_label_chunk(u_char proto, u_short instance, - u_char keep, uint32_t size) +struct label_manager_chunk *assign_label_chunk(uint8_t proto, + unsigned short instance, + uint8_t keep, uint32_t size) { struct label_manager_chunk *lmc; struct listnode *node; @@ -321,7 +322,7 @@ struct label_manager_chunk *assign_label_chunk(u_char proto, u_short instance, * @param end Last label of the chunk * @return 0 on success, -1 otherwise */ -int release_label_chunk(u_char proto, u_short instance, uint32_t start, +int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start, uint32_t end) { struct listnode *node; @@ -362,7 +363,7 @@ int release_label_chunk(u_char proto, u_short instance, uint32_t start, * @param instance Instance, to identify the owner * @return Number of chunks released */ -int release_daemon_chunks(u_char proto, u_short instance) +int release_daemon_label_chunks(uint8_t proto, unsigned short instance) { struct listnode *node; struct label_manager_chunk *lmc; diff --git a/zebra/label_manager.h b/zebra/label_manager.h index 8756983621..4395e6897e 100644 --- a/zebra/label_manager.h +++ b/zebra/label_manager.h @@ -44,9 +44,9 @@ * the same proto and instance values) */ struct label_manager_chunk { - u_char proto; - u_short instance; - u_char keep; + uint8_t proto; + unsigned short instance; + uint8_t keep; uint32_t start; /* First label of the chunk */ uint32_t end; /* Last label of the chunk */ }; @@ -64,11 +64,12 @@ bool lm_is_external; int zread_relay_label_manager_request(int cmd, struct zserv *zserv, vrf_id_t vrf_id); void label_manager_init(char *lm_zserv_path); -struct label_manager_chunk *assign_label_chunk(u_char proto, u_short instance, - u_char keep, uint32_t size); -int release_label_chunk(u_char proto, u_short instance, uint32_t start, +struct label_manager_chunk *assign_label_chunk(uint8_t proto, + unsigned short instance, + uint8_t keep, uint32_t size); +int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start, uint32_t end); -int release_daemon_chunks(u_char proto, u_short instance); +int release_daemon_label_chunks(uint8_t proto, unsigned short instance); void label_manager_close(void); #endif /* _LABEL_MANAGER_H */ diff --git a/zebra/main.c b/zebra/main.c index b0a19c5aa5..c8d7f83fb7 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -75,7 +75,7 @@ int keep_kernel_mode = 0; #ifdef HAVE_NETLINK /* Receive buffer size for netlink socket */ -u_int32_t nl_rcvbufsize = 4194304; +uint32_t nl_rcvbufsize = 4194304; #endif /* HAVE_NETLINK */ /* Command line options. */ diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 89c17b069a..15e7d4437a 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -48,9 +48,9 @@ /* array holding redistribute info about table redistribution */ /* bit AFI is set if that AFI is redistributing routes from this table */ static int zebra_import_table_used[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; -static u_int32_t zebra_import_table_distance[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; +static uint32_t zebra_import_table_distance[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; -int is_zebra_import_table_enabled(afi_t afi, u_int32_t table_id) +int is_zebra_import_table_enabled(afi_t afi, uint32_t table_id) { /* * Make sure that what we are called with actualy makes sense @@ -98,8 +98,9 @@ static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) } /* Redistribute routes. */ -static void zebra_redistribute(struct zserv *client, int type, u_short instance, - vrf_id_t vrf_id, int afi) +static void zebra_redistribute(struct zserv *client, int type, + unsigned short instance, vrf_id_t vrf_id, + int afi) { struct route_entry *newre; struct route_table *table; @@ -249,7 +250,7 @@ void zebra_redistribute_add(ZAPI_HANDLER_ARGS) { afi_t afi = 0; int type = 0; - u_short instance; + unsigned short instance; STREAM_GETC(msg, afi); STREAM_GETC(msg, type); @@ -301,7 +302,7 @@ void zebra_redistribute_delete(ZAPI_HANDLER_ARGS) { afi_t afi = 0; int type = 0; - u_short instance; + unsigned short instance; STREAM_GETC(msg, afi); STREAM_GETC(msg, type); @@ -582,7 +583,7 @@ int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re) } /* Assuming no one calls this with the main routing table */ -int zebra_import_table(afi_t afi, u_int32_t table_id, u_int32_t distance, +int zebra_import_table(afi_t afi, uint32_t table_id, uint32_t distance, const char *rmap_name, int add) { struct route_table *table; diff --git a/zebra/redistribute.h b/zebra/redistribute.h index e551f820cc..c78480d9a3 100644 --- a/zebra/redistribute.h +++ b/zebra/redistribute.h @@ -55,7 +55,7 @@ extern void zebra_interface_vrf_update_del(struct interface *, extern void zebra_interface_vrf_update_add(struct interface *, vrf_id_t old_vrf_id); -extern int zebra_import_table(afi_t afi, u_int32_t table_id, u_int32_t distance, +extern int zebra_import_table(afi_t afi, uint32_t table_id, uint32_t distance, const char *rmap_name, int add); extern int zebra_add_import_table_entry(struct route_node *rn, @@ -63,7 +63,7 @@ extern int zebra_add_import_table_entry(struct route_node *rn, const char *rmap_name); extern int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re); -extern int is_zebra_import_table_enabled(afi_t, u_int32_t table_id); +extern int is_zebra_import_table_enabled(afi_t, uint32_t table_id); extern int zebra_import_table_config(struct vty *); diff --git a/zebra/rib.h b/zebra/rib.h index 0562d544e6..d68bf787c0 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -56,7 +56,7 @@ struct route_entry { int type; /* Source protocol instance */ - u_short instance; + unsigned short instance; /* VRF identifier. */ vrf_id_t vrf_id; @@ -65,11 +65,11 @@ struct route_entry { uint32_t table; /* Metric */ - u_int32_t metric; + uint32_t metric; /* MTU */ - u_int32_t mtu; - u_int32_t nexthop_mtu; + uint32_t mtu; + uint32_t nexthop_mtu; /* Distance. */ uint8_t distance; @@ -78,10 +78,10 @@ struct route_entry { * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed * to clients via Zserv */ - u_int32_t flags; + uint32_t flags; /* RIB internal status */ - u_char status; + uint8_t status; #define ROUTE_ENTRY_REMOVED 0x1 /* to simplify NHT logic when NHs change, instead of doing a NH by NH cmp */ #define ROUTE_ENTRY_NEXTHOPS_CHANGED 0x2 @@ -89,8 +89,8 @@ struct route_entry { #define ROUTE_ENTRY_LABELS_CHANGED 0x8 /* Nexthop information. */ - u_char nexthop_num; - u_char nexthop_active_num; + uint8_t nexthop_num; + uint8_t nexthop_active_num; }; /* meta-queue structure: @@ -103,7 +103,7 @@ struct route_entry { #define MQ_SIZE 5 struct meta_queue { struct list *subq[MQ_SIZE]; - u_int32_t size; /* sum of lengths of all subqueues */ + uint32_t size; /* sum of lengths of all subqueues */ }; /* @@ -127,7 +127,7 @@ typedef struct rib_dest_t_ { /* * Flags, see below. */ - u_int32_t flags; + uint32_t flags; /* * Linkage to put dest on the FPM processing queue. @@ -287,8 +287,8 @@ extern int rib_lookup_ipv4_route(struct prefix_ipv4 *p, union sockunion *qgate, #define ZEBRA_RIB_FOUND_CONNECTED 2 #define ZEBRA_RIB_NOTFOUND 3 -extern int is_zebra_valid_kernel_table(u_int32_t table_id); -extern int is_zebra_main_routing_table(u_int32_t table_id); +extern int is_zebra_valid_kernel_table(uint32_t table_id); +extern int is_zebra_main_routing_table(uint32_t table_id); extern int zebra_check_addr(struct prefix *p); extern void rib_addnode(struct route_node *rn, struct route_entry *re, @@ -302,18 +302,18 @@ extern void rib_uninstall_kernel(struct route_node *rn, struct route_entry *re); * All rib_add function will not just add prefix into RIB, but * also implicitly withdraw equal prefix of same type. */ extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, - u_short instance, int flags, struct prefix *p, + unsigned short instance, int flags, struct prefix *p, struct prefix_ipv6 *src_p, const struct nexthop *nh, - u_int32_t table_id, u_int32_t metric, u_int32_t mtu, + uint32_t table_id, uint32_t metric, uint32_t mtu, uint8_t distance, route_tag_t tag); extern int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, struct prefix_ipv6 *src_p, struct route_entry *re); extern void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, - u_short instance, int flags, struct prefix *p, + unsigned short instance, int flags, struct prefix *p, struct prefix_ipv6 *src_p, const struct nexthop *nh, - u_int32_t table_id, u_int32_t metric, bool fromkernel, + uint32_t table_id, uint32_t metric, bool fromkernel, struct ethaddr *rmac); extern struct route_entry *rib_match(afi_t afi, safi_t safi, vrf_id_t vrf_id, @@ -331,8 +331,9 @@ extern void rib_sweep_route(void); extern void rib_sweep_table(struct route_table *table); extern void rib_close_table(struct route_table *table); extern void rib_init(void); -extern unsigned long rib_score_proto(u_char proto, u_short instance); -extern unsigned long rib_score_proto_table(u_char proto, u_short instance, +extern unsigned long rib_score_proto(uint8_t proto, unsigned short instance); +extern unsigned long rib_score_proto_table(uint8_t proto, + unsigned short instance, struct route_table *table); extern void rib_queue_add(struct route_node *rn); extern void meta_queue_free(struct meta_queue *mq); @@ -395,7 +396,7 @@ static inline struct prefix *rib_dest_prefix(rib_dest_t *dest) * * Returns the address family that the destination is for. */ -static inline u_char rib_dest_af(rib_dest_t *dest) +static inline uint8_t rib_dest_af(rib_dest_t *dest) { return dest->rnode->p.family; } diff --git a/zebra/rt.h b/zebra/rt.h index 399f6e8453..fd298fd236 100644 --- a/zebra/rt.h +++ b/zebra/rt.h @@ -107,7 +107,7 @@ extern int kernel_del_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip); extern int kernel_add_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac, struct in_addr vtep_ip, - u_char sticky); + uint8_t sticky); extern int kernel_del_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac, struct in_addr vtep_ip, int local); diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 2b758c58d8..d1edea804a 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -72,8 +72,8 @@ static vlanid_t filter_vlan = 0; struct gw_family_t { - u_int16_t filler; - u_int16_t family; + uint16_t filler; + uint16_t family; union g_addr gate; }; @@ -194,7 +194,7 @@ static inline int proto2zebra(int proto, int family) /* Pending: create an efficient table_id (in a tree/hash) based lookup) */ -static vrf_id_t vrf_lookup_by_table(u_int32_t table_id, ns_id_t ns_id) +static vrf_id_t vrf_lookup_by_table(uint32_t table_id, ns_id_t ns_id) { struct vrf *vrf; struct zebra_vrf *zvrf; @@ -226,7 +226,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, int len; struct rtmsg *rtm; struct rtattr *tb[RTA_MAX + 1]; - u_char flags = 0; + uint8_t flags = 0; struct prefix p; struct prefix_ipv6 src_p = {}; vrf_id_t vrf_id; @@ -237,7 +237,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, int index = 0; int table; int metric = 0; - u_int32_t mtu = 0; + uint32_t mtu = 0; uint8_t distance = 0; route_tag_t tag = 0; @@ -344,7 +344,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, RTA_PAYLOAD(tb[RTA_METRICS])); if (mxrta[RTAX_MTU]) - mtu = *(u_int32_t *)RTA_DATA(mxrta[RTAX_MTU]); + mtu = *(uint32_t *)RTA_DATA(mxrta[RTAX_MTU]); } if (rtm->rtm_family == AF_INET) { @@ -772,8 +772,8 @@ int netlink_route_read(struct zebra_ns *zns) return 0; } -static void _netlink_route_nl_add_gateway_info(u_char route_family, - u_char gw_family, +static void _netlink_route_nl_add_gateway_info(uint8_t route_family, + uint8_t gw_family, struct nlmsghdr *nlmsg, size_t req_size, int bytelen, struct nexthop *nexthop) @@ -798,8 +798,8 @@ static void _netlink_route_nl_add_gateway_info(u_char route_family, } } -static void _netlink_route_rta_add_gateway_info(u_char route_family, - u_char gw_family, +static void _netlink_route_rta_add_gateway_info(uint8_t route_family, + uint8_t gw_family, struct rtattr *rta, struct rtnexthop *rtnh, size_t req_size, int bytelen, @@ -896,10 +896,10 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, num_labels * sizeof(mpls_lse_t)); else { struct rtattr *nest; - u_int16_t encap = LWTUNNEL_ENCAP_MPLS; + uint16_t encap = LWTUNNEL_ENCAP_MPLS; addattr_l(nlmsg, req_size, RTA_ENCAP_TYPE, &encap, - sizeof(u_int16_t)); + sizeof(uint16_t)); nest = addattr_nest(nlmsg, req_size, RTA_ENCAP); addattr_l(nlmsg, req_size, MPLS_IPTUNNEL_DST, &out_lse, num_labels * sizeof(mpls_lse_t)); @@ -927,9 +927,9 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( " 5549: _netlink_route_build_singlepath() (%s): " - "nexthop via %s %s if %u", + "nexthop via %s %s if %u(%u)", routedesc, ipv4_ll_buf, label_buf, - nexthop->ifindex); + nexthop->ifindex, nexthop->vrf_id); return; } @@ -953,9 +953,9 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u", + "nexthop via %s %s if %u(%u)", routedesc, inet_ntoa(nexthop->gate.ipv4), - label_buf, nexthop->ifindex); + label_buf, nexthop->ifindex, nexthop->vrf_id); } if (nexthop->type == NEXTHOP_TYPE_IPV6 @@ -976,9 +976,9 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u", + "nexthop via %s %s if %u(%u)", routedesc, inet6_ntoa(nexthop->gate.ipv6), - label_buf, nexthop->ifindex); + label_buf, nexthop->ifindex, nexthop->vrf_id); } /* @@ -1003,8 +1003,8 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "netlink_route_multipath() (%s): " - "nexthop via if %u", - routedesc, nexthop->ifindex); + "nexthop via if %u(%u)", + routedesc, nexthop->ifindex, nexthop->vrf_id); } if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX) { @@ -1020,8 +1020,8 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "netlink_route_multipath() (%s): " - "nexthop via if %u", - routedesc, nexthop->ifindex); + "nexthop via if %u(%u)", + routedesc, nexthop->ifindex, nexthop->vrf_id); } } @@ -1108,11 +1108,11 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, RTA_LENGTH(num_labels * sizeof(mpls_lse_t)); } else { struct rtattr *nest; - u_int16_t encap = LWTUNNEL_ENCAP_MPLS; + uint16_t encap = LWTUNNEL_ENCAP_MPLS; int len = rta->rta_len; rta_addattr_l(rta, NL_PKT_BUF_SIZE, RTA_ENCAP_TYPE, - &encap, sizeof(u_int16_t)); + &encap, sizeof(uint16_t)); nest = rta_nest(rta, NL_PKT_BUF_SIZE, RTA_ENCAP); rta_addattr_l(rta, NL_PKT_BUF_SIZE, MPLS_IPTUNNEL_DST, &out_lse, @@ -1224,7 +1224,7 @@ static inline void _netlink_mpls_build_singlepath(const char *routedesc, size_t req_size, int cmd) { int bytelen; - u_char family; + uint8_t family; family = NHLFE_FAMILY(nhlfe); bytelen = (family == AF_INET ? 4 : 16); @@ -1239,7 +1239,7 @@ _netlink_mpls_build_multipath(const char *routedesc, zebra_nhlfe_t *nhlfe, struct rtmsg *rtmsg, union g_addr **src) { int bytelen; - u_char family; + uint8_t family; family = NHLFE_FAMILY(nhlfe); bytelen = (family == AF_INET ? 4 : 16); @@ -1260,19 +1260,20 @@ _netlink_mpls_build_multipath(const char *routedesc, zebra_nhlfe_t *nhlfe, */ static void _netlink_route_debug(int cmd, struct prefix *p, struct nexthop *nexthop, const char *routedesc, - int family, struct zebra_vrf *zvrf) + int family, struct zebra_vrf *zvrf, + uint32_t tableid) { if (IS_ZEBRA_DEBUG_KERNEL) { char buf[PREFIX_STRLEN]; zlog_debug( - "netlink_route_multipath() (%s): %s %s vrf %u type %s", + "netlink_route_multipath() (%s): %s %s vrf %u(%u) type %s", routedesc, nl_msg_type_to_str(cmd), - prefix2str(p, buf, sizeof(buf)), zvrf_id(zvrf), + prefix2str(p, buf, sizeof(buf)), zvrf_id(zvrf), tableid, (nexthop) ? nexthop_type_to_str(nexthop->type) : "UNK"); } } -static void _netlink_mpls_debug(int cmd, u_int32_t label, const char *routedesc) +static void _netlink_mpls_debug(int cmd, uint32_t label, const char *routedesc) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("netlink_mpls_multipath() (%s): %s %u/20", routedesc, @@ -1385,7 +1386,7 @@ static int netlink_route_multipath(int cmd, struct prefix *p, if (re->mtu || re->nexthop_mtu) { char buf[NL_PKT_BUF_SIZE]; struct rtattr *rta = (void *)buf; - u_int32_t mtu = re->mtu; + uint32_t mtu = re->mtu; if (!mtu || (re->nexthop_mtu && re->nexthop_mtu < mtu)) mtu = re->nexthop_mtu; rta->rta_type = RTA_METRICS; @@ -1486,7 +1487,7 @@ static int netlink_route_multipath(int cmd, struct prefix *p, : "single-path"; _netlink_route_debug(cmd, p, nexthop, routedesc, - family, zvrf); + family, zvrf, re->table); _netlink_route_build_singlepath( routedesc, bytelen, nexthop, &req.n, &req.r, sizeof req, cmd); @@ -1570,7 +1571,7 @@ static int netlink_route_multipath(int cmd, struct prefix *p, nexthop_num++; _netlink_route_debug(cmd, p, nexthop, routedesc, - family, zvrf); + family, zvrf, re->table); _netlink_route_build_multipath( routedesc, bytelen, nexthop, rta, rtnh, &req.r, &src1); @@ -1724,7 +1725,7 @@ static int netlink_vxlan_flood_list_update(struct interface *ifp, struct ndmsg ndm; char buf[256]; } req; - u_char dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; + uint8_t dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); zns = zvrf->zns; @@ -1797,7 +1798,7 @@ static int netlink_macfdb_change(struct sockaddr_nl *snl, struct nlmsghdr *h, char buf[ETHER_ADDR_STRLEN]; char vid_buf[20]; char dst_buf[30]; - u_char sticky = 0; + uint8_t sticky = 0; ndm = NLMSG_DATA(h); @@ -1854,7 +1855,7 @@ static int netlink_macfdb_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if ((NDA_VLAN <= NDA_MAX) && tb[NDA_VLAN]) { vid_present = 1; - vid = *(u_int16_t *)RTA_DATA(tb[NDA_VLAN]); + vid = *(uint16_t *)RTA_DATA(tb[NDA_VLAN]); sprintf(vid_buf, " VLAN %u", vid); } @@ -2017,7 +2018,7 @@ int netlink_macfdb_read_for_bridge(struct zebra_ns *zns, struct interface *ifp, static int netlink_macfdb_update(struct interface *ifp, vlanid_t vid, struct ethaddr *mac, struct in_addr vtep_ip, - int local, int cmd, u_char sticky) + int local, int cmd, uint8_t sticky) { struct zebra_ns *zns; struct { @@ -2107,25 +2108,57 @@ static int netlink_ipneigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; int mac_present = 0; - u_char ext_learned; + uint8_t ext_learned; ndm = NLMSG_DATA(h); - /* We only process neigh notifications if EVPN is enabled */ - if (!is_evpn_enabled()) - return 0; - /* The interface should exist. */ ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id), ndm->ndm_ifindex); if (!ifp || !ifp->info) return 0; - /* Drop "permanent" entries. */ - if (ndm->ndm_state & NUD_PERMANENT) + zif = (struct zebra_if *)ifp->info; + + /* Parse attributes and extract fields of interest. */ + memset(tb, 0, sizeof tb); + netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len); + + if (!tb[NDA_DST]) { + zlog_warn("%s family %s IF %s(%u) - no DST", + nl_msg_type_to_str(h->nlmsg_type), + nl_family_to_str(ndm->ndm_family), ifp->name, + ndm->ndm_ifindex); return 0; + } + + memset(&ip, 0, sizeof(struct ipaddr)); + ip.ipa_type = (ndm->ndm_family == AF_INET) ? IPADDR_V4 : IPADDR_V6; + memcpy(&ip.ip.addr, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); + + /* Drop some "permanent" entries. */ + if (ndm->ndm_state & NUD_PERMANENT) { + char buf[16] = "169.254.0.1"; + struct in_addr ipv4_ll; + + if (ndm->ndm_family != AF_INET) + return 0; + + if (!zif->v6_2_v4_ll_neigh_entry) + return 0; + + if (h->nlmsg_type != RTM_DELNEIGH) + return 0; + + inet_pton(AF_INET, buf, &ipv4_ll); + if (ipv4_ll.s_addr != ip.ip._v4_addr.s_addr) + return 0; + + if_nbr_ipv6ll_to_ipv4ll_neigh_update( + ifp, &zif->v6_2_v4_ll_addr6, true); + return 0; + } - zif = (struct zebra_if *)ifp->info; /* The neighbor is present on an SVI. From this, we locate the * underlying * bridge because we're only interested in neighbors on a VxLAN bridge. @@ -2147,22 +2180,7 @@ static int netlink_ipneigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, else return 0; - /* Parse attributes and extract fields of interest. */ - memset(tb, 0, sizeof tb); - netlink_parse_rtattr(tb, NDA_MAX, NDA_RTA(ndm), len); - - if (!tb[NDA_DST]) { - zlog_warn("%s family %s IF %s(%u) - no DST", - nl_msg_type_to_str(h->nlmsg_type), - nl_family_to_str(ndm->ndm_family), ifp->name, - ndm->ndm_ifindex); - return 0; - } memset(&mac, 0, sizeof(struct ethaddr)); - memset(&ip, 0, sizeof(struct ipaddr)); - ip.ipa_type = (ndm->ndm_family == AF_INET) ? IPADDR_V4 : IPADDR_V6; - memcpy(&ip.ip.addr, RTA_DATA(tb[NDA_DST]), RTA_PAYLOAD(tb[NDA_DST])); - if (h->nlmsg_type == RTM_NEWNEIGH) { if (tb[NDA_LLADDR]) { if (RTA_PAYLOAD(tb[NDA_LLADDR]) != ETH_ALEN) { @@ -2329,7 +2347,7 @@ int netlink_neigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, } static int netlink_neigh_update2(struct interface *ifp, struct ipaddr *ip, - struct ethaddr *mac, u_int32_t flags, int cmd) + struct ethaddr *mac, uint32_t flags, int cmd) { struct { struct nlmsghdr n; @@ -2377,7 +2395,7 @@ static int netlink_neigh_update2(struct interface *ifp, struct ipaddr *ip, } int kernel_add_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac, - struct in_addr vtep_ip, u_char sticky) + struct in_addr vtep_ip, uint8_t sticky) { return netlink_macfdb_update(ifp, vid, mac, vtep_ip, 0, RTM_NEWNEIGH, sticky); diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 433faf789a..f9cd1cbab0 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -444,7 +444,7 @@ int kernel_del_vtep(vni_t vni, struct interface *ifp, struct in_addr *vtep_ip) } int kernel_add_mac(struct interface *ifp, vlanid_t vid, struct ethaddr *mac, - struct in_addr vtep_ip, u_char sticky) + struct in_addr vtep_ip, uint8_t sticky) { return 0; } diff --git a/zebra/rtadv.c b/zebra/rtadv.c index d0b821bfd2..c695b65660 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -95,7 +95,7 @@ static int rtadv_increment_received(struct zebra_ns *zns, ifindex_t *ifindex) return ret; } -static int rtadv_recv_packet(struct zebra_ns *zns, int sock, u_char *buf, +static int rtadv_recv_packet(struct zebra_ns *zns, int sock, uint8_t *buf, int buflen, struct sockaddr_in6 *from, ifindex_t *ifindex, int *hoplimit) { @@ -164,10 +164,10 @@ static void rtadv_send_packet(int sock, struct interface *ifp) int len = 0; struct zebra_if *zif; struct rtadv_prefix *rprefix; - u_char all_nodes_addr[] = {0xff, 0x02, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1}; + uint8_t all_nodes_addr[] = {0xff, 0x02, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1}; struct listnode *node; - u_int16_t pkt_RouterLifetime; + uint16_t pkt_RouterLifetime; /* * Allocate control message bufffer. This is dynamic because @@ -315,7 +315,7 @@ static void rtadv_send_packet(int sock, struct interface *ifp) #ifdef DEBUG { - u_char buf[INET6_ADDRSTRLEN]; + uint8_t buf[INET6_ADDRSTRLEN]; zlog_debug("DEBUG %s", inet_ntop(AF_INET6, &pinfo->nd_opt_pi_prefix, @@ -452,7 +452,7 @@ static void rtadv_process_solicit(struct interface *ifp) rtadv_send_packet(zns->rtadv.sock, ifp); } -static void rtadv_process_advert(u_char *msg, unsigned int len, +static void rtadv_process_advert(uint8_t *msg, unsigned int len, struct interface *ifp, struct sockaddr_in6 *addr) { @@ -526,7 +526,7 @@ static void rtadv_process_advert(u_char *msg, unsigned int len, } -static void rtadv_process_packet(u_char *buf, unsigned int len, +static void rtadv_process_packet(uint8_t *buf, unsigned int len, ifindex_t ifindex, int hoplimit, struct sockaddr_in6 *from, struct zebra_ns *zns) @@ -596,7 +596,7 @@ static int rtadv_read(struct thread *thread) { int sock; int len; - u_char buf[RTADV_MSG_SIZE]; + uint8_t buf[RTADV_MSG_SIZE]; struct sockaddr_in6 from; ifindex_t ifindex = 0; int hoplimit = -1; diff --git a/zebra/rtadv.h b/zebra/rtadv.h index 8fd67c8a63..03db13fd69 100644 --- a/zebra/rtadv.h +++ b/zebra/rtadv.h @@ -34,7 +34,7 @@ struct rtadv_prefix { struct prefix_ipv6 prefix; /* The value to be placed in the Valid Lifetime in the Prefix */ - u_int32_t AdvValidLifetime; + uint32_t AdvValidLifetime; #define RTADV_VALID_LIFETIME 2592000 /* The value to be placed in the on-link flag */ @@ -42,7 +42,7 @@ struct rtadv_prefix { /* The value to be placed in the Preferred Lifetime in the Prefix Information option, in seconds.*/ - u_int32_t AdvPreferredLifetime; + uint32_t AdvPreferredLifetime; #define RTADV_PREFERRED_LIFETIME 604800 /* The value to be placed in the Autonomous Flag. */ @@ -83,11 +83,11 @@ struct nd_opt_adv_interval { /* Advertisement interval option */ #ifndef HAVE_STRUCT_ND_OPT_HOMEAGENT_INFO struct nd_opt_homeagent_info { /* Home Agent info */ - u_int8_t nd_opt_hai_type; - u_int8_t nd_opt_hai_len; - u_int16_t nd_opt_hai_reserved; - u_int16_t nd_opt_hai_preference; - u_int16_t nd_opt_hai_lifetime; + uint8_t nd_opt_hai_type; + uint8_t nd_opt_hai_len; + uint16_t nd_opt_hai_reserved; + uint16_t nd_opt_hai_preference; + uint16_t nd_opt_hai_lifetime; } __attribute__((__packed__)); #endif diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 38321bc416..b3aeaf2f76 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -77,7 +77,7 @@ static void handle_route_entry(mib2_ipRouteEntry_t *routeEntry) struct prefix prefix; struct in_addr tmpaddr; struct nexthop nh; - u_char zebra_flags = 0; + uint8_t zebra_flags = 0; if (routeEntry->ipRouteInfo.re_ire_type & IRE_CACHETABLE) return; diff --git a/zebra/subdir.am b/zebra/subdir.am index ef157b7539..9dbff7d40c 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -70,6 +70,7 @@ zebra_zebra_SOURCES = \ zebra/zserv.c \ zebra/zebra_netns_id.c \ zebra/zebra_netns_notify.c \ + zebra/table_manager.c \ # end zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS) @@ -113,6 +114,7 @@ noinst_HEADERS += \ zebra/zserv.h \ zebra/zebra_netns_id.h \ zebra/zebra_netns_notify.h \ + zebra/table_manager.h \ # end zebra_zebra_irdp_la_SOURCES = \ diff --git a/zebra/table_manager.c b/zebra/table_manager.c new file mode 100644 index 0000000000..db07f402f3 --- /dev/null +++ b/zebra/table_manager.c @@ -0,0 +1,235 @@ +/* zebra table Manager for routing table identifier management + * Copyright (C) 2018 6WIND + * + * 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 <stdio.h> +#include <string.h> +#include <sys/types.h> + +#include "zebra.h" +#include "zserv.h" +#include "lib/log.h" +#include "lib/memory.h" +#include "lib/table.h" +#include "lib/network.h" +#include "lib/stream.h" +#include "lib/zclient.h" +#include "lib/libfrr.h" +#include "lib/vrf.h" + +#include "zebra_vrf.h" +#include "label_manager.h" /* for NO_PROTO */ +#include "table_manager.h" + +/* routing table identifiers + * + */ +#ifdef SUNOS_5 +/* SunOS + */ +#else +#if !defined(GNU_LINUX) && !defined(SUNOS_5) +/* BSD systems + */ +#else +/* Linux Systems + */ +#define RT_TABLE_ID_LOCAL 255 +#define RT_TABLE_ID_MAIN 254 +#define RT_TABLE_ID_DEFAULT 253 +#define RT_TABLE_ID_COMPAT 252 +#define RT_TABLE_ID_UNSPEC 0 +#endif /* !def(GNU_LINUX) && !defined(SUNOS_5) */ +#endif /* SUNOS_5 */ +#define RT_TABLE_ID_UNRESERVED_MIN 1 +#define RT_TABLE_ID_UNRESERVED_MAX 0xffffffff + +struct table_manager tbl_mgr; + +DEFINE_MGROUP(TABLE_MGR, "Table Manager"); +DEFINE_MTYPE_STATIC(TABLE_MGR, TM_CHUNK, "Table Manager Chunk"); + +static void delete_table_chunk(void *val) +{ + XFREE(MTYPE_TM_CHUNK, val); +} + +/** + * Init table manager + */ +void table_manager_enable(ns_id_t ns_id) +{ + if (ns_id != NS_DEFAULT) + return; + tbl_mgr.lc_list = list_new(); + tbl_mgr.lc_list->del = delete_table_chunk; +} + +/** + * Core function, assigns table chunks + * + * It first searches through the list to check if there's one available + * (previously released). Otherwise it creates and assigns a new one + * + * @param proto Daemon protocol of client, to identify the owner + * @param instance Instance, to identify the owner + * @para size Size of the table chunk + * @return Pointer to the assigned table chunk + */ +struct table_manager_chunk *assign_table_chunk(uint8_t proto, uint16_t instance, + uint32_t size) +{ + struct table_manager_chunk *tmc; + struct listnode *node; + uint32_t start; + + /* first check if there's one available */ + for (ALL_LIST_ELEMENTS_RO(tbl_mgr.lc_list, node, tmc)) { + if (tmc->proto == NO_PROTO + && tmc->end - tmc->start + 1 == size) { + tmc->proto = proto; + tmc->instance = instance; + return tmc; + } + } + /* otherwise create a new one */ + tmc = XCALLOC(MTYPE_TM_CHUNK, sizeof(struct table_manager_chunk)); + if (!tmc) + return NULL; + + /* table RT IDs range are [1;252] and [256;0xffffffff] + * - check if the requested range can be within the first range, + * otherwise elect second one + * - TODO : vrf-lites have their own table identifier. + * In that case, table_id should be removed from the table range. + */ + if (list_isempty(tbl_mgr.lc_list)) + start = RT_TABLE_ID_UNRESERVED_MIN; + else + start = ((struct table_manager_chunk *)listgetdata( + listtail(tbl_mgr.lc_list)))->end + 1; + +#ifdef SUNOS_5 +/* SunOS + */ +#else +#if !defined(GNU_LINUX) && !defined(SUNOS_5) +/* BSD systems + */ +#else +/* Linux Systems + */ + /* if not enough room space between MIN and COMPAT, + * then begin after LOCAL + */ + if (start < RT_TABLE_ID_COMPAT && (size > + RT_TABLE_ID_COMPAT + - RT_TABLE_ID_UNRESERVED_MIN)) + start = RT_TABLE_ID_LOCAL + 1; +#endif /* !def(GNU_LINUX) && !defined(SUNOS_5) */ +#endif /* SUNOS_5 */ + tmc->start = start; + if (RT_TABLE_ID_UNRESERVED_MAX - size + 1 < start) { + zlog_err("Reached max table id. Start/Size %u/%u", + start, size); + XFREE(MTYPE_TM_CHUNK, tmc); + return NULL; + } + tmc->end = tmc->start + size - 1; + tmc->proto = proto; + tmc->instance = instance; + listnode_add(tbl_mgr.lc_list, tmc); + + return tmc; +} + +/** + * Core function, release no longer used table chunks + * + * @param proto Daemon protocol of client, to identify the owner + * @param instance Instance, to identify the owner + * @param start First table RT ID of the chunk + * @param end Last table RT ID of the chunk + * @return 0 on success, -1 otherwise + */ +int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start, + uint32_t end) +{ + struct listnode *node; + struct table_manager_chunk *tmc; + int ret = -1; + + /* check that size matches */ + zlog_debug("Releasing table chunk: %u - %u", start, end); + /* find chunk and disown */ + for (ALL_LIST_ELEMENTS_RO(tbl_mgr.lc_list, node, tmc)) { + if (tmc->start != start) + continue; + if (tmc->end != end) + continue; + if (tmc->proto != proto || tmc->instance != instance) { + zlog_err("%s: Daemon mismatch!!", __func__); + continue; + } + tmc->proto = NO_PROTO; + tmc->instance = 0; + ret = 0; + break; + } + if (ret != 0) + zlog_err("%s: Table chunk not released!!", __func__); + + return ret; +} + +/** + * Release table chunks from a client. + * + * Called on client disconnection or reconnection. It only releases chunks + * with empty keep value. + * + * @param proto Daemon protocol of client, to identify the owner + * @param instance Instance, to identify the owner + * @return Number of chunks released + */ +int release_daemon_table_chunks(uint8_t proto, uint16_t instance) +{ + struct listnode *node; + struct table_manager_chunk *tmc; + int count = 0; + int ret; + + for (ALL_LIST_ELEMENTS_RO(tbl_mgr.lc_list, node, tmc)) { + if (tmc->proto == proto && tmc->instance == instance) { + ret = release_table_chunk(tmc->proto, tmc->instance, + tmc->start, tmc->end); + if (ret == 0) + count++; + } + } + + zlog_debug("%s: Released %d table chunks", __func__, count); + + return count; +} + +void table_manager_disable(ns_id_t ns_id) +{ + if (ns_id != NS_DEFAULT) + return; + list_delete_and_null(&tbl_mgr.lc_list); +} diff --git a/zebra/table_manager.h b/zebra/table_manager.h new file mode 100644 index 0000000000..527d5c29e8 --- /dev/null +++ b/zebra/table_manager.h @@ -0,0 +1,63 @@ +/* zebra table Manager for routing table identifier management + * Copyright (C) 2018 6WIND + * + * 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 _TABLE_MANAGER_H +#define _TABLE_MANAGER_H + +#include <stdint.h> + +#include "lib/linklist.h" +#include "lib/thread.h" + +/* + * Table chunk struct + * Client daemon which the chunk belongs to can be identified by either + * proto (daemon protocol) + instance + VRF. + * If the client then passes a non-empty value to keep field when it requests + * for chunks, the chunks won't be garbage collected and the client will be + * responsible of its release. + * Otherwise, if the keep field is not set (value 0) for the chunk, it will be + * automatically released when the client disconnects or when it reconnects + * (in case it died unexpectedly, we can know it's the same because it will have + * the same proto and instance values) + */ +struct table_manager_chunk { + vrf_id_t vrf_id; + uint8_t proto; + uint16_t instance; + uint32_t start; /* First table RT ID of the chunk */ + uint32_t end; /* Last table RT ID of the chunk */ +}; + +/* + * Main table manager struct + * Holds a linked list of table chunks. + */ +struct table_manager { + struct list *lc_list; +}; + +void table_manager_enable(ns_id_t ns_id); +struct table_manager_chunk *assign_table_chunk(uint8_t proto, uint16_t instance, + uint32_t size); +int release_table_chunk(uint8_t proto, uint16_t instance, uint32_t start, + uint32_t end); +int release_daemon_table_chunks(uint8_t proto, uint16_t instance); +void table_manager_disable(ns_id_t ns_id); + +#endif /* _TABLE_MANAGER_H */ diff --git a/zebra/zebra_fpm_dt.c b/zebra/zebra_fpm_dt.c index 48db246bc2..e87fa0ad71 100644 --- a/zebra/zebra_fpm_dt.c +++ b/zebra/zebra_fpm_dt.c @@ -176,7 +176,7 @@ static void zfpm_dt_log_fpm_message(Fpm__Message *msg) Fpm__AddRoute *add_route; Fpm__Nexthop *nexthop; struct prefix prefix; - u_char family, nh_family; + uint8_t family, nh_family; uint if_index; char *if_name; size_t i; diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index 97a0e142fb..c27884ec48 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -45,7 +45,7 @@ * * Returns string representation of an address of the given AF. */ -static inline const char *addr_to_a(u_char af, void *addr) +static inline const char *addr_to_a(uint8_t af, void *addr) { if (!addr) return "<No address>"; @@ -83,7 +83,7 @@ static const char *prefix_addr_to_a(struct prefix *prefix) * * The size of an address in a given address family. */ -static size_t af_addr_size(u_char af) +static size_t af_addr_size(uint8_t af) { switch (af) { @@ -125,10 +125,10 @@ typedef struct netlink_nh_info_t_ { */ typedef struct netlink_route_info_t_ { uint16_t nlmsg_type; - u_char rtm_type; + uint8_t rtm_type; uint32_t rtm_table; - u_char rtm_protocol; - u_char af; + uint8_t rtm_protocol; + uint8_t af; struct prefix *prefix; uint32_t *metric; unsigned int num_nhs; @@ -199,7 +199,7 @@ static int netlink_route_info_add_nh(netlink_route_info_t *ri, /* * netlink_proto_from_route_type */ -static u_char netlink_proto_from_route_type(int type) +static uint8_t netlink_proto_from_route_type(int type) { switch (type) { case ZEBRA_ROUTE_KERNEL: diff --git a/zebra/zebra_fpm_protobuf.c b/zebra/zebra_fpm_protobuf.c index e661b6efc7..ebd632270c 100644 --- a/zebra/zebra_fpm_protobuf.c +++ b/zebra/zebra_fpm_protobuf.c @@ -163,6 +163,7 @@ static Fpm__AddRoute *create_add_route_message(qpb_allocator_t *allocator, msg->sub_address_family = QPB__SUB_ADDRESS_FAMILY__UNICAST; msg->key = fpm_route_key_create(allocator, rib_dest_prefix(dest)); qpb_protocol_set(&msg->protocol, re->type); + msg->has_route_type = 1; msg->route_type = FPM__ROUTE_TYPE__NORMAL; msg->metric = re->metric; @@ -245,6 +246,7 @@ static Fpm__Message *create_route_message(qpb_allocator_t *allocator, fpm__message__init(msg); if (!re) { + msg->has_type = 1; msg->type = FPM__MESSAGE__TYPE__DELETE_ROUTE; msg->delete_route = create_delete_route_message(allocator, dest, re); @@ -255,6 +257,7 @@ static Fpm__Message *create_route_message(qpb_allocator_t *allocator, return msg; } + msg->has_type = 1; msg->type = FPM__MESSAGE__TYPE__ADD_ROUTE; msg->add_route = create_add_route_message(allocator, dest, re); if (!msg->add_route) { diff --git a/zebra/zebra_l2.h b/zebra/zebra_l2.h index 0d0c5aaf22..db6cb0e53a 100644 --- a/zebra/zebra_l2.h +++ b/zebra/zebra_l2.h @@ -37,7 +37,7 @@ struct zebra_l2info_brslave { /* zebra L2 interface information - bridge interface */ struct zebra_l2info_bridge { - u_char vlan_aware; /* VLAN-aware bridge? */ + uint8_t vlan_aware; /* VLAN-aware bridge? */ }; /* zebra L2 interface information - VLAN interface */ diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 8375d45d2f..3cc1848ee3 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -60,8 +60,8 @@ extern struct zebra_t zebrad; /* static function declarations */ static void fec_evaluate(struct zebra_vrf *zvrf); -static u_int32_t fec_derive_label_from_index(struct zebra_vrf *vrf, - zebra_fec_t *fec); +static uint32_t fec_derive_label_from_index(struct zebra_vrf *vrf, + zebra_fec_t *fec); static int lsp_install(struct zebra_vrf *zvrf, mpls_label_t label, struct route_node *rn, struct route_entry *re); static int lsp_uninstall(struct zebra_vrf *zvrf, mpls_label_t label); @@ -72,8 +72,8 @@ static void fec_update_clients(zebra_fec_t *fec); static void fec_print(zebra_fec_t *fec, struct vty *vty); static zebra_fec_t *fec_find(struct route_table *table, struct prefix *p); static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p, - mpls_label_t label, u_int32_t flags, - u_int32_t label_index); + mpls_label_t label, uint32_t flags, + uint32_t label_index); static int fec_del(zebra_fec_t *fec); static unsigned int label_hash(void *p); @@ -330,7 +330,7 @@ static void fec_evaluate(struct zebra_vrf *zvrf) { struct route_node *rn; zebra_fec_t *fec; - u_int32_t old_label, new_label; + uint32_t old_label, new_label; int af; char buf[BUFSIZ]; @@ -382,10 +382,10 @@ static void fec_evaluate(struct zebra_vrf *zvrf) * its label index. The index is "acceptable" if it falls within the * globally configured label block (SRGB). */ -static u_int32_t fec_derive_label_from_index(struct zebra_vrf *zvrf, - zebra_fec_t *fec) +static uint32_t fec_derive_label_from_index(struct zebra_vrf *zvrf, + zebra_fec_t *fec) { - u_int32_t label; + uint32_t label; if (fec->label_index != MPLS_INVALID_LABEL_INDEX && zvrf->mpls_srgb.start_label @@ -532,8 +532,8 @@ static zebra_fec_t *fec_find(struct route_table *table, struct prefix *p) * or when a binding is configured. */ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p, - mpls_label_t label, u_int32_t flags, - u_int32_t label_index) + mpls_label_t label, uint32_t flags, + uint32_t label_index) { struct route_node *rn; zebra_fec_t *fec; @@ -1734,7 +1734,7 @@ void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum southbound_results res) * -2 if a label was inside the reserved range (0-15) * -3 if the number of labels given exceeds MPLS_MAX_LABELS */ -int mpls_str2label(const char *label_str, u_int8_t *num_labels, +int mpls_str2label(const char *label_str, uint8_t *num_labels, mpls_label_t *labels) { char *ostr; // copy of label string (start) @@ -1779,7 +1779,7 @@ int mpls_str2label(const char *label_str, u_int8_t *num_labels, /* * Label to string conversion, labels in string separated by '/'. */ -char *mpls_label2str(u_int8_t num_labels, mpls_label_t *labels, char *buf, +char *mpls_label2str(uint8_t num_labels, mpls_label_t *labels, char *buf, int len, int pretty) { char label_buf[BUFSIZ]; @@ -1860,14 +1860,14 @@ int zebra_mpls_lsp_uninstall(struct zebra_vrf *zvrf, struct route_node *rn, * is acceptable. */ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p, - u_int32_t label_index, struct zserv *client) + uint32_t label_index, struct zserv *client) { struct route_table *table; zebra_fec_t *fec; char buf[BUFSIZ]; int new_client; int label_change = 0; - u_int32_t old_label; + uint32_t old_label; table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))]; if (!table) @@ -2272,7 +2272,7 @@ static bool mpls_ftn_update_nexthop(int add, struct nexthop *nexthop, */ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type, struct prefix *prefix, enum nexthop_types_t gtype, - union g_addr *gate, ifindex_t ifindex, u_int8_t distance, + union g_addr *gate, ifindex_t ifindex, uint8_t distance, mpls_label_t out_label) { struct route_table *table; @@ -2742,7 +2742,7 @@ void zebra_mpls_lsp_schedule(struct zebra_vrf *zvrf) * (VTY command handler). */ void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf, - mpls_label_t label, u_char use_json) + mpls_label_t label, uint8_t use_json) { struct hash *lsp_table; zebra_lsp_t *lsp; @@ -2773,7 +2773,7 @@ void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf, * Display MPLS label forwarding table (VTY command handler). */ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json) + uint8_t use_json) { char buf[BUFSIZ]; json_object *json = NULL; @@ -2893,8 +2893,8 @@ int zebra_mpls_write_lsp_config(struct vty *vty, struct zebra_vrf *zvrf) /* * Add/update global label block. */ -int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, u_int32_t start_label, - u_int32_t end_label) +int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, uint32_t start_label, + uint32_t end_label) { zvrf->mpls_srgb.start_label = start_label; zvrf->mpls_srgb.end_label = end_label; diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h index fd14b29ca9..2637327a7e 100644 --- a/zebra/zebra_mpls.h +++ b/zebra/zebra_mpls.h @@ -91,7 +91,7 @@ struct zebra_nhlfe_t_ { zebra_lsp_t *lsp; /* Runtime info - flags, pointers etc. */ - u_int32_t flags; + uint32_t flags; #define NHLFE_FLAG_CHANGED (1 << 0) #define NHLFE_FLAG_SELECTED (1 << 1) #define NHLFE_FLAG_MULTIPATH (1 << 2) @@ -100,7 +100,7 @@ struct zebra_nhlfe_t_ { zebra_nhlfe_t *next; zebra_nhlfe_t *prev; - u_char distance; + uint8_t distance; }; /* @@ -131,17 +131,17 @@ struct zebra_lsp_t_ { /* List of NHLFE, pointer to best and num equal-cost. */ zebra_nhlfe_t *nhlfe_list; zebra_nhlfe_t *best_nhlfe; - u_int32_t num_ecmp; + uint32_t num_ecmp; /* Flags */ - u_int32_t flags; + uint32_t flags; #define LSP_FLAG_SCHEDULED (1 << 0) #define LSP_FLAG_INSTALLED (1 << 1) #define LSP_FLAG_CHANGED (1 << 2) /* Address-family of NHLFE - saved here for delete. All NHLFEs */ /* have to be of the same AF */ - u_char addr_family; + uint8_t addr_family; }; /* @@ -155,10 +155,10 @@ struct zebra_fec_t_ { mpls_label_t label; /* Label index (into global label block), if valid */ - u_int32_t label_index; + uint32_t label_index; /* Flags. */ - u_int32_t flags; + uint32_t flags; #define FEC_FLAG_CONFIGURED (1 << 0) /* Clients interested in this FEC. */ @@ -170,20 +170,20 @@ struct zebra_fec_t_ { /* * String to label conversion, labels separated by '/'. */ -int mpls_str2label(const char *label_str, u_int8_t *num_labels, +int mpls_str2label(const char *label_str, uint8_t *num_labels, mpls_label_t *labels); /* * Label to string conversion, labels in string separated by '/'. */ -char *mpls_label2str(u_int8_t num_labels, mpls_label_t *labels, char *buf, +char *mpls_label2str(uint8_t num_labels, mpls_label_t *labels, char *buf, int len, int pretty); /* * Add/update global label block. */ -int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, u_int32_t start_label, - u_int32_t end_label); +int zebra_mpls_label_block_add(struct zebra_vrf *zvrf, uint32_t start_label, + uint32_t end_label); /* * Delete global label block. @@ -216,7 +216,7 @@ int zebra_mpls_lsp_uninstall(struct zebra_vrf *zvrf, struct route_node *rn, * is acceptable. */ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p, - u_int32_t label_index, struct zserv *client); + uint32_t label_index, struct zserv *client); /* * Deregistration from a client for the label binding for a FEC. The FEC @@ -284,7 +284,7 @@ void zebra_mpls_print_fec(struct vty *vty, struct zebra_vrf *zvrf, */ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type, struct prefix *prefix, enum nexthop_types_t gtype, - union g_addr *gate, ifindex_t ifindex, u_int8_t distance, + union g_addr *gate, ifindex_t ifindex, uint8_t distance, mpls_label_t out_label); /* @@ -371,13 +371,13 @@ void zebra_mpls_lsp_schedule(struct zebra_vrf *zvrf); * (VTY command handler). */ void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf, - mpls_label_t label, u_char use_json); + mpls_label_t label, uint8_t use_json); /* * Display MPLS label forwarding table (VTY command handler). */ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json); + uint8_t use_json); /* * Display MPLS LSP configuration of all static LSPs (VTY command handler). @@ -419,7 +419,7 @@ void zebra_mpls_vty_init(void); /* * Distance (priority) definition for LSP NHLFE. */ -static inline u_char lsp_distance(enum lsp_types_t type) +static inline uint8_t lsp_distance(enum lsp_types_t type) { switch (type) { case ZEBRA_LSP_STATIC: diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index 2c7fe577ef..2d75353c71 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -35,7 +35,7 @@ extern struct zebra_privs_t zserv_privs; struct { - u_int32_t rtseq; + uint32_t rtseq; int fd; int ioctl_fd; } kr_state; diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index 0d922830c7..01bc66e5cd 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -198,7 +198,7 @@ static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix, { struct zebra_vrf *zvrf; struct prefix p; - u_int32_t label; + uint32_t label; int ret; zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -340,7 +340,7 @@ DEFUN (show_mpls_table, JSON_STR) { struct zebra_vrf *zvrf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zvrf = vrf_info_lookup(VRF_DEFAULT); zebra_mpls_print_lsp_table(vty, zvrf, uj); @@ -356,9 +356,9 @@ DEFUN (show_mpls_table_lsp, "LSP to display information about\n" JSON_STR) { - u_int32_t label; + uint32_t label; struct zebra_vrf *zvrf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zvrf = vrf_info_lookup(VRF_DEFAULT); label = atoi(argv[3]->arg); @@ -384,8 +384,8 @@ static int zebra_mpls_global_block(struct vty *vty, int add_cmd, const char *end_label_str) { int ret; - u_int32_t start_label; - u_int32_t end_label; + uint32_t start_label; + uint32_t end_label; struct zebra_vrf *zvrf; zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); diff --git a/zebra/zebra_netns_id.c b/zebra/zebra_netns_id.c index 57f311aac5..317b02f601 100644 --- a/zebra/zebra_netns_id.c +++ b/zebra/zebra_netns_id.c @@ -143,7 +143,7 @@ static ns_id_t extract_nsid(struct nlmsghdr *nlh, char *buf) attr += NETLINK_ALIGN(attr->nla_len)) { curr_length += attr->nla_len; if ((attr->nla_type & NLA_TYPE_MASK) == NETNSA_NSID) { - u_int32_t *ptr = (u_int32_t *)(attr); + uint32_t *ptr = (uint32_t *)(attr); ns_id = ptr[1]; break; diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index d841bdeec4..7393f767af 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -38,6 +38,7 @@ #include "zebra_netns_id.h" #include "zebra_pbr.h" #include "rib.h" +#include "table_manager.h" extern struct zebra_privs_t zserv_privs; @@ -147,6 +148,9 @@ int zebra_ns_enable(ns_id_t ns_id, void **info) interface_list(zns); route_read(zns); + /* Initiate Table Manager per ZNS */ + table_manager_enable(ns_id); + return 0; } @@ -167,7 +171,7 @@ struct route_table *zebra_ns_find_table(struct zebra_ns *zns, uint32_t tableid, return NULL; } -unsigned long zebra_ns_score_proto(u_char proto, u_short instance) +unsigned long zebra_ns_score_proto(uint8_t proto, unsigned short instance) { struct zebra_ns *zns; struct zebra_ns_table *znst; @@ -259,6 +263,8 @@ int zebra_ns_disable(ns_id_t ns_id, void **info) kernel_terminate(zns); + table_manager_disable(zns->ns_id); + zns->ns_id = NS_DEFAULT; return 0; diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index 6655e5c019..66b73148d2 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -91,6 +91,6 @@ extern struct route_table *zebra_ns_get_table(struct zebra_ns *zns, uint32_t tableid, afi_t afi); int zebra_ns_config_write(struct vty *vty, struct ns *ns); -unsigned long zebra_ns_score_proto(u_char proto, u_short instance); +unsigned long zebra_ns_score_proto(uint8_t proto, unsigned short instance); void zebra_ns_sweep_route(void); #endif diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 67c7220b6f..2fe6797eef 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -666,13 +666,13 @@ void zebra_ptm_bfd_dst_register(ZAPI_HANDLER_ARGS) struct stream *s; struct prefix src_p; struct prefix dst_p; - u_char multi_hop; - u_char multi_hop_cnt; - u_char detect_mul; + uint8_t multi_hop; + uint8_t multi_hop_cnt; + uint8_t detect_mul; unsigned int min_rx_timer; unsigned int min_tx_timer; char if_name[INTERFACE_NAMSIZ]; - u_char len; + uint8_t len; void *out_ctxt; char buf[INET6_ADDRSTRLEN]; char tmp_buf[64]; @@ -827,9 +827,9 @@ void zebra_ptm_bfd_dst_deregister(ZAPI_HANDLER_ARGS) struct stream *s; struct prefix src_p; struct prefix dst_p; - u_char multi_hop; + uint8_t multi_hop; char if_name[INTERFACE_NAMSIZ]; - u_char len; + uint8_t len; char buf[INET6_ADDRSTRLEN]; char tmp_buf[64]; int data_len = ZEBRA_PTM_SEND_MAX_SOCKBUF; diff --git a/zebra/zebra_ptm.h b/zebra/zebra_ptm.h index 0b41410bec..937c2584f5 100644 --- a/zebra/zebra_ptm.h +++ b/zebra/zebra_ptm.h @@ -46,7 +46,7 @@ struct zebra_ptm_cb { int ptm_enable; int pid; - u_int8_t client_flags[ZEBRA_ROUTE_MAX]; + uint8_t client_flags[ZEBRA_ROUTE_MAX]; }; #define ZEBRA_PTM_STATUS_DOWN 0 diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 0c87e7efce..6ad60a6fff 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -137,7 +137,7 @@ uint8_t route_distance(int type) return distance; } -int is_zebra_valid_kernel_table(u_int32_t table_id) +int is_zebra_valid_kernel_table(uint32_t table_id) { #ifdef linux if ((table_id == RT_TABLE_UNSPEC) || (table_id == RT_TABLE_LOCAL) @@ -148,7 +148,7 @@ int is_zebra_valid_kernel_table(u_int32_t table_id) return 1; } -int is_zebra_main_routing_table(u_int32_t table_id) +int is_zebra_main_routing_table(uint32_t table_id) { if ((table_id == RT_TABLE_MAIN) || (table_id == zebrad.rtm_table_default)) @@ -159,7 +159,7 @@ int is_zebra_main_routing_table(u_int32_t table_id) int zebra_check_addr(struct prefix *p) { if (p->family == AF_INET) { - u_int32_t addr; + uint32_t addr; addr = p->u.prefix4.s_addr; addr = ntohl(addr); @@ -1736,7 +1736,7 @@ static void rib_process(struct route_node *rn) * picked from it and processed by rib_process(). Don't process more, * than one RN record; operate only in the specified sub-queue. */ -static unsigned int process_subq(struct list *subq, u_char qindex) +static unsigned int process_subq(struct list *subq, uint8_t qindex) { struct listnode *lnode = listhead(subq); struct route_node *rnode; @@ -1839,31 +1839,31 @@ static wq_item_status meta_queue_process(struct work_queue *dummy, void *data) /* * Map from rib types to queue type (priority) in meta queue */ -static const u_char meta_queue_map[ZEBRA_ROUTE_MAX] = { - [ZEBRA_ROUTE_SYSTEM] = 4, - [ZEBRA_ROUTE_KERNEL] = 0, - [ZEBRA_ROUTE_CONNECT] = 0, - [ZEBRA_ROUTE_STATIC] = 1, - [ZEBRA_ROUTE_RIP] = 2, - [ZEBRA_ROUTE_RIPNG] = 2, - [ZEBRA_ROUTE_OSPF] = 2, - [ZEBRA_ROUTE_OSPF6] = 2, - [ZEBRA_ROUTE_ISIS] = 2, - [ZEBRA_ROUTE_BGP] = 3, - [ZEBRA_ROUTE_PIM] = 4, // Shouldn't happen but for safety - [ZEBRA_ROUTE_EIGRP] = 2, - [ZEBRA_ROUTE_NHRP] = 2, - [ZEBRA_ROUTE_HSLS] = 4, - [ZEBRA_ROUTE_OLSR] = 4, - [ZEBRA_ROUTE_TABLE] = 1, - [ZEBRA_ROUTE_LDP] = 4, - [ZEBRA_ROUTE_VNC] = 3, - [ZEBRA_ROUTE_VNC_DIRECT] = 3, - [ZEBRA_ROUTE_VNC_DIRECT_RH] = 3, - [ZEBRA_ROUTE_BGP_DIRECT] = 3, - [ZEBRA_ROUTE_BGP_DIRECT_EXT] = 3, - [ZEBRA_ROUTE_BABEL] = 2, - [ZEBRA_ROUTE_ALL] = 4, // Shouldn't happen but for safety +static const uint8_t meta_queue_map[ZEBRA_ROUTE_MAX] = { + [ZEBRA_ROUTE_SYSTEM] = 4, + [ZEBRA_ROUTE_KERNEL] = 0, + [ZEBRA_ROUTE_CONNECT] = 0, + [ZEBRA_ROUTE_STATIC] = 1, + [ZEBRA_ROUTE_RIP] = 2, + [ZEBRA_ROUTE_RIPNG] = 2, + [ZEBRA_ROUTE_OSPF] = 2, + [ZEBRA_ROUTE_OSPF6] = 2, + [ZEBRA_ROUTE_ISIS] = 2, + [ZEBRA_ROUTE_BGP] = 3, + [ZEBRA_ROUTE_PIM] = 4, // Shouldn't happen but for safety + [ZEBRA_ROUTE_EIGRP] = 2, + [ZEBRA_ROUTE_NHRP] = 2, + [ZEBRA_ROUTE_HSLS] = 4, + [ZEBRA_ROUTE_OLSR] = 4, + [ZEBRA_ROUTE_TABLE] = 1, + [ZEBRA_ROUTE_LDP] = 4, + [ZEBRA_ROUTE_VNC] = 3, + [ZEBRA_ROUTE_VNC_DIRECT] = 3, + [ZEBRA_ROUTE_VNC_DIRECT_RH] = 3, + [ZEBRA_ROUTE_BGP_DIRECT] = 3, + [ZEBRA_ROUTE_BGP_DIRECT_EXT] = 3, + [ZEBRA_ROUTE_BABEL] = 2, + [ZEBRA_ROUTE_ALL] = 4, // Shouldn't happen but for safety }; /* Look into the RN and queue it into one or more priority queues, @@ -1874,7 +1874,7 @@ static void rib_meta_queue_add(struct meta_queue *mq, struct route_node *rn) struct route_entry *re; RNODE_FOREACH_RE (rn, re) { - u_char qindex = meta_queue_map[re->type]; + uint8_t qindex = meta_queue_map[re->type]; struct zebra_vrf *zvrf; /* Invariant: at this point we always have rn->info set. */ @@ -2392,9 +2392,9 @@ int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *p, } void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, - u_short instance, int flags, struct prefix *p, + unsigned short instance, int flags, struct prefix *p, struct prefix_ipv6 *src_p, const struct nexthop *nh, - u_int32_t table_id, u_int32_t metric, bool fromkernel, + uint32_t table_id, uint32_t metric, bool fromkernel, struct ethaddr *rmac) { struct route_table *table; @@ -2491,8 +2491,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, * If we can show that this code path is * dead then we can remove it. */ - if (fib && type == ZEBRA_ROUTE_KERNEL - && CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE)) { + if (fib && CHECK_FLAG(flags, ZEBRA_FLAG_SELFROUTE)) { if (IS_ZEBRA_DEBUG_RIB) { rnode_debug( rn, vrf_id, @@ -2582,10 +2581,11 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, } -int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, - int flags, struct prefix *p, struct prefix_ipv6 *src_p, - const struct nexthop *nh, u_int32_t table_id, u_int32_t metric, - u_int32_t mtu, uint8_t distance, route_tag_t tag) +int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, + unsigned short instance, int flags, struct prefix *p, + struct prefix_ipv6 *src_p, const struct nexthop *nh, + uint32_t table_id, uint32_t metric, uint32_t mtu, uint8_t distance, + route_tag_t tag) { struct route_entry *re; struct nexthop *nexthop; @@ -2769,7 +2769,7 @@ void rib_sweep_route(void) } /* Remove specific by protocol routes from 'table'. */ -unsigned long rib_score_proto_table(u_char proto, u_short instance, +unsigned long rib_score_proto_table(uint8_t proto, unsigned short instance, struct route_table *table) { struct route_node *rn; @@ -2792,7 +2792,7 @@ unsigned long rib_score_proto_table(u_char proto, u_short instance, } /* Remove specific by protocol routes. */ -unsigned long rib_score_proto(u_char proto, u_short instance) +unsigned long rib_score_proto(uint8_t proto, unsigned short instance) { struct vrf *vrf; struct zebra_vrf *zvrf; diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 48f9f4f366..65df4e15aa 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -985,7 +985,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, struct stream *s; struct route_entry *re; unsigned long nump; - u_char num; + uint8_t num; struct nexthop *nh; struct route_node *rn; int cmd = (type == RNH_IMPORT_CHECK_TYPE) ? ZEBRA_IMPORT_CHECK_UPDATE diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h index 7af1dbeaf1..f783696c0e 100644 --- a/zebra/zebra_rnh.h +++ b/zebra/zebra_rnh.h @@ -27,7 +27,7 @@ /* Nexthop structure. */ struct rnh { - u_char flags; + uint8_t flags; #define ZEBRA_NHT_CONNECTED 0x1 #define ZEBRA_NHT_DELETED 0x2 diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 64c38635fb..013e841a5c 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -38,7 +38,7 @@ #include "zebra/zebra_rnh.h" #include "zebra/zebra_routemap.h" -static u_int32_t zebra_rmap_update_timer = ZEBRA_RMAP_DEFAULT_UPDATE_TIMER; +static uint32_t zebra_rmap_update_timer = ZEBRA_RMAP_DEFAULT_UPDATE_TIMER; static struct thread *zebra_t_rmap_update = NULL; char *proto_rm[AFI_MAX][ZEBRA_ROUTE_MAX + 1]; /* "any" == ZEBRA_ROUTE_MAX */ /* NH Tracking route map */ @@ -48,12 +48,12 @@ char *zebra_import_table_routemap[AFI_MAX][ZEBRA_KERNEL_TABLE_MAX]; struct nh_rmap_obj { struct nexthop *nexthop; vrf_id_t vrf_id; - u_int32_t source_protocol; + uint32_t source_protocol; int metric; route_tag_t tag; }; -static void zebra_route_map_set_delay_timer(u_int32_t value); +static void zebra_route_map_set_delay_timer(uint32_t value); /* Add zebra route map rule */ @@ -424,7 +424,7 @@ DEFUN (zebra_route_map_timer, "0 means event-driven updates are disabled\n") { int idx_number = 3; - u_int32_t rmap_delay_timer; + uint32_t rmap_delay_timer; rmap_delay_timer = strtoul(argv[idx_number]->arg, NULL, 10); zebra_route_map_set_delay_timer(rmap_delay_timer); @@ -1041,7 +1041,7 @@ static route_map_result_t route_match_address_prefix_len(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_int32_t *prefixlen = (u_int32_t *)rule; + uint32_t *prefixlen = (uint32_t *)rule; if (type == RMAP_ZEBRA) { return ((prefix->prefixlen == *prefixlen) ? RMAP_MATCH @@ -1052,7 +1052,7 @@ route_match_address_prefix_len(void *rule, struct prefix *prefix, static void *route_match_address_prefix_len_compile(const char *arg) { - u_int32_t *prefix_len; + uint32_t *prefix_len; char *endptr = NULL; unsigned long tmpval; @@ -1065,7 +1065,7 @@ static void *route_match_address_prefix_len_compile(const char *arg) if (*endptr != '\0' || errno || tmpval > UINT32_MAX) return NULL; - prefix_len = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + prefix_len = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); if (!prefix_len) return prefix_len; @@ -1095,7 +1095,7 @@ static route_map_result_t route_match_ip_nexthop_prefix_len(void *rule, struct prefix *prefix, route_map_object_t type, void *object) { - u_int32_t *prefixlen = (u_int32_t *)rule; + uint32_t *prefixlen = (uint32_t *)rule; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; @@ -1136,7 +1136,7 @@ static route_map_result_t route_match_source_protocol(void *rule, route_map_object_t type, void *object) { - u_int32_t *rib_type = (u_int32_t *)rule; + uint32_t *rib_type = (uint32_t *)rule; struct nh_rmap_obj *nh_data; if (type == RMAP_ZEBRA) { @@ -1152,11 +1152,11 @@ static route_map_result_t route_match_source_protocol(void *rule, static void *route_match_source_protocol_compile(const char *arg) { - u_int32_t *rib_type; + uint32_t *rib_type; int i; i = proto_name2num(arg); - rib_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(u_int32_t)); + rib_type = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); *rib_type = i; @@ -1232,7 +1232,7 @@ static int zebra_route_map_update_timer(struct thread *thread) return (0); } -static void zebra_route_map_set_delay_timer(u_int32_t value) +static void zebra_route_map_set_delay_timer(uint32_t value) { zebra_rmap_update_timer = value; if (!value && zebra_t_rmap_update) { diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c index 3ab208d30b..74eab765c8 100644 --- a/zebra/zebra_snmp.c +++ b/zebra/zebra_snmp.c @@ -89,14 +89,14 @@ static oid ipfw_oid[] = {IPFWMIB}; /* Hook functions. */ -static u_char *ipFwNumber(struct variable *, oid[], size_t *, int, size_t *, +static uint8_t *ipFwNumber(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ipFwTable(struct variable *, oid[], size_t *, int, size_t *, WriteMethod **); -static u_char *ipFwTable(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); -static u_char *ipCidrNumber(struct variable *, oid[], size_t *, int, size_t *, +static uint8_t *ipCidrNumber(struct variable *, oid[], size_t *, int, size_t *, + WriteMethod **); +static uint8_t *ipCidrTable(struct variable *, oid[], size_t *, int, size_t *, WriteMethod **); -static u_char *ipCidrTable(struct variable *, oid[], size_t *, int, size_t *, - WriteMethod **); static struct variable zebra_variables[] = { {0, GAUGE32, RONLY, ipFwNumber, 1, {1}}, @@ -134,9 +134,9 @@ static struct variable zebra_variables[] = { {IPCIDRROUTESTATUS, ROWSTATUS, RONLY, ipCidrTable, 3, {4, 1, 16}}}; -static u_char *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len, - int exact, size_t *val_len, - WriteMethod **write_method) +static uint8_t *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len, + int exact, size_t *val_len, + WriteMethod **write_method) { static int result; struct route_table *table; @@ -159,12 +159,12 @@ static u_char *ipFwNumber(struct variable *v, oid objid[], size_t *objid_len, result++; } - return (u_char *)&result; + return (uint8_t *)&result; } -static u_char *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len, - int exact, size_t *val_len, - WriteMethod **write_method) +static uint8_t *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len, + int exact, size_t *val_len, + WriteMethod **write_method) { static int result; struct route_table *table; @@ -187,10 +187,10 @@ static u_char *ipCidrNumber(struct variable *v, oid objid[], size_t *objid_len, result++; } - return (u_char *)&result; + return (uint8_t *)&result; } -static int in_addr_cmp(u_char *p1, u_char *p2) +static int in_addr_cmp(uint8_t *p1, uint8_t *p2) { int i; @@ -205,7 +205,7 @@ static int in_addr_cmp(u_char *p1, u_char *p2) return 0; } -static int in_addr_add(u_char *p, int num) +static int in_addr_add(uint8_t *p, int num) { int i, ip0; @@ -285,8 +285,8 @@ static void check_replace(struct route_node *np2, struct route_entry *re2, return; } - if (in_addr_cmp((u_char *)&(*re)->ng.nexthop->gate.ipv4, - (u_char *)&re2->ng.nexthop->gate.ipv4) + if (in_addr_cmp((uint8_t *)&(*re)->ng.nexthop->gate.ipv4, + (uint8_t *)&re2->ng.nexthop->gate.ipv4) <= 0) return; @@ -307,16 +307,16 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], int proto; int policy; struct in_addr nexthop; - u_char *pnt; + uint8_t *pnt; int i; /* Init index variables */ - pnt = (u_char *)&dest; + pnt = (uint8_t *)&dest; for (i = 0; i < 4; i++) *pnt++ = 0; - pnt = (u_char *)&nexthop; + pnt = (uint8_t *)&nexthop; for (i = 0; i < 4; i++) *pnt++ = 0; @@ -358,7 +358,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], /* Apply GETNEXT on not exact search */ if (!exact && (*objid_len >= (unsigned)v->namelen + 10)) { - if (!in_addr_add((u_char *)&nexthop, 1)) + if (!in_addr_add((uint8_t *)&nexthop, 1)) return; } @@ -368,12 +368,13 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], if (policy) /* Not supported (yet?) */ return; for (*np = route_top(table); *np; *np = route_next(*np)) { - if (!in_addr_cmp(&(*np)->p.u.prefix, (u_char *)&dest)) { + if (!in_addr_cmp(&(*np)->p.u.prefix, + (uint8_t *)&dest)) { RNODE_FOREACH_RE (*np, *re) { - if (!in_addr_cmp( - (u_char *)&(*re) - ->ng.nexthop->gate.ipv4, - (u_char *)&nexthop)) + if (!in_addr_cmp((uint8_t *)&(*re) + ->ng.nexthop + ->gate.ipv4, + (uint8_t *)&nexthop)) if (proto == proto_trans((*re)->type)) return; @@ -388,12 +389,12 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], for (np2 = route_top(table); np2; np2 = route_next(np2)) { /* Check destination first */ - if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) > 0) + if (in_addr_cmp(&np2->p.u.prefix, (uint8_t *)&dest) > 0) RNODE_FOREACH_RE (np2, re2) { check_replace(np2, re2, np, re); } - if (in_addr_cmp(&np2->p.u.prefix, (u_char *)&dest) + if (in_addr_cmp(&np2->p.u.prefix, (uint8_t *)&dest) == 0) { /* have to look at each re individually */ RNODE_FOREACH_RE (np2, re2) { int proto2, policy2; @@ -405,9 +406,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], || ((policy == policy2) && (proto < proto2)) || ((policy == policy2) && (proto == proto2) && (in_addr_cmp( - (u_char *)&re2->ng.nexthop - ->gate.ipv4, - (u_char *)&nexthop) + (uint8_t *)&re2->ng.nexthop + ->gate.ipv4, + (uint8_t *)&nexthop) >= 0))) check_replace(np2, re2, np, re); } @@ -421,7 +422,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], proto = proto_trans((*re)->type); *objid_len = v->namelen + 10; - pnt = (u_char *)&(*np)->p.u.prefix; + pnt = (uint8_t *)&(*np)->p.u.prefix; for (i = 0; i < 4; i++) objid[v->namelen + i] = *pnt++; @@ -433,7 +434,7 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], nexthop = (*re)->ng.nexthop; if (nexthop) { - pnt = (u_char *)&nexthop->gate.ipv4; + pnt = (uint8_t *)&nexthop->gate.ipv4; for (i = 0; i < 4; i++) objid[i + v->namelen + 6] = *pnt++; } @@ -442,8 +443,9 @@ static void get_fwtable_route_node(struct variable *v, oid objid[], return; } -static u_char *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, - int exact, size_t *val_len, WriteMethod **write_method) +static uint8_t *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, + int exact, size_t *val_len, + WriteMethod **write_method) { struct route_node *np; struct route_entry *re; @@ -472,20 +474,20 @@ static u_char *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, case IPFORWARDMASK: masklen2ip(np->p.prefixlen, &netmask); *val_len = 4; - return (u_char *)&netmask; + return (uint8_t *)&netmask; break; case IPFORWARDPOLICY: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDNEXTHOP: *val_len = 4; - return (u_char *)&nexthop->gate.ipv4; + return (uint8_t *)&nexthop->gate.ipv4; break; case IPFORWARDIFINDEX: *val_len = sizeof(int); - return (u_char *)&nexthop->ifindex; + return (uint8_t *)&nexthop->ifindex; break; case IPFORWARDTYPE: if (nexthop->type == NEXTHOP_TYPE_IFINDEX) @@ -493,53 +495,53 @@ static u_char *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, else result = 4; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDPROTO: result = proto_trans(re->type); *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDAGE: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDINFO: resarr[0] = 0; resarr[1] = 0; *val_len = 2 * sizeof(int); - return (u_char *)resarr; + return (uint8_t *)resarr; break; case IPFORWARDNEXTHOPAS: result = -1; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDMETRIC1: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDMETRIC2: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDMETRIC3: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDMETRIC4: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; case IPFORWARDMETRIC5: result = 0; *val_len = sizeof(int); - return (u_char *)&result; + return (uint8_t *)&result; break; default: return NULL; @@ -548,9 +550,9 @@ static u_char *ipFwTable(struct variable *v, oid objid[], size_t *objid_len, return NULL; } -static u_char *ipCidrTable(struct variable *v, oid objid[], size_t *objid_len, - int exact, size_t *val_len, - WriteMethod **write_method) +static uint8_t *ipCidrTable(struct variable *v, oid objid[], size_t *objid_len, + int exact, size_t *val_len, + WriteMethod **write_method) { if (smux_header_table(v, objid, objid_len, exact, val_len, write_method) == MATCH_FAILED) diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c index c8e49cb293..914b049c05 100644 --- a/zebra/zebra_static.c +++ b/zebra/zebra_static.c @@ -390,10 +390,10 @@ void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p, route_unlock_node(rn); } -int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, +int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p, struct prefix_ipv6 *src_p, union g_addr *gate, const char *ifname, enum static_blackhole_type bh_type, - route_tag_t tag, u_char distance, struct zebra_vrf *zvrf, + route_tag_t tag, uint8_t distance, struct zebra_vrf *zvrf, struct zebra_vrf *nh_zvrf, struct static_nh_label *snh_label) { @@ -522,9 +522,9 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, return 1; } -int static_delete_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, +int static_delete_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p, struct prefix_ipv6 *src_p, union g_addr *gate, - const char *ifname, route_tag_t tag, u_char distance, + const char *ifname, route_tag_t tag, uint8_t distance, struct zebra_vrf *zvrf, struct static_nh_label *snh_label) { diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h index de3143aaa7..341905f422 100644 --- a/zebra/zebra_static.h +++ b/zebra/zebra_static.h @@ -26,8 +26,8 @@ /* Static route label information */ struct static_nh_label { - u_int8_t num_labels; - u_int8_t reserved[3]; + uint8_t num_labels; + uint8_t reserved[3]; mpls_label_t label[MPLS_MAX_LABELS]; }; @@ -58,7 +58,7 @@ struct static_route { char nh_vrfname[VRF_NAMSIZ + 1]; /* Administrative distance. */ - u_char distance; + uint8_t distance; /* Tag */ route_tag_t tag; @@ -86,18 +86,18 @@ extern void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p, struct prefix_ipv6 *src_p, struct static_route *si); -extern int static_add_route(afi_t, safi_t safi, u_char type, struct prefix *p, +extern int static_add_route(afi_t, safi_t safi, uint8_t type, struct prefix *p, struct prefix_ipv6 *src_p, union g_addr *gate, const char *ifname, enum static_blackhole_type bh_type, route_tag_t tag, - u_char distance, struct zebra_vrf *zvrf, + uint8_t distance, struct zebra_vrf *zvrf, struct zebra_vrf *nh_zvrf, struct static_nh_label *snh_label); -extern int static_delete_route(afi_t, safi_t safi, u_char type, +extern int static_delete_route(afi_t, safi_t safi, uint8_t type, struct prefix *p, struct prefix_ipv6 *src_p, union g_addr *gate, const char *ifname, - route_tag_t tag, u_char distance, + route_tag_t tag, uint8_t distance, struct zebra_vrf *zvrf, struct static_nh_label *snh_label); diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 83cfb7bb10..76dc5657d4 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -118,8 +118,8 @@ static int zebra_vrf_enable(struct vrf *vrf) /* Inform clients that the VRF is now active. This is an * add for the clients. */ - zebra_vrf_add_update(zvrf); + zebra_vrf_add_update(zvrf); /* Allocate tables */ for (afi = AFI_IP; afi <= AFI_IP6; afi++) { for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) @@ -332,7 +332,7 @@ int zebra_vrf_has_config(struct zebra_vrf *zvrf) */ struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id, - u_int32_t table_id) + uint32_t table_id) { struct route_table *table = NULL; @@ -486,7 +486,7 @@ struct route_table *zebra_vrf_static_table(afi_t afi, safi_t safi, return zvrf->stable[afi][safi]; } -struct route_table *zebra_vrf_other_route_table(afi_t afi, u_int32_t table_id, +struct route_table *zebra_vrf_other_route_table(afi_t afi, uint32_t table_id, vrf_id_t vrf_id) { struct zebra_vrf *zvrf; diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index 4c12d7dee9..5c5d2f5225 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -28,8 +28,8 @@ /* MPLS (Segment Routing) global block */ typedef struct mpls_srgb_t_ { - u_int32_t start_label; - u_int32_t end_label; + uint32_t start_label; + uint32_t end_label; } mpls_srgb_t; /* Routing table instance. */ @@ -41,14 +41,14 @@ struct zebra_vrf { char *desc; /* FIB identifier. */ - u_char fib_id; + uint8_t fib_id; /* Flags. */ - u_int16_t flags; + uint16_t flags; #define ZEBRA_VRF_RIB_SCHEDULED (1 << 0) #define ZEBRA_VRF_RETAIN (2 << 0) - u_int32_t table_id; + uint32_t table_id; /* Routing table. */ struct route_table *table[AFI_MAX][SAFI_MAX]; @@ -96,7 +96,7 @@ struct zebra_vrf { struct zebra_static_pw_head static_pseudowires; /* MPLS processing flags */ - u_int16_t mpls_flags; + uint16_t mpls_flags; #define MPLS_FLAG_SCHEDULE_LSPS (1 << 0) /* @@ -152,7 +152,7 @@ static inline bool zvrf_is_active(struct zebra_vrf *zvrf) struct route_table *zebra_vrf_table_with_table_id(afi_t afi, safi_t safi, vrf_id_t vrf_id, - u_int32_t table_id); + uint32_t table_id); extern void zebra_vrf_update_all(struct zserv *client); extern struct zebra_vrf *zebra_vrf_lookup_by_id(vrf_id_t vrf_id); @@ -162,7 +162,7 @@ extern struct route_table *zebra_vrf_table(afi_t, safi_t, vrf_id_t); extern struct route_table *zebra_vrf_static_table(afi_t, safi_t, struct zebra_vrf *zvrf); extern struct route_table * -zebra_vrf_other_route_table(afi_t afi, u_int32_t table_id, vrf_id_t vrf_id); +zebra_vrf_other_route_table(afi_t afi, uint32_t table_id, vrf_id_t vrf_id); extern int zebra_vrf_has_config(struct zebra_vrf *zvrf); extern void zebra_vrf_init(void); diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index a9107dc4a0..84fc76d7f6 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -55,11 +55,11 @@ extern int allow_delete; static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, - safi_t safi, bool use_fib, u_char use_json, + safi_t safi, bool use_fib, uint8_t use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - u_short ospf_instance_id); + unsigned short ospf_instance_id); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast); static void vty_show_ip_route_summary(struct vty *vty, @@ -91,6 +91,9 @@ struct static_hold_route { char *tag_str; char *distance_str; char *label_str; + + /* processed & masked destination, used for config display */ + struct prefix dest; }; static struct list *static_list; @@ -160,11 +163,7 @@ static int static_list_compare(void *arg1, void *arg2) if (ret) return ret; - ret = static_list_compare_helper(shr1->dest_str, shr2->dest_str); - if (ret) - return ret; - - ret = static_list_compare_helper(shr1->mask_str, shr2->mask_str); + ret = prefix_cmp(&shr1->dest, &shr2->dest); if (ret) return ret; @@ -198,15 +197,12 @@ static int static_list_compare(void *arg1, void *arg2) /* General function for static route. */ -static int zebra_static_route_holdem(struct zebra_vrf *zvrf, - struct zebra_vrf *nh_zvrf, - afi_t afi, safi_t safi, - const char *negate, const char *dest_str, - const char *mask_str, const char *src_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, - const char *label_str) +static int zebra_static_route_holdem( + struct zebra_vrf *zvrf, struct zebra_vrf *nh_zvrf, afi_t afi, + safi_t safi, const char *negate, struct prefix *dest, + const char *dest_str, const char *mask_str, const char *src_str, + const char *gate_str, const char *ifname, const char *flag_str, + const char *tag_str, const char *distance_str, const char *label_str) { struct static_hold_route *shr, *lookup; struct listnode *node; @@ -216,6 +212,8 @@ static int zebra_static_route_holdem(struct zebra_vrf *zvrf, shr->nhvrf_name = XSTRDUP(MTYPE_STATIC_ROUTE, nh_zvrf->vrf->name); shr->afi = afi; shr->safi = safi; + if (dest) + prefix_copy(&shr->dest, dest); if (dest_str) shr->dest_str = XSTRDUP(MTYPE_STATIC_ROUTE, dest_str); if (mask_str) @@ -273,7 +271,7 @@ static int zebra_static_route_leak( const char *distance_str, const char *label_str) { int ret; - u_char distance; + uint8_t distance; struct prefix p, src; struct prefix_ipv6 *src_p = NULL; union g_addr gate; @@ -281,7 +279,7 @@ static int zebra_static_route_leak( struct in_addr mask; enum static_blackhole_type bh_type = 0; route_tag_t tag = 0; - u_char type; + uint8_t type; struct static_nh_label snh_label; ret = str2prefix(dest_str, &p); @@ -294,14 +292,6 @@ static int zebra_static_route_leak( return CMD_WARNING_CONFIG_FAILED; } - if (zvrf->vrf->vrf_id == VRF_UNKNOWN - || nh_zvrf->vrf->vrf_id == VRF_UNKNOWN) { - vrf_set_user_cfged(zvrf->vrf); - return zebra_static_route_holdem( - zvrf, nh_zvrf, afi, safi, negate, dest_str, mask_str, - src_str, gate_str, ifname, flag_str, tag_str, - distance_str, label_str); - } switch (afi) { case AFI_IP: /* Cisco like mask notation. */ @@ -343,6 +333,15 @@ static int zebra_static_route_leak( /* Apply mask for given prefix. */ apply_mask(&p); + if (zvrf->vrf->vrf_id == VRF_UNKNOWN + || nh_zvrf->vrf->vrf_id == VRF_UNKNOWN) { + vrf_set_user_cfged(zvrf->vrf); + return zebra_static_route_holdem( + zvrf, nh_zvrf, afi, safi, negate, &p, dest_str, + mask_str, src_str, gate_str, ifname, flag_str, tag_str, + distance_str, label_str); + } + /* Administrative distance. */ if (distance_str) distance = atoi(distance_str); @@ -1534,7 +1533,8 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, bool use_fib, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - u_short ospf_instance_id, u_char use_json) + unsigned short ospf_instance_id, + uint8_t use_json) { struct route_node *rn; struct route_entry *re; @@ -1623,11 +1623,11 @@ static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf, } static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, - safi_t safi, bool use_fib, u_char use_json, + safi_t safi, bool use_fib, uint8_t use_json, route_tag_t tag, const struct prefix *longer_prefix_p, bool supernets_only, int type, - u_short ospf_instance_id) + unsigned short ospf_instance_id) { struct route_table *table; struct zebra_vrf *zvrf = NULL; @@ -2066,10 +2066,10 @@ static void vty_show_ip_route_summary(struct vty *vty, struct route_entry *re; #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1) - u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; - u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; - u_int32_t i; - u_int32_t is_ibgp; + uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t i; + uint32_t is_ibgp; memset(&rib_cnt, 0, sizeof(rib_cnt)); memset(&fib_cnt, 0, sizeof(fib_cnt)); @@ -2135,9 +2135,9 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, struct nexthop *nexthop; #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1) - u_int32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; - u_int32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; - u_int32_t i; + uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1]; + uint32_t i; int cnt; memset(&rib_cnt, 0, sizeof(rib_cnt)); @@ -2226,11 +2226,13 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, if (strcmp(zvrf->vrf->name, shr->vrf_name) != 0) continue; + char dest_str[PREFIX_STRLEN]; + + prefix2str(&shr->dest, dest_str, sizeof(dest_str)); + vty_out(vty, "%s ", spacing); if (shr->dest_str) - vty_out(vty, "%s ", shr->dest_str); - if (shr->mask_str) - vty_out(vty, "%s ", shr->mask_str); + vty_out(vty, "%s ", dest_str); if (shr->src_str) vty_out(vty, "from %s ", shr->src_str); if (shr->gate_str) @@ -2300,10 +2302,6 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, if (si->distance != ZEBRA_STATIC_DISTANCE_DEFAULT) vty_out(vty, " %d", si->distance); - if (si->nh_vrf_id != si->vrf_id) { - vty_out(vty, " nexthop-vrf %s", si->nh_vrfname); - } - /* Label information */ if (si->snh_label.num_labels) vty_out(vty, " label %s", @@ -2311,6 +2309,10 @@ int static_config(struct vty *vty, struct zebra_vrf *zvrf, afi_t afi, si->snh_label.label, buf, sizeof buf, 0)); + if (si->nh_vrf_id != si->vrf_id) { + vty_out(vty, " nexthop-vrf %s", si->nh_vrfname); + } + vty_out(vty, "\n"); write = 1; @@ -2826,7 +2828,7 @@ DEFUN (show_vrf_vni, struct zebra_vrf *zvrf; json_object *json = NULL; json_object *json_vrfs = NULL; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (uj) { json = json_object_new_object(); @@ -2862,7 +2864,7 @@ DEFUN (show_evpn_global, "EVPN\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zebra_vxlan_print_evpn(vty, uj); return CMD_SUCCESS; @@ -2877,7 +2879,7 @@ DEFUN (show_evpn_vni, JSON_STR) { struct zebra_vrf *zvrf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zvrf = vrf_info_lookup(VRF_DEFAULT); zebra_vxlan_print_vnis(vty, zvrf, uj); @@ -2895,7 +2897,7 @@ DEFUN (show_evpn_vni_vni, { struct zebra_vrf *zvrf; vni_t vni; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[3]->arg, NULL, 10); zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -2917,7 +2919,7 @@ DEFUN (show_evpn_rmac_vni_mac, { vni_t l3vni = 0; struct ethaddr mac; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); l3vni = strtoul(argv[4]->arg, NULL, 10); if (!prefix_str2mac(argv[6]->arg, &mac)) { @@ -2939,7 +2941,7 @@ DEFUN (show_evpn_rmac_vni, JSON_STR) { vni_t l3vni = 0; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); l3vni = strtoul(argv[4]->arg, NULL, 10); zebra_vxlan_print_rmacs_l3vni(vty, l3vni, uj); @@ -2957,7 +2959,7 @@ DEFUN (show_evpn_rmac_vni_all, "All VNIs\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zebra_vxlan_print_rmacs_all_l3vni(vty, uj); @@ -2978,7 +2980,7 @@ DEFUN (show_evpn_nh_vni_ip, { vni_t l3vni; struct ipaddr ip; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); l3vni = strtoul(argv[4]->arg, NULL, 10); if (str2ipaddr(argv[6]->arg, &ip) != 0) { @@ -3002,7 +3004,7 @@ DEFUN (show_evpn_nh_vni, JSON_STR) { vni_t l3vni; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); l3vni = strtoul(argv[4]->arg, NULL, 10); zebra_vxlan_print_nh_l3vni(vty, l3vni, uj); @@ -3020,7 +3022,7 @@ DEFUN (show_evpn_nh_vni_all, "All VNIs\n" JSON_STR) { - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zebra_vxlan_print_nh_all_l3vni(vty, uj); @@ -3039,7 +3041,7 @@ DEFUN (show_evpn_mac_vni, { struct zebra_vrf *zvrf; vni_t vni; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[4]->arg, NULL, 10); zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -3058,7 +3060,7 @@ DEFUN (show_evpn_mac_vni_all, JSON_STR) { struct zebra_vrf *zvrf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zvrf = vrf_info_lookup(VRF_DEFAULT); zebra_vxlan_print_macs_all_vni(vty, zvrf, uj); @@ -3079,7 +3081,7 @@ DEFUN (show_evpn_mac_vni_all_vtep, { struct zebra_vrf *zvrf; struct in_addr vtep_ip; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); if (!inet_aton(argv[6]->arg, &vtep_ip)) { if (!uj) @@ -3133,7 +3135,7 @@ DEFUN (show_evpn_mac_vni_vtep, struct zebra_vrf *zvrf; vni_t vni; struct in_addr vtep_ip; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[4]->arg, NULL, 10); if (!inet_aton(argv[6]->arg, &vtep_ip)) { @@ -3159,7 +3161,7 @@ DEFUN (show_evpn_neigh_vni, { struct zebra_vrf *zvrf; vni_t vni; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[4]->arg, NULL, 10); zvrf = vrf_info_lookup(VRF_DEFAULT); @@ -3178,7 +3180,7 @@ DEFUN (show_evpn_neigh_vni_all, JSON_STR) { struct zebra_vrf *zvrf; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); zvrf = vrf_info_lookup(VRF_DEFAULT); zebra_vxlan_print_neigh_all_vni(vty, zvrf, uj); @@ -3200,7 +3202,7 @@ DEFUN (show_evpn_neigh_vni_neigh, struct zebra_vrf *zvrf; vni_t vni; struct ipaddr ip; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[4]->arg, NULL, 10); if (str2ipaddr(argv[6]->arg, &ip) != 0) { @@ -3228,7 +3230,7 @@ DEFUN (show_evpn_neigh_vni_vtep, struct zebra_vrf *zvrf; vni_t vni; struct in_addr vtep_ip; - u_char uj = use_json(argc, argv); + uint8_t uj = use_json(argc, argv); vni = strtoul(argv[4]->arg, NULL, 10); if (!inet_aton(argv[6]->arg, &vtep_ip)) { @@ -3263,7 +3265,7 @@ DEFUN (ip_zebra_import_table_distance, "route-map for filtering\n" "route-map name\n") { - u_int32_t table_id = 0; + uint32_t table_id = 0; table_id = strtoul(argv[2]->arg, NULL, 10); int distance = ZEBRA_TABLE_DISTANCE_DEFAULT; @@ -3366,7 +3368,7 @@ DEFUN (no_ip_zebra_import_table, "route-map for filtering\n" "route-map name\n") { - u_int32_t table_id = 0; + uint32_t table_id = 0; table_id = strtoul(argv[3]->arg, NULL, 10); if (!is_zebra_valid_kernel_table(table_id)) { diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 256fa9e4b7..7784403fff 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -75,8 +75,8 @@ static void zvni_print(zebra_vni_t *zvni, void **ctxt); static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]); static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, - struct ipaddr *ip, u_char flags, - u_int16_t cmd); + struct ipaddr *ip, uint8_t flags, + uint16_t cmd); static unsigned int neigh_hash_keymake(void *p); static int neigh_cmp(const void *p1, const void *p2); static void *zvni_neigh_alloc(void *p); @@ -87,12 +87,14 @@ static int zvni_neigh_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, - u_int32_t flags); + uint32_t flags); static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip); static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, - struct ethaddr *macaddr, u_char flags); + struct ethaddr *macaddr, + uint8_t flags); static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, - struct ethaddr *macaddr, u_char flags); + struct ethaddr *macaddr, + uint8_t flags); static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n); static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n); static zebra_vni_t *zvni_from_svi(struct interface *ifp, @@ -141,12 +143,12 @@ static int zvni_mac_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, - u_int32_t flags); + uint32_t flags); static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *macaddr); static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, - u_char flags); + uint8_t flags); static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, - u_char flags); + uint8_t flags); static zebra_vni_t *zvni_map_vlan(struct interface *ifp, struct interface *br_if, vlanid_t vid); static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac); @@ -186,10 +188,10 @@ static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac, * Return number of valid MACs in a VNI's MAC hash table - all * remote MACs and non-internal (auto) local MACs count. */ -static u_int32_t num_valid_macs(zebra_vni_t *zvni) +static uint32_t num_valid_macs(zebra_vni_t *zvni) { unsigned int i; - u_int32_t num_macs = 0; + uint32_t num_macs = 0; struct hash *hash; struct hash_backet *hb; zebra_mac_t *mac; @@ -378,7 +380,7 @@ static void zvni_print_neigh_hash_all_vni(struct hash_backet *backet, struct vty *vty; json_object *json = NULL, *json_vni = NULL; zebra_vni_t *zvni; - u_int32_t num_neigh; + uint32_t num_neigh; struct neigh_walk_ctx wctx; char vni_str[VNI_STR_LEN]; @@ -673,7 +675,7 @@ static void zvni_print_mac_hash_all_vni(struct hash_backet *backet, void *ctxt) json_object *json = NULL, *json_vni = NULL; json_object *json_mac = NULL; zebra_vni_t *zvni; - u_int32_t num_macs; + uint32_t num_macs; struct mac_walk_ctx *wctx = ctxt; char vni_str[VNI_STR_LEN]; @@ -810,7 +812,7 @@ static void zl3vni_print_rmac_hash_all_vni(struct hash_backet *backet, json_object *json = NULL; json_object *json_vni = NULL; zebra_l3vni_t *zl3vni = NULL; - u_int32_t num_rmacs; + uint32_t num_rmacs; struct rmac_walk_ctx wctx; char vni_str[VNI_STR_LEN]; @@ -953,8 +955,8 @@ static void zvni_print(zebra_vni_t *zvni, void **ctxt) { struct vty *vty; zebra_vtep_t *zvtep; - u_int32_t num_macs; - u_int32_t num_neigh; + uint32_t num_macs; + uint32_t num_neigh; json_object *json = NULL; json_object *json_vtep_list = NULL; json_object *json_ip_str = NULL; @@ -1081,9 +1083,9 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) struct vty *vty; zebra_vni_t *zvni; zebra_vtep_t *zvtep; - u_int32_t num_vteps = 0; - u_int32_t num_macs = 0; - u_int32_t num_neigh = 0; + uint32_t num_vteps = 0; + uint32_t num_macs = 0; + uint32_t num_neigh = 0; json_object *json = NULL; json_object *json_vni = NULL; json_object *json_ip_str = NULL; @@ -1143,8 +1145,8 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) * Inform BGP about local MACIP. */ static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, - struct ipaddr *ip, u_char flags, - u_int16_t cmd) + struct ipaddr *ip, uint8_t flags, + uint16_t cmd) { char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; @@ -1343,7 +1345,7 @@ static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, * Delete all neighbor entries for this VNI. */ static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, - u_int32_t flags) + uint32_t flags) { struct neigh_walk_ctx wctx; @@ -1512,9 +1514,9 @@ static void zvni_process_neigh_on_remote_mac_del(zebra_vni_t *zvni, */ static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, - u_char neigh_flags) + uint8_t neigh_flags) { - u_char flags = 0; + uint8_t flags = 0; if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_DEF_GW)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW); @@ -1527,7 +1529,7 @@ static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, * Inform BGP about local neighbor deletion. */ static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, - struct ethaddr *macaddr, u_char flags) + struct ethaddr *macaddr, uint8_t flags) { return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags, ZEBRA_MACIP_DEL); @@ -2062,7 +2064,7 @@ static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, * Delete all MAC entries for this VNI. */ static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, - u_int32_t flags) + uint32_t flags) { struct mac_walk_ctx wctx; @@ -2099,9 +2101,9 @@ static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *mac) * Inform BGP about local MAC addition. */ static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, - u_char mac_flags) + uint8_t mac_flags) { - u_char flags = 0; + uint8_t flags = 0; if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); @@ -2116,9 +2118,9 @@ static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, * Inform BGP about local MAC deletion. */ static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, - u_char mac_flags) + uint8_t mac_flags) { - u_char flags = 0; + uint8_t flags = 0; if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY)) SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); @@ -2142,7 +2144,7 @@ static zebra_vni_t *zvni_map_vlan(struct interface *ifp, struct zebra_if *zif; struct zebra_l2info_bridge *br; struct zebra_l2info_vxlan *vxl = NULL; - u_char bridge_vlan_aware; + uint8_t bridge_vlan_aware; zebra_vni_t *zvni; int found = 0; @@ -2195,7 +2197,7 @@ static zebra_vni_t *zvni_from_svi(struct interface *ifp, struct zebra_if *zif; struct zebra_l2info_bridge *br; struct zebra_l2info_vxlan *vxl = NULL; - u_char bridge_vlan_aware; + uint8_t bridge_vlan_aware; vlanid_t vid = 0; zebra_vni_t *zvni; int found = 0; @@ -2269,7 +2271,7 @@ static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if) struct zebra_if *zif; struct zebra_l2info_bridge *br; struct zebra_l2info_vlan *vl; - u_char bridge_vlan_aware; + uint8_t bridge_vlan_aware; int found = 0; /* Defensive check, caller expected to invoke only with valid bridge. */ @@ -2316,7 +2318,7 @@ static int zvni_mac_install(zebra_vni_t *zvni, zebra_mac_t *mac) { struct zebra_if *zif; struct zebra_l2info_vxlan *vxl; - u_char sticky; + uint8_t sticky; if (!(mac->flags & ZEBRA_MAC_REMOTE)) return 0; @@ -3241,7 +3243,7 @@ static int zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, struct ipaddr *vtep_ip, * readd stale entries. */ static int zl3vni_local_nh_add_update(zebra_l3vni_t *zl3vni, struct ipaddr *ip, - u_int16_t state) + uint16_t state) { #ifdef GNU_LINUX zebra_neigh_t *n = NULL; @@ -3466,7 +3468,7 @@ static zebra_l3vni_t *zl3vni_from_svi(struct interface *ifp, { int found = 0; vlanid_t vid = 0; - u_char bridge_vlan_aware = 0; + uint8_t bridge_vlan_aware = 0; zebra_l3vni_t *zl3vni = NULL; struct zebra_ns *zns = NULL; struct route_node *rn = NULL; @@ -3811,7 +3813,7 @@ void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, struct ethaddr *rmac, void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, struct ethaddr *rmac, - u_char use_json) + uint8_t use_json) { zebra_l3vni_t *zl3vni = NULL; zebra_mac_t *zrmac = NULL; @@ -3856,10 +3858,10 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, } void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, - u_char use_json) + uint8_t use_json) { zebra_l3vni_t *zl3vni; - u_int32_t num_rmacs; + uint32_t num_rmacs; struct rmac_walk_ctx wctx; json_object *json = NULL; @@ -3900,7 +3902,7 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, } } -void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, u_char use_json) +void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, uint8_t use_json) { struct zebra_ns *zns = NULL; json_object *json = NULL; @@ -3937,7 +3939,7 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, u_char use_json) } void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, - struct ipaddr *ip, u_char use_json) + struct ipaddr *ip, uint8_t use_json) { zebra_l3vni_t *zl3vni = NULL; zebra_neigh_t *n = NULL; @@ -3981,9 +3983,9 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, } } -void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, u_char use_json) +void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, uint8_t use_json) { - u_int32_t num_nh; + uint32_t num_nh; struct nh_walk_ctx wctx; json_object *json = NULL; zebra_l3vni_t *zl3vni = NULL; @@ -4025,7 +4027,7 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, u_char use_json) } } -void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, u_char use_json) +void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, uint8_t use_json) { struct zebra_ns *zns = NULL; json_object *json = NULL; @@ -4062,7 +4064,7 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, u_char use_json) /* * Display L3 VNI information (VTY command handler). */ -void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, u_char use_json) +void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, uint8_t use_json) { void *args[2]; json_object *json = NULL; @@ -4135,10 +4137,10 @@ void zebra_vxlan_print_vrf_vni(struct vty *vty, struct zebra_vrf *zvrf, * Display Neighbors for a VNI (VTY command handler). */ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, - vni_t vni, u_char use_json) + vni_t vni, uint8_t use_json) { zebra_vni_t *zvni; - u_int32_t num_neigh; + uint32_t num_neigh; struct neigh_walk_ctx wctx; json_object *json = NULL; @@ -4191,7 +4193,7 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, * Display neighbors across all VNIs (VTY command handler). */ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json) + uint8_t use_json) { json_object *json = NULL; void *args[2]; @@ -4220,7 +4222,7 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, */ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, - struct ipaddr *ip, u_char use_json) + struct ipaddr *ip, uint8_t use_json) { zebra_vni_t *zvni; zebra_neigh_t *n; @@ -4262,10 +4264,10 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, */ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct in_addr vtep_ip, - u_char use_json) + uint8_t use_json) { zebra_vni_t *zvni; - u_int32_t num_neigh; + uint32_t num_neigh; struct neigh_walk_ctx wctx; json_object *json = NULL; @@ -4302,10 +4304,10 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, * Display MACs for a VNI (VTY command handler). */ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, - vni_t vni, u_char use_json) + vni_t vni, uint8_t use_json) { zebra_vni_t *zvni; - u_int32_t num_macs; + uint32_t num_macs; struct mac_walk_ctx wctx; json_object *json = NULL; json_object *json_mac = NULL; @@ -4357,7 +4359,7 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, * Display MACs for all VNIs (VTY command handler). */ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json) + uint8_t use_json) { struct mac_walk_ctx wctx; json_object *json = NULL; @@ -4388,7 +4390,7 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, struct in_addr vtep_ip, - u_char use_json) + uint8_t use_json) { struct mac_walk_ctx wctx; json_object *json = NULL; @@ -4444,10 +4446,10 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf, */ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct in_addr vtep_ip, - u_char use_json) + uint8_t use_json) { zebra_vni_t *zvni; - u_int32_t num_macs; + uint32_t num_macs; struct mac_walk_ctx wctx; json_object *json = NULL; json_object *json_mac = NULL; @@ -4494,7 +4496,7 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, * Display VNI information (VTY command handler). */ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, - u_char use_json) + uint8_t use_json) { json_object *json = NULL; void *args[2]; @@ -4533,7 +4535,7 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, } /* Display all global details for EVPN */ -void zebra_vxlan_print_evpn(struct vty *vty, u_char uj) +void zebra_vxlan_print_evpn(struct vty *vty, uint8_t uj) { int num_l2vnis = 0; int num_l3vnis = 0; @@ -4582,7 +4584,7 @@ void zebra_vxlan_print_evpn(struct vty *vty, u_char uj) * Display VNI hash table (VTY command handler). */ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json) + uint8_t use_json) { json_object *json = NULL; struct zebra_ns *zns = NULL; @@ -4712,8 +4714,8 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, int zebra_vxlan_local_neigh_add_update(struct interface *ifp, struct interface *link_if, struct ipaddr *ip, - struct ethaddr *macaddr, u_int16_t state, - u_char ext_learned) + struct ethaddr *macaddr, uint16_t state, + uint8_t ext_learned) { char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; @@ -4762,7 +4764,7 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, } memset(&zmac->fwd_info, 0, sizeof(zmac->fwd_info)); - memset(&zmac->flags, 0, sizeof(u_int32_t)); + memset(&zmac->flags, 0, sizeof(uint32_t)); SET_FLAG(zmac->flags, ZEBRA_MAC_AUTO); } @@ -4868,7 +4870,7 @@ void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS) zebra_vni_t *zvni; zebra_mac_t *mac; zebra_neigh_t *n; - u_short l = 0, ipa_len; + unsigned short l = 0, ipa_len; char buf[ETHER_ADDR_STRLEN]; char buf1[INET6_ADDRSTRLEN]; struct interface *ifp = NULL; @@ -5021,12 +5023,12 @@ void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS) zebra_vtep_t *zvtep; zebra_mac_t *mac, *old_mac; zebra_neigh_t *n; - u_short l = 0, ipa_len; + unsigned short l = 0, ipa_len; int update_mac = 0, update_neigh = 0; char buf[ETHER_ADDR_STRLEN]; char buf1[INET6_ADDRSTRLEN]; - u_char sticky = 0; - u_char flags = 0; + uint8_t sticky = 0; + uint8_t flags = 0; struct interface *ifp = NULL; struct zebra_if *zif = NULL; @@ -5414,13 +5416,13 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, int zebra_vxlan_local_mac_add_update(struct interface *ifp, struct interface *br_if, struct ethaddr *macaddr, vlanid_t vid, - u_char sticky) + uint8_t sticky) { zebra_vni_t *zvni; zebra_mac_t *mac; char buf[ETHER_ADDR_STRLEN]; int add = 1; - u_char mac_sticky; + uint8_t mac_sticky; /* We are interested in MACs only on ports or (port, VLAN) that * map to a VNI. @@ -5539,7 +5541,7 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS) { struct stream *s; - u_short l = 0; + unsigned short l = 0; vni_t vni; struct in_addr vtep_ip; zebra_vni_t *zvni; @@ -5624,7 +5626,7 @@ stream_failure: void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS) { struct stream *s; - u_short l = 0; + unsigned short l = 0; vni_t vni; struct in_addr vtep_ip; zebra_vni_t *zvni; @@ -6114,7 +6116,7 @@ int zebra_vxlan_if_del(struct interface *ifp) /* * Handle VxLAN interface update - change to tunnel IP, master or VLAN. */ -int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) +int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags) { vni_t vni; struct zebra_if *zif = NULL; diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index 6f25ad1e24..16b01e6acd 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -68,52 +68,53 @@ extern int zebra_vxlan_vrf_enable(struct zebra_vrf *zvrf); extern int zebra_vxlan_vrf_disable(struct zebra_vrf *zvrf); extern int zebra_vxlan_vrf_delete(struct zebra_vrf *zvrf); extern void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, - struct ipaddr *ip, u_char uj); -extern void zebra_vxlan_print_evpn(struct vty *vty, u_char uj); + struct ipaddr *ip, uint8_t uj); +extern void zebra_vxlan_print_evpn(struct vty *vty, uint8_t uj); extern void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, struct ethaddr *rmac, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, - vni_t vni, u_char use_json); + vni_t vni, uint8_t use_json); extern void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, struct in_addr vtep_ip, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct ethaddr *mac); extern void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct in_addr vtep_ip, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, - vni_t vni, u_char use_json); + vni_t vni, uint8_t use_json); extern void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct ipaddr *ip, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, struct in_addr vtep_ip, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, - vni_t vni, u_char use_json); + vni_t vni, uint8_t use_json); extern void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t vni, - u_char use_json); -extern void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, u_char use_json); + uint8_t use_json); +extern void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, + uint8_t use_json); extern void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t vni, - u_char use_json); -extern void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, u_char use_json); + uint8_t use_json); +extern void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, uint8_t use_json); extern void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, - u_char use_json); + uint8_t use_json); extern void zebra_vxlan_print_vrf_vni(struct vty *vty, struct zebra_vrf *zvrf, json_object *json_vrfs); extern int zebra_vxlan_add_del_gw_macip(struct interface *ifp, struct prefix *p, @@ -123,14 +124,14 @@ extern int zebra_vxlan_svi_down(struct interface *ifp, struct interface *link_if); extern int zebra_vxlan_local_neigh_add_update( struct interface *ifp, struct interface *link_if, struct ipaddr *ip, - struct ethaddr *macaddr, u_int16_t state, u_char ext_learned); + struct ethaddr *macaddr, uint16_t state, uint8_t ext_learned); extern int zebra_vxlan_local_neigh_del(struct interface *ifp, struct interface *link_if, struct ipaddr *ip); extern int zebra_vxlan_local_mac_add_update(struct interface *ifp, struct interface *br_if, struct ethaddr *mac, vlanid_t vid, - u_char sticky); + uint8_t sticky); extern int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, struct ethaddr *mac, vlanid_t vid); @@ -144,7 +145,7 @@ extern int zebra_vxlan_check_del_local_mac(struct interface *ifp, extern int zebra_vxlan_if_up(struct interface *ifp); extern int zebra_vxlan_if_down(struct interface *ifp); extern int zebra_vxlan_if_add(struct interface *ifp); -extern int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags); +extern int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags); extern int zebra_vxlan_if_del(struct interface *ifp); extern int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni, char *err, int err_str_sz, diff --git a/zebra/zebra_vxlan_null.c b/zebra/zebra_vxlan_null.c index 1bac2cafb6..afc59774c9 100644 --- a/zebra/zebra_vxlan_null.c +++ b/zebra/zebra_vxlan_null.c @@ -83,23 +83,23 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf) { } -void zebra_vxlan_print_evpn(struct vty *vty, u_char uj) +void zebra_vxlan_print_evpn(struct vty *vty, uint8_t uj) { } -void zebra_vxlan_print_rmacs_l3vni(struct vty *, vni_t, u_char) +void zebra_vxlan_print_rmacs_l3vni(struct vty *, vni_t, uint8_t) { } -void zebra_vxlan_print_rmacs_all_l3vni(struct vty *, u_char) +void zebra_vxlan_print_rmacs_all_l3vni(struct vty *, uint8_t) { } -void zebra_vxlan_print_nh_l3vni(struct vty *, vni_t, u_char) +void zebra_vxlan_print_nh_l3vni(struct vty *, vni_t, uint8_t) { } -void zebra_vxlan_print_nh_all_l3vni(struct vty *, u_char) +void zebra_vxlan_print_nh_all_l3vni(struct vty *, uint8_t) { } @@ -117,14 +117,14 @@ int zebra_vxlan_svi_down(struct interface *ifp, struct interface *link_if) return 0; } -int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, - struct zebra_vrf *zvrf) +int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, + unsigned short length, struct zebra_vrf *zvrf) { return 0; } -int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, u_short length, - struct zebra_vrf *zvrf) +int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, + unsigned short length, struct zebra_vrf *zvrf) { return 0; } @@ -132,7 +132,7 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, u_short length, int zebra_vxlan_local_mac_add_update(struct interface *ifp, struct interface *br_if, struct ethaddr *mac, vlanid_t vid, - u_char sticky) + uint8_t sticky) { return 0; } @@ -172,7 +172,7 @@ int zebra_vxlan_if_add(struct interface *ifp) return 0; } -int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) +int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags) { return 0; } @@ -182,20 +182,20 @@ int zebra_vxlan_if_del(struct interface *ifp) return 0; } -int zebra_vxlan_remote_vtep_add(struct zserv *client, int sock, u_short length, - struct zebra_vrf *zvrf) +int zebra_vxlan_remote_vtep_add(struct zserv *client, int sock, + unsigned short length, struct zebra_vrf *zvrf) { return 0; } -int zebra_vxlan_remote_vtep_del(struct zserv *client, int sock, u_short length, - struct zebra_vrf *zvrf) +int zebra_vxlan_remote_vtep_del(struct zserv *client, int sock, + unsigned short length, struct zebra_vrf *zvrf) { return 0; } int zebra_vxlan_advertise_all_vni(struct zserv *client, int sock, - u_short length, struct zebra_vrf *zvrf) + unsigned short length, struct zebra_vrf *zvrf) { return 0; } diff --git a/zebra/zebra_vxlan_private.h b/zebra/zebra_vxlan_private.h index 6174c6a56d..b4a8b5d480 100644 --- a/zebra/zebra_vxlan_private.h +++ b/zebra/zebra_vxlan_private.h @@ -68,10 +68,10 @@ struct zebra_vni_t_ { vni_t vni; /* Flag for advertising gw macip */ - u_int8_t advertise_gw_macip; + uint8_t advertise_gw_macip; /* Flag for advertising gw macip */ - u_int8_t advertise_subnet; + uint8_t advertise_subnet; /* Corresponding VxLAN interface. */ struct interface *vxlan_if; @@ -231,7 +231,7 @@ struct zebra_mac_t_ { /* MAC address. */ struct ethaddr macaddr; - u_int32_t flags; + uint32_t flags; #define ZEBRA_MAC_LOCAL 0x01 #define ZEBRA_MAC_REMOTE 0x02 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */ @@ -265,7 +265,7 @@ struct mac_walk_ctx { int uninstall; /* uninstall from kernel? */ int upd_client; /* uninstall from client? */ - u_int32_t flags; + uint32_t flags; #define DEL_LOCAL_MAC 0x1 #define DEL_REMOTE_MAC 0x2 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC) @@ -275,7 +275,7 @@ struct mac_walk_ctx { struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */ struct vty *vty; /* Used by VTY handlers */ - u_int32_t count; /* Used by VTY handlers */ + uint32_t count; /* Used by VTY handlers */ struct json_object *json; /* Used for JSON Output */ }; @@ -315,7 +315,7 @@ struct zebra_neigh_t_ { /* Underlying interface. */ ifindex_t ifindex; - u_int32_t flags; + uint32_t flags; #define ZEBRA_NEIGH_LOCAL 0x01 #define ZEBRA_NEIGH_REMOTE 0x02 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */ @@ -339,7 +339,7 @@ struct neigh_walk_ctx { int uninstall; /* uninstall from kernel? */ int upd_client; /* uninstall from client? */ - u_int32_t flags; + uint32_t flags; #define DEL_LOCAL_NEIGH 0x1 #define DEL_REMOTE_NEIGH 0x2 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH) @@ -349,8 +349,8 @@ struct neigh_walk_ctx { struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */ struct vty *vty; /* Used by VTY handlers */ - u_int32_t count; /* Used by VTY handlers */ - u_char addr_width; /* Used by VTY handlers */ + uint32_t count; /* Used by VTY handlers */ + uint8_t addr_width; /* Used by VTY handlers */ struct json_object *json; /* Used for JSON Output */ }; diff --git a/zebra/zserv.c b/zebra/zserv.c index f11c0dd2fd..c06efbfb4b 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -61,6 +61,7 @@ #include "zebra/zebra_vxlan.h" #include "zebra/rt.h" #include "zebra/zebra_pbr.h" +#include "zebra/table_manager.h" /* Event list of zebra. */ enum event { ZEBRA_READ, ZEBRA_WRITE }; @@ -631,7 +632,7 @@ static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client, { struct stream *s; unsigned long nump; - u_char num; + uint8_t num; struct nexthop *nexthop; /* Get output stream. */ @@ -828,7 +829,8 @@ static int zsend_assign_label_chunk_response(struct zserv *client, /* Send response to a label manager connect request to client */ static int zsend_label_manager_connect_response(struct zserv *client, - vrf_id_t vrf_id, u_short result) + vrf_id_t vrf_id, + unsigned short result) { int ret; struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); @@ -862,8 +864,8 @@ static void zread_rnh_register(ZAPI_HANDLER_ARGS) struct rnh *rnh; struct stream *s; struct prefix p; - u_short l = 0; - u_char flags = 0; + unsigned short l = 0; + uint8_t flags = 0; uint16_t type = cmd2type[hdr->command]; if (IS_ZEBRA_DEBUG_NHT) @@ -939,7 +941,7 @@ static void zread_rnh_unregister(ZAPI_HANDLER_ARGS) struct rnh *rnh; struct stream *s; struct prefix p; - u_short l = 0; + unsigned short l = 0; uint16_t type = cmd2type[hdr->command]; if (IS_ZEBRA_DEBUG_NHT) @@ -1000,7 +1002,7 @@ stream_failure: static void zread_fec_register(ZAPI_HANDLER_ARGS) { struct stream *s; - u_short l = 0; + unsigned short l = 0; struct prefix p; uint16_t flags; uint32_t label_index = MPLS_INVALID_LABEL_INDEX; @@ -1059,7 +1061,7 @@ stream_failure: static void zread_fec_unregister(ZAPI_HANDLER_ARGS) { struct stream *s; - u_short l = 0; + unsigned short l = 0; struct prefix p; uint16_t flags; @@ -1432,10 +1434,10 @@ static void zread_ipv4_add(ZAPI_HANDLER_ARGS) int i; struct route_entry *re; struct prefix p; - u_char message; + uint8_t message; struct in_addr nhop_addr; - u_char nexthop_num; - u_char nexthop_type; + uint8_t nexthop_num; + uint8_t nexthop_type; struct stream *s; ifindex_t ifindex; safi_t safi; @@ -1585,7 +1587,7 @@ static void zread_ipv4_delete(ZAPI_HANDLER_ARGS) struct stream *s; struct zapi_ipv4 api; struct prefix p; - u_int32_t table_id; + uint32_t table_id; s = msg; @@ -1638,9 +1640,9 @@ static void zread_ipv4_route_ipv6_nexthop_add(ZAPI_HANDLER_ARGS) struct stream *s; struct in6_addr nhop_addr; struct route_entry *re; - u_char message; - u_char nexthop_num; - u_char nexthop_type; + uint8_t message; + uint8_t nexthop_num; + uint8_t nexthop_type; struct prefix p; safi_t safi; static struct in6_addr nexthops[MULTIPATH_NUM]; @@ -1810,9 +1812,9 @@ static void zread_ipv6_add(ZAPI_HANDLER_ARGS) struct in6_addr nhop_addr; ifindex_t ifindex; struct route_entry *re; - u_char message; - u_char nexthop_num; - u_char nexthop_type; + uint8_t message; + uint8_t nexthop_num; + uint8_t nexthop_type; struct prefix p; struct prefix_ipv6 src_p, *src_pp; safi_t safi; @@ -2060,9 +2062,9 @@ static void zread_router_id_delete(ZAPI_HANDLER_ARGS) static void zread_hello(ZAPI_HANDLER_ARGS) { /* type of protocol (lib/zebra.h) */ - u_char proto; - u_short instance; - u_char notify; + uint8_t proto; + unsigned short instance; + uint8_t notify; STREAM_GETC(msg, proto); STREAM_GETW(msg, instance); @@ -2110,7 +2112,7 @@ static void zread_mpls_labels(ZAPI_HANDLER_ARGS) union g_addr gate; ifindex_t ifindex; mpls_label_t in_label, out_label; - u_int8_t distance; + uint8_t distance; /* Get input stream. */ s = msg; @@ -2185,13 +2187,67 @@ stream_failure: return; } +static int zsend_table_manager_connect_response(struct zserv *client, + vrf_id_t vrf_id, uint16_t result) +{ + struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); + + zclient_create_header(s, ZEBRA_TABLE_MANAGER_CONNECT, vrf_id); + + /* result */ + stream_putc(s, result); + + stream_putw_at(s, 0, stream_get_endp(s)); + + return zebra_server_send_message(client, s); +} + +/* Send response to a table manager connect request to client */ +static void zread_table_manager_connect(struct zserv *client, + struct stream *msg, + vrf_id_t vrf_id) +{ + struct stream *s; + uint8_t proto; + uint16_t instance; + + s = msg; + + /* Get data. */ + STREAM_GETC(s, proto); + STREAM_GETW(s, instance); + + /* accept only dynamic routing protocols */ + if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) { + zlog_err("client %d has wrong protocol %s", client->sock, + zebra_route_string(proto)); + zsend_table_manager_connect_response(client, vrf_id, 1); + return; + } + zlog_notice("client %d with vrf %u instance %u connected as %s", + client->sock, vrf_id, instance, zebra_route_string(proto)); + client->proto = proto; + client->instance = instance; + + /* + * Release previous labels of same protocol and instance. + * This is done in case it restarted from an unexpected shutdown. + */ + release_daemon_table_chunks(proto, instance); + + zsend_table_manager_connect_response(client, vrf_id, 0); + + stream_failure: + return; +} + static void zread_label_manager_connect(struct zserv *client, struct stream *msg, vrf_id_t vrf_id) { struct stream *s; /* type of protocol (lib/zebra.h) */ - u_char proto; - u_short instance; + uint8_t proto; + unsigned short instance; /* Get input stream. */ s = msg; @@ -2216,7 +2272,7 @@ static void zread_label_manager_connect(struct zserv *client, Release previous labels of same protocol and instance. This is done in case it restarted from an unexpected shutdown. */ - release_daemon_chunks(proto, instance); + release_daemon_label_chunks(proto, instance); zlog_debug( " Label Manager client connected: sock %d, proto %s, vrf %u instance %u", @@ -2224,7 +2280,7 @@ static void zread_label_manager_connect(struct zserv *client, /* send response back */ zsend_label_manager_connect_response(client, vrf_id, 0); -stream_failure: + stream_failure: return; } @@ -2232,7 +2288,7 @@ static void zread_get_label_chunk(struct zserv *client, struct stream *msg, vrf_id_t vrf_id) { struct stream *s; - u_char keep; + uint8_t keep; uint32_t size; struct label_manager_chunk *lmc; @@ -2304,6 +2360,92 @@ static void zread_label_manager_request(ZAPI_HANDLER_ARGS) } } +/* Send response to a get table chunk request to client */ +static int zsend_assign_table_chunk_response(struct zserv *client, + vrf_id_t vrf_id, + struct table_manager_chunk *tmc) +{ + struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); + + zclient_create_header(s, ZEBRA_GET_TABLE_CHUNK, vrf_id); + + if (tmc) { + /* start and end labels */ + stream_putl(s, tmc->start); + stream_putl(s, tmc->end); + } + + /* Write packet size. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return zebra_server_send_message(client, s); +} + +static void zread_get_table_chunk(struct zserv *client, struct stream *msg, + vrf_id_t vrf_id) +{ + struct stream *s; + uint32_t size; + struct table_manager_chunk *tmc; + + /* Get input stream. */ + s = msg; + + /* Get data. */ + STREAM_GETL(s, size); + + tmc = assign_table_chunk(client->proto, client->instance, size); + if (!tmc) + zlog_err("%s: Unable to assign Table Chunk of size %u", + __func__, size); + else + zlog_debug("Assigned Table Chunk %u - %u", tmc->start, + tmc->end); + /* send response back */ + zsend_assign_table_chunk_response(client, vrf_id, tmc); + +stream_failure: + return; +} + +static void zread_release_table_chunk(struct zserv *client, struct stream *msg) +{ + struct stream *s; + uint32_t start, end; + + /* Get input stream. */ + s = msg; + + /* Get data. */ + STREAM_GETL(s, start); + STREAM_GETL(s, end); + + release_table_chunk(client->proto, client->instance, start, end); + +stream_failure: + return; +} + +static void zread_table_manager_request(ZAPI_HANDLER_ARGS) +{ + /* to avoid sending other messages like ZERBA_INTERFACE_UP */ + if (hdr->command == ZEBRA_TABLE_MANAGER_CONNECT) + zread_table_manager_connect(client, msg, zvrf_id(zvrf)); + else { + /* Sanity: don't allow 'unidentified' requests */ + if (!client->proto) { + zlog_err( + "Got table request from an unidentified client"); + return; + } + if (hdr->command == ZEBRA_GET_TABLE_CHUNK) + zread_get_table_chunk(client, msg, + zvrf_id(zvrf)); + else if (hdr->command == ZEBRA_RELEASE_TABLE_CHUNK) + zread_release_table_chunk(client, msg); + } +} + static void zread_pseudowire(ZAPI_HANDLER_ARGS) { struct stream *s; @@ -2626,6 +2768,9 @@ void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = { [ZEBRA_PW_UNSET] = zread_pseudowire, [ZEBRA_RULE_ADD] = zread_rule, [ZEBRA_RULE_DELETE] = zread_rule, + [ZEBRA_TABLE_MANAGER_CONNECT] = zread_table_manager_request, + [ZEBRA_GET_TABLE_CHUNK] = zread_table_manager_request, + [ZEBRA_RELEASE_TABLE_CHUNK] = zread_table_manager_request, }; static inline void zserv_handle_commands(struct zserv *client, @@ -2657,7 +2802,10 @@ static void zebra_client_free(struct zserv *client) zebra_client_close_cleanup_rnh(client); /* Release Label Manager chunks */ - release_daemon_chunks(client->proto, client->instance); + release_daemon_label_chunks(client->proto, client->instance); + + /* Release Table Manager chunks */ + release_daemon_table_chunks(client->proto, client->instance); /* Cleanup any FECs registered by this client. */ zebra_mpls_cleanup_fecs_for_client(vrf_info_lookup(VRF_DEFAULT), @@ -2926,6 +3074,7 @@ static int zserv_process_messages(struct thread *thread) if (!hdrvalid) continue; + hdr.length -= ZEBRA_HEADER_SIZE; /* lookup vrf */ zvrf = zebra_vrf_lookup_by_id(hdr.vrf_id); if (!zvrf && IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) { @@ -3046,7 +3195,6 @@ static int zserv_read(struct thread *thread) #if defined(HANDLE_ZAPI_FUZZING) zserv_write_incoming(client->ibuf_work, command); #endif - hdr.length -= ZEBRA_HEADER_SIZE; /* Debug packet information. */ if (IS_ZEBRA_DEBUG_EVENT) @@ -3319,7 +3467,7 @@ static void zebra_show_client_brief(struct vty *vty, struct zserv *client) client->v6_route_del_cnt); } -struct zserv *zebra_find_client(u_char proto, u_short instance) +struct zserv *zebra_find_client(uint8_t proto, unsigned short instance) { struct listnode *node, *nnode; struct zserv *client; diff --git a/zebra/zserv.h b/zebra/zserv.h index 62707510c2..947e11e35b 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -83,44 +83,44 @@ struct zserv { bool notify_owner; /* client's protocol */ - u_char proto; - u_short instance; - u_char is_synchronous; + uint8_t proto; + unsigned short instance; + uint8_t is_synchronous; /* Statistics */ - u_int32_t redist_v4_add_cnt; - u_int32_t redist_v4_del_cnt; - u_int32_t redist_v6_add_cnt; - u_int32_t redist_v6_del_cnt; - u_int32_t v4_route_add_cnt; - u_int32_t v4_route_upd8_cnt; - u_int32_t v4_route_del_cnt; - u_int32_t v6_route_add_cnt; - u_int32_t v6_route_del_cnt; - u_int32_t v6_route_upd8_cnt; - u_int32_t connected_rt_add_cnt; - u_int32_t connected_rt_del_cnt; - u_int32_t ifup_cnt; - u_int32_t ifdown_cnt; - u_int32_t ifadd_cnt; - u_int32_t ifdel_cnt; - u_int32_t if_bfd_cnt; - u_int32_t bfd_peer_add_cnt; - u_int32_t bfd_peer_upd8_cnt; - u_int32_t bfd_peer_del_cnt; - u_int32_t bfd_peer_replay_cnt; - u_int32_t vrfadd_cnt; - u_int32_t vrfdel_cnt; - u_int32_t if_vrfchg_cnt; - u_int32_t bfd_client_reg_cnt; - u_int32_t vniadd_cnt; - u_int32_t vnidel_cnt; - u_int32_t l3vniadd_cnt; - u_int32_t l3vnidel_cnt; - u_int32_t macipadd_cnt; - u_int32_t macipdel_cnt; - u_int32_t prefixadd_cnt; - u_int32_t prefixdel_cnt; + uint32_t redist_v4_add_cnt; + uint32_t redist_v4_del_cnt; + uint32_t redist_v6_add_cnt; + uint32_t redist_v6_del_cnt; + uint32_t v4_route_add_cnt; + uint32_t v4_route_upd8_cnt; + uint32_t v4_route_del_cnt; + uint32_t v6_route_add_cnt; + uint32_t v6_route_del_cnt; + uint32_t v6_route_upd8_cnt; + uint32_t connected_rt_add_cnt; + uint32_t connected_rt_del_cnt; + uint32_t ifup_cnt; + uint32_t ifdown_cnt; + uint32_t ifadd_cnt; + uint32_t ifdel_cnt; + uint32_t if_bfd_cnt; + uint32_t bfd_peer_add_cnt; + uint32_t bfd_peer_upd8_cnt; + uint32_t bfd_peer_del_cnt; + uint32_t bfd_peer_replay_cnt; + uint32_t vrfadd_cnt; + uint32_t vrfdel_cnt; + uint32_t if_vrfchg_cnt; + uint32_t bfd_client_reg_cnt; + uint32_t vniadd_cnt; + uint32_t vnidel_cnt; + uint32_t l3vniadd_cnt; + uint32_t l3vnidel_cnt; + uint32_t macipadd_cnt; + uint32_t macipdel_cnt; + uint32_t prefixadd_cnt; + uint32_t prefixdel_cnt; time_t connect_time; time_t last_read_time; @@ -144,7 +144,7 @@ struct zebra_t { struct list *client_list; /* default table */ - u_int32_t rtm_table_default; + uint32_t rtm_table_default; /* rib work queue */ #define ZEBRA_RIB_PROCESS_HOLD_TIME 10 @@ -155,7 +155,7 @@ struct zebra_t { struct work_queue *lsp_process_q; #define ZEBRA_ZAPI_PACKETS_TO_PROCESS 10 - u_int32_t packets_to_process; + uint32_t packets_to_process; }; extern struct zebra_t zebrad; extern unsigned int multipath_num; @@ -195,7 +195,7 @@ extern void zserv_nexthop_num_warn(const char *, const struct prefix *, const unsigned int); extern int zebra_server_send_message(struct zserv *client, struct stream *msg); -extern struct zserv *zebra_find_client(u_char proto, u_short instance); +extern struct zserv *zebra_find_client(uint8_t proto, unsigned short instance); #if defined(HANDLE_ZAPI_FUZZING) extern void zserv_read_file(char *input); |
