Module Name:    src
Committed By:   pooka
Date:           Mon Nov 15 22:42:38 UTC 2010

Modified Files:
        src/sbin/ifconfig: ifconfig.8 ifconfig.c
        src/sys/net: if.c if.h
        src/sys/sys: sockio.h

Log Message:
Implement ifconfig linkstr as proposed on tech-net.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sbin/ifconfig/ifconfig.8
cvs rdiff -u -r1.222 -r1.223 src/sbin/ifconfig/ifconfig.c
cvs rdiff -u -r1.248 -r1.249 src/sys/net/if.c
cvs rdiff -u -r1.147 -r1.148 src/sys/net/if.h
cvs rdiff -u -r1.29 -r1.30 src/sys/sys/sockio.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/ifconfig/ifconfig.8
diff -u src/sbin/ifconfig/ifconfig.8:1.101 src/sbin/ifconfig/ifconfig.8:1.102
--- src/sbin/ifconfig/ifconfig.8:1.101	Mon Sep 14 10:36:49 2009
+++ src/sbin/ifconfig/ifconfig.8	Mon Nov 15 22:42:37 2010
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ifconfig.8,v 1.101 2009/09/14 10:36:49 degroote Exp $
+.\"	$NetBSD: ifconfig.8,v 1.102 2010/11/15 22:42:37 pooka Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)ifconfig.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd August 7, 2009
+.Dd November 15, 2010
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -569,6 +569,13 @@
 for more information.
 .It Fl link[0-2]
 Disable special processing at the link level with the specified interface.
+.It Cm linkstr
+Set a link-level string parameter for the interface.
+This functionality varies from interface to interface.
+Refer to the man page for the specific driver
+for more information.
+.It Fl linkstr
+Remove an interface link-level string parameter.
 .It Cm up
 Mark an interface ``up''.
 This may be used to enable an interface after an ``ifconfig down.''

Index: src/sbin/ifconfig/ifconfig.c
diff -u src/sbin/ifconfig/ifconfig.c:1.222 src/sbin/ifconfig/ifconfig.c:1.223
--- src/sbin/ifconfig/ifconfig.c:1.222	Fri Nov  5 13:52:41 2010
+++ src/sbin/ifconfig/ifconfig.c	Mon Nov 15 22:42:37 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: ifconfig.c,v 1.222 2010/11/05 13:52:41 pooka Exp $	*/
+/*	$NetBSD: ifconfig.c,v 1.223 2010/11/15 22:42:37 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: ifconfig.c,v 1.222 2010/11/05 13:52:41 pooka Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.223 2010/11/15 22:42:37 pooka Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -126,6 +126,8 @@
 static int setifmtu(prop_dictionary_t, prop_dictionary_t);
 static int setifnetmask(prop_dictionary_t, prop_dictionary_t);
 static int setifprefixlen(prop_dictionary_t, prop_dictionary_t);
+static int setlinkstr(prop_dictionary_t, prop_dictionary_t);
+static int unsetlinkstr(prop_dictionary_t, prop_dictionary_t);
 static void status(const struct sockaddr *, prop_dictionary_t,
     prop_dictionary_t);
 static void usage(void);
@@ -164,6 +166,7 @@
 extern struct pbranch opt_command;
 extern struct pbranch opt_family, opt_silent_family;
 extern struct pkw cloning, silent_family, family, ifcaps, ifflags, misc;
+extern struct pstr parse_linkstr;
 
 struct pinteger parse_metric = PINTEGER_INITIALIZER(&parse_metric, "metric", 10,
     setifmetric, "metric", &command_root.pb_parser);
@@ -202,6 +205,9 @@
 	, {.k_word = "prefixlen", .k_nextparser = &parse_prefixlen.pi_parser}
 	, {.k_word = "trailers", .k_neg = true,
 	   .k_exec = notrailers, .k_nextparser = &command_root.pb_parser}
+	, {.k_word = "linkstr", .k_nextparser = &parse_linkstr.ps_parser }
+	, {.k_word = "-linkstr", .k_exec = unsetlinkstr,
+	   .k_nextparser = &command_root.pb_parser }
 };
 
 /* key: clonecmd */
@@ -237,6 +243,9 @@
     setifbroadaddr, "broadcast", NULL, "dstormask", "broadcast",
     &command_root.pb_parser);
 
+struct pstr parse_linkstr = PSTR_INITIALIZER(&parse_linkstr, "linkstr",
+    setlinkstr, "linkstr", &command_root.pb_parser);
+
 static SIMPLEQ_HEAD(, afswtch) aflist = SIMPLEQ_HEAD_INITIALIZER(aflist);
 
 static SIMPLEQ_HEAD(, usage_func) usage_funcs =
@@ -1159,6 +1168,7 @@
 	statistics_func_t *statistics_f;
 	struct ifdatareq ifdr;
 	struct ifreq ifr;
+	struct ifdrv ifdrv;
 	char fbuf[BUFSIZ];
 	int af, s;
 	const char *ifname;
@@ -1210,6 +1220,25 @@
 
 	print_link_addresses(env, true);
 
