Hello!

I am working on a meshnet concept and am using netgraph to put it right
on top of the MAC layer. I am using ng_iface to do some tunneling of IP
over my protocol and I thought it would be nice to be able to set the
MTU of the created interface using the netgraph interface.

I created a patch to do just that and thought I could share it if
someone would find it worthwhile using for something, but I couldn't
really figure out where to share it. I couldn't really get clarity from
the contribution section in the handbook.

If someone could point me in the right direction, it would be
appreciated. I'll attach the patch to this mail as well since it is a
quite small one.

Cordially,
Andreas Kempe
Index: share/man/man4/ng_iface.4
===================================================================
--- share/man/man4/ng_iface.4	(revision 338702)
+++ share/man/man4/ng_iface.4	(arbetskopia)
@@ -111,6 +111,8 @@
 .It Dv NGM_IFACE_BROADCAST Pq Ic broadcast
 Set the interface to broadcast mode.
 The interface must not currently be up.
+.It Dv NGM_IFACE_SET_MTU Pq Ic setmtu
+Set the MTU of the interface. Given as a 16 bit unsigned integer.
 .El
 .Sh SHUTDOWN
 This node shuts down upon receipt of a
Index: sys/netgraph/ng_iface.c
===================================================================
--- sys/netgraph/ng_iface.c	(revision 338702)
+++ sys/netgraph/ng_iface.c	(arbetskopia)
@@ -181,6 +181,13 @@
 	  NULL,
 	  &ng_parse_uint32_type
 	},
+	{
+	  NGM_IFACE_COOKIE,
+	  NGM_IFACE_SET_MTU,
+	  "setmtu",
+	  &ng_parse_uint16_type,
+	  NULL
+	},
 	{ 0 }
 };
 
@@ -601,6 +608,7 @@
 	struct ng_mesg *resp = NULL;
 	int error = 0;
 	struct ng_mesg *msg;
+	struct ifreq ifr;
 
 	NGI_GET_MSG(item, msg);
 	switch (msg->header.typecookie) {
@@ -646,6 +654,13 @@
 			*((uint32_t *)resp->data) = priv->ifp->if_index;
 			break;
 
+		case NGM_IFACE_SET_MTU:
+		    {
+			ifr.ifr_mtu = *((uint16_t *)msg->data);
+			error = ng_iface_ioctl(ifp, SIOCSIFMTU, (caddr_t) &ifr);
+			break;
+		    }
+
 		default:
 			error = EINVAL;
 			break;
Index: sys/netgraph/ng_iface.h
===================================================================
--- sys/netgraph/ng_iface.h	(revision 338702)
+++ sys/netgraph/ng_iface.h	(arbetskopia)
@@ -68,6 +68,7 @@
 	NGM_IFACE_POINT2POINT,
 	NGM_IFACE_BROADCAST,
 	NGM_IFACE_GET_IFINDEX,
+	NGM_IFACE_SET_MTU,
 };
 
 #endif /* _NETGRAPH_NG_IFACE_H_ */

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to