Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Jul 2014 10:51:16 GMT
From:      zkorchev@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r271471 - soc2014/zkorchev/freebsd_head/sbin/ifconfig
Message-ID:  <201407281051.s6SApGwj004535@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zkorchev
Date: Mon Jul 28 10:51:16 2014
New Revision: 271471
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271471

Log:
  ifconfig partial support for libsol

Modified:
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/Makefile
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet6.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_link.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_nd6.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/carp.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.h
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmac.c
  soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmedia.c

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/Makefile
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/Makefile	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/Makefile	Mon Jul 28 10:51:16 2014	(r271471)
@@ -58,6 +58,9 @@
 LDADD+= -ljail
 .endif
 
+LDADD+= -lsol
+CFLAGS+= -DSOL_ON -I/usr/local/include
+
 MAN=	ifconfig.8
 
 CFLAGS+= -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wnested-externs

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -50,6 +50,9 @@
 #include <netinet/in_var.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -67,6 +70,41 @@
 	if (sin == NULL)
 		return;
 
+#if defined(SOL_ON)
+	if (sol_format) {
+		const char *inet = inet_ntoa(sin->sin_addr);
+
+		SOL_MAP_KEYL(&sol_stream, "inet");
+		sol_string(&sol_stream, inet, strlen(inet));
+
+		if (ifa->ifa_flags & IFF_POINTOPOINT) {
+			sin = ifa->ifa_dstaddr ?
+				(struct sockaddr_in *)ifa->ifa_dstaddr : &null_sin;
+			inet = inet_ntoa(sin->sin_addr);
+			SOL_MAP_KEYL(&sol_stream, "-->");
+			sol_string(&sol_stream, inet, strlen(inet));
+		}
+
+		sin = ifa->ifa_netmask ?
+			(struct sockaddr_in *)ifa->ifa_netmask : &null_sin;
+		SOL_MAP_KEYL(&sol_stream, "netmask");
+		sol_uinteger(&sol_stream, ntohl(sin->sin_addr.s_addr));
+
+		if (ifa->ifa_flags & IFF_BROADCAST) {
+			sin = (struct sockaddr_in *)ifa->ifa_broadaddr;
+			if (sin != NULL && sin->sin_addr.s_addr != 0) {
+				inet = inet_ntoa(sin->sin_addr);
+				SOL_MAP_KEYL(&sol_stream, "broadcast");
+				sol_string(&sol_stream, inet, strlen(inet));
+			}
+		}
+
+		print_vhid(ifa, " ");
+
+		return;
+	}
+#endif
+
 	printf("\tinet %s ", inet_ntoa(sin->sin_addr));
 
 	if (ifa->ifa_flags & IFF_POINTOPOINT) {
@@ -170,7 +208,16 @@
 	if (getnameinfo(sa, sa->sa_len, dst, sizeof(dst), 0, 0, NI_NUMERICHOST) != 0)
 		dst[0] = '\0';
 
-	printf("\ttunnel inet %s --> %s\n", src, dst);
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "tunnel inet src");
+		sol_string(&sol_stream, src, strlen(src));
+		SOL_MAP_KEYL(&sol_stream, "tunnel inet dst");
+		sol_string(&sol_stream, dst, strlen(dst));
+	}
+	else
+#endif
+		printf("\ttunnel inet %s --> %s\n", src, dst);
 }
 
 static void

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet6.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet6.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_inet6.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -51,6 +51,9 @@
 #include <netinet/in_var.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include <netinet6/nd6.h>	/* Define ND6_INFINITE_LIFETIME */
 
@@ -208,7 +211,14 @@
 	if (error != 0)
 		inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
 			  sizeof(addr_buf));
-	printf("\tinet6 %s ", addr_buf);
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "inet6");
+		sol_string(&sol_stream, addr_buf, strlen(addr_buf));
+	}
+	else
+#endif
+		printf("\tinet6 %s ", addr_buf);
 
 	if (ifa->ifa_flags & IFF_POINTOPOINT) {
 		sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
@@ -226,15 +236,78 @@
 			if (error != 0)
 				inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf,
 					  sizeof(addr_buf));
-			printf("--> %s ", addr_buf);
+#if defined(SOL_ON)
+			if (sol_format) {
+				SOL_MAP_KEYL(&sol_stream, "-->");
+				sol_string(&sol_stream, addr_buf, strlen(addr_buf));
+			}
+			else
+#endif
+				printf("--> %s ", addr_buf);
 		}
 	}
 
 	sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
 	if (sin == NULL)
 		sin = &null_sin;
