diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2015-11-21 15:57:49 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2015-11-21 15:57:49 +0300 |
commit | 4a41fc593e56691172a58b511a1d9ade63982c32 (patch) | |
tree | 535c8a5a53b737998d85ff097a059de4d582c3aa /accel-pppd/vlan-mon | |
parent | 9190fe47e0ce57e8f0b3360f2fe0404169b44263 (diff) | |
download | accel-ppp-4a41fc593e56691172a58b511a1d9ade63982c32.tar.gz accel-ppp-4a41fc593e56691172a58b511a1d9ade63982c32.zip |
move parse_vlan_mon function to vlan-mon module
Diffstat (limited to 'accel-pppd/vlan-mon')
-rw-r--r-- | accel-pppd/vlan-mon/vlan_mon.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/accel-pppd/vlan-mon/vlan_mon.c b/accel-pppd/vlan-mon/vlan_mon.c index 898d7dcd..7f15aa06 100644 --- a/accel-pppd/vlan-mon/vlan_mon.c +++ b/accel-pppd/vlan-mon/vlan_mon.c @@ -305,6 +305,59 @@ int __export make_vlan_name(const char *pattern, const char *parent, int svid, i return 0; } +int __export parse_vlan_mon(const char *opt, long *mask) +{ + char *ptr, *ptr2; + int vid, vid2; + + ptr = strchr(opt, ','); + if (!ptr) + ptr = strchr(opt, 0); + + if (*ptr == ',') + memset(mask, 0xff, 4096/8); + else if (*ptr == 0) { + memset(mask, 0, 4096/8); + return 0; + } else + goto out_err; + + while (1) { + vid = strtol(ptr + 1, &ptr2, 10); + if (vid <= 0 || vid >= 4096) { + log_error("vlan-mon=%s: invalid vlan %i\n", opt, vid); + return -1; + } + + if (*ptr2 == '-') { + vid2 = strtol(ptr2 + 1, &ptr2, 10); + if (vid2 <= 0 || vid2 >= 4096) { + log_error("vlan-mon=%s: invalid vlan %i\n", opt, vid2); + return -1; + } + + for (; vid < vid2; vid++) + mask[vid / (8*sizeof(long))] &= ~(1lu << (vid % (8*sizeof(long)))); + } + + mask[vid / (8*sizeof(long))] &= ~(1lu << (vid % (8*sizeof(long)))); + + if (*ptr2 == 0) + break; + + if (*ptr2 != ',') + goto out_err; + + ptr = ptr2; + } + + return 0; + +out_err: + log_error("vlan-mon=%s: failed to parse\n", opt); + return -1; +} + static void vlan_mon_mc_close(struct triton_context_t *ctx) { |