From a93e68447a55735675b885b2530557a16d24e5b2 Mon Sep 17 00:00:00 2001 From: Sven Eckelmann Date: Thu, 1 Aug 2019 18:52:28 +0200 Subject: [PATCH] alfred: Merge bugfixes from 2019.3 * vis: Use rtnl to query list of hardifs of meshif * vis: Retrieve hardif status via generic netlink Signed-off-by: Sven Eckelmann --- alfred/Makefile | 2 +- ...tnl-to-query-list-of-hardifs-of-mesh.patch | 242 +++++++++++++++++ ...eve-hardif-status-via-generic-netlin.patch | 201 ++++++++++++++ ...is-Add-missing-include-for-ifinfomsg.patch | 21 ++ ...v-convert-stream-like-files-from-non.patch | 55 ---- ...v-compat-Drop-support-for-genl_ops-s.patch | 29 -- ...v-genetlink-optionally-validate-stri.patch | 222 --------------- ...v-genetlink-make-policy-common-to-fa.patch | 256 ------------------ 8 files changed, 465 insertions(+), 563 deletions(-) create mode 100644 alfred/patches/0001-alfred-vis-Use-rtnl-to-query-list-of-hardifs-of-mesh.patch create mode 100644 alfred/patches/0002-alfred-vis-Retrieve-hardif-status-via-generic-netlin.patch create mode 100644 alfred/patches/0003-alfred-vis-Add-missing-include-for-ifinfomsg.patch delete mode 100644 batman-adv/patches/0001-Revert-batman-adv-convert-stream-like-files-from-non.patch delete mode 100644 batman-adv/patches/0002-Revert-batman-adv-compat-Drop-support-for-genl_ops-s.patch delete mode 100644 batman-adv/patches/0003-Revert-batman-adv-genetlink-optionally-validate-stri.patch delete mode 100644 batman-adv/patches/0004-Revert-batman-adv-genetlink-make-policy-common-to-fa.patch diff --git a/alfred/Makefile b/alfred/Makefile index 535e712..66e82ce 100644 --- a/alfred/Makefile +++ b/alfred/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=alfred PKG_VERSION:=2019.2 -PKG_RELEASE:=0 +PKG_RELEASE:=1 PKG_HASH:=b656f0e9a97a99c7531b6d49ebfd663451c16cdd275bbf7d48ff8daed3880bf2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz diff --git a/alfred/patches/0001-alfred-vis-Use-rtnl-to-query-list-of-hardifs-of-mesh.patch b/alfred/patches/0001-alfred-vis-Use-rtnl-to-query-list-of-hardifs-of-mesh.patch new file mode 100644 index 0000000..b5b9c55 --- /dev/null +++ b/alfred/patches/0001-alfred-vis-Use-rtnl-to-query-list-of-hardifs-of-mesh.patch @@ -0,0 +1,242 @@ +From: Sven Eckelmann +Date: Wed, 19 Jun 2019 21:38:09 +0200 +Subject: alfred: vis: Use rtnl to query list of hardifs of meshif + +The normal way of network related programs to query the state of interfaces +is to use the rtnetlink. Most of these data can also be queried via sysfs +but it is better to use the same way for both retrieving the list of +interfaces and modifying the list of interfaces. + +Also the sysfs files are deprecated and cause warnings when access: + + batman_adv: [Deprecated]: batadv-vis (pid 832) Use of sysfs file "mesh_iface". + Use batadv genl family instead + +In worst case, the file doesn't even exist when batman-adv was compiled +without sysfs support. + +Reported-by: Linus Lüssing +Signed-off-by: Sven Eckelmann + +Origin: upstream, https://git.open-mesh.org/alfred.git/commit/a34f044de561ce90f67b5760059f818bfb35b449 + +diff --git a/vis/vis.c b/vis/vis.c +index beaeca150bcac583e9506b9504fa026131f50d5d..37956b100fad72257f5bab2b9f49908da59520cc 100644 +--- a/vis/vis.c ++++ b/vis/vis.c +@@ -372,70 +372,146 @@ static void clear_lists(struct globals *globals) + } + } + ++static int query_rtnl_link(int ifindex, nl_recvmsg_msg_cb_t func, void *arg) ++{ ++ struct ifinfomsg rt_hdr = { ++ .ifi_family = IFLA_UNSPEC, ++ }; ++ struct nl_sock *sock; ++ struct nl_msg *msg; ++ struct nl_cb *cb; ++ int err = 0; ++ int ret; ++ ++ sock = nl_socket_alloc(); ++ if (!sock) ++ return -ENOMEM; ++ ++ ret = nl_connect(sock, NETLINK_ROUTE); ++ if (ret < 0) { ++ err = -ENOMEM; ++ goto err_free_sock; ++ } ++ ++ cb = nl_cb_alloc(NL_CB_DEFAULT); ++ if (!cb) { ++ err = -ENOMEM; ++ goto err_free_sock; ++ } ++ ++ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, func, arg); ++ ++ msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_REQUEST | NLM_F_DUMP); ++ if (!msg) { ++ err = -ENOMEM; ++ goto err_free_cb; ++ } ++ ++ ret = nlmsg_append(msg, &rt_hdr, sizeof(rt_hdr), NLMSG_ALIGNTO); ++ if (ret < 0) { ++ err = -ENOMEM; ++ goto err_free_msg; ++ } ++ ++ ret = nla_put_u32(msg, IFLA_MASTER, ifindex); ++ if (ret < 0) { ++ err = -ENOMEM; ++ goto err_free_msg; ++ } ++ ++ ret = nl_send_auto_complete(sock, msg); ++ if (ret < 0) ++ goto err_free_msg; ++ ++ nl_recvmsgs(sock, cb); ++ ++err_free_msg: ++ nlmsg_free(msg); ++err_free_cb: ++ nl_cb_put(cb); ++err_free_sock: ++ nl_socket_free(sock); ++ ++ return err; ++} ++ ++struct register_interfaces_rtnl_arg { ++ struct globals *globals; ++ int ifindex; ++}; ++ ++static struct nla_policy link_policy[IFLA_MAX + 1] = { ++ [IFLA_IFNAME] = { .type = NLA_STRING, .maxlen = IFNAMSIZ }, ++ [IFLA_MASTER] = { .type = NLA_U32 }, ++}; ++ ++static int register_interfaces_rtnl_parse(struct nl_msg *msg, void *arg) ++{ ++ struct register_interfaces_rtnl_arg *register_arg = arg; ++ struct nlattr *attrs[IFLA_MAX + 1]; ++ char path_buff[PATH_BUFF_LEN]; ++ struct ifinfomsg *ifm; ++ char *content_newline; ++ char *file_content; ++ char *ifname; ++ int master; ++ int ret; ++ ++ ifm = nlmsg_data(nlmsg_hdr(msg)); ++ ret = nlmsg_parse(nlmsg_hdr(msg), sizeof(*ifm), attrs, IFLA_MAX, ++ link_policy); ++ if (ret < 0) ++ goto err; ++ ++ if (!attrs[IFLA_IFNAME]) ++ goto err; ++ ++ if (!attrs[IFLA_MASTER]) ++ goto err; ++ ++ ifname = nla_get_string(attrs[IFLA_IFNAME]); ++ master = nla_get_u32(attrs[IFLA_MASTER]); ++ ++ /* required on older kernels which don't prefilter the results */ ++ if (master != register_arg->ifindex) ++ goto err; ++ ++ snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, ifname); ++ file_content = read_file(path_buff); ++ if (!file_content) ++ goto free_file; ++ ++ content_newline = strstr(file_content, "\n"); ++ if (content_newline) ++ *content_newline = '\0'; ++ ++ if (strcmp(file_content, "active") != 0) ++ goto err; ++ ++ get_if_index_byname(register_arg->globals, ifname); ++ ++free_file: ++ free(file_content); ++ file_content = NULL; ++err: ++ return NL_OK; ++} ++ + static int register_interfaces(struct globals *globals) + { +- DIR *iface_base_dir; +- struct dirent *iface_dir; +- char *path_buff, *file_content; +- char *content_newline; ++ struct register_interfaces_rtnl_arg register_arg = { ++ .globals = globals, ++ }; + +- path_buff = malloc(PATH_BUFF_LEN); +- if (!path_buff) { +- perror("Error - could not allocate path buffer"); +- goto err; +- } ++ register_arg.ifindex = if_nametoindex(globals->interface); ++ if (!globals->interface) ++ return EXIT_FAILURE; + +- iface_base_dir = opendir(SYS_IFACE_PATH); +- if (!iface_base_dir) { +- fprintf(stderr, "Error - the directory '%s' could not be read: %s\n", +- SYS_IFACE_PATH, strerror(errno)); +- fprintf(stderr, "Is the batman-adv module loaded and sysfs mounted ?\n"); +- goto err_buff; +- } + +- while ((iface_dir = readdir(iface_base_dir)) != NULL) { +- snprintf(path_buff, PATH_BUFF_LEN, SYS_MESH_IFACE_FMT, iface_dir->d_name); +- file_content = read_file(path_buff); +- if (!file_content) +- continue; ++ query_rtnl_link(register_arg.ifindex, register_interfaces_rtnl_parse, ++ ®ister_arg); + +- if (file_content[strlen(file_content) - 1] == '\n') +- file_content[strlen(file_content) - 1] = '\0'; +- +- if (strcmp(file_content, "none") == 0) +- goto free_line; +- +- if (strcmp(file_content, globals->interface) != 0) +- goto free_line; +- +- free(file_content); +- file_content = NULL; +- +- snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, iface_dir->d_name); +- file_content = read_file(path_buff); +- if (!file_content) +- continue; +- +- content_newline = strstr(file_content, "\n"); +- if (content_newline) +- *content_newline = '\0'; +- +- if (strcmp(file_content, "active") == 0) +- get_if_index_byname(globals, iface_dir->d_name); +- +-free_line: +- free(file_content); +- file_content = NULL; +- } +- +- free(path_buff); +- closedir(iface_base_dir); + return EXIT_SUCCESS; +- +-err_buff: +- free(path_buff); +-err: +- return EXIT_FAILURE; + } + + static const int parse_orig_list_mandatory[] = { +diff --git a/vis/vis.h b/vis/vis.h +index 6870dd4ad8570135f4ab2edf0219d74778b7d061..b04a89351778806e84acae88ff3869cf68bcb1a3 100644 +--- a/vis/vis.h ++++ b/vis/vis.h +@@ -25,7 +25,6 @@ + + #define SYS_IFACE_PATH "/sys/class/net" + #define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s" +-#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface" + #define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status" + + diff --git a/alfred/patches/0002-alfred-vis-Retrieve-hardif-status-via-generic-netlin.patch b/alfred/patches/0002-alfred-vis-Retrieve-hardif-status-via-generic-netlin.patch new file mode 100644 index 0000000..f08c5c3 --- /dev/null +++ b/alfred/patches/0002-alfred-vis-Retrieve-hardif-status-via-generic-netlin.patch @@ -0,0 +1,201 @@ +From: Sven Eckelmann +Date: Wed, 19 Jun 2019 21:38:10 +0200 +Subject: alfred: vis: Retrieve hardif status via generic netlink + +The batman-adv kernel module can now be compiled without support for sysfs. +But the batadv-vis interface retriever can only get the status via the per +hardif sysfs file iface_status. To still have some information, use +BATADV_CMD_GET_HARDIF to retrieve the status and fall back to sysfs when +the status could not retrieved via generic netlink. + +This also solved the warning about deprecated sysfs file access + + batman_adv: [Deprecated]: batadv-vis (pid 1365) Use of sysfs file "iface_status". + Use batadv genl family instead + +Reported-by: Linus Lüssing +Signed-off-by: Sven Eckelmann + +Origin: upstream, https://git.open-mesh.org/alfred.git/commit/0fc6e6674428ce7085b07645895ef837604e18b5 + +diff --git a/vis/vis.c b/vis/vis.c +index 37956b100fad72257f5bab2b9f49908da59520cc..947456343125458845f26dc38b53f18d6fd42d75 100644 +--- a/vis/vis.c ++++ b/vis/vis.c +@@ -27,6 +27,8 @@ + #include "netlink.h" + #include "debugfs.h" + ++#define IFACE_STATUS_LEN 256 ++ + static struct globals vis_globals; + + struct vis_netlink_opts { +@@ -435,6 +437,131 @@ err_free_sock: + return err; + } + ++static int get_iface_status_netlink_parse(struct nl_msg *msg, void *arg) ++{ ++ struct nlattr *attrs[NUM_BATADV_ATTR]; ++ struct nlmsghdr *nlh = nlmsg_hdr(msg); ++ char *iface_status = arg; ++ struct genlmsghdr *ghdr; ++ ++ if (!genlmsg_valid_hdr(nlh, 0)) ++ return NL_OK; ++ ++ ghdr = nlmsg_data(nlh); ++ if (ghdr->cmd != BATADV_CMD_GET_HARDIF) ++ return NL_OK; ++ ++ if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0), ++ genlmsg_len(ghdr), batadv_netlink_policy)) ++ return NL_OK; ++ ++ if (attrs[BATADV_ATTR_ACTIVE]) ++ strncpy(iface_status, "active\n", IFACE_STATUS_LEN); ++ else ++ strncpy(iface_status, "inactive\n", IFACE_STATUS_LEN); ++ ++ iface_status[IFACE_STATUS_LEN - 1] = '\0'; ++ ++ return NL_STOP; ++} ++ ++static char *get_iface_status_netlink(unsigned int meshif, unsigned int hardif, ++ char *iface_status) ++{ ++ char *ret_status = NULL; ++ struct nl_sock *sock; ++ struct nl_msg *msg; ++ int batadv_family; ++ struct nl_cb *cb; ++ int ret; ++ ++ iface_status[0] = '\0'; ++ ++ sock = nl_socket_alloc(); ++ if (!sock) ++ return NULL; ++ ++ ret = genl_connect(sock); ++ if (ret < 0) ++ goto err_free_sock; ++ ++ batadv_family = genl_ctrl_resolve(sock, BATADV_NL_NAME); ++ if (batadv_family < 0) ++ goto err_free_sock; ++ ++ cb = nl_cb_alloc(NL_CB_DEFAULT); ++ if (!cb) ++ goto err_free_sock; ++ ++ nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, get_iface_status_netlink_parse, ++ iface_status); ++ ++ msg = nlmsg_alloc(); ++ if (!msg) ++ goto err_free_cb; ++ ++ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, batadv_family, ++ 0, 0, BATADV_CMD_GET_HARDIF, 1); ++ ++ nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, meshif); ++ nla_put_u32(msg, BATADV_ATTR_HARD_IFINDEX, hardif); ++ ++ ret = nl_send_auto_complete(sock, msg); ++ if (ret < 0) ++ goto err_free_msg; ++ ++ nl_recvmsgs(sock, cb); ++ ++ if (strlen(iface_status) > 0) ++ ret_status = iface_status; ++ ++err_free_msg: ++ nlmsg_free(msg); ++err_free_cb: ++ nl_cb_put(cb); ++err_free_sock: ++ nl_socket_free(sock); ++ ++ return ret_status; ++} ++ ++static bool interface_active(unsigned int meshif, unsigned int hardif, ++ const char *ifname) ++{ ++ char iface_status[IFACE_STATUS_LEN]; ++ char path_buff[PATH_BUFF_LEN]; ++ char *file_content = NULL; ++ char *content_newline; ++ bool active = false; ++ char *status; ++ ++ status = get_iface_status_netlink(meshif, hardif, iface_status); ++ if (!status) { ++ snprintf(path_buff, sizeof(path_buff), SYS_IFACE_STATUS_FMT, ++ ifname); ++ file_content = read_file(path_buff); ++ if (!file_content) ++ return false; ++ ++ status = file_content; ++ } ++ ++ content_newline = strstr(status, "\n"); ++ if (content_newline) ++ *content_newline = '\0'; ++ ++ if (strcmp(status, "active") != 0) ++ goto free_file; ++ ++ active = true; ++ ++free_file: ++ free(file_content); ++ file_content = NULL; ++ ++ return active; ++} ++ + struct register_interfaces_rtnl_arg { + struct globals *globals; + int ifindex; +@@ -449,10 +576,7 @@ static int register_interfaces_rtnl_parse(struct nl_msg *msg, void *arg) + { + struct register_interfaces_rtnl_arg *register_arg = arg; + struct nlattr *attrs[IFLA_MAX + 1]; +- char path_buff[PATH_BUFF_LEN]; + struct ifinfomsg *ifm; +- char *content_newline; +- char *file_content; + char *ifname; + int master; + int ret; +@@ -476,23 +600,11 @@ static int register_interfaces_rtnl_parse(struct nl_msg *msg, void *arg) + if (master != register_arg->ifindex) + goto err; + +- snprintf(path_buff, PATH_BUFF_LEN, SYS_IFACE_STATUS_FMT, ifname); +- file_content = read_file(path_buff); +- if (!file_content) +- goto free_file; +- +- content_newline = strstr(file_content, "\n"); +- if (content_newline) +- *content_newline = '\0'; +- +- if (strcmp(file_content, "active") != 0) ++ if (!interface_active(master, ifm->ifi_index, ifname)) + goto err; + + get_if_index_byname(register_arg->globals, ifname); + +-free_file: +- free(file_content); +- file_content = NULL; + err: + return NL_OK; + } diff --git a/alfred/patches/0003-alfred-vis-Add-missing-include-for-ifinfomsg.patch b/alfred/patches/0003-alfred-vis-Add-missing-include-for-ifinfomsg.patch new file mode 100644 index 0000000..3a982b8 --- /dev/null +++ b/alfred/patches/0003-alfred-vis-Add-missing-include-for-ifinfomsg.patch @@ -0,0 +1,21 @@ +From: Sven Eckelmann +Date: Thu, 1 Aug 2019 15:54:32 +0200 +Subject: alfred: vis: Add missing include for ifinfomsg + +Fixes: 0fc6e6674428 ("alfred: vis: Retrieve hardif status via generic netlink") +Signed-off-by: Sven Eckelmann + +Origin: upstream, https://git.open-mesh.org/alfred.git/commit/ce26453bd72829ac9561acd8d3a06a3937341687 + +diff --git a/vis/vis.c b/vis/vis.c +index 947456343125458845f26dc38b53f18d6fd42d75..8df3056612d5da3678603a6e6430923c0c86cde0 100644 +--- a/vis/vis.c ++++ b/vis/vis.c +@@ -10,6 +10,7 @@ + #include + #include + #include ++#include + #include + #include + #include diff --git a/batman-adv/patches/0001-Revert-batman-adv-convert-stream-like-files-from-non.patch b/batman-adv/patches/0001-Revert-batman-adv-convert-stream-like-files-from-non.patch deleted file mode 100644 index 201e327..0000000 --- a/batman-adv/patches/0001-Revert-batman-adv-convert-stream-like-files-from-non.patch +++ /dev/null @@ -1,55 +0,0 @@ -From: Sven Eckelmann -Date: Thu, 23 May 2019 19:26:27 +0200 -Subject: Revert "batman-adv: convert stream-like files from nonseekable_open -> stream_open" - -OpenWrt's mac80211 package is not yet ready to support the generic netlink -API of Linux 5.2. - -This reverts commit 337ae19a00d4455cf84afa58abfb432f78c882b9. - -diff --git a/compat-include/linux/fs.h b/compat-include/linux/fs.h -index 480722f04ba7ddefc837d5e55a340271e0814b14..c52e0e8e87584d106ab64ef2c522e6ac1ff6e796 100644 ---- a/compat-include/linux/fs.h -+++ b/compat-include/linux/fs.h -@@ -31,15 +31,4 @@ static inline struct dentry *batadv_file_dentry(const struct file *file) - - #endif /* < KERNEL_VERSION(4, 6, 0) */ - --#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0) -- --static inline int batadv_stream_open(struct inode *inode, struct file *filp) --{ -- return nonseekable_open(inode, filp); --} -- --#define stream_open batadv_stream_open -- --#endif /* < KERNEL_VERSION(5, 2, 0) */ -- - #endif /* _NET_BATMAN_ADV_COMPAT_LINUX_FS_H_ */ -diff --git a/net/batman-adv/icmp_socket.c b/net/batman-adv/icmp_socket.c -index 0a91c8661357d4ddbea1ba20dcd0df67b8ba5a97..de81b5ecad91afd8d684edbf781c70a3bae38c60 100644 ---- a/net/batman-adv/icmp_socket.c -+++ b/net/batman-adv/icmp_socket.c -@@ -65,7 +65,7 @@ static int batadv_socket_open(struct inode *inode, struct file *file) - - batadv_debugfs_deprecated(file, ""); - -- stream_open(inode, file); -+ nonseekable_open(inode, file); - - socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL); - if (!socket_client) { -diff --git a/net/batman-adv/log.c b/net/batman-adv/log.c -index f79ebd5b46e95b3b6de717c7ea1ecf44e5c96051..60ce11e16a905e790424a2d7aca81c1f945c1ec2 100644 ---- a/net/batman-adv/log.c -+++ b/net/batman-adv/log.c -@@ -90,7 +90,7 @@ static int batadv_log_open(struct inode *inode, struct file *file) - batadv_debugfs_deprecated(file, - "Use tracepoint batadv:batadv_dbg instead\n"); - -- stream_open(inode, file); -+ nonseekable_open(inode, file); - file->private_data = inode->i_private; - return 0; - } diff --git a/batman-adv/patches/0002-Revert-batman-adv-compat-Drop-support-for-genl_ops-s.patch b/batman-adv/patches/0002-Revert-batman-adv-compat-Drop-support-for-genl_ops-s.patch deleted file mode 100644 index e3b7dec..0000000 --- a/batman-adv/patches/0002-Revert-batman-adv-compat-Drop-support-for-genl_ops-s.patch +++ /dev/null @@ -1,29 +0,0 @@ -From: Sven Eckelmann -Date: Thu, 23 May 2019 19:26:36 +0200 -Subject: Revert "batman-adv: compat: Drop support for genl_ops->start" - -OpenWrt's mac80211 package is not yet ready to support the generic netlink -API of Linux 5.2. - -This reverts commit 1d30dbe3917d0d6fdb8ba473dfdd6265ac46670b. - -diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h -index ee5b82288be97193c1a8e8340a2ea7e0c7ce112c..fbfdb733a3dd63c251def43cae416c7fe32cadab 100644 ---- a/compat-include/net/genetlink.h -+++ b/compat-include/net/genetlink.h -@@ -42,6 +42,7 @@ enum genl_validate_flags { - struct batadv_genl_ops { - int (*doit)(struct sk_buff *skb, - struct genl_info *info); -+ int (*start)(struct netlink_callback *cb); - int (*dumpit)(struct sk_buff *skb, - struct netlink_callback *cb); - int (*done)(struct netlink_callback *cb); -@@ -104,6 +105,7 @@ static inline int batadv_genl_register_family(struct batadv_genl_family *family) - - for (i = 0; i < family->family.n_ops; i++) { - ops[i].doit = family->ops[i].doit; -+ ops[i].start = family->ops[i].start; - ops[i].dumpit = family->ops[i].dumpit; - ops[i].done = family->ops[i].done; - ops[i].cmd = family->ops[i].cmd; diff --git a/batman-adv/patches/0003-Revert-batman-adv-genetlink-optionally-validate-stri.patch b/batman-adv/patches/0003-Revert-batman-adv-genetlink-optionally-validate-stri.patch deleted file mode 100644 index c383c69..0000000 --- a/batman-adv/patches/0003-Revert-batman-adv-genetlink-optionally-validate-stri.patch +++ /dev/null @@ -1,222 +0,0 @@ -From: Sven Eckelmann -Date: Thu, 23 May 2019 19:26:45 +0200 -Subject: Revert "batman-adv: genetlink: optionally validate strictly/dumps" - -OpenWrt's mac80211 package is not yet ready to support the generic netlink -API of Linux 5.2. - -This reverts commit 2ee47abaeb35ca62bb909830e10b0e973393b853. - -diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h -index fbfdb733a3dd63c251def43cae416c7fe32cadab..7d17a705273650355f074788e9220fc4981b0db1 100644 ---- a/compat-include/net/genetlink.h -+++ b/compat-include/net/genetlink.h -@@ -33,25 +33,6 @@ void batadv_genl_dump_check_consistent(struct netlink_callback *cb, - - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0) - --enum genl_validate_flags { -- GENL_DONT_VALIDATE_STRICT = BIT(0), -- GENL_DONT_VALIDATE_DUMP = BIT(1), -- GENL_DONT_VALIDATE_DUMP_STRICT = BIT(2), --}; -- --struct batadv_genl_ops { -- int (*doit)(struct sk_buff *skb, -- struct genl_info *info); -- int (*start)(struct netlink_callback *cb); -- int (*dumpit)(struct sk_buff *skb, -- struct netlink_callback *cb); -- int (*done)(struct netlink_callback *cb); -- u8 cmd; -- u8 internal_flags; -- u8 flags; -- u8 validate; --}; -- - struct batadv_genl_family { - /* data handled by the actual kernel */ - struct genl_family family; -@@ -69,7 +50,7 @@ struct batadv_genl_family { - struct genl_info *info); - void (*post_doit)(const struct genl_ops *ops, struct sk_buff *skb, - struct genl_info *info); -- const struct batadv_genl_ops *ops; -+ const struct genl_ops *ops; - const struct genl_multicast_group *mcgrps; - unsigned int n_ops; - unsigned int n_mcgrps; -@@ -82,6 +63,8 @@ struct batadv_genl_family { - struct genl_ops *copy_ops; - }; - -+#define genl_family batadv_genl_family -+ - static inline int batadv_genl_register_family(struct batadv_genl_family *family) - { - struct genl_ops *ops; -@@ -99,20 +82,12 @@ static inline int batadv_genl_register_family(struct batadv_genl_family *family) - family->family.n_mcgrps = family->n_mcgrps; - family->family.module = family->module; - -- ops = kzalloc(sizeof(*ops) * family->n_ops, GFP_KERNEL); -+ ops = kmemdup(family->ops, sizeof(*ops) * family->n_ops, GFP_KERNEL); - if (!ops) - return -ENOMEM; - -- for (i = 0; i < family->family.n_ops; i++) { -- ops[i].doit = family->ops[i].doit; -- ops[i].start = family->ops[i].start; -- ops[i].dumpit = family->ops[i].dumpit; -- ops[i].done = family->ops[i].done; -- ops[i].cmd = family->ops[i].cmd; -- ops[i].internal_flags = family->ops[i].internal_flags; -- ops[i].flags = family->ops[i].flags; -+ for (i = 0; i < family->family.n_ops; i++) - ops[i].policy = family->policy; -- } - - family->family.ops = ops; - family->copy_ops = ops; -@@ -120,17 +95,6 @@ static inline int batadv_genl_register_family(struct batadv_genl_family *family) - return genl_register_family(&family->family); - } - --typedef struct genl_ops batadv_genl_ops_old; -- --#define batadv_pre_doit(__x, __y, __z) \ -- batadv_pre_doit(const batadv_genl_ops_old *ops, __y, __z) -- --#define batadv_post_doit(__x, __y, __z) \ -- batadv_post_doit(const batadv_genl_ops_old *ops, __y, __z) -- --#define genl_ops batadv_genl_ops --#define genl_family batadv_genl_family -- - #define genl_register_family(family) \ - batadv_genl_register_family((family)) - -diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c -index a67720fad46ca496c932c0306e2f7ec4ed496fc9..e7907308b331ddc3e4917ff7d648bca27a65536b 100644 ---- a/net/batman-adv/netlink.c -+++ b/net/batman-adv/netlink.c -@@ -1343,34 +1343,29 @@ static void batadv_post_doit(const struct genl_ops *ops, struct sk_buff *skb, - static const struct genl_ops batadv_netlink_ops[] = { - { - .cmd = BATADV_CMD_GET_MESH, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - /* can be retrieved by unprivileged users */ - .doit = batadv_netlink_get_mesh, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_TP_METER, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .doit = batadv_netlink_tp_meter_start, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_TP_METER_CANCEL, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .doit = batadv_netlink_tp_meter_cancel, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_GET_ROUTING_ALGOS, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_algo_dump, - }, - { - .cmd = BATADV_CMD_GET_HARDIF, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - /* can be retrieved by unprivileged users */ - .dumpit = batadv_netlink_dump_hardif, - .doit = batadv_netlink_get_hardif, -@@ -1379,68 +1374,57 @@ static const struct genl_ops batadv_netlink_ops[] = { - }, - { - .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_tt_local_dump, - }, - { - .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_tt_global_dump, - }, - { - .cmd = BATADV_CMD_GET_ORIGINATORS, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_orig_dump, - }, - { - .cmd = BATADV_CMD_GET_NEIGHBORS, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_hardif_neigh_dump, - }, - { - .cmd = BATADV_CMD_GET_GATEWAYS, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_gw_dump, - }, - { - .cmd = BATADV_CMD_GET_BLA_CLAIM, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_bla_claim_dump, - }, - { - .cmd = BATADV_CMD_GET_BLA_BACKBONE, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_bla_backbone_dump, - }, - { - .cmd = BATADV_CMD_GET_DAT_CACHE, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_dat_cache_dump, - }, - { - .cmd = BATADV_CMD_GET_MCAST_FLAGS, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .dumpit = batadv_mcast_flags_dump, - }, - { - .cmd = BATADV_CMD_SET_MESH, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .doit = batadv_netlink_set_mesh, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_SET_HARDIF, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .doit = batadv_netlink_set_hardif, - .internal_flags = BATADV_FLAG_NEED_MESH | -@@ -1448,7 +1432,6 @@ static const struct genl_ops batadv_netlink_ops[] = { - }, - { - .cmd = BATADV_CMD_GET_VLAN, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - /* can be retrieved by unprivileged users */ - .doit = batadv_netlink_get_vlan, - .internal_flags = BATADV_FLAG_NEED_MESH | -@@ -1456,7 +1439,6 @@ static const struct genl_ops batadv_netlink_ops[] = { - }, - { - .cmd = BATADV_CMD_SET_VLAN, -- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .flags = GENL_ADMIN_PERM, - .doit = batadv_netlink_set_vlan, - .internal_flags = BATADV_FLAG_NEED_MESH | diff --git a/batman-adv/patches/0004-Revert-batman-adv-genetlink-make-policy-common-to-fa.patch b/batman-adv/patches/0004-Revert-batman-adv-genetlink-make-policy-common-to-fa.patch deleted file mode 100644 index a5814e7..0000000 --- a/batman-adv/patches/0004-Revert-batman-adv-genetlink-make-policy-common-to-fa.patch +++ /dev/null @@ -1,256 +0,0 @@ -From: Sven Eckelmann -Date: Thu, 23 May 2019 19:26:58 +0200 -Subject: Revert "batman-adv: genetlink: make policy common to family" - -OpenWrt's mac80211 package is not yet ready to support the generic netlink -API of Linux 5.2. - -This reverts commit acfc9a214d01695d1676313ca80cfd2d9309f633. - -diff --git a/compat-include/linux/cache.h b/compat-include/linux/cache.h -index 9ddda31232ed4b58efcb57dc2ee99ae82d09d6e2..efe440d11d04a1c3999649ba52058ad82e4d6bea 100644 ---- a/compat-include/linux/cache.h -+++ b/compat-include/linux/cache.h -@@ -13,8 +13,12 @@ - #include - #include_next - --#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0) -+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) - -+/* hack for netlink.c which marked the family ops as ro */ -+#ifdef __ro_after_init -+#undef __ro_after_init -+#endif - #define __ro_after_init - - #endif /* < KERNEL_VERSION(4, 6, 0) */ -diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h -index 7d17a705273650355f074788e9220fc4981b0db1..58fc24d7147a7f79c2db1976b36351d294f2aa4c 100644 ---- a/compat-include/net/genetlink.h -+++ b/compat-include/net/genetlink.h -@@ -30,92 +30,4 @@ void batadv_genl_dump_check_consistent(struct netlink_callback *cb, - - #endif /* < KERNEL_VERSION(4, 15, 0) */ - -- --#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0) -- --struct batadv_genl_family { -- /* data handled by the actual kernel */ -- struct genl_family family; -- -- /* data which has to be copied to family by -- * batadv_genl_register_family -- */ -- unsigned int hdrsize; -- char name[GENL_NAMSIZ]; -- unsigned int version; -- unsigned int maxattr; -- const struct nla_policy *policy; -- bool netnsok; -- int (*pre_doit)(const struct genl_ops *ops, struct sk_buff *skb, -- struct genl_info *info); -- void (*post_doit)(const struct genl_ops *ops, struct sk_buff *skb, -- struct genl_info *info); -- const struct genl_ops *ops; -- const struct genl_multicast_group *mcgrps; -- unsigned int n_ops; -- unsigned int n_mcgrps; -- struct module *module; -- -- /* allocated by batadv_genl_register_family and free'd by -- * batadv_genl_unregister_family. Used to modify the usually read-only -- * ops -- */ -- struct genl_ops *copy_ops; --}; -- --#define genl_family batadv_genl_family -- --static inline int batadv_genl_register_family(struct batadv_genl_family *family) --{ -- struct genl_ops *ops; -- unsigned int i; -- -- family->family.hdrsize = family->hdrsize; -- strncpy(family->family.name, family->name, sizeof(family->family.name)); -- family->family.version = family->version; -- family->family.maxattr = family->maxattr; -- family->family.netnsok = family->netnsok; -- family->family.pre_doit = family->pre_doit; -- family->family.post_doit = family->post_doit; -- family->family.mcgrps = family->mcgrps; -- family->family.n_ops = family->n_ops; -- family->family.n_mcgrps = family->n_mcgrps; -- family->family.module = family->module; -- -- ops = kmemdup(family->ops, sizeof(*ops) * family->n_ops, GFP_KERNEL); -- if (!ops) -- return -ENOMEM; -- -- for (i = 0; i < family->family.n_ops; i++) -- ops[i].policy = family->policy; -- -- family->family.ops = ops; -- family->copy_ops = ops; -- -- return genl_register_family(&family->family); --} -- --#define genl_register_family(family) \ -- batadv_genl_register_family((family)) -- --static inline void --batadv_genl_unregister_family(struct batadv_genl_family *family) --{ -- -- genl_unregister_family(&family->family); -- kfree(family->copy_ops); --} -- --#define genl_unregister_family(family) \ -- batadv_genl_unregister_family((family)) -- --#define genlmsg_put(_skb, _pid, _seq, _family, _flags, _cmd) \ -- genlmsg_put(_skb, _pid, _seq, &(_family)->family, _flags, _cmd) -- --#define genlmsg_multicast_netns(_family, _net, _skb, _portid, _group, _flags) \ -- genlmsg_multicast_netns(&(_family)->family, _net, _skb, _portid, \ -- _group, _flags) -- --#endif /* < KERNEL_VERSION(5, 2, 0) */ -- - #endif /* _NET_BATMAN_ADV_COMPAT_NET_GENETLINK_H_ */ -diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c -index e7907308b331ddc3e4917ff7d648bca27a65536b..daf56933223d478399c63360203bcf283d7686a3 100644 ---- a/net/batman-adv/netlink.c -+++ b/net/batman-adv/netlink.c -@@ -1344,29 +1344,34 @@ static const struct genl_ops batadv_netlink_ops[] = { - { - .cmd = BATADV_CMD_GET_MESH, - /* can be retrieved by unprivileged users */ -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_get_mesh, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_TP_METER, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_tp_meter_start, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_TP_METER_CANCEL, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_tp_meter_cancel, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_GET_ROUTING_ALGOS, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_algo_dump, - }, - { - .cmd = BATADV_CMD_GET_HARDIF, - /* can be retrieved by unprivileged users */ -+ .policy = batadv_netlink_policy, - .dumpit = batadv_netlink_dump_hardif, - .doit = batadv_netlink_get_hardif, - .internal_flags = BATADV_FLAG_NEED_MESH | -@@ -1375,57 +1380,68 @@ static const struct genl_ops batadv_netlink_ops[] = { - { - .cmd = BATADV_CMD_GET_TRANSTABLE_LOCAL, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_tt_local_dump, - }, - { - .cmd = BATADV_CMD_GET_TRANSTABLE_GLOBAL, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_tt_global_dump, - }, - { - .cmd = BATADV_CMD_GET_ORIGINATORS, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_orig_dump, - }, - { - .cmd = BATADV_CMD_GET_NEIGHBORS, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_hardif_neigh_dump, - }, - { - .cmd = BATADV_CMD_GET_GATEWAYS, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_gw_dump, - }, - { - .cmd = BATADV_CMD_GET_BLA_CLAIM, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_bla_claim_dump, - }, - { - .cmd = BATADV_CMD_GET_BLA_BACKBONE, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_bla_backbone_dump, - }, - { - .cmd = BATADV_CMD_GET_DAT_CACHE, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_dat_cache_dump, - }, - { - .cmd = BATADV_CMD_GET_MCAST_FLAGS, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .dumpit = batadv_mcast_flags_dump, - }, - { - .cmd = BATADV_CMD_SET_MESH, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_set_mesh, - .internal_flags = BATADV_FLAG_NEED_MESH, - }, - { - .cmd = BATADV_CMD_SET_HARDIF, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_set_hardif, - .internal_flags = BATADV_FLAG_NEED_MESH | - BATADV_FLAG_NEED_HARDIF, -@@ -1433,6 +1449,7 @@ static const struct genl_ops batadv_netlink_ops[] = { - { - .cmd = BATADV_CMD_GET_VLAN, - /* can be retrieved by unprivileged users */ -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_get_vlan, - .internal_flags = BATADV_FLAG_NEED_MESH | - BATADV_FLAG_NEED_VLAN, -@@ -1440,6 +1457,7 @@ static const struct genl_ops batadv_netlink_ops[] = { - { - .cmd = BATADV_CMD_SET_VLAN, - .flags = GENL_ADMIN_PERM, -+ .policy = batadv_netlink_policy, - .doit = batadv_netlink_set_vlan, - .internal_flags = BATADV_FLAG_NEED_MESH | - BATADV_FLAG_NEED_VLAN, -@@ -1451,7 +1469,6 @@ struct genl_family batadv_netlink_family __ro_after_init = { - .name = BATADV_NL_NAME, - .version = 1, - .maxattr = BATADV_ATTR_MAX, -- .policy = batadv_netlink_policy, - .netnsok = true, - .pre_doit = batadv_pre_doit, - .post_doit = batadv_post_doit, -- 2.30.2