routing: add abitity to set the protocol that installed route/nexthop.
Routing daemons such as bird need to know if they install certain route so they can clean it up on startup, as a form of achieving consistent state during the crash recovery. Currently they use combination of routing flags (RTF_PROTO1) to detect these routes when interacting via route(4) rtsock protocol. Netlink protocol has a special "rtm_protocol" field that is filled and checked by the route originator. To prepare for the upcoming netlink introduction, add ability to record origing to both nexthops and nexthop groups via <nhop|nhgrp>_<get|set>_origin() KPI. The actual calls will be used in the followup commits. MFC after: 1 month
This commit is contained in:
parent
bab32a8029
commit
000250be0d
@ -217,6 +217,7 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway,
|
||||
nhop_set_pxtype_flag(nh, NHF_HOST);
|
||||
nhop_set_expire(nh, lifetime_sec + time_uptime);
|
||||
nhop_set_redirect(nh, true);
|
||||
nhop_set_origin(nh, NH_ORIGIN_REDIRECT);
|
||||
rnd.rnd_nhop = nhop_get_nhop(nh, &error);
|
||||
if (error == 0) {
|
||||
error = rib_add_route_px(fibnum, dst, -1,
|
||||
|
@ -852,6 +852,18 @@ nhgrp_get_idx(const struct nhgrp_object *nhg)
|
||||
return (nhg_priv->nhg_idx);
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nhgrp_get_origin(struct nhgrp_object *nhg)
|
||||
{
|
||||
return (NHGRP_PRIV(nhg)->nhg_origin);
|
||||
}
|
||||
|
||||
void
|
||||
nhgrp_set_origin(struct nhgrp_object *nhg, uint8_t origin)
|
||||
{
|
||||
NHGRP_PRIV(nhg)->nhg_origin = origin;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
nhgrp_get_count(struct rib_head *rh)
|
||||
{
|
||||
|
@ -49,7 +49,8 @@ struct nhgrp_priv {
|
||||
uint32_t nhg_idx;
|
||||
uint32_t nhg_uidx;
|
||||
uint8_t nhg_nh_count; /* number of items in nh_weights */
|
||||
uint8_t nhg_spare[3];
|
||||
uint8_t nhg_origin; /* protocol which created the group */
|
||||
uint8_t nhg_spare[2];
|
||||
u_int nhg_refcount; /* use refcount */
|
||||
u_int nhg_linked; /* refcount(9), == 2 if linked to the list */
|
||||
struct nh_control *nh_control; /* parent control structure */
|
||||
|
@ -199,6 +199,14 @@ void nhop_set_type(struct nhop_object *nh, enum nhop_type nh_type);
|
||||
void nhop_set_src(struct nhop_object *nh, struct ifaddr *ifa);
|
||||
void nhop_set_transmit_ifp(struct nhop_object *nh, struct ifnet *ifp);
|
||||
|
||||
#define NH_ORIGIN_UNSPEC 0 /* not set */
|
||||
#define NH_ORIGIN_REDIRECT 1 /* kernel-originated redirect */
|
||||
#define NH_ORIGIN_KERNEL 2 /* kernel (interface) routes */
|
||||
#define NH_ORIGIN_BOOT 3 /* kernel-originated routes at boot */
|
||||
#define NH_ORIGIN_STATIC 4 /* route(8) routes */
|
||||
void nhop_set_origin(struct nhop_object *nh, uint8_t origin);
|
||||
uint8_t nhop_get_origin(struct nhop_object *nh);
|
||||
|
||||
uint32_t nhop_get_idx(const struct nhop_object *nh);
|
||||
uint32_t nhop_get_uidx(const struct nhop_object *nh);
|
||||
void nhop_set_uidx(struct nhop_object *nh, uint32_t uidx);
|
||||
@ -217,6 +225,8 @@ struct rib_head *nhop_get_rh(const struct nhop_object *nh);
|
||||
|
||||
struct nhgrp_object;
|
||||
uint32_t nhgrp_get_uidx(const struct nhgrp_object *nhg);
|
||||
uint8_t nhgrp_get_origin(struct nhgrp_object *nhg);
|
||||
void nhgrp_set_origin(struct nhgrp_object *nhg, uint8_t origin);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
/* Kernel <> userland structures */
|
||||
|
@ -1012,6 +1012,18 @@ nhop_get_rh(const struct nhop_object *nh)
|
||||
return (rt_tables_get_rnh(fibnum, family));
|
||||
}
|
||||
|
||||
uint8_t
|
||||
nhop_get_origin(struct nhop_object *nh)
|
||||
{
|
||||
return (nh->nh_priv->nh_origin);
|
||||
}
|
||||
|
||||
void
|
||||
nhop_set_origin(struct nhop_object *nh, uint8_t origin)
|
||||
{
|
||||
nh->nh_priv->nh_origin = origin;
|
||||
}
|
||||
|
||||
void
|
||||
nhops_update_ifmtu(struct rib_head *rh, struct ifnet *ifp, uint32_t mtu)
|
||||
{
|
||||
|
@ -87,6 +87,7 @@ struct nhop_priv {
|
||||
u_int nh_refcnt; /* number of references, refcount(9) */
|
||||
u_int nh_linked; /* refcount(9), == 2 if linked to the list */
|
||||
int nh_finalized; /* non-zero if finalized() was called */
|
||||
uint8_t nh_origin; /* protocol that originated the nexthop */
|
||||
struct nhop_object *nh; /* backreference to the dataplane nhop */
|
||||
struct nh_control *nh_control; /* backreference to the rnh */
|
||||
struct nhop_priv *nh_next; /* hash table membership */
|
||||
|
@ -622,6 +622,7 @@ rib_copy_route(struct rtentry *rt, const struct route_nhop_data *rnd_src,
|
||||
return (ENOMEM);
|
||||
}
|
||||
nhop_copy(nh, rnd_src->rnd_nhop);
|
||||
nhop_set_origin(nh, nhop_get_origin(rnd_src->rnd_nhop));
|
||||
nhop_set_fibnum(nh, rh_dst->rib_fibnum);
|
||||
nh = nhop_get_nhop_internal(rh_dst, nh, &error);
|
||||
if (error != 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user