diff options
| author | Ivan Mosin | 2025-05-09 22:48:23 +0000 |
|---|---|---|
| committer | Robert Marko | 2025-05-18 16:22:22 +0000 |
| commit | d476e18e8d430ddfe3ae1809ddeea035bbb9a998 (patch) | |
| tree | b65e18811ab54173c6fab06f24a4e62b9996f5fa | |
| parent | 723c699e84f4b0f4515928f0cc57a5be2a317ced (diff) | |
| download | netifd-d476e18e8d430ddfe3ae1809ddeea035bbb9a998.tar.gz | |
iprule: resolve ipproto by name
Handle ipproto as an string. Set protocol in lowercase for musl libc compatibility.
Signed-off-by: Ivan Mosin <astrcomp@gmail.com>
Link: https://github.com/openwrt/netifd/pull/43
Signed-off-by: Robert Marko <robimarko@gmail.com>
| -rw-r--r-- | iprule.c | 6 | ||||
| -rw-r--r-- | system-dummy.c | 6 | ||||
| -rw-r--r-- | system-linux.c | 22 | ||||
| -rw-r--r-- | system.h | 1 |
4 files changed, 32 insertions, 3 deletions
@@ -64,7 +64,7 @@ static const struct blobmsg_policy rule_attr[__RULE_MAX] = { [RULE_UIDRANGE] = { .name = "uidrange", .type = BLOBMSG_TYPE_STRING }, [RULE_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING }, [RULE_GOTO] = { .name = "goto", .type = BLOBMSG_TYPE_INT32 }, - [RULE_IPPROTO] = { .name = "ipproto", .type = BLOBMSG_TYPE_INT32 }, + [RULE_IPPROTO] = { .name = "ipproto", .type = BLOBMSG_TYPE_STRING }, [RULE_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL }, }; @@ -312,8 +312,8 @@ iprule_add(struct blob_attr *attr, bool v6) } if ((cur = tb[RULE_IPPROTO]) != NULL) { - if ((rule->ipproto = blobmsg_get_u32(cur)) > 255) { - D(INTERFACE, "Invalid ipproto value: %u", blobmsg_get_u32(cur)); + if (!system_resolve_iprule_ipproto(blobmsg_data(cur), &rule->ipproto)) { + D(INTERFACE, "Failed to parse rule ip protocol: %s", (char *) blobmsg_data(cur)); goto error; } rule->flags |= IPRULE_IPPROTO; diff --git a/system-dummy.c b/system-dummy.c index a6e52bf..c698361 100644 --- a/system-dummy.c +++ b/system-dummy.c @@ -323,6 +323,12 @@ int system_flush_iprules(void) return 0; } +bool system_resolve_iprule_ipproto(const char *name, unsigned int *id) +{ + *id = 0; + return true; +} + bool system_resolve_iprule_action(const char *action, unsigned int *id) { *id = 0; diff --git a/system-linux.c b/system-linux.c index 46b5b9b..5c525ce 100644 --- a/system-linux.c +++ b/system-linux.c @@ -27,6 +27,7 @@ #include <net/if_arp.h> #include <limits.h> +#include <netdb.h> #include <arpa/inet.h> #include <netinet/in.h> #include <netinet/ether.h> @@ -3746,6 +3747,27 @@ bool system_resolve_iprule_action(const char *action, unsigned int *id) return system_rtn_aton(action, id); } +bool system_resolve_iprule_ipproto(const char *name, unsigned int *id) +{ + char *e; + struct protoent *ent; + unsigned int n, ipproto = 0; + + if ((n = strtoul(name, &e, 0)) > 0 && *e == '\0') + ipproto = n; + else { + ent = getprotobyname(name); + + if (ent) + ipproto = ent->p_proto; + else + return false; + } + + *id = ipproto; + return true; +} + time_t system_get_rtime(void) { struct timespec ts; @@ -311,6 +311,7 @@ int system_add_iprule(struct iprule *rule); int system_del_iprule(struct iprule *rule); int system_flush_iprules(void); +bool system_resolve_iprule_ipproto(const char *name, unsigned int *id); bool system_resolve_iprule_action(const char *action, unsigned int *id); time_t system_get_rtime(void); |