예제 #1
0
int
inttunnel(char *ifname, int ifs, int argc, char **argv)
{
	int set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((set && argc != 2) || (!set && argc > 2)) {
		printf("%% tunnel <src ip> <dest ip>\n");
		printf("%% no tunnel [src ip] [dest ip]\n");
		return(0);
	}

	if(set)
		settunnel(ifs, ifname, argv[0], argv[1]);
	else
		deletetunnel(ifs, ifname);
	return(0);
}
예제 #2
0
파일: tunnel.c 프로젝트: arnobroekhof/nsh
int
inttunnel(char *ifname, int ifs, int argc, char **argv)
{
	int set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if (((set && argc !=2 && argc != 4) || (set && argc == 4 &&
	    !isprefix(argv[2], "rdomain"))) || (!set && argc > 4)) {
		printf("%% tunnel <src ip> <dest ip> [rdomain <domain>]\n");
		printf("%% no tunnel [src ip] [dest ip] [rdomain <domain>]\n");
		return(0);
	}

	if(set && argc == 2)
		settunnel(ifs, ifname, argv[0], argv[1], NULL);
	else if(set && argc == 4)
		settunnel(ifs, ifname, argv[0], argv[1], argv[3]);
	else
		deletetunnel(ifs, ifname);
	return(0);
}
예제 #3
0
static gint
calculate_max_length (GOptionGroup *group)
{
  GOptionEntry *entry;
  gint i, len, max_length;

  max_length = 0;

  for (i = 0; i < group->n_entries; i++)
    {
      entry = &group->entries[i];

      if (entry->flags & G_OPTION_FLAG_HIDDEN)
	continue;

      len = g_utf8_strlen (entry->long_name, -1);
      
      if (entry->short_name)
	len += 4;
      
      if (!NO_ARG (entry) && entry->arg_description)
	len += 1 + g_utf8_strlen (TRANSLATE (group, entry->arg_description), -1);
      
      max_length = MAX (max_length, len);
    }

  return max_length;
}
예제 #4
0
파일: if.c 프로젝트: yellowman/nsh
int
intdesc(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	char desc[IFDESCRSIZE];
	struct ifreq ifr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if (set && argc < 1) {
		printf("%% description <text of description>\n");
		printf("%% no description\n");
		return(0);
	}

	argvtostring(argc, argv, desc, sizeof(desc));

	if (set)
		ifr.ifr_data = (caddr_t)&desc;
	else
		ifr.ifr_data = (caddr_t)"";
	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSIFDESCR, &ifr) < 0)
		printf("%% intdesc: SIOCSIFDESCR: %s\n", strerror(errno));

	return(0);
}
예제 #5
0
파일: bridge.c 프로젝트: muhammadn/nsh
int 
brstatic(char *ifname, int ifs, int argc, char **argv)
{
	int set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;
	argv++;
	argc--;

	if ((set && argc != 2) || ((!set && argc <1) || (!set && argc > 2))) {
		printf("%% static <mac address> <member>\n");
		printf("%% no static <mac address> [member]\n");
		return(0);
	}

	if (argv[1] && (!is_valid_ifname(argv[1]) || is_bridge(ifs, argv[1])))
	{
		printf("%% invalid member: %s\n", argv[1]);
		return(0);
	}

	if (set)
		bridge_addaddr(ifs, ifname, argv[1], argv[0]);
	else
		bridge_deladdr(ifs, ifname, argv[0]);

	return(0);
}
예제 #6
0
파일: if.c 프로젝트: yellowman/nsh
int
intaf(char *ifname, int ifs, int argc, char **argv)
{
	int set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	if (argc > 1) {
		printf("%% Invalid argument\n");
		return(1);
	}

	if (isprefix(argv[0], "inet6")) {
		if (set)
			addaf(ifname, AF_INET6, ifs);
		else
			removeaf(ifname, AF_INET6, ifs);
	} else {
		printf("%% intaf: prefix internal error\n");
	}
	return(0);
}
예제 #7
0
int
intdhcrelay(char *ifname, int ifs, int argc, char **argv)
{
	char *cmd[] = { DHCRELAY, "-i", ifname, NULL, '\0' };
 	char fname[SIZE_CONF_TEMP];
	int set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 1) || (set && argc != 1)) {
		printf("%% dhcrelay <relayserver>\n");
		printf("%% no dhcrelay [relayserver]\n");
		return(0);
	}

	cmd[3] = argv[0];

	snprintf(fname, sizeof(fname), "/var/run/dhcrelay.%s", ifname);
	
	if (set) {
		flag_x(fname, X_ENABLE, argv[0]);
		cmdargs(DHCRELAY, cmd);
	} else {
		char server[24], argue[SIZE_CONF_TEMP];
		char *killcmd[] = { PKILL, "-xf", NULL, '\0' };

		if (conf_dhcrelay(ifname, server, sizeof(server)) == NULL) {
			if (errno == ENOENT)
				printf("%% No relay configured for %s\n", ifname);
			else
				printf("%% int_dhcrelay: conf_dhcrelay failed: %s\n", strerror(errno));
			return(0);
		}

		/* if dhcrelay not relaying to specified dhcp server, bail out */
		if (argc && strcmp(server, argv[0]) != 0) {
			printf("%% Server expected: %s (not %s)\n", server, argv[0]);
			return(0);
		}

		/* delete .enabled file */
		flag_x(fname, X_DISABLE, NULL);

		/* setup argument list as one argument for pkill -xf */
		snprintf(argue, sizeof(argue), "%s %s %s %s", cmd[0], cmd[1], cmd[2], server);
		killcmd[2] = argue;

		cmdargs(PKILL, killcmd);
	}
	return(0);
}
예제 #8
0
파일: pfsync.c 프로젝트: bklang/nsh
int
intmaxupd(char *ifname, int ifs, int argc, char **argv)
{
	struct ifreq ifr;
	struct pfsyncreq preq;
	u_int32_t val;
	int set;
	const char *errmsg = NULL;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 2) || (set && (argc < 1 || argc > 2)) ||
	    (set && argc == 2 && !isprefix(argv[1], "defer"))) {
		printf("%% maxupd <max pfsync updates> [defer]\n");
		printf("%% no maxupd [max pfsync updates] [defer]\n");
		return (0);
	}
	bzero((char *) &preq, sizeof(struct pfsyncreq));
	ifr.ifr_data = (caddr_t) & preq;
	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

	if (ioctl(ifs, SIOCGETPFSYNC, (caddr_t) & ifr) == -1) {
		printf("%% intmaxupd: SIOCGETPFSYNC: %s\n", strerror(errno));
		return (0);
	}
	if (set) {
		errno = 0;
		val = strtonum(argv[0], 0, INT_MAX, &errmsg);
		if (errmsg) {
			printf("%% maxupd value out of range %s: %s\n", argv[0],
			    errmsg);
			return (0);
		}
		preq.pfsyncr_maxupdates = (int)val;
		if (argc == 2)
			preq.pfsyncr_defer = 1;
	} else
		preq.pfsyncr_maxupdates = PFSYNC_MAXUPDATES;

	if (ioctl(ifs, SIOCSETPFSYNC, (caddr_t) & ifr) == -1) {
		if (errno == EINVAL)
			printf("%% maxupd value out of range\n");
		else
			printf("%% intmaxupd: SIOCSETPFSYNC: %s\n",
			    strerror(errno));
	}
	return (0);
}
예제 #9
0
파일: trunk.c 프로젝트: arnobroekhof/nsh
int
inttrunkproto(char *ifname, int ifs, int argc, char **argv)
{
	int i, set;
	struct trunk_reqall ra;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc != 1) || (set && argc != 1)) {
                printf("%% trunkproto <proto>\n");
                printf("%% no trunkproto\n");
                return(0);
        }

	bzero(&ra, sizeof(ra));
	strlcpy(ra.ra_ifname, ifname, sizeof(ra.ra_ifname));

	if (set) {
		for (i = 0; i < TRUNK_PROTO_MAX; ++i) {
			if (isprefix(argv[0], (char *)tpr[i].tpr_name)) {
				ra.ra_proto = tpr[i].tpr_proto;
				break;
			}
		}
		if (i == TRUNK_PROTO_MAX) {
			printf("%% trunkproto <");
			for (i = 0; i < TRUNK_PROTO_MAX; ++i)
				printf("%s%s", i == 0 ? "" : "|", tpr[i].tpr_name);
			printf(">\n");
			return(0);
		}
	} else
		ra.ra_proto = TRUNK_PROTO_DEFAULT;

	if (ioctl(ifs, SIOCSTRUNK, &ra) != 0) {
		switch(errno) {
		case ENOTTY:
			printf("%% %s not trunk\n", ifname);
			break;
		default:
			printf("%% inttrunkproto: SIOCSTRUNK: %s\n", strerror(errno));
		}
		return 1;
	}

	return 0;
}
예제 #10
0
파일: if.c 프로젝트: yellowman/nsh
int
intgroup(char *ifname, int ifs, int argc, char **argv)
{
	int set, i;
	struct ifgroupreq ifgr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if (argc < 1) {
		printf("%% group <group-name> [group-name ...]\n");
		printf("%% no group <group-name> [group-name ...]\n");
		return 0;
	}

	for (i = 0; i < argc; i++) {
		/* Validate supplied argument(s) before applying them */
		if (isdigit(argv[i][strlen(argv[i]) - 1])) {
			printf("%% Group names may not end with a digit\n");
			return 0;
		}
		if (strlen(argv[i]) >= IFNAMSIZ) {
			printf("%% Group name too long (%s)\n", argv[i]);
			return 0;
		}
	}

	for (i = 0; i < argc; i++) {
		bzero(&ifgr, sizeof(ifgr));
		strlcpy(ifgr.ifgr_name, ifname, IFNAMSIZ);
		strlcpy(ifgr.ifgr_group, argv[i], IFNAMSIZ);

		if (ioctl(ifs, set ? SIOCAIFGROUP : SIOCDIFGROUP,
		    (caddr_t)&ifgr) == -1) {
			switch(errno) {
			case EEXIST:
				break;
			default:
				printf("%% intgroup: SIOC%sIFGROUP: %s\n",
				    set ? "S" : "D", strerror(errno));
				break;
			}
		}
	}

	return 0;
}
예제 #11
0
int
intflags(char *ifname, int ifs, int argc, char **argv)
{
	int set, value, flags;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	if (isprefix(argv[0], "debug")) {
		/* debug */
		value = IFF_DEBUG;
	} else if (isprefix(argv[0], "shutdown")) {
		/* shutdown */
		value = -IFF_UP;
	} else if (isprefix(argv[0], "arp")) {
		/* arp */
		value = -IFF_NOARP;
	} else {
		printf("%% intflags: Internal error\n");
		return(0);
	}

	flags = get_ifflags(ifname, ifs);
	if (value < 0) {
		/*
		 * Idea from ifconfig.  If value is negative then
		 * we just reverse the operation. (e.g. 'shutdown' is
		 * the opposite of the IFF_UP flag)
		 */
		if (set) {
			value = -value;
			flags &= ~value;
		} else {
			value = -value;
			flags |= value;
		}
	} else if (value > 0) {
		if (set)
			flags |= value;
		else
			flags &= ~value;
	} else {
		printf("%% intflags: value internal error\n");
	}
	set_ifflags(ifname, ifs, flags);
	return(0);
}
예제 #12
0
파일: media.c 프로젝트: muhammadn/nsh
int
intmediaopt(char *ifname, int ifs, int argc, char **argv)
{
	int set, media_current, mediaopt;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argv++;
	argc--;

	if ((set && (argc != 1)) || (!set && (argc > 1))) {
		printf("%% mediaopt <option>\n");
		printf("%% no mediaopt [option]\n");
		return(0);
	}

        media_current = init_current_media(ifs, ifname);

	if (media_current == -1) {
		if (errno == EINVAL)
			printf("%% This device does not support "
			    "media commands.\n");
		else
			printf("%% Failed to initialize media: %s\n",
			    strerror(errno));
		return(0);
	}

	if (argc == 1)
		mediaopt = get_media_options(IFM_TYPE(media_current), argv[0]);
	else
		mediaopt = IFM_OPTIONS(media_current);

	if (mediaopt == -1)
		return(0);

	if (set)
		media_current |= mediaopt;
	else
		media_current &= ~mediaopt;

	process_media_commands(ifs, ifname, media_current);

	return(0);
}
예제 #13
0
파일: if.c 프로젝트: yellowman/nsh
int
intpowersave(char *ifname, int ifs, int argc, char **argv)
{
	const char *errmsg = NULL;
	struct ieee80211_power power;
	int  set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

 	if (argc > 1) {
		printf("%% powersave [milisec]\n");
		printf("%% no powersave [milisec]\n");
	}

	strlcpy(power.i_name, ifname, sizeof(power.i_name));

	if (ioctl(ifs, SIOCG80211POWER, (caddr_t)&power) == -1) {
		printf("%% intpowersave: SIOCG80211POWER: %s\n",
		    strerror(errno));
		return(0);
	}

	if (argc == 1)
		power.i_maxsleep = strtonum(argv[0], 0, 1000, &errmsg);
		if (errmsg) {
			printf("%% Power save invalid %s: %s", argv[0],
			    errmsg);
			return(0);
		}
	else
		power.i_maxsleep = DEFAULT_POWERSAVE;
	power.i_enabled = set;

	if (ioctl(ifs, SIOCS80211POWER, (caddr_t)&power) == -1) {
		printf("%% intpowersave: SIOCS80211POWER: %s\n",
		    strerror(errno));
		return(0);
	}

	return(0);
}
예제 #14
0
파일: if.c 프로젝트: yellowman/nsh
int
intkeepalive(char *ifname, int ifs, int argc, char **argv)
{
	struct ifkalivereq ikar;
	int set;
	const char *errmsg = NULL;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 2) || (set && argc != 2)) {
		printf("%% keepalive <period> <count>\n");
		printf("%% no keepalive [period] [count]\n");
		return(0);
	}

	bzero(&ikar, sizeof(ikar));

	if (set) {
		ikar.ikar_timeo = strtonum(argv[0], 1, 3600, &errmsg);
		if (errmsg) {
			printf("%% Invalid period %s: %s\n", argv[0], errmsg);
			return(0);
		}
		ikar.ikar_cnt = strtonum(argv[1], 2, 600, &errmsg);
		if (errmsg) {
			printf("%% Invalid count %s: %s\n", argv[1], errmsg);
			return(0);
		}
	}

	strlcpy(ikar.ikar_name, ifname, sizeof(ikar.ikar_name));
	if (ioctl(ifs, SIOCSETKALIVE, (caddr_t)&ikar) < 0) {
		if (errno == ENOTTY)
			printf("%% Keepalive not available on %s\n", ifname);
		else
			printf("%% intkeepalive: SIOCSETKALIVE: %s\n",
			    strerror(errno));
	}

	return(0);
}
예제 #15
0
파일: if.c 프로젝트: yellowman/nsh
int
intmpelabel(char *ifname, int ifs, int argc, char **argv)
{
	struct ifreq ifr;
	struct shim_hdr shim;
	int set;
	const char *errmsg = NULL;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 1) || (set && argc != 1)) {
		printf("%% label <mplslabel>\n");
		printf("%% no label [mplslabel]\n");
		return(0);
	}

	bzero(&shim, sizeof(shim));
	ifr.ifr_data = (caddr_t)&shim;

	if (set) {
		shim.shim_label = strtonum(argv[0], 0, MPLS_LABEL_MAX,
		    &errmsg);
		if (errmsg) {
			printf("%% Invalid MPLS Label %s: %s\n", argv[0],
			    errmsg);
			return(0);
		}
	} else
		shim.shim_label = 0;

	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSETLABEL, (caddr_t)&ifr) < 0) {
		if (errno == ENOTTY)
			printf("%% MPLS label not supported on %s\n", ifname);
		else
			printf("%% intlabel: SIOCSETLABEL: %s\n",
			    strerror(errno));
	}
	return(0);
}
예제 #16
0
파일: if.c 프로젝트: yellowman/nsh
int
intxflags(char *ifname, int ifs, int argc, char **argv)
{
	int set, value, flags;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	if (isprefix(argv[0], "autoconfprivacy")) {
		value = -IFXF_INET6_NOPRIVACY;
	} else if (isprefix(argv[0], "autoconf6")) {
		value = IFXF_AUTOCONF6;
	} else if (isprefix(argv[0], "mpls")) {
		value = IFXF_MPLS;
	} else if (isprefix(argv[0], "wol")) {
		value = IFXF_WOL;
	} else {
		printf("%% intxflags: Internal error\n");
		return(0);
	}

	flags = get_ifxflags(ifname, ifs);
	if (value < 0) {
		if (set) {
			value = -value;
			flags &= ~value;
		} else {
			value = -value;
			flags |= value;
		}
	} else if (value > 0) {
		if (set)
			flags |= value;
		else
			flags &= ~value;
	} else {
		printf("%% intxflags: value internal error\n");
	}
	set_ifxflags(ifname, ifs, flags);
	return(0);
}
예제 #17
0
int
inttxpower(char *ifname, int ifs, int argc, char **argv)
{
	const char *errmsg = NULL;
	struct ieee80211_txpower txpower;
	short dbm, set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% txpower <dBm>\n");
		printf("%% no txpower     (auto-select)\n");
		return(0);
	}

	strlcpy(txpower.i_name, ifname, sizeof(txpower.i_name));
   
	if (!set) {
		txpower.i_val = 100;
		txpower.i_mode = IEEE80211_TXPOWER_MODE_AUTO;
	} else {
		dbm = strtonum(argv[0], SHRT_MIN, SHRT_MAX, &errmsg);
		if (errmsg) {
			printf("%% inttxpower: txpower %sdBm: %s\n", argv[0],
			    errmsg);
			return(0);
		}
		txpower.i_val = (int16_t)dbm;
		txpower.i_mode = IEEE80211_TXPOWER_MODE_FIXED;
	}

	if (ioctl(ifs, SIOCS80211TXPOWER, (caddr_t)&txpower) == -1)
		printf("%% inttxpower: SIOCS80211TXPOWER failed: %s\n",
		    strerror(errno));

	return(0);
}
예제 #18
0
int
intnwid(char *ifname, int ifs, int argc, char **argv)
{
	struct ieee80211_nwid nwid;
	struct ifreq ifr;
	int set, len;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% nwid <nwid>\n");
		printf("%% no nwid [nwid]\n");
		return(0);
	}

	len = sizeof(nwid.i_nwid);

	if (set) {
		if (get_string(argv[0], NULL, nwid.i_nwid, &len) == NULL) {
			printf("%% intnwid: bad input\n");
			return(0);
		}
	} else
		len = 0; /* nwid "" */

	nwid.i_len = len;
	ifr.ifr_data = (caddr_t)&nwid;
	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

	if (ioctl(ifs, SIOCS80211NWID, (caddr_t)&ifr) < 0)
		printf("%% intnwid: SIOCS80211NWID: %s\n", strerror(errno));

	return(0);
}
예제 #19
0
파일: if.c 프로젝트: yellowman/nsh
int
intpatch(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	struct ifreq ifr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% patch <pair interface>\n");
		printf("%% no patch [pair interface]\n");
		return 0;
	}

	bzero(&ifr, sizeof(ifr));

	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (set) {
		if ((ifr.ifr_index = if_nametoindex(argv[0])) == 0) {
			printf("%% invalid interface %s\n", argv[0]);
			return 0;
		}
	} else {
		ifr.ifr_index = 0;
	}
