Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 May 2015 07:37:28 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r282809 - in head: sbin/ifconfig sys/net sys/sys
Message-ID:  <201505120737.t4C7bS9i092832@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Tue May 12 07:37:27 2015
New Revision: 282809
URL: https://svnweb.freebsd.org/changeset/base/282809

Log:
  Add new socket ioctls SIOC[SG]TUNFIB to set FIB number of encapsulated
  packets on tunnel interfaces. Add support of these ioctls to gre(4),
  gif(4) and me(4) interfaces. For incoming packets M_SETFIB() should use
  if_fib value from ifnet structure, use proper value in gre(4) and me(4).
  
  Differential Revision:	https://reviews.freebsd.org/D2462
  No objection from:	#network
  MFC after:	2 weeks
  Sponsored by:	Yandex LLC

Modified:
  head/sbin/ifconfig/ifconfig.8
  head/sbin/ifconfig/iffib.c
  head/sys/net/if_gif.c
  head/sys/net/if_gre.c
  head/sys/net/if_me.c
  head/sys/sys/sockio.h

Modified: head/sbin/ifconfig/ifconfig.8
==============================================================================
--- head/sbin/ifconfig/ifconfig.8	Tue May 12 05:42:13 2015	(r282808)
+++ head/sbin/ifconfig/ifconfig.8	Tue May 12 07:37:27 2015	(r282809)
@@ -316,6 +316,14 @@ using the
 kernel configuration option, or the
 .Va net.fibs
 tunable.
+.It Cm tunnelfib Ar fib_number
+Specify tunnel FIB.
+A FIB
+.Ar fib_number
+is assigned to all packets encapsulated by tunnel interface, e.g.,
+.Xr gif 4
+and
+.Xr gre 4 .
 .It Cm maclabel Ar label
 If Mandatory Access Control support is enabled in the kernel,
 set the MAC label to

Modified: head/sbin/ifconfig/iffib.c
==============================================================================
--- head/sbin/ifconfig/iffib.c	Tue May 12 05:42:13 2015	(r282808)
+++ head/sbin/ifconfig/iffib.c	Tue May 12 07:37:27 2015	(r282809)
@@ -50,15 +50,15 @@ fib_status(int s)
 
 	memset(&ifr, 0, sizeof(ifr));
 	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+	if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) == 0 &&
+	    ifr.ifr_fib != RT_DEFAULT_FIB)
+		printf("\tfib: %u\n", ifr.ifr_fib);
 
-	if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) < 0)
-		return;
-
-	/* Ignore if it is the default. */
-	if (ifr.ifr_fib == 0)
-		return;
-
-	printf("\tfib: %u\n", ifr.ifr_fib);
+	memset(&ifr, 0, sizeof(ifr));
+	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+	if (ioctl(s, SIOCGTUNFIB, (caddr_t)&ifr) == 0 &&
+	    ifr.ifr_fib != RT_DEFAULT_FIB)
+		printf("\ttunnelfib: %u\n", ifr.ifr_fib);
 }
 
 static void
@@ -80,8 +80,28 @@ setiffib(const char *val, int dummy __un
 		warn("ioctl (SIOCSIFFIB)");
 }
 
