diff options
author | Phil Sutter <phil@nwl.cc> | 2018-09-19 15:16:44 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2018-09-24 11:23:46 +0200 |
commit | 31f1434dfe3770ecbdac1bacb8e0fc4a17b3d671 (patch) | |
tree | 0816392be62930436e984e1300c088fdf8f4d551 /extensions/libebt_vlan.c | |
parent | 7ae4fb1348874afbfd760d6b7a24e4ea2d6e67ab (diff) |
libxtables: Integrate getethertype.c from xtables core
This moves getethertype.c into libxtables so that both extensions and
xtables-nft-multi may use the implementations therein. New users are
libebt_arp and libebt_vlan which drop their own duplicated
implementations of getethertypebyname() for the shared one.
This change originated from a covscan report of extensions'
implementations not checking fopen() return value which should be
implicitly fixed by this as well.
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'extensions/libebt_vlan.c')
-rw-r--r-- | extensions/libebt_vlan.c | 72 |
1 files changed, 1 insertions, 71 deletions
diff --git a/extensions/libebt_vlan.c b/extensions/libebt_vlan.c index 4e2ea0fc..52cc99fa 100644 --- a/extensions/libebt_vlan.c +++ b/extensions/libebt_vlan.c @@ -50,76 +50,6 @@ static void brvlan_print_help(void) "--vlan-encap [!] encap : Encapsulated frame protocol (hexadecimal or name)\n"); } -static struct ethertypeent *vlan_getethertypeent(FILE *etherf, const char *name) -{ - static struct ethertypeent et_ent; - char *e, *found_name; - char line[1024]; - - while ((e = fgets(line, sizeof(line), etherf))) { - char *endptr, *cp; - - if (*e == '#') - continue; - - cp = strpbrk(e, "#\n"); - if (cp == NULL) - continue; - *cp = '\0'; - found_name = e; - - cp = strpbrk(e, " \t"); - if (cp == NULL) - continue; - - *cp++ = '\0'; - while (*cp == ' ' || *cp == '\t') - cp++; - e = strpbrk(cp, " \t"); - if (e != NULL) - *e++ = '\0'; - - et_ent.e_ethertype = strtol(cp, &endptr, 16); - if (*endptr != '\0' || - (et_ent.e_ethertype < ETH_ZLEN || et_ent.e_ethertype > 0xFFFF)) - continue; // skip invalid etherproto type entry - - if (strcasecmp(found_name, name) == 0) - return (&et_ent); - - if (e != NULL) { - cp = e; - while (cp && *cp) { - if (*cp == ' ' || *cp == '\t') { - cp++; - continue; - } - e = cp; - cp = strpbrk(cp, " \t"); - if (cp != NULL) - *cp++ = '\0'; - if (strcasecmp(e, name) == 0) - return (&et_ent); - e = cp; - } - } - } - - return NULL; -} - -static struct ethertypeent *brvlan_getethertypebyname(const char *name) -{ - struct ethertypeent *e; - FILE *etherf; - - etherf = fopen(_PATH_ETHERTYPES, "r"); - - e = vlan_getethertypeent(etherf, name); - fclose(etherf); - return (e); -} - static int brvlan_parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, struct xt_entry_match **match) @@ -156,7 +86,7 @@ brvlan_parse(int c, char **argv, int invert, unsigned int *flags, vlaninfo->invflags |= EBT_VLAN_ENCAP; local.encap = strtoul(optarg, &end, 16); if (*end != '\0') { - ethent = brvlan_getethertypebyname(optarg); + ethent = getethertypebyname(optarg); if (ethent == NULL) xtables_error(PARAMETER_PROBLEM, "Unknown --vlan-encap value ('%s')", optarg); local.encap = ethent->e_ethertype; |