Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147319406
D51244.1782899061.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D51244.1782899061.diff
View Options
diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c
--- a/sbin/ifconfig/ifbridge.c
+++ b/sbin/ifconfig/ifbridge.c
@@ -82,6 +82,22 @@
return (0);
}
+static int
+get_vlan_id(const char *cp, ether_vlanid_t *valp)
+{
+ char *endptr;
+ u_long val;
+
+ errno = 0;
+ val = strtoul(cp, &endptr, 0);
+ if (cp[0] == '\0' || endptr[0] != '\0' || errno == ERANGE ||
+ val < DOT1Q_VID_MIN || val > DOT1Q_VID_MAX)
+ return (-1);
+
+ *valp = (ether_vlanid_t)val;
+ return (0);
+}
+
static int
do_cmd(if_ctx *ctx, u_long op, void *arg, size_t argsize, int set)
{
@@ -545,28 +561,25 @@
{
struct ifbareq req;
struct ether_addr *ea;
- u_long vlan_id;
if (argc < 3)
errx(1, "usage: vstatic <interface> <address> <vlan id>");
- if (get_val(argv[2], &vlan_id) < 0 || vlan_id < DOT1Q_VID_MIN ||
- vlan_id > DOT1Q_VID_MAX)
- errx(1, "invalid vlan id: %s", argv[2]);
-
memset(&req, 0, sizeof(req));
+ req.ifba_flags = IFBAF_STATIC;
strlcpy(req.ifba_ifsname, argv[0], sizeof(req.ifba_ifsname));
ea = ether_aton(argv[1]);
if (ea == NULL)
errx(1, "invalid address: %s", argv[1]);
-
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
- req.ifba_flags = IFBAF_STATIC;
- req.ifba_vlan = vlan_id;
+
+ if (get_vlan_id(argv[2], &req.ifba_vlan) < 0)
+ errx(1, "invalid vlan id: %s", argv[2]);
if (do_cmd(ctx, BRDGSADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGSADDR %s %s %lu", argv[0], argv[1], vlan_id);
+ err(1, "BRDGSADDR %s %s %u", argv[0], argv[1],
+ (unsigned)req.ifba_vlan);
return 3;
}
@@ -576,26 +589,22 @@
{
struct ifbareq req;
struct ether_addr *ea;
- u_long vlan_id;
if (argc < 2)
errx(1, "usage: vdeladdr <address> <vlan id>");
- if (get_val(argv[1], &vlan_id) < 0 || vlan_id < DOT1Q_VID_MIN ||
- vlan_id > DOT1Q_VID_MAX)
- errx(1, "invalid vlan id: %s", argv[1]);
-
memset(&req, 0, sizeof(req));
ea = ether_aton(argv[0]);
if (ea == NULL)
errx(1, "invalid address: %s", argv[0]);
-
memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst));
- req.ifba_vlan = vlan_id;
+
+ if (get_vlan_id(argv[1], &req.ifba_vlan) < 0)
+ errx(1, "invalid vlan id: %s", argv[1]);
if (do_cmd(ctx, BRDGDADDR, &req, sizeof(req), 1) < 0)
- err(1, "BRDGDADDR %s %lu", argv[0], vlan_id);
+ err(1, "BRDGDADDR %s %u", argv[0], (unsigned)req.ifba_vlan);
return 2;
}
@@ -753,23 +762,13 @@
setbridge_untagged(if_ctx *ctx, const char *ifn, const char *vlanid)
{
struct ifbreq req;
- u_long val;
memset(&req, 0, sizeof(req));
+ strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
- if (get_val(vlanid, &val) < 0)
+ if (get_vlan_id(vlanid, &req.ifbr_pvid) < 0)
errx(1, "invalid VLAN identifier: %s", vlanid);
- /*
- * Reject vlan 0, since it's not a valid vlan identifier and has a
- * special meaning in the kernel interface.
- */
- if (val == 0)
- errx(1, "invalid VLAN identifier: %lu", val);
-
- strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname));
- req.ifbr_pvid = val;
-
if (do_cmd(ctx, BRDGSIFPVID, &req, sizeof(req), 1) < 0)
err(1, "BRDGSIFPVID %s", vlanid);
}
@@ -956,14 +955,11 @@
setbridge_defuntagged(if_ctx *ctx, const char *arg, int dummy __unused)
{
struct ifbrparam req;
- u_long vid;
-
- if (get_val(arg, &vid) < 0 || vid < DOT1Q_VID_MIN ||
- vid > DOT1Q_VID_MAX)
- errx(1, "invalid value: %s", arg);
memset(&req, 0, sizeof(req));
- req.ifbrp_defpvid = (ether_vlanid_t)vid;
+
+ if (get_vlan_id(arg, &req.ifbrp_defpvid) < 0)
+ errx(1, "invalid VLAN ID: %s", arg);
if (do_cmd(ctx, BRDGSDEFPVID, &req, sizeof(req), 1) < 0)
err(1, "BRDGSDEFPVID");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 1, 9:44 AM (7 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28997256
Default Alt Text
D51244.1782899061.diff (3 KB)
Attached To
Mode
D51244: ifconfig/ifbridge.c: add get_vlan_id() [old]
Attached
Detach File
Event Timeline
Log In to Comment