-	printf("prefixlen %d ", prefix(&sin->sin6_addr,
-		sizeof(struct in6_addr)));
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "prefixlen");
+		sol_integer(&sol_stream, prefix(&sin->sin6_addr,
+			sizeof(struct in6_addr)));
+	}
+	else
+#endif
+		printf("prefixlen %d ", prefix(&sin->sin6_addr,
+			sizeof(struct in6_addr)));
+
+#if defined(SOL_ON)
+# define S(s) sol_string(&sol_stream, s, sizeof(s) - 1)
+	if (sol_format)
+	{
+		SOL_MAP_KEYL(&sol_stream, "inet6 iff");
+		sol_array_start(&sol_stream);
+		if ((flags6 & IN6_IFF_ANYCAST) != 0) S("anycast");
+		if ((flags6 & IN6_IFF_TENTATIVE) != 0) S("tentative");
+		if ((flags6 & IN6_IFF_DUPLICATED) != 0) S("duplicated");
+		if ((flags6 & IN6_IFF_DETACHED) != 0) S("detached");
+		if ((flags6 & IN6_IFF_DEPRECATED) != 0) S("deprecated");
+		if ((flags6 & IN6_IFF_AUTOCONF) != 0) S("autoconf");
+		if ((flags6 & IN6_IFF_TEMPORARY) != 0) S("temporary");
+		sol_array_end(&sol_stream);
+
+		if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) {
+			SOL_MAP_KEYL(&sol_stream, "scopeid");
+			sol_uinteger(&sol_stream, 
+				((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
+		}
+
+		if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
+			SOL_MAP_KEYL(&sol_stream, "pltime");
+			if (lifetime.ia6t_preferred) {
+				const char *pltime = lifetime.ia6t_preferred < t
+					? "0" : sec2str(lifetime.ia6t_preferred - t);
+
+				sol_string(&sol_stream, pltime, strlen(pltime));
+			} else
+				S("infty");
+
+			SOL_MAP_KEYL(&sol_stream, "vltime");
+			if (lifetime.ia6t_expire) {
+				const char *vltime = lifetime.ia6t_expire < t
+					? "0" : sec2str(lifetime.ia6t_expire - t);
+
+				sol_string(&sol_stream, vltime, strlen(vltime));
+			} else
+				S("infty");
+		}
+
+		print_vhid(ifa, " ");
+
+		return;
+	}
+# undef S
+#endif
 
 	if ((flags6 & IN6_IFF_ANYCAST) != 0)
 		printf("anycast ");
@@ -253,7 +326,7 @@
 
 	if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
 		printf("scopeid 0x%x ",
-		    ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
+			((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
 
 	if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
 		printf("pltime ");
@@ -434,7 +507,16 @@
 	    NI_NUMERICHOST) != 0)
 		dst[0] = '\0';
 
-	printf("\ttunnel inet6 %s --> %s\n", src, dst);
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "tunnel inet6 src");
+		sol_string(&sol_stream, src, strlen(src));
+		SOL_MAP_KEYL(&sol_stream, "tunnel inet6 dst");
+		sol_string(&sol_stream, dst, strlen(dst));
+	}
+	else
+#endif
+		printf("\ttunnel inet6 %s --> %s\n", src, dst);
 }
 
 static void

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_link.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_link.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_link.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -46,6 +46,9 @@
 #include <net/if_dl.h>
 #include <net/if_types.h>
 #include <net/ethernet.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -56,18 +59,36 @@
 {
 	/* XXX no const 'cuz LLADDR is defined wrong */
 	struct sockaddr_dl *sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+	const char *address;
 
 	if (sdl != NULL && sdl->sdl_alen > 0) {
 		if ((sdl->sdl_type == IFT_ETHER ||
 		    sdl->sdl_type == IFT_L2VLAN ||
 		    sdl->sdl_type == IFT_BRIDGE) &&
-		    sdl->sdl_alen == ETHER_ADDR_LEN)
-			printf("\tether %s\n",
-			    ether_ntoa((struct ether_addr *)LLADDR(sdl)));
+		    sdl->sdl_alen == ETHER_ADDR_LEN) {
+#if defined(SOL_ON)
+			if (sol_format) {
+				address = ether_ntoa((struct ether_addr *)LLADDR(sdl));
+				SOL_MAP_KEYL(&sol_stream, "ether");
+				sol_string(&sol_stream, address, strlen(address));
+			}
+			else
+#endif
+				printf("\tether %s\n",
+					ether_ntoa((struct ether_addr *)LLADDR(sdl)));
+		}
 		else {
 			int n = sdl->sdl_nlen > 0 ? sdl->sdl_nlen + 1 : 0;
 
-			printf("\tlladdr %s\n", link_ntoa(sdl) + n);
+#if defined(SOL_ON)
+			if (sol_format) {
+				address = link_ntoa(sdl) + n;
+				SOL_MAP_KEYL(&sol_stream, "lladdr");
+				sol_string(&sol_stream, address, strlen(address));
+			}
+			else
+#endif
+				printf("\tlladdr %s\n", link_ntoa(sdl) + n);
 		}
 	}
 }

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_nd6.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_nd6.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/af_nd6.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -52,6 +52,9 @@
 #include <netdb.h>
 
 #include <netinet6/nd6.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -163,7 +166,15 @@
 	close(s6);
 	if (nd.ndi.flags == 0 && !isdefif)
 		return;
