diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-05-02 02:37:45 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2017-11-30 22:17:59 +0100 |
commit | 424ab01d0f69a71b865e5f2d817baea7ce263e44 (patch) | |
tree | 82f06cf1dae116f6db05cd5409475a6f8b6dcf1e /bgpd/bgp_attr.c | |
parent | bgpd: move bgp i/o to a separate source file (diff) | |
download | frr-424ab01d0f69a71b865e5f2d817baea7ce263e44.tar.xz frr-424ab01d0f69a71b865e5f2d817baea7ce263e44.zip |
bgpd: implement buffered reads
* Move and modify all network input related code to bgp_io.c
* Add a real input buffer to `struct peer`
* Move connection initialization to its own thread.c task instead of
piggybacking off of bgp_read()
* Tons of little fixups
Primary changes are in bgp_packet.[ch], bgp_io.[ch], bgp_fsm.[ch].
Changes made elsewhere are almost exclusively refactoring peer->ibuf to
peer->curr since peer->ibuf is now the true FIFO packet input buffer
while peer->curr represents the packet currently being processed by the
main pthread.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'bgpd/bgp_attr.c')
-rw-r--r-- | bgpd/bgp_attr.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 6ddb2ec8a..859158e3c 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1156,7 +1156,7 @@ static int bgp_attr_aspath(struct bgp_attr_parser_args *args) * peer with AS4 => will get 4Byte ASnums * otherwise, will get 16 Bit */ - attr->aspath = aspath_parse(peer->ibuf, length, + attr->aspath = aspath_parse(peer->curr, length, CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)); /* In case of IBGP, length will be zero. */ @@ -1230,7 +1230,7 @@ static int bgp_attr_as4_path(struct bgp_attr_parser_args *args, struct attr *const attr = args->attr; const bgp_size_t length = args->length; - *as4_path = aspath_parse(peer->ibuf, length, 1); + *as4_path = aspath_parse(peer->curr, length, 1); /* In case of IBGP, length will be zero. */ if (!*as4_path) { @@ -1271,7 +1271,7 @@ static bgp_attr_parse_ret_t bgp_attr_nexthop(struct bgp_attr_parser_args *args) logged locally (this is implemented somewhere else). The UPDATE message gets ignored in any of these cases. */ - nexthop_n = stream_get_ipv4(peer->ibuf); + nexthop_n = stream_get_ipv4(peer->curr); nexthop_h = ntohl(nexthop_n); if ((IPV4_NET0(nexthop_h) || IPV4_NET127(nexthop_h) || IPV4_CLASS_DE(nexthop_h)) @@ -1307,7 +1307,7 @@ static bgp_attr_parse_ret_t bgp_attr_med(struct bgp_attr_parser_args *args) args->total); } - attr->med = stream_getl(peer->ibuf); + attr->med = stream_getl(peer->curr); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC); @@ -1333,11 +1333,11 @@ bgp_attr_local_pref(struct bgp_attr_parser_args *args) external peer, then this attribute MUST be ignored by the receiving speaker. */ if (peer->sort == BGP_PEER_EBGP) { - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); return BGP_ATTR_PARSE_PROCEED; } - attr->local_pref = stream_getl(peer->ibuf); + attr->local_pref = stream_getl(peer->curr); /* Set the local-pref flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); @@ -1386,10 +1386,10 @@ static int bgp_attr_aggregator(struct bgp_attr_parser_args *args) } if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)) - attr->aggregator_as = stream_getl(peer->ibuf); + attr->aggregator_as = stream_getl(peer->curr); else - attr->aggregator_as = stream_getw(peer->ibuf); - attr->aggregator_addr.s_addr = stream_get_ipv4(peer->ibuf); + attr->aggregator_as = stream_getw(peer->curr); + attr->aggregator_addr.s_addr = stream_get_ipv4(peer->curr); /* Set atomic aggregate flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR); @@ -1413,8 +1413,8 @@ bgp_attr_as4_aggregator(struct bgp_attr_parser_args *args, 0); } - *as4_aggregator_as = stream_getl(peer->ibuf); - as4_aggregator_addr->s_addr = stream_get_ipv4(peer->ibuf); + *as4_aggregator_as = stream_getl(peer->curr); + as4_aggregator_addr->s_addr = stream_get_ipv4(peer->curr); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_AGGREGATOR); @@ -1540,10 +1540,10 @@ bgp_attr_community(struct bgp_attr_parser_args *args) } attr->community = - community_parse((u_int32_t *)stream_pnt(peer->ibuf), length); + community_parse((u_int32_t *)stream_pnt(peer->curr), length); /* XXX: fix community_parse to use stream API and remove this */ - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); if (!attr->community) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, @@ -1570,7 +1570,7 @@ bgp_attr_originator_id(struct bgp_attr_parser_args *args) args->total); } - attr->originator_id.s_addr = stream_get_ipv4(peer->ibuf); + attr->originator_id.s_addr = stream_get_ipv4(peer->curr); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID); @@ -1594,10 +1594,10 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) } attr->cluster = - cluster_parse((struct in_addr *)stream_pnt(peer->ibuf), length); + cluster_parse((struct in_addr *)stream_pnt(peer->curr), length); /* XXX: Fix cluster_parse to use stream API and then remove this */ - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST); @@ -1778,7 +1778,7 @@ int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, struct attr *const attr = args->attr; const bgp_size_t length = args->length; - s = peer->ibuf; + s = peer->curr; #define BGP_MP_UNREACH_MIN_SIZE 3 if ((length > STREAM_READABLE(s)) || (length < BGP_MP_UNREACH_MIN_SIZE)) @@ -1832,9 +1832,9 @@ bgp_attr_large_community(struct bgp_attr_parser_args *args) } attr->lcommunity = - lcommunity_parse((u_int8_t *)stream_pnt(peer->ibuf), length); + lcommunity_parse((u_int8_t *)stream_pnt(peer->curr), length); /* XXX: fix ecommunity_parse to use stream API */ - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); if (!attr->lcommunity) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, @@ -1861,9 +1861,9 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args) } attr->ecommunity = - ecommunity_parse((u_int8_t *)stream_pnt(peer->ibuf), length); + ecommunity_parse((u_int8_t *)stream_pnt(peer->curr), length); /* XXX: fix ecommunity_parse to use stream API */ - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); if (!attr->ecommunity) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, @@ -1957,7 +1957,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ + sublength); tlv->type = subtype; tlv->length = sublength; - stream_get(tlv->value, peer->ibuf, sublength); + stream_get(tlv->value, peer->curr, sublength); length -= sublength; /* attach tlv to encap chain */ @@ -2025,8 +2025,8 @@ bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID); - type = stream_getc(peer->ibuf); - length = stream_getw(peer->ibuf); + type = stream_getc(peer->curr); + length = stream_getw(peer->curr); if (type == BGP_PREFIX_SID_LABEL_INDEX) { if (length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) { @@ -2039,11 +2039,11 @@ bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, } /* Ignore flags and reserved */ - stream_getc(peer->ibuf); - stream_getw(peer->ibuf); + stream_getc(peer->curr); + stream_getw(peer->curr); /* Fetch the label index and see if it is valid. */ - label_index = stream_getl(peer->ibuf); + label_index = stream_getl(peer->curr); if (label_index == BGP_INVALID_LABEL_INDEX) return bgp_attr_malformed( args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, @@ -2074,16 +2074,16 @@ bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, } /* Ignore reserved */ - stream_getc(peer->ibuf); - stream_getw(peer->ibuf); + stream_getc(peer->curr); + stream_getw(peer->curr); - stream_get(&ipv6_sid, peer->ibuf, 16); + stream_get(&ipv6_sid, peer->curr, 16); } /* Placeholder code for the Originator SRGB type */ else if (type == BGP_PREFIX_SID_ORIGINATOR_SRGB) { /* Ignore flags */ - stream_getw(peer->ibuf); + stream_getw(peer->curr); length -= 2; @@ -2099,8 +2099,8 @@ bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, srgb_count = length / BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH; for (int i = 0; i < srgb_count; i++) { - stream_get(&srgb_base, peer->ibuf, 3); - stream_get(&srgb_range, peer->ibuf, 3); + stream_get(&srgb_base, peer->curr, 3); + stream_get(&srgb_range, peer->curr, 3); } } @@ -2125,7 +2125,7 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args) peer->host, type, length); /* Forward read pointer of input stream. */ - stream_forward_getp(peer->ibuf, length); + stream_forward_getp(peer->curr, length); /* If any of the mandatory well-known attributes are not recognized, then the Error Subcode is set to Unrecognized Well-known |