#ifdef SIOCSIFPAIR /* 6.0+ */
	if (ioctl(ifs, SIOCSIFPAIR, &ifr) == -1)
		printf("%% intpatch: SIOCSIFPAIR: %s\n", strerror(errno));
#else
	printf("%% Unsupported OpenBSD version\n");
#endif

	return 0;
}
예제 #20
0
int
intbssid(char *ifname, int ifs, int argc, char **argv)
{
	struct ieee80211_bssid bssid;
	struct ether_addr *ea;
	short set;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% bssid <xx:xx:xx:xx:xx:xx>\n");
		printf("%% no bssid       (auto-select)\n");
		return(0);
	}

	if (set) {
		ea = ether_aton(argv[1]);
		if (ea == NULL) {
			printf("%% Invalid bssid\n");
			return(0);
		}
		memcpy(&bssid.i_bssid, ea->ether_addr_octet,
		    sizeof(bssid.i_bssid));
	} else
		memset(&bssid.i_bssid, 0, sizeof(bssid.i_bssid));

	strlcpy(bssid.i_name, ifname, sizeof(bssid.i_name));
	if (ioctl(ifs, SIOCS80211BSSID, &bssid) == -1) {
		printf("%% inttxpower: SIOCS80211BSSID failed: %s\n",
		    strerror(errno));
	}

	return (0);
}
예제 #21
0
파일: bridge.c 프로젝트: muhammadn/nsh
int
brrule(char *ifname, int ifs, int argc, char **argv)
{
	if (NO_ARG(argv[0])) {
		printf("%% all rules for a member must be applied in order\n");
		printf("%% use flush bridge-rules <bridge> <member>\n");
		printf("%% to erase all rules on interface <member>\n");
		return(0);
	}

	argv++;
	argc--;

	if (argc == 0) {
		printf("%% rule {block | pass} {in | out | in/out} on <member> [{src} mac] [{dst} mac]\n");
		return(0);
	}

	bridge_rule(ifs, ifname, argc, argv, -1);
	return(0);
}
예제 #22
0
파일: if.c 프로젝트: yellowman/nsh
int
intrdomain(char *ifname, int ifs, int argc, char **argv)
{
	int set, rdomain;
	const char *errmsg = NULL;
	struct ifreq ifr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if (set && argc < 1) {
		printf("%% rdomain <routing domain number>\n");
		printf("%% no rdomain\n");
		return(0);
	}

	rdomain = strtonum(argv[0], 0, RT_TABLEID_MAX, &errmsg);
	if (errmsg) {
		printf("%% Routing domain %s invalid (%s)\n", argv[0], errmsg);
		return(0);
	}

	if (set)
		ifr.ifr_rdomainid = rdomain;
	else
		ifr.ifr_rdomainid = 0;
	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSIFRDOMAIN, &ifr) < 0)
		printf("%% intrdomain: SIOCSIFRDOMAIN: %s\n", strerror(errno));

	return(0);
}
예제 #23
0
int
intmetric(char *ifname, int ifs, int argc, char **argv)
{
	struct ifreq ifr;
	int set;
	const char *errmsg = NULL;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 1) || (set && argc != 1)) {
		printf("%% metric <metric>\n");
		printf("%% no metric [metric]\n");
		return(0);
	}

	if (set)
		ifr.ifr_metric = strtonum(argv[0], 0, ULONG_MAX, &errmsg);
	else
		ifr.ifr_metric = 0;

	if (errmsg) {
		printf("%% Invalid metric %s: %s\n", argv[0], errmsg);
		return(0);
	}

	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
		printf("%% intmetric: SIOCSIFMETRIC: %s\n", strerror(errno));

	return(0);
}
예제 #24
0
파일: if.c 프로젝트: yellowman/nsh
int
intparent(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	struct if_parent ifp;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((set && argc != 1) || (!set && argc > 1)) {
                printf("%% parent <parent interface>\n");
                printf("%% no parent [parent interface]\n");
                return 0;
        }

	bzero(&ifp, sizeof(ifp));

	strlcpy(ifp.ifp_name, ifname, IFNAMSIZ);

	if (set && strlcpy(ifp.ifp_parent, argv[0], sizeof(ifp.ifp_parent)) >=
	    sizeof(ifp.ifp_parent)) {
		printf("%% parent name too long\n");
		return 0;
	}

	if (ioctl(ifs, set ? SIOCSIFPARENT : SIOCDIFPARENT, &ifp) == -1)
		printf("%% intparent: SIOC%sIFPARENT: %s\n", set ? "S" : "D",
		    strerror(errno));

	return 0;
}
예제 #25
0
int
intmtu(char *ifname, int ifs, int argc, char **argv)
{
	struct ifreq ifr;
	int set;
	const char *errmsg = NULL;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc > 1) || (set && argc != 1)) {
		printf("%% mtu <mtu>\n");
		printf("%% no mtu [mtu]\n");
		return(0);
	}

	if (set) {
		ifr.ifr_mtu = strtonum(argv[0], 0, INT_MAX, &errmsg);
		if (errmsg) {
			printf("%% Invalid MTU %s: %s\n", argv[0], errmsg);
			return(0);
		}
	} else
		ifr.ifr_mtu = default_mtu(ifname);

	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSIFMTU, (caddr_t)&ifr) < 0)
		printf("%% intmtu: SIOCSIFMTU: %s\n", strerror(errno));

	return(0);
}
예제 #26
0
int
intdesc(char *ifname, int ifs, int argc, char **argv)
{
	int set, i;
	char desc[IFDESCRSIZE];
	struct ifreq ifr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	argv++;
	argc--;

	if (set && argc < 1) {
		printf("%% description <text of description>\n");
		printf("%% no description\n");
		return(0);
	}

	for (i = 0; (set && i < argc); i++) {
		snprintf(desc, sizeof(desc), "%s%s%s", i == 0 ? "" : desc,
		    i != 0 ? " " : "", argv[i]);
	}

	if (set)
		ifr.ifr_data = (caddr_t)&desc;
	else
		ifr.ifr_data = (caddr_t)"";
	strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
	if (ioctl(ifs, SIOCSIFDESCR, &ifr) < 0)
		printf("%% intdesc: SIOCSIFDESCR: %s\n", strerror(errno));

	return(0);
}
예제 #27
0
int
intrtlabel(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	struct ifreq ifr;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	bzero(&ifr, sizeof(ifr));

	strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);

	if (set) {
		if (strlen(argv[0]) >= RTLABEL_LEN) {
			printf("%% label too long (max %d char)\n",
			    RTLABEL_LEN - 1);
			return 0;
		}
		ifr.ifr_data = (caddr_t)argv[0];
	} else {
		ifr.ifr_data = (caddr_t)(const char *)"";
	}

	if (ioctl(ifs, SIOCSIFRTLABEL, &ifr) == -1)
		printf("%% intrtlabel: SIOCSIFRTLABEL: %s\n", strerror(errno));

	return 0;
}
예제 #28
0
파일: trunk.c 프로젝트: arnobroekhof/nsh
int
inttrunkport(char *ifname, int ifs, int argc, char **argv)
{
	struct trunk_reqport rp;
	int set, i;

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	argc--;
	argv++;

	if ((!set && argc < 1) || (set && argc < 1)) {
		printf("%% trunkport <ifname> [ifname ...]\n");
		printf("%% no trunkport <ifname> [ifname ...]\n");
		return(0);   
	}

	bzero(&rp, sizeof(rp));
	strlcpy(rp.rp_ifname, ifname, sizeof(rp.rp_ifname));

	for (i = 0; i < argc; i++) {
		if (set) {  
			strlcpy(rp.rp_portname, argv[i],
			    sizeof(rp.rp_portname));
			if (ioctl(ifs, SIOCSTRUNKPORT, &rp) < 0) {
				switch(errno) {
				case ENOTTY:
					printf("%% %s not trunk\n",ifname);
					break;
				case EBUSY:
					printf("%% Failed (port %s already"
					    " assigned to a trunk group)\n",
					    argv[i]);
					break;
				case ENETDOWN:
					printf("%% Failed (port %s is "
					    "shutdown)\n", argv[i]);
					break;
				default:
					printf("%% inttrunkport:"
					    " SIOCSTRUNKPORT: %s\n",
				    strerror(errno));
				}
			}
		} else {
			strlcpy(rp.rp_portname, argv[i],
			    sizeof(rp.rp_portname));
			if (ioctl(ifs, SIOCSTRUNKDELPORT, &rp) < 0) {
				switch(errno) {
				case ENOTTY:
					printf("%% %s not trunk\n",ifname);
					break;
				case ENOENT:
					printf("%% Port %s not part of %s\n",
					    argv[i], ifname);
					break;
				default:
					printf("%% inttrunkport:"
					    " SIOCSTRUNKDELPORT: %s\n,",
				    strerror(errno));
				}
				return 1;
			}
		}
	}
	return 0;
}
예제 #29
0
파일: bridge.c 프로젝트: muhammadn/nsh
int
brpri(char *ifname, int ifs, int argc, char **argv)   
{
	int set, val;
	const char *errmsg = NULL;
	struct brd *x;
         
	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	x = (struct brd *) genget(argv[0], (char **)brds, sizeof(struct brd));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argv++;
	argc--;

	/*
	 * the ifpriority value is ignored for 'no ifpriority' but
	 * we allow it anyways to retain compatibility with the 
	 * set form of this command
	 */
	if ((set && argc != 2) || (!set && (argc < 1 || argc > 2))) {
		printf("%% %s <member> <%s>\n", x->name, x->descr);
		printf("%% no %s <member> [%s]\n", x->name, x->descr);
		return(0);
	}

	if (!is_valid_ifname(argv[0]) || is_bridge(ifs, argv[0]))
	{
		printf("%% invalid member name: %s", argv[0]);
		return(0);
	}

	errno = 0;
	val = strtonum(argv[1], 0, 0xff, &errmsg);
	if (errmsg) {
		printf("%% invalid priority %s: %s\n", argv[1], errmsg);
		return (0);
        }

	switch(x->type) {
	case BRPRI_IFPRIORITY:
		if (set) {
			if (val > 0xff) {
				printf("%% %s exceeds limit\n", x->name);
				return(0);
			}
			bridge_ifprio(ifs, ifname, argv[0], val);
		} else {
			bridge_ifprio(ifs, ifname, argv[0], DEFAULT_IFPRIORITY);
		}	
	break;
	case BRPRI_IFCOST:
		if (set) {
			if (val > 65535) {
				printf("%% %s exceeds limit\n", x->name);
				return(0);
			}
			bridge_ifcost(ifs, ifname, argv[0], val);
		} else {
			bridge_ifcost(ifs, ifname, argv[0], DEFAULT_IFCOST);
		}
	break;
	}
	

	return(0);
}
예제 #30
0
파일: bridge.c 프로젝트: muhammadn/nsh
int
brval(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	u_int32_t val = 0;
	const char *errmsg = NULL;
	struct brc *x;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	x = (struct brc *) genget(argv[0], (char **)brvs, sizeof(struct brc));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argv++;
	argc--;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% %s <val>\n", x->name);
		printf("%% no %s [val]\n", x->name);
		return(0);
	}

	if (set) {
		errno = 0;
		val = strtonum(argv[0], 0, ULONG_MAX, &errmsg);
		if (errmsg) {
			printf("%% invalid %s argument %s: %s\n", x->name,
			    argv[0], errmsg);
			return(0);
		}
	}

	switch(x->type) {
	case BRVAL_MAXADDR:
		if (set)
			bridge_maxaddr(ifs, ifname, val);
		else
			bridge_maxaddr(ifs, ifname, DEFAULT_MAXADDR);
		break;
	case BRVAL_TIMEOUT:
		if (set)
			bridge_timeout(ifs, ifname, (int)val);
		else
			bridge_timeout(ifs, ifname, DEFAULT_TIMEOUT);
		break;
	case BRVAL_MAXAGE:
		if (val > 0xff) {
			printf("%% maxage too large\n");
			return(0);
		}
		if (set)
			bridge_maxage(ifs, ifname, val);
		else
			bridge_maxage(ifs, ifname, DEFAULT_MAXAGE);
		break;
	case BRVAL_FWDDELAY:
		if (val > 0xff) {
			printf("%% fwddelay too large\n");
			return(0);
		}
		if (set)
			bridge_fwddelay(ifs, ifname, val);
		else
			bridge_fwddelay(ifs, ifname, DEFAULT_FWDDELAY);
		break;
	case BRVAL_HELLOTIME:
		if (val > 0xff) {
			printf("%% hellotime too large\n");
			return(0);
		}
		if (set)
			bridge_hellotime(ifs, ifname, val);
		else
			bridge_hellotime(ifs, ifname, DEFAULT_HELLOTIME);
		break;
	case BRVAL_PRIORITY:
		if (val > 0xffff) {
			printf("%% priority too large\n");
			return(0);
		}
		if (set)
			bridge_priority(ifs, ifname, val);
		else
			bridge_priority(ifs, ifname, DEFAULT_PRIORITY);
		break;
	}

	return(0);
}