-	printb("\tnd6 options",
-	    (unsigned int)(nd.ndi.flags | (isdefif << 15)), ND6BITS);
-	putchar('\n');
+#if defined(SOL_ON)
+	if (sol_format)
+		printb("nd6 options",
+			(unsigned int)(nd.ndi.flags | (isdefif << 15)), ND6BITS);
+	else
+#endif
+	{
+		printb("\tnd6 options",
+			(unsigned int)(nd.ndi.flags | (isdefif << 15)), ND6BITS);
+		putchar('\n');
+	}
 }

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/carp.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/carp.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/carp.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -48,6 +48,9 @@
 #include <unistd.h>
 #include <err.h>
 #include <errno.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -79,6 +82,33 @@
 	if (ioctl(s, SIOCGVH, (caddr_t)&ifr) == -1)
 		return;
 
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "carp");
+		sol_array_start(&sol_stream);
+		for (i = 0; i < carpr[0].carpr_count; i++) {
+			sol_map_start(&sol_stream);
+			SOL_MAP_KEYL(&sol_stream, "state");
+			sol_string(&sol_stream, carp_states[carpr[i].carpr_state],
+				strlen(carp_states[carpr[i].carpr_state]));
+			SOL_MAP_KEYL(&sol_stream, "vhid");
+			sol_integer(&sol_stream, carpr[i].carpr_vhid);
+			SOL_MAP_KEYL(&sol_stream, "advbase");
+			sol_integer(&sol_stream, carpr[i].carpr_advbase);
+			SOL_MAP_KEYL(&sol_stream, "advskew");
+			sol_integer(&sol_stream, carpr[i].carpr_advskew);
+			if (printkeys && carpr[i].carpr_key[0] != '\0') {
+				SOL_MAP_KEYL(&sol_stream, "key");
+				sol_string(&sol_stream, carpr[i].carpr_key, strlen(carpr[i].carpr_key));
+			}
+			sol_map_end(&sol_stream);
+		}
+		sol_array_end(&sol_stream);
+
+		return;
+	}
+#endif
+
 	for (i = 0; i < carpr[0].carpr_count; i++) {
 		printf("\tcarp: %s vhid %d advbase %d advskew %d",
 		    carp_states[carpr[i].carpr_state], carpr[i].carpr_vhid,

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -73,6 +73,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -94,6 +97,11 @@
 int	verbose;
 int	noload;
 
+#if defined(SOL_ON)
+struct sol_stream sol_stream;
+#endif
+int sol_format;
+
 int	supmedia = 0;
 int	printkeys = 0;		/* Print keying material for interfaces. */
 
@@ -287,6 +295,10 @@
 		err(EXIT_FAILURE, "getifaddrs");
 	cp = NULL;
 	ifindex = 0;
+#if defined(SOL_ON)
+	sol_format = sol_init(&sol_stream);
+	if (sol_format) sol_map_start(&sol_stream);
+#endif
 	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
 		memset(&paifr, 0, sizeof(paifr));
 		strncpy(paifr.ifr_name, ifa->ifa_name, sizeof(paifr.ifr_name));
@@ -351,8 +363,15 @@
 		else
 			status(afp, sdl, ifa);
 	}
-	if (namesonly)
-		printf("\n");
+#if defined(SOL_ON)
+	if (sol_format) {
+		sol_map_end(&sol_stream);
+		sol_term(&sol_stream);
+	}
+	else
+#endif
+		if (namesonly)
+			printf("\n");
 	freeifaddrs(ifap);
 
 	exit(0);
@@ -931,13 +950,32 @@
 	if (s < 0)
 		err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
 
-	printf("%s: ", name);
-	printb("flags", ifa->ifa_flags, IFFBITS);
-	if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
-		printf(" metric %d", ifr.ifr_metric);
-	if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
-		printf(" mtu %d", ifr.ifr_mtu);
-	putchar('\n');
+#if defined(SOL_ON)
+	if (sol_format)
+	{
+		sol_map_key(&sol_stream, name, strlen(name));
+		sol_map_start(&sol_stream);
+		printb("flags", ifa->ifa_flags, IFFBITS);
+		if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1) {
+			SOL_MAP_KEYL(&sol_stream, "metric");
+			sol_integer(&sol_stream, ifr.ifr_metric);
+		}
+		if (ioctl(s, SIOCGIFMTU, &ifr) != -1) {
+			SOL_MAP_KEYL(&sol_stream, "mtu");
+			sol_integer(&sol_stream, ifr.ifr_mtu);
+		}
+	}
+	else
+#endif
+	{
+		printf("%s: ", name);
+		printb("flags", ifa->ifa_flags, IFFBITS);
+		if (ioctl(s, SIOCGIFMETRIC, &ifr) != -1)
+			printf(" metric %d", ifr.ifr_metric);
+		if (ioctl(s, SIOCGIFMTU, &ifr) != -1)
+			printf(" mtu %d", ifr.ifr_mtu);
+		putchar('\n');
+	}
 
 	for (;;) {
 		if ((descr = reallocf(descr, descrlen)) != NULL) {
@@ -945,9 +983,18 @@
 			ifr.ifr_buffer.length = descrlen;
 			if (ioctl(s, SIOCGIFDESCR, &ifr) == 0) {
 				if (ifr.ifr_buffer.buffer == descr) {
-					if (strlen(descr) > 0)
-						printf("\tdescription: %s\n",
-						    descr);
+					size_t len = strlen(descr);
+
+					if (len > 0) {
+#if defined(SOL_ON)
+						if (sol_format) {
+							SOL_MAP_KEYL(&sol_stream, "description");
+							sol_string(&sol_stream, descr, len);
+						}
+						else
+#endif
+							printf("\tdescription: %s\n", descr);
+					}
 				} else if (ifr.ifr_buffer.length > descrlen) {
 					descrlen = ifr.ifr_buffer.length;
 					continue;
@@ -960,13 +1007,25 @@
 	}
 
 	if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) {
-		if (ifr.ifr_curcap != 0) {
-			printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
-			putchar('\n');
-		}
-		if (supmedia && ifr.ifr_reqcap != 0) {
-			printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS);
-			putchar('\n');
+#if defined(SOL_ON)
+		if (sol_format)
+		{
+			if (ifr.ifr_curcap != 0)
+				printb("options", ifr.ifr_curcap, IFCAPBITS);
+			if (supmedia && ifr.ifr_reqcap != 0)
+				printb("capabilities", ifr.ifr_reqcap, IFCAPBITS);
+		}
+		else
+#endif
+		{
+			if (ifr.ifr_curcap != 0) {
+				printb("\toptions", ifr.ifr_curcap, IFCAPBITS);
+				putchar('\n');
+			}
+			if (supmedia && ifr.ifr_reqcap != 0) {
+				printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS);
+				putchar('\n');
+			}
 		}
 	}
 
@@ -1011,6 +1070,10 @@
 	if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) 
 		printf("%s", ifs.ascii);
 