+static void
+settunfib(const char *val, int dummy __unused, int s,
+    const struct afswtch *afp)
+{
+	unsigned long fib;
+	char *ep;
+
+	fib = strtoul(val, &ep, 0);
+	if (*ep != '\0' || fib > UINT_MAX) {
+		warn("fib %s not valid", val);
+		return;
+	}
+
+	strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
+	ifr.ifr_fib = fib;
+	if (ioctl(s, SIOCSTUNFIB, (caddr_t)&ifr) < 0)
+		warn("ioctl (SIOCSTUNFIB)");
+}
+
 static struct cmd fib_cmds[] = {
 	DEF_CMD_ARG("fib", setiffib),
+	DEF_CMD_ARG("tunnelfib", settunfib),
 };
 
 static struct afswtch af_fib = {

Modified: head/sys/net/if_gif.c
==============================================================================
--- head/sys/net/if_gif.c	Tue May 12 05:42:13 2015	(r282808)
+++ head/sys/net/if_gif.c	Tue May 12 07:37:27 2015	(r282809)
@@ -920,6 +920,17 @@ gif_ioctl(struct ifnet *ifp, u_long cmd,
 #endif
 		}
 		break;
+	case SIOCGTUNFIB:
+		ifr->ifr_fib = sc->gif_fibnum;
+		break;
+	case SIOCSTUNFIB:
+		if ((error = priv_check(curthread, PRIV_NET_GIF)) != 0)
+			break;
+		if (ifr->ifr_fib >= rt_numfibs)
+			error = EINVAL;
+		else
+			sc->gif_fibnum = ifr->ifr_fib;
+		break;
 	case GIFGOPTS:
 		options = sc->gif_options;
 		error = copyout(&options, ifr->ifr_data, sizeof(options));
@@ -935,7 +946,6 @@ gif_ioctl(struct ifnet *ifp, u_long cmd,
 		else
 			sc->gif_options = options;
 		break;
-
 	default:
 		error = EINVAL;
 		break;

Modified: head/sys/net/if_gre.c
==============================================================================
--- head/sys/net/if_gre.c	Tue May 12 05:42:13 2015	(r282808)
+++ head/sys/net/if_gre.c	Tue May 12 07:37:27 2015	(r282809)
@@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_types.h>
 #include <net/netisr.h>
 #include <net/vnet.h>
+#include <net/route.h>
 
 #include <netinet/in.h>
 #ifdef INET
@@ -441,6 +442,17 @@ gre_ioctl(struct ifnet *ifp, u_long cmd,
 #endif
 		}
 		break;
+	case SIOCGTUNFIB:
+		ifr->ifr_fib = sc->gre_fibnum;
+		break;
+	case SIOCSTUNFIB:
+		if ((error = priv_check(curthread, PRIV_NET_GRE)) != 0)
+			break;
+		if (ifr->ifr_fib >= rt_numfibs)
+			error = EINVAL;
+		else
+			sc->gre_fibnum = ifr->ifr_fib;
+		break;
 	case GRESKEY:
 		if ((error = priv_check(curthread, PRIV_NET_GRE)) != 0)
 			break;
@@ -454,7 +466,8 @@ gre_ioctl(struct ifnet *ifp, u_long cmd,
 		}
 		break;
 	case GREGKEY:
-		error = copyout(&sc->gre_key, ifr->ifr_data, sizeof(sc->gre_key));
+		error = copyout(&sc->gre_key, ifr->ifr_data,
+		    sizeof(sc->gre_key));
 		break;
 	case GRESOPTS:
 		if ((error = priv_check(curthread, PRIV_NET_GRE)) != 0)
@@ -725,7 +738,7 @@ gre_input(struct mbuf **mp, int *offp, i
 	m_adj(m, *offp + hlen);
 	m_clrprotoflags(m);
 	m->m_pkthdr.rcvif = ifp;
-	M_SETFIB(m, sc->gre_fibnum);
+	M_SETFIB(m, ifp->if_fib);
 #ifdef MAC
 	mac_ifnet_create_mbuf(ifp, m);
 #endif

Modified: head/sys/net/if_me.c
==============================================================================
--- head/sys/net/if_me.c	Tue May 12 05:42:13 2015	(r282808)
+++ head/sys/net/if_me.c	Tue May 12 07:37:27 2015	(r282809)
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
 #include <net/if_types.h>
 #include <net/netisr.h>
 #include <net/vnet.h>
+#include <net/route.h>
 
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
@@ -297,6 +298,17 @@ me_ioctl(struct ifnet *ifp, u_long cmd, 
 		if (error != 0)
 			memset(src, 0, sizeof(*src));
 		break;
+	case SIOCGTUNFIB:
+		ifr->ifr_fib = sc->me_fibnum;
+		break;
+	case SIOCSTUNFIB:
+		if ((error = priv_check(curthread, PRIV_NET_GRE)) != 0)
+			break;
+		if (ifr->ifr_fib >= rt_numfibs)
+			error = EINVAL;
+		else
+			sc->me_fibnum = ifr->ifr_fib;
+		break;
 	default:
 		error = EINVAL;
 		break;
@@ -453,7 +465,7 @@ me_input(struct mbuf **mp, int *offp, in
 	m_clrprotoflags(m);
 	m->m_pkthdr.rcvif = ifp;
 	m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID);
-	M_SETFIB(m, sc->me_fibnum);
+	M_SETFIB(m, ifp->if_fib);
 	hlen = AF_INET;
 	BPF_MTAP2(ifp, &hlen, sizeof(hlen), m);
 	if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);

Modified: head/sys/sys/sockio.h
==============================================================================
--- head/sys/sys/sockio.h	Tue May 12 05:42:13 2015	(r282808)
+++ head/sys/sys/sockio.h	Tue May 12 07:37:27 2015	(r282809)
@@ -114,6 +114,9 @@
 #define	SIOCGIFFIB	_IOWR('i', 92, struct ifreq)	/* get IF fib */
 #define	SIOCSIFFIB	 _IOW('i', 93, struct ifreq)	/* set IF fib */
 
+#define	SIOCGTUNFIB	_IOWR('i', 94, struct ifreq)	/* get tunnel fib */
+#define	SIOCSTUNFIB	 _IOW('i', 95, struct ifreq)	/* set tunnel fib */
+
 #define	SIOCSDRVSPEC	_IOW('i', 123, struct ifdrv)	/* set driver-specific
 								  parameters */
 #define	SIOCGDRVSPEC	_IOWR('i', 123, struct ifdrv)	/* get driver-specific



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505120737.t4C7bS9i092832>