+	estrlcpy(ifdrv.ifd_name, ifname, sizeof(ifdrv.ifd_name));
+	ifdrv.ifd_cmd = IFLINKSTR_QUERYLEN;
+	ifdrv.ifd_len = 0;
+	ifdrv.ifd_data = NULL;
+	/* interface supports linkstr? */
+	if (ioctl(s, SIOCGLINKSTR, &ifdrv) != -1) {
+		char *p;
+
+		p = malloc(ifdrv.ifd_len);
+		if (p == NULL)
+			err(EXIT_FAILURE, "malloc linkstr buf failed");
+		ifdrv.ifd_data = p;
+		ifdrv.ifd_cmd = 0;
+		if (ioctl(s, SIOCGLINKSTR, &ifdrv) == -1)
+			err(EXIT_FAILURE, "failed to query linkstr");
+		printf("\tlinkstr: %s\n", (char *)ifdrv.ifd_data);
+		free(p);
+	}
+
 	media_status(env, oenv);
 
 	if (!vflag && !zflag)
@@ -1283,6 +1312,46 @@
 	return 0;
 }
 
+static int
+setlinkstr(prop_dictionary_t env, prop_dictionary_t oenv)
+{
+	struct ifdrv ifdrv;
+	const char *linkstr;
+	size_t linkstrlen;
+	prop_data_t data;
+
+	data = (prop_data_t)prop_dictionary_get(env, "linkstr");
+	if (data == NULL) {
+		errno = ENOENT;
+		return -1;
+	}
+	linkstrlen = prop_data_size(data)+1;
+	linkstr = prop_data_data_nocopy(data);
+
+	ifdrv.ifd_cmd = 0;
+	ifdrv.ifd_len = linkstrlen;
+	ifdrv.ifd_data = __UNCONST(linkstr);
+
+	if (direct_ioctl(env, SIOCSLINKSTR, &ifdrv) == -1)
+		err(EXIT_FAILURE, "SIOCSLINKSTR");
+
+	return 0;
+}
+
+static int
+unsetlinkstr(prop_dictionary_t env, prop_dictionary_t oenv)
+{
+	struct ifdrv ifdrv;
+
+	memset(&ifdrv, 0, sizeof(ifdrv));
+	ifdrv.ifd_cmd = IFLINKSTR_UNSET;
+
+	if (direct_ioctl(env, SIOCSLINKSTR, &ifdrv) == -1)
+		err(EXIT_FAILURE, "SIOCSLINKSTR");
+
+	return 0;
+}
+
 static void
 usage(void)
 {

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.248 src/sys/net/if.c:1.249
--- src/sys/net/if.c:1.248	Sat Nov  6 23:28:58 2010
+++ src/sys/net/if.c	Mon Nov 15 22:42:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.248 2010/11/06 23:28:58 christos Exp $	*/
+/*	$NetBSD: if.c,v 1.249 2010/11/15 22:42:36 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.248 2010/11/06 23:28:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.249 2010/11/15 22:42:36 pooka Exp $");
 
 #include "opt_inet.h"
 
@@ -1775,6 +1775,7 @@
 	case SIOCS80211POWER:
 	case SIOCS80211BSSID:
 	case SIOCS80211CHANNEL:
+	case SIOCSLINKSTR:
 		if (l != NULL) {
 			error = kauth_authorize_network(l->l_cred,
 			    KAUTH_NETWORK_INTERFACE,

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.147 src/sys/net/if.h:1.148
--- src/sys/net/if.h:1.147	Wed Oct 20 15:02:17 2010
+++ src/sys/net/if.h	Mon Nov 15 22:42:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.147 2010/10/20 15:02:17 pooka Exp $	*/
+/*	$NetBSD: if.h,v 1.148 2010/11/15 22:42:36 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -603,6 +603,8 @@
 	size_t		ifd_len;
 	void		*ifd_data;
 };
+#define IFLINKSTR_QUERYLEN	0x01
+#define IFLINKSTR_UNSET		0x02
 
 /*
  * Structure used in SIOCGIFCONF request.

Index: src/sys/sys/sockio.h
diff -u src/sys/sys/sockio.h:1.29 src/sys/sys/sockio.h:1.30
--- src/sys/sys/sockio.h:1.29	Mon Sep 14 10:36:50 2009
+++ src/sys/sys/sockio.h	Mon Nov 15 22:42:36 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockio.h,v 1.29 2009/09/14 10:36:50 degroote Exp $	*/
+/*	$NetBSD: sockio.h,v 1.30 2010/11/15 22:42:36 pooka Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993, 1994
@@ -129,6 +129,9 @@
 #define	SIOCZIFDATA	_IOWR('i', 134, struct ifdatareq) /* get if_data then
 							     zero ctrs*/
 
+#define SIOCGLINKSTR	_IOWR('i', 135, struct ifdrv)
+#define SIOCSLINKSTR	 _IOW('i', 136, struct ifdrv)
+
 #define	SIOCSETPFSYNC	_IOW('i', 247, struct ifreq)	
 #define	SIOCGETPFSYNC	_IOWR('i', 248, struct ifreq)
 

Reply via email to