Changeset View
Changeset View
Standalone View
Standalone View
sys/net/route/route_ctl.c
Show First 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
#include <netinet/in.h> | #include <netinet/in.h> | ||||
#include <netinet6/scope6_var.h> | #include <netinet6/scope6_var.h> | ||||
#include <vm/uma.h> | #include <vm/uma.h> | ||||
#define DEBUG_MOD_NAME route_ctl | #define DEBUG_MOD_NAME route_ctl | ||||
#define DEBUG_MAX_LEVEL LOG_DEBUG | #define DEBUG_MAX_LEVEL LOG_DEBUG | ||||
#include <net/route/route_debug.h> | #include <net/route/route_debug.h> | ||||
_DECLARE_DEBUG(LOG_INFO); | _DECLARE_DEBUG(LOG_DEBUG3); | ||||
/* | /* | ||||
* This file contains control plane routing tables functions. | * This file contains control plane routing tables functions. | ||||
* | * | ||||
* All functions assumes they are called in net epoch. | * All functions assumes they are called in net epoch. | ||||
*/ | */ | ||||
struct rib_subscription { | struct rib_subscription { | ||||
▲ Show 20 Lines • Show All 1,368 Lines • ▼ Show 20 Lines | rib_print_family(int family) | ||||
case AF_LINK: | case AF_LINK: | ||||
return ("link"); | return ("link"); | ||||
} | } | ||||
return ("unknown"); | return ("unknown"); | ||||
} | } | ||||
static void | static void | ||||
rib_notify(struct rib_head *rnh, enum rib_subscription_type type, | rib_notify(struct rib_head *rnh, enum rib_subscription_type type, | ||||
struct rib_cmd_info *rc) | struct rib_cmd_info *rc) | ||||
glebius: Why not static? | |||||
{ | { | ||||
struct rib_subscription *rs; | struct rib_subscription *rs; | ||||
CK_STAILQ_FOREACH(rs, &rnh->rnh_subscribers, next) { | CK_STAILQ_FOREACH(rs, &rnh->rnh_subscribers, next) { | ||||
if (rs->type == type) | if (rs->type == type) | ||||
rs->func(rnh, rc, rs->arg); | rs->func(rnh, rc, rs->arg); | ||||
} | } | ||||
} | } | ||||
Done Inline ActionsBoth tailq head and mutex can be initialized with standard initializer macros. glebius: Both tailq head and mutex can be initialized with standard initializer macros. | |||||
static struct rib_subscription * | static struct rib_subscription * | ||||
allocate_subscription(rib_subscription_cb_t *f, void *arg, | allocate_subscription(rib_subscription_cb_t *f, void *arg, | ||||
enum rib_subscription_type type, bool waitok) | enum rib_subscription_type type, bool waitok) | ||||
{ | { | ||||
struct rib_subscription *rs; | struct rib_subscription *rs; | ||||
int flags = M_ZERO | (waitok ? M_WAITOK : M_NOWAIT); | int flags = M_ZERO | (waitok ? M_WAITOK : M_NOWAIT); | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | rib_destroy_subscriptions(struct rib_head *rnh) | ||||
while ((rs = CK_STAILQ_FIRST(&rnh->rnh_subscribers)) != NULL) { | while ((rs = CK_STAILQ_FIRST(&rnh->rnh_subscribers)) != NULL) { | ||||
CK_STAILQ_REMOVE_HEAD(&rnh->rnh_subscribers, next); | CK_STAILQ_REMOVE_HEAD(&rnh->rnh_subscribers, next); | ||||
epoch_call(net_epoch_preempt, destroy_subscription_epoch, | epoch_call(net_epoch_preempt, destroy_subscription_epoch, | ||||
&rs->epoch_ctx); | &rs->epoch_ctx); | ||||
} | } | ||||
RIB_WUNLOCK(rnh); | RIB_WUNLOCK(rnh); | ||||
NET_EPOCH_EXIT(et); | NET_EPOCH_EXIT(et); | ||||
} | } | ||||
CK_STAILQ_HEAD(rib_event_bridge_head, rib_event_bridge); | |||||
static struct rib_event_bridge_head bridge_head; | |||||
struct mtx bridge_lock; | |||||
static void | |||||
rib_bridge_init(void) | |||||
{ | |||||
CK_STAILQ_INIT(&bridge_head); | |||||
mtx_init(&bridge_lock, "rib_event_bridge_lock", NULL, MTX_DEF); | |||||
} | |||||
SYSINIT(rib_bridge_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, rib_bridge_init, NULL); | |||||
void | |||||
rib_bridge_generic_event(int provider_id, uint32_t event_type, uint32_t val1, | |||||
const void *ptr1, const void *ptr2) | |||||
{ | |||||
struct rib_event_bridge *reb; | |||||
NET_EPOCH_ASSERT(); | |||||
CK_STAILQ_FOREACH(reb, &bridge_head, reb_link) { | |||||
RT_LOG(LOG_DEBUG, "HERE reb %p %d", reb, reb->reb_provider_id); | |||||
if (reb->reb_provider_id != provider_id) | |||||
reb->reb_cb(event_type, val1, ptr1, ptr2, reb->reb_cb_arg); | |||||
} | |||||
} | |||||
void | |||||
rib_bridge_rt_event(int provider_id, uint32_t fibnum, const struct rt_addrinfo *info, | |||||
const struct rib_cmd_info *rc) | |||||
{ | |||||
#if DEBUG_MAX_LEVEL >= LOG_DEBUG3 | |||||
char rtbuf[INET6_ADDRSTRLEN + 5]; | |||||
FIB_LOG(LOG_DEBUG3, fibnum, rt_get_family(rc->rc_rt), "received cmd %s for %s", | |||||
rib_print_cmd(rc->rc_cmd), rt_print_buf(rc->rc_rt, rtbuf, sizeof(rtbuf))); | |||||
#endif | |||||
RT_LOG(LOG_DEBUG, "HERE %u", fibnum); | |||||
rib_bridge_generic_event(provider_id, NLBR_EVENT_ROUTE, fibnum, info, rc); | |||||
} | |||||
void | |||||
rib_bridge_link(struct rib_event_bridge *reb) | |||||
{ | |||||
mtx_lock(&bridge_lock); | |||||
CK_STAILQ_INSERT_HEAD(&bridge_head, reb, reb_link); | |||||
mtx_unlock(&bridge_lock); | |||||
RT_LOG(LOG_DEBUG, "link %p", reb); | |||||
} | |||||
void | |||||
rib_bridge_unlink(struct rib_event_bridge *reb) | |||||
{ | |||||
mtx_lock(&bridge_lock); | |||||
CK_STAILQ_REMOVE(&bridge_head, reb, rib_event_bridge, reb_link); | |||||
mtx_unlock(&bridge_lock); | |||||
RT_LOG(LOG_DEBUG, "unlink %p", reb); | |||||
} | |||||
Why not static?