+#if defined(SOL_ON)
+	if (sol_format) sol_map_end(&sol_stream);
+#endif
+
 	close(s);
 	return;
 }
@@ -1048,6 +1111,34 @@
 	int i, any = 0;
 	char c;
 
+#if defined(SOL_ON)
+	if (sol_format) {
+		sol_map_key(&sol_stream, s, strlen(s));
+		sol_map_start(&sol_stream);
+		SOL_MAP_KEYL(&sol_stream, "value");
+		sol_integer(&sol_stream, v);
+		SOL_MAP_KEYL(&sol_stream, "list");
+		if (++bits) {
+			const char *start;
+
+			sol_array_start(&sol_stream);
+			while ((i = *bits++) != '\0') {
+				if (v & (1 << (i-1))) {
+					start = bits;
+					while ((c = *bits) > 32)
+						bits++;
+					sol_string(&sol_stream, start, bits - start);
+				} else
+					for (; *bits > 32; bits++)
+						;
+			}
+			sol_array_end(&sol_stream);
+		}
+		sol_map_end(&sol_stream);
+		return;
+	}
+#endif
+
 	if (bits && *bits == 8)
 		printf("%s=%o", s, v);
 	else
@@ -1081,8 +1172,15 @@
 	ifd = ifa->ifa_data;
 	if (ifd->ifi_vhid == 0)
 		return;
