svn commit: r353480 - in head/sys: net netinet sys

Michael Tuexen tuexen at FreeBSD.org
Sun Oct 13 18:17:10 UTC 2019


Author: tuexen
Date: Sun Oct 13 18:17:08 2019
New Revision: 353480
URL: https://svnweb.freebsd.org/changeset/base/353480

Log:
  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

Modified:
  head/sys/net/route.c
  head/sys/netinet/sctp_bsd_addr.c
  head/sys/netinet/sctp_bsd_addr.h
  head/sys/netinet/sctp_usrreq.c
  head/sys/sys/eventhandler.h

Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c	Sun Oct 13 18:03:23 2019	(r353479)
+++ head/sys/net/route.c	Sun Oct 13 18:17:08 2019	(r353480)
@@ -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
 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));
 }
 

Modified: head/sys/netinet/sctp_bsd_addr.c
==============================================================================
--- head/sys/netinet/sctp_bsd_addr.c	Sun Oct 13 18:03:23 2019	(r353479)
+++ head/sys/netinet/sctp_bsd_addr.c	Sun Oct 13 18:17:08 2019	(r353480)
@@ -358,6 +358,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;
 	struct ifaddr *ifa;

Modified: head/sys/netinet/sctp_bsd_addr.h
==============================================================================
--- head/sys/netinet/sctp_bsd_addr.h	Sun Oct 13 18:03:23 2019	(r353479)
+++ head/sys/netinet/sctp_bsd_addr.h	Sun Oct 13 18:17:08 2019	(r353480)
@@ -61,6 +61,8 @@ int sctp_copy_out_packet_log(uint8_t *target, int leng
 
 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

Modified: head/sys/netinet/sctp_usrreq.c
==============================================================================
--- head/sys/netinet/sctp_usrreq.c	Sun Oct 13 18:03:23 2019	(r353479)
+++ head/sys/netinet/sctp_usrreq.c	Sun Oct 13 18:17:08 2019	(r353480)
@@ -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

Modified: head/sys/sys/eventhandler.h
==============================================================================
--- head/sys/sys/eventhandler.h	Sun Oct 13 18:03:23 2019	(r353479)
+++ head/sys/sys/eventhandler.h	Sun Oct 13 18:17:08 2019	(r353480)
@@ -312,4 +312,9 @@ typedef void (*device_detach_fn)(void *, device_t, enu
 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_ */


More information about the svn-src-all mailing list