Example #1
0
File: conf.c Project: rheoli/nsh
void conf_ifmetrics(FILE *output, int ifs, struct if_data if_data,
    char *ifname)
{
	int vnetid;
	int dstport;
	char tmpa[IPSIZ], tmpb[IPSIZ], tmpc[TMPSIZ];
	struct ifreq ifrpriority;

	/*
	 * Various metrics for non-bridge interfaces
	 */
	if ((dstport=
	    phys_status(ifs, ifname, tmpa, tmpb, IPSIZ, IPSIZ)) >= 0) {
		int physrt, physttl;

		fprintf(output, " tunnel %s %s", tmpa, tmpb);
		if (dstport > 0)
			fprintf(output, ":%i", dstport);
		if (((physrt = conf_physrtable(ifs, ifname)) != 0))
			fprintf(output, " rdomain %i", physrt);
		if (((physttl = conf_physttl(ifs, ifname)) != 0))
			fprintf(output, " ttl %i", physttl);
		fprintf(output, "\n");
	}

	if (((vnetid = conf_vnetid(ifs, ifname)) != 0))
			fprintf(output, " vnetid %i\n", vnetid);

	/*
	 * print interface mtu, metric
	 *
	 * ignore interfaces named "pfsync" since their mtu
	 * is dynamic and controlled by the kernel
	 */
	if (!MIN_ARG(ifname, "pfsync") &&
	    (if_data.ifi_mtu != default_mtu(ifname) &&
	    default_mtu(ifname) != MTU_IGNORE) && if_data.ifi_mtu != 0)
		fprintf(output, " mtu %u\n", if_data.ifi_mtu);
	if (if_data.ifi_metric)
		fprintf(output, " metric %u\n", if_data.ifi_metric);

	strlcpy(ifrpriority.ifr_name, ifname, IFNAMSIZ);
	if (ioctl(ifs, SIOCGIFPRIORITY, (caddr_t)&ifrpriority) == 0)
		if(ifrpriority.ifr_metric)
			fprintf(output, " priority %u\n",
			    ifrpriority.ifr_metric);

	if (get_nwinfo(ifname, tmpc, TMPSIZ, NWID) != 0) {
		fprintf(output, " nwid %s\n", tmpc);
		if (get_nwinfo(ifname, tmpc, TMPSIZ, NWKEY) != 0)
			fprintf(output, " nwkey %s\n", tmpc);
		if (get_nwinfo(ifname, tmpc, TMPSIZ, TXPOWER) != 0)
			fprintf(output, " txpower %s\n", tmpc);
		if (get_nwinfo(ifname, tmpc, TMPSIZ, POWERSAVE) != 0)
			fprintf(output, " powersave %s\n", tmpc);
	}
}
Example #2
0
File: conf.c Project: sthen/nsh
void conf_interfaces(FILE *output, char *only)
{
	int ifs, flags, ippntd, br;
	char *lladdr;
	char ifdescr[IFDESCRSIZE];

	struct if_nameindex *ifn_list, *ifnp;
	struct ifreq ifr, ifrdesc;
	struct if_data if_data;

	if ((ifn_list = if_nameindex()) == NULL) {
		printf("%% conf_interfaces: if_nameindex failed\n");
		return;
	}

	if ((ifs = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
		printf("%% conf_interfaces socket: %s\n", strerror(errno));
		if_freenameindex(ifn_list);
		return;
	}

	for (ifnp = ifn_list; ifnp->if_name != NULL; ifnp++) {
		if (only && !isprefix(only, ifnp->if_name))
			/* only display interfaces which start with ... */
			continue;
		if (!only && islateif(ifnp->if_name))
			/* interface prefixes to exclude on generic run */
			continue;

		strlcpy(ifr.ifr_name, ifnp->if_name, sizeof(ifr.ifr_name));

		if (ioctl(ifs, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
			printf("%% conf: SIOCGIFFLAGS: %s\n", strerror(errno));
			continue;
		}
		flags = ifr.ifr_flags;

		ifr.ifr_data = (caddr_t)&if_data;
		if (ioctl(ifs, SIOCGIFDATA, (caddr_t)&ifr) < 0) {
			printf("%% conf: SIOCGIFDATA: %s\n", strerror(errno));
			continue;
		}

		/* The output order is important! */

		/* set interface/bridge mode */
		if (!(br = is_bridge(ifs, ifnp->if_name)))
			br = 0;
		fprintf(output, "%s %s\n", br ? "bridge" : "interface",
		    ifnp->if_name);

		/*
		 * description, if available
		 * copied straight from ifconfig.c
		 */
		memset(&ifrdesc, 0, sizeof(ifrdesc));
		strlcpy(ifrdesc.ifr_name, ifnp->if_name,
		    sizeof(ifrdesc.ifr_name));
		ifrdesc.ifr_data = (caddr_t)&ifdescr;
		if (ioctl(ifs, SIOCGIFDESCR, &ifrdesc) == 0 &&
		    strlen(ifrdesc.ifr_data))
			fprintf(output, " description %s\n", ifrdesc.ifr_data);

		if ((lladdr = get_hwdaddr(ifnp->if_name)) != NULL)
			conf_db_single(output, "lladdr", lladdr, ifnp->if_name);
		conf_db_single(output, "rtadvd", NULL, ifnp->if_name);

		conf_vnetid(output, ifs, ifnp->if_name);
		conf_parent(output, ifs, ifnp->if_name);
		conf_rdomain(output, ifs, ifnp->if_name);
		conf_intrtlabel(output, ifs, ifnp->if_name);
		conf_intgroup(output, ifs, ifnp->if_name);
		conf_carp(output, ifs, ifnp->if_name);

		ippntd = conf_ifaddr_dhcp(output, ifnp->if_name, flags);

		if (br) {
			conf_brcfg(output, ifs, ifn_list, ifnp->if_name);
		} else {
			char tmp[24];

			conf_media_status(output, ifs, ifnp->if_name);
			conf_ifmetrics(output, ifs, if_data, ifnp->if_name);
			conf_keepalive(output, ifs, ifnp->if_name);
			conf_pfsync(output, ifs, ifnp->if_name);
			conf_trunk(output, ifs, ifnp->if_name);
			conf_pflow(output, ifs, ifnp->if_name);
			conf_ifxflags(output, ifs, ifnp->if_name);
			if (timeslot_status(ifs, ifnp->if_name, tmp,
			    sizeof(tmp)) == 1) 
				fprintf(output, " timeslots %s\n", tmp);
			if (conf_dhcrelay(ifnp->if_name, tmp, sizeof(tmp))
			    > 0)
				fprintf(output, " dhcrelay %s\n", tmp);
			conf_sppp(output, ifs, ifnp->if_name);
			conf_pppoe(output, ifs, ifnp->if_name);
		}
		conf_ifflags(output, flags, ifnp->if_name, ippntd);
	}
	close(ifs);
	if_freenameindex(ifn_list);
}