Use an event handler to notify the SCTP about IP address changes

instead of calling an SCTP specific function from the IP code.
This is a requirement of supporting SCTP as a kernel loadable module.
This patch was developed by markj@, I tweaked a bit the SCTP related
code.

Submitted by:		markj@
MFC after:		3 days
This commit is contained in:
Michael Tuexen 2019-10-13 18:17:08 +00:00
parent 861e74ac19
commit d6e23cf0cf
5 changed files with 20 additions and 20 deletions

View File

@ -38,10 +38,9 @@
#include "opt_inet.h"
#include "opt_inet6.h"
#include "opt_route.h"
#include "opt_sctp.h"
#include "opt_mrouting.h"
#include "opt_mpath.h"
#include "opt_route.h"
#include <sys/param.h>
#include <sys/systm.h>
@ -90,13 +89,6 @@
#define RT_NUMFIBS 1
#endif
#if defined(INET) || defined(INET6)
#ifdef SCTP
extern void sctp_addr_change(struct ifaddr *ifa, int cmd);
#endif /* SCTP */
#endif
/* This is read-only.. */
u_int rt_numfibs = RT_NUMFIBS;
SYSCTL_UINT(_net, OID_AUTO, fibs, CTLFLAG_RDTUN, &rt_numfibs, 0, "");
@ -140,6 +132,8 @@ VNET_DEFINE(int, rttrash); /* routes not in table but not freed */
VNET_DEFINE_STATIC(uma_zone_t, rtzone); /* Routing table UMA zone. */
#define V_rtzone VNET(rtzone)
EVENTHANDLER_LIST_DEFINE(rt_addrmsg);
static int rtrequest1_fib_change(struct rib_head *, struct rt_addrinfo *,
struct rtentry **, u_int);
static void rt_setmetrics(const struct rt_addrinfo *, struct rtentry *);
@ -2224,20 +2218,10 @@ rt_addrmsg(int cmd, struct ifaddr *ifa, int fibnum)
KASSERT(cmd == RTM_ADD || cmd == RTM_DELETE,
("unexpected cmd %d", cmd));
KASSERT(fibnum == RT_ALL_FIBS || (fibnum >= 0 && fibnum < rt_numfibs),
("%s: fib out of range 0 <=%d<%d", __func__, fibnum, rt_numfibs));
#if defined(INET) || defined(INET6)
#ifdef SCTP
/*
* notify the SCTP stack
* this will only get called when an address is added/deleted
* XXX pass the ifaddr struct instead if ifa->ifa_addr...
*/
sctp_addr_change(ifa, cmd);
#endif /* SCTP */
#endif
EVENTHANDLER_DIRECT_INVOKE(rt_addrmsg, ifa, cmd);
return (rtsock_addrmsg(cmd, ifa, fibnum));
}

View File

@ -357,6 +357,12 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
}
}
void
sctp_addr_change_event_handler(void *arg __unused, struct ifaddr *ifa, int cmd)
{
sctp_addr_change(ifa, cmd);
}
void
sctp_add_or_del_interfaces(int (*pred) (struct ifnet *), int add){
struct ifnet *ifn;

View File

@ -61,6 +61,8 @@ int sctp_copy_out_packet_log(uint8_t *target, int length);
void sctp_addr_change(struct ifaddr *ifa, int cmd);
void sctp_addr_change_event_handler(void *, struct ifaddr *, int);
void sctp_add_or_del_interfaces(int (*pred) (struct ifnet *), int add);
#endif

View File

@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/sctp_auth.h>
#include <netinet/sctp_bsd_addr.h>
#include <netinet/udp.h>
#include <sys/eventhandler.h>
@ -89,6 +90,8 @@ sctp_init(void)
SCTP_BASE_VAR(packet_log_end) = 0;
memset(&SCTP_BASE_VAR(packet_log_buffer), 0, SCTP_PACKET_LOG_SIZE);
#endif
EVENTHANDLER_REGISTER(rt_addrmsg, sctp_addr_change_event_handler,
NULL, EVENTHANDLER_PRI_FIRST);
}
#ifdef VIMAGE

View File

@ -312,4 +312,9 @@ typedef void (*device_detach_fn)(void *, device_t, enum evhdev_detach);
EVENTHANDLER_DECLARE(device_attach, device_attach_fn);
EVENTHANDLER_DECLARE(device_detach, device_detach_fn);
/* Interface address addition and removal event */
struct ifaddr;
typedef void (*rt_addrmsg_fn)(void *, struct ifaddr *, int);
EVENTHANDLER_DECLARE(rt_addrmsg, rt_addrmsg_fn);
#endif /* _SYS_EVENTHANDLER_H_ */