-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zebra neigh update #15179
Zebra neigh update #15179
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,24 +75,6 @@ static void nhrp_route_update_zebra(const struct prefix *p, | |
} | ||
} | ||
|
||
static void nhrp_zebra_register_neigh(vrf_id_t vrf_id, afi_t afi, bool reg) | ||
{ | ||
struct stream *s; | ||
|
||
if (!zclient || zclient->sock < 0) | ||
return; | ||
|
||
s = zclient->obuf; | ||
stream_reset(s); | ||
|
||
zclient_create_header(s, reg ? ZEBRA_NHRP_NEIGH_REGISTER : | ||
ZEBRA_NHRP_NEIGH_UNREGISTER, | ||
vrf_id); | ||
stream_putw(s, afi); | ||
stream_putw_at(s, 0, stream_get_endp(s)); | ||
zclient_send_message(zclient); | ||
} | ||
|
||
void nhrp_route_update_nhrp(const struct prefix *p, struct interface *ifp) | ||
{ | ||
struct route_node *rn; | ||
|
@@ -368,18 +350,18 @@ static void nhrp_zebra_connected(struct zclient *zclient) | |
ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT); | ||
zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, | ||
ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT); | ||
nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP, true); | ||
nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP6, true); | ||
zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP, true); | ||
zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP6, true); | ||
} | ||
|
||
static zclient_handler *const nhrp_handlers[] = { | ||
[ZEBRA_INTERFACE_ADDRESS_ADD] = nhrp_interface_address_add, | ||
[ZEBRA_INTERFACE_ADDRESS_DELETE] = nhrp_interface_address_delete, | ||
[ZEBRA_REDISTRIBUTE_ROUTE_ADD] = nhrp_route_read, | ||
[ZEBRA_REDISTRIBUTE_ROUTE_DEL] = nhrp_route_read, | ||
[ZEBRA_NHRP_NEIGH_ADDED] = nhrp_neighbor_operation, | ||
[ZEBRA_NHRP_NEIGH_REMOVED] = nhrp_neighbor_operation, | ||
[ZEBRA_NHRP_NEIGH_GET] = nhrp_neighbor_operation, | ||
[ZEBRA_NEIGH_ADDED] = nhrp_neighbor_operation, | ||
[ZEBRA_NEIGH_REMOVED] = nhrp_neighbor_operation, | ||
[ZEBRA_NEIGH_GET] = nhrp_neighbor_operation, | ||
[ZEBRA_GRE_UPDATE] = nhrp_gre_update, | ||
}; | ||
|
||
|
@@ -456,10 +438,11 @@ void nhrp_send_zebra_nbr(union sockunion *in, | |
return; | ||
s = zclient->obuf; | ||
stream_reset(s); | ||
zclient_neigh_ip_encode(s, out ? ZEBRA_NEIGH_IP_ADD : | ||
ZEBRA_NEIGH_IP_DEL, in, out, | ||
ifp, out ? ZEBRA_NEIGH_STATE_REACHABLE | ||
: ZEBRA_NEIGH_STATE_FAILED); | ||
zclient_neigh_ip_encode(s, out ? ZEBRA_NEIGH_IP_ADD : ZEBRA_NEIGH_IP_DEL, | ||
in, out, ifp, | ||
out ? ZEBRA_NEIGH_STATE_REACHABLE | ||
: ZEBRA_NEIGH_STATE_FAILED, | ||
0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add comment of the meaning of 0 (hardcoded value) 0); // meaning something cool This is the ip_len. Why are you using 0? |
||
stream_putw_at(s, 0, stream_get_endp(s)); | ||
zclient_send_message(zclient); | ||
} | ||
|
@@ -471,8 +454,8 @@ int nhrp_send_zebra_gre_request(struct interface *ifp) | |
|
||
void nhrp_zebra_terminate(void) | ||
{ | ||
nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP, false); | ||
nhrp_zebra_register_neigh(VRF_DEFAULT, AFI_IP6, false); | ||
zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP, false); | ||
zclient_register_neigh(zclient, VRF_DEFAULT, AFI_IP6, false); | ||
zclient_stop(zclient); | ||
zclient_free(zclient); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,32 @@ | |
|
||
DEFINE_MTYPE_STATIC(SHARPD, SRV6_LOCATOR, "SRv6 Locator"); | ||
|
||
DEFPY(watch_neighbor, watch_neighbor_cmd, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a v6 watch too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a Proof of Concept bit of code. I don't mind having it and I don't mind not having it. An end operator is not likely to ever use this. |
||
"sharp watch [vrf NAME$vrf_name] neighbor", | ||
"Sharp routing Protocol\n" | ||
"Watch for changes\n" | ||
"The vrf we would like to watch if non-default\n" | ||
"The NAME of the vrf\n" | ||
"Neighbor events\n") | ||
{ | ||
struct vrf *vrf; | ||
|
||
if (!vrf_name) | ||
vrf_name = VRF_DEFAULT_NAME; | ||
vrf = vrf_lookup_by_name(vrf_name); | ||
|
||
if (!vrf) { | ||
vty_out(vty, "The vrf NAME specified: %s does not exist\n", | ||
vrf_name); | ||
return CMD_WARNING; | ||
} | ||
|
||
sharp_zebra_register_neigh(vrf->vrf_id, AFI_IP, true); | ||
|
||
return CMD_SUCCESS; | ||
} | ||
|
||
|
||
DEFPY(watch_redistribute, watch_redistribute_cmd, | ||
"sharp watch [vrf NAME$vrf_name] redistribute " FRR_REDIST_STR_SHARPD, | ||
"Sharp routing Protocol\n" | ||
|
@@ -1419,6 +1445,7 @@ void sharp_vty_init(void) | |
install_element(ENABLE_NODE, &remove_routes_cmd); | ||
install_element(ENABLE_NODE, &vrf_label_cmd); | ||
install_element(ENABLE_NODE, &sharp_nht_data_dump_cmd); | ||
install_element(ENABLE_NODE, &watch_neighbor_cmd); | ||
install_element(ENABLE_NODE, &watch_redistribute_cmd); | ||
install_element(ENABLE_NODE, &watch_nexthop_v6_cmd); | ||
install_element(ENABLE_NODE, &watch_nexthop_v4_cmd); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -989,6 +989,41 @@ static int sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) | |
return 0; | ||
} | ||
|
||
static int sharp_zebra_process_neigh(ZAPI_CALLBACK_ARGS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function always return 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit of a historical baggage that is carried around at the moment, that needs to be cleaned up. The original code all had this idea of returning error messages. But whenever a non-zero was returned it was always ignored. When the current handler code was abstracted, by Quentin, to use arrays of function pointers it got carried over. The original coder of a lot of functionality in FRR had this idea of returning 0 or 1 for success and immediately throwing the answer away and never using it. We've cleaned up large swaths. This is just another example of something that needs to be fixed from my perspective. |
||
{ | ||
union sockunion addr = {}, lladdr = {}; | ||
struct zapi_neigh_ip api = {}; | ||
struct interface *ifp; | ||
|
||
zlog_debug("Received a neighbor event"); | ||
zclient_neigh_ip_decode(zclient->ibuf, &api); | ||
|
||
if (api.ip_in.ipa_type == AF_UNSPEC) | ||
return 0; | ||
|
||
sockunion_family(&addr) = api.ip_in.ipa_type; | ||
memcpy((uint8_t *)sockunion_get_addr(&addr), &api.ip_in.ip.addr, | ||
family2addrsize(api.ip_in.ipa_type)); | ||
|
||
sockunion_family(&lladdr) = api.ip_out.ipa_type; | ||
if (api.ip_out.ipa_type != AF_UNSPEC) | ||
memcpy((uint8_t *)sockunion_get_addr(&lladdr), | ||
&api.ip_out.ip.addr, | ||
family2addrsize(api.ip_out.ipa_type)); | ||
ifp = if_lookup_by_index(api.index, vrf_id); | ||
if (!ifp) { | ||
zlog_debug("Failed to lookup interface for neighbor entry: %u for %u", | ||
api.index, vrf_id); | ||
return 0; | ||
} | ||
|
||
zlog_debug("Received: %s %pSU dev %s lladr %pSU", | ||
(cmd = ZEBRA_NEIGH_ADDED) ? "NEW" : "DEL", &addr, ifp->name, | ||
&lladdr); | ||
|
||
return 0; | ||
} | ||
|
||
int sharp_zebra_send_interface_protodown(struct interface *ifp, bool down) | ||
{ | ||
zlog_debug("Sending zebra to set %s protodown %s", ifp->name, | ||
|
@@ -1059,6 +1094,12 @@ int sharp_zebra_send_tc_filter_rate(struct interface *ifp, | |
return 0; | ||
} | ||
|
||
void sharp_zebra_register_neigh(vrf_id_t vrf_id, afi_t afi, bool reg) | ||
{ | ||
zclient_register_neigh(zclient, vrf_id, afi, reg); | ||
} | ||
|
||
|
||
static zclient_handler *const sharp_handlers[] = { | ||
[ZEBRA_INTERFACE_ADDRESS_ADD] = interface_address_add, | ||
[ZEBRA_INTERFACE_ADDRESS_DELETE] = interface_address_delete, | ||
|
@@ -1070,6 +1111,8 @@ static zclient_handler *const sharp_handlers[] = { | |
[ZEBRA_OPAQUE_NOTIFY] = sharp_opq_notify_handler, | ||
[ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = | ||
sharp_zebra_process_srv6_locator_chunk, | ||
[ZEBRA_NEIGH_ADDED] = sharp_zebra_process_neigh, | ||
[ZEBRA_NEIGH_REMOVED] = sharp_zebra_process_neigh, | ||
}; | ||
|
||
void sharp_zebra_init(void) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a comment on why you are allowing only /32 is welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol. That is what the original code did. I just moved it from Zebra to up into nhrpd. I don't fully understand it but if I had to guess it's a RTM_NEIGH entry where the lladr is set to a v4 address. I left it alone mainly because I didn't know and didn't want to take the time to figure it out.