-	
-	printf("vhid %d ", ifd->ifi_vhid);
+
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "vhid");
+		sol_integer(&sol_stream, ifd->ifi_vhid);
+	}
+	else
+#endif
+		printf("vhid %d ", ifd->ifi_vhid);
 }
 
 void

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.h
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.h	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifconfig.h	Mon Jul 28 10:51:16 2014	(r271471)
@@ -36,6 +36,11 @@
 
 #define	__constructor	__attribute__((constructor))
 
+#if defined(SOL_ON)
+extern struct sol_stream sol_stream;
+#endif
+extern int sol_format;
+
 struct afswtch;
 struct cmd;
 

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmac.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmac.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmac.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -46,6 +46,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -55,6 +58,7 @@
 	struct ifreq ifr;
 	mac_t label;
 	char *label_text;
+	size_t len;
 
 	memset(&ifr, 0, sizeof(ifr));
 	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
@@ -69,8 +73,17 @@
 	if (mac_to_text(label, &label_text) == -1)
 		goto mac_free;
 
-	if (strlen(label_text) != 0)
-		printf("\tmaclabel %s\n", label_text);
+	len = strlen(label_text);
+	if (len != 0) {
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "maclabel");
+			sol_string(&sol_stream, label_text, len);
+		}
+		else
+#endif
+			printf("\tmaclabel %s\n", label_text);
+	}
 	free(label_text);
 
 mac_free:

Modified: soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmedia.c
==============================================================================
--- soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmedia.c	Mon Jul 28 08:22:08 2014	(r271470)
+++ soc2014/zkorchev/freebsd_head/sbin/ifconfig/ifmedia.c	Mon Jul 28 10:51:16 2014	(r271471)
@@ -82,6 +82,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if defined(SOL_ON)
+# include <sol.h>
+#endif
 
 #include "ifconfig.h"
 
@@ -133,56 +136,111 @@
 	if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
 		err(1, "SIOCGIFMEDIA");
 
