Merge pull request #3390 from pguibert6WIND/bgp_flowspec_new_redirect_ip_draft

bgpd: add new draft for redirect ip for flowspec
This commit is contained in:
Donald Sharp 2018-11-30 18:36:25 -05:00 committed by GitHub
commit ad395eb3d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 8 deletions

View File

@ -688,9 +688,23 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
/* Low-order octet of type. */
sub_type = *pnt++;
if (sub_type != ECOMMUNITY_ROUTE_TARGET
&& sub_type != ECOMMUNITY_SITE_ORIGIN)
unk_ecom = 1;
else
&& sub_type != ECOMMUNITY_SITE_ORIGIN) {
if (sub_type ==
ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 &&
type == ECOMMUNITY_ENCODE_IP) {
struct in_addr *ipv4 =
(struct in_addr *)pnt;
char ipv4str[INET_ADDRSTRLEN];
inet_ntop(AF_INET, ipv4,
ipv4str,
INET_ADDRSTRLEN);
len = sprintf(str_buf + str_pnt,
"NH:%s:%d",
ipv4str, pnt[5]);
} else
unk_ecom = 1;
} else
len = ecommunity_rt_soo_str(str_buf + str_pnt,
pnt, type, sub_type,
format);

View File

@ -41,6 +41,10 @@
#define ECOMMUNITY_REDIRECT_VRF 0x08
#define ECOMMUNITY_TRAFFIC_MARKING 0x09
#define ECOMMUNITY_REDIRECT_IP_NH 0x00
/* from IANA: bgp-extended-communities/bgp-extended-communities.xhtml
* 0x0c Flow-spec Redirect to IPv4 - draft-ietf-idr-flowspec-redirect
*/
#define ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4 0x0c
/* Low-order octet of the Extended Communities type field for EVPN types */
#define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY 0x00

View File

@ -315,7 +315,8 @@ void route_vty_out_flowspec(struct vty *vty, struct prefix *p,
}
if (attr->nexthop.s_addr != 0 &&
display == NLRI_STRING_FORMAT_LARGE)
vty_out(vty, "\tNH %-16s\n", inet_ntoa(attr->nexthop));
vty_out(vty, "\tNLRI NH %-16s\n",
inet_ntoa(attr->nexthop));
XFREE(MTYPE_ECOMMUNITY_STR, s);
}
peer_uptime(path->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL);

View File

@ -638,6 +638,7 @@ static int bgp_pbr_build_and_validate_entry(struct prefix *p,
struct prefix *src = NULL, *dst = NULL;
int valid_prefix = 0;
afi_t afi = AFI_IP;
struct bgp_pbr_entry_action *api_action_redirect_ip = NULL;
/* extract match from flowspec entries */
ret = bgp_flowspec_match_rules_fill((uint8_t *)p->u.prefix_flowspec.ptr,
@ -688,10 +689,55 @@ static int bgp_pbr_build_and_validate_entry(struct prefix *p,
(char)ECOMMUNITY_ENCODE_REDIRECT_IP_NH) &&
(ecom_eval->val[1] ==
(char)ECOMMUNITY_REDIRECT_IP_NH)) {
api_action->action = ACTION_REDIRECT_IP;
api_action->u.zr.redirect_ip_v4.s_addr =
path->attr->nexthop.s_addr;
api_action->u.zr.duplicate = ecom_eval->val[7];
/* in case the 2 ecom present,
* do not overwrite
* draft-ietf-idr-flowspec-redirect
*/
if (api_action_redirect_ip) {
if (api_action_redirect_ip->u
.zr.redirect_ip_v4.s_addr)
continue;
if (!path->attr->nexthop.s_addr)
continue;
api_action_redirect_ip->u
.zr.redirect_ip_v4.s_addr =
path->attr->nexthop.s_addr;
api_action_redirect_ip->u.zr.duplicate
= ecom_eval->val[7];
continue;
} else {
api_action->action = ACTION_REDIRECT_IP;
api_action->u.zr.redirect_ip_v4.s_addr =
path->attr->nexthop.s_addr;
api_action->u.zr.duplicate =
ecom_eval->val[7];
api_action_redirect_ip = api_action;
}
} else if ((ecom_eval->val[0] ==
(char)ECOMMUNITY_ENCODE_IP) &&
(ecom_eval->val[1] ==
(char)ECOMMUNITY_FLOWSPEC_REDIRECT_IPV4)) {
/* in case the 2 ecom present,
* overwrite simpson draft
* update redirect ip fields
*/
if (api_action_redirect_ip) {
memcpy(&(api_action_redirect_ip->u
.zr.redirect_ip_v4.s_addr),
(ecom_eval->val+2), 4);
api_action_redirect_ip->u
.zr.duplicate =
ecom_eval->val[7];
continue;
} else {
api_action->action = ACTION_REDIRECT_IP;
memcpy(&(api_action->u
.zr.redirect_ip_v4.s_addr),
(ecom_eval->val+2), 4);
api_action->u.zr.duplicate =
ecom_eval->val[7];
api_action_redirect_ip = api_action;
}
} else {
if (ecom_eval->val[0] !=
(char)ECOMMUNITY_ENCODE_TRANS_EXP)