-	printf("\tmedia: ");
-	print_media_word(ifmr.ifm_current, 1);
-	if (ifmr.ifm_active != ifmr.ifm_current) {
-		putchar(' ');
-		putchar('(');
-		print_media_word(ifmr.ifm_active, 0);
-		putchar(')');
+#if defined(SOL_ON)
+	if (sol_format)
+	{
+		SOL_MAP_KEYL(&sol_stream, "media");
+		sol_map_start(&sol_stream);
+		print_media_word(ifmr.ifm_current, 1);
+		if (ifmr.ifm_active != ifmr.ifm_current) {
+			SOL_MAP_KEYL(&sol_stream, "active");
+			sol_map_start(&sol_stream);
+			print_media_word(ifmr.ifm_active, 0);
+			sol_map_end(&sol_stream);
+		}
+		sol_map_end(&sol_stream);
 	}
+	else
+#endif
+	{
+		printf("\tmedia: ");
+		print_media_word(ifmr.ifm_current, 1);
+		if (ifmr.ifm_active != ifmr.ifm_current) {
+			putchar(' ');
+			putchar('(');
+			print_media_word(ifmr.ifm_active, 0);
+			putchar(')');
+		}
 
-	putchar('\n');
+		putchar('\n');
+	}
 
 	if (ifmr.ifm_status & IFM_AVALID) {
-		printf("\tstatus: ");
+		const char *status = 0;
+		size_t status_len;
+
+#define set(s) do { \
+	status = s; \
+	status_len = sizeof(s) - 1; \
+} while (0)
+
+#if defined(SOL_ON)
+		if (!sol_format)
+#endif
+			printf("\tstatus: ");
 		switch (IFM_TYPE(ifmr.ifm_active)) {
 		case IFM_ETHER:
 		case IFM_ATM:
 			if (ifmr.ifm_status & IFM_ACTIVE)
-				printf("active");
+				set("active");
 			else
-				printf("no carrier");
+				set("no carrier");
 			break;
 
 		case IFM_FDDI:
 		case IFM_TOKEN:
 			if (ifmr.ifm_status & IFM_ACTIVE)
-				printf("inserted");
+				set("inserted");
 			else
-				printf("no ring");
+				set("no ring");
 			break;
 
 		case IFM_IEEE80211:
 			if (ifmr.ifm_status & IFM_ACTIVE) {
 				/* NB: only sta mode associates */
 				if (IFM_OPMODE(ifmr.ifm_active) == IFM_IEEE80211_STA)
-					printf("associated");
+					set("associated");
 				else
-					printf("running");
+					set("running");
 			} else
-				printf("no carrier");
+				set("no carrier");
 			break;
 		}
-		putchar('\n');
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "status");
+			if (status_len)
+				sol_string(&sol_stream, status, status_len);
+		}
+		else
+#endif
+			putchar('\n');
+
+#undef set
 	}
 
 	if (ifmr.ifm_count > 0 && supmedia) {
-		printf("\tsupported media:\n");
-		for (i = 0; i < ifmr.ifm_count; i++) {
-			printf("\t\t");
-			print_media_word_ifconfig(media_list[i]);
-			putchar('\n');
+#if defined(SOL_ON)
+		if (sol_format)
+		{
+			SOL_MAP_KEYL(&sol_stream, "supported media");
+			sol_array_start(&sol_stream);
+			for (i = 0; i < ifmr.ifm_count; i++) {
+				sol_map_start(&sol_stream);
+				print_media_word_ifconfig(media_list[i]);
+				sol_map_end(&sol_stream);
+			}
+			sol_array_end(&sol_stream);
+		}
+		else
+#endif
+		{
+			printf("\tsupported media:\n");
+			for (i = 0; i < ifmr.ifm_count; i++) {
+				printf("\t\t");
+				print_media_word_ifconfig(media_list[i]);
+				putchar('\n');
+			}
 		}
 	}
 
@@ -703,10 +761,20 @@
 	desc = get_toptype_desc(ifmw);
 	ttos = get_toptype_ttos(ifmw);
 	if (desc->ifmt_string == NULL) {
-		printf("<unknown type>");
+#if defined(SOL_ON)
+		if (!sol_format)
+#endif
+			printf("<unknown type>");
 		return;
 	} else if (print_toptype) {
-		printf("%s", desc->ifmt_string);
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "type");
+			sol_string(&sol_stream, desc->ifmt_string, strlen(desc->ifmt_string));
+		}
+		else
+#endif
+			printf("%s", desc->ifmt_string);
 	}
 
 	/*
@@ -717,39 +785,87 @@
 	/* Find subtype. */
 	desc = get_subtype_desc(ifmw, ttos);
 	if (desc == NULL) {
-		printf("<unknown subtype>");
+#if defined(SOL_ON)
+		if (!sol_format)
+#endif
+			printf("<unknown subtype>");
 		return;
 	}
 
-	if (print_toptype)
-		putchar(' ');
-
-	printf("%s", desc->ifmt_string);
+#if defined(SOL_ON)
+	if (!sol_format)
+#endif
+		if (print_toptype)
+			putchar(' ');
+
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "subtype");
+		sol_string(&sol_stream, desc->ifmt_string, strlen(desc->ifmt_string));
+	}
+	else
+#endif
+		printf("%s", desc->ifmt_string);
 
 	if (print_toptype) {
 		desc = get_mode_desc(ifmw, ttos);
-		if (desc != NULL && strcasecmp("autoselect", desc->ifmt_string))
-			printf(" mode %s", desc->ifmt_string);
+		if (desc != NULL && strcasecmp("autoselect", desc->ifmt_string)) {
+#if defined(SOL_ON)
+			if (sol_format) {
+				SOL_MAP_KEYL(&sol_stream, "mode");
+				sol_string(&sol_stream, desc->ifmt_string, strlen(desc->ifmt_string));
+			}
+			else
+#endif
+				printf(" mode %s", desc->ifmt_string);
+		}
 	}
 
 	/* Find options. */
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "options");
+		sol_array_start(&sol_stream);
+	}
+#endif
 	for (i = 0; ttos->options[i].desc != NULL; i++) {
 		if (ttos->options[i].alias)
 			continue;
 		for (desc = ttos->options[i].desc;
 		    desc->ifmt_string != NULL; desc++) {
 			if (ifmw & desc->ifmt_word) {
-				if (seen_option == 0)
-					printf(" <");
-				printf("%s%s", seen_option++ ? "," : "",
-				    desc->ifmt_string);
+#if defined(SOL_ON)
+				if (sol_format)
+					sol_string(&sol_stream,
+						desc->ifmt_string, strlen(desc->ifmt_string));
+				else
+#endif
+				{
+					if (seen_option == 0)
+						printf(" <");
+					printf("%s%s", seen_option++ ? "," : "",
+						desc->ifmt_string);
+				}
 			}
 		}
 	}
-	printf("%s", seen_option ? ">" : "");
-
-	if (print_toptype && IFM_INST(ifmw) != 0)
-		printf(" instance %d", IFM_INST(ifmw));
+#if defined(SOL_ON)
+	if (sol_format)
+		sol_array_end(&sol_stream);
+	else
+#endif
+		printf("%s", seen_option ? ">" : "");
+
+	if (print_toptype && IFM_INST(ifmw) != 0) {
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "instance");
+			sol_integer(&sol_stream, IFM_INST(ifmw));
+		}
+		else
+#endif
+			printf(" instance %d", IFM_INST(ifmw));
+	}
 }
 
 static void
@@ -763,7 +879,10 @@
 	desc = get_toptype_desc(ifmw);
 	ttos = get_toptype_ttos(ifmw);
 	if (desc->ifmt_string == NULL) {
-		printf("<unknown type>");
+#if defined(SOL_ON)
+		if (!sol_format)
+#endif
+			printf("<unknown type>");
 		return;
 	}
 
@@ -775,33 +894,76 @@
 	/* Find subtype. */
 	desc = get_subtype_desc(ifmw, ttos);
 	if (desc == NULL) {
-		printf("<unknown subtype>");
+#if defined(SOL_ON)
+		if (!sol_format)
+#endif
+			printf("<unknown subtype>");
 		return;
 	}
 
-	printf("media %s", desc->ifmt_string);
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "media");
+		sol_string(&sol_stream, desc->ifmt_string, strlen(desc->ifmt_string));
+	}
+	else
+#endif
+		printf("media %s", desc->ifmt_string);
 
 	desc = get_mode_desc(ifmw, ttos);
-	if (desc != NULL)
-		printf(" mode %s", desc->ifmt_string);
+	if (desc != NULL) {
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "mode");
+			sol_string(&sol_stream, desc->ifmt_string, strlen(desc->ifmt_string));
+		}
+		else
+#endif
+			printf(" mode %s", desc->ifmt_string);
+	}
 
 	/* Find options. */
+#if defined(SOL_ON)
+	if (sol_format) {
+		SOL_MAP_KEYL(&sol_stream, "options");
+		sol_array_start(&sol_stream);
+	}
+#endif
 	for (i = 0; ttos->options[i].desc != NULL; i++) {
 		if (ttos->options[i].alias)
 			continue;
 		for (desc = ttos->options[i].desc;
 		    desc->ifmt_string != NULL; desc++) {
 			if (ifmw & desc->ifmt_word) {
-				if (seen_option == 0)
-					printf(" mediaopt ");
-				printf("%s%s", seen_option++ ? "," : "",
-				    desc->ifmt_string);
+#if defined(SOL_ON)
+				if (sol_format)
+					sol_string(&sol_stream,
+						desc->ifmt_string, strlen(desc->ifmt_string));
+				else
+#endif
+				{
+					if (seen_option == 0)
+						printf(" mediaopt ");
+					printf("%s%s", seen_option++ ? "," : "",
+						desc->ifmt_string);
+				}
 			}
 		}
 	}
-
-	if (IFM_INST(ifmw) != 0)
-		printf(" instance %d", IFM_INST(ifmw));
+#if defined(SOL_ON)
+	if (sol_format) sol_array_end(&sol_stream);
+#endif
+
+	if (IFM_INST(ifmw) != 0) {
+#if defined(SOL_ON)
+		if (sol_format) {
+			SOL_MAP_KEYL(&sol_stream, "instance");
+			sol_integer(&sol_stream, IFM_INST(ifmw));
+		}
+		else
+#endif
+			printf(" instance %d", IFM_INST(ifmw));
+	}
 }
 
 /**********************************************************************



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