aboutsummaryrefslogtreecommitdiffstats
path: root/package/libs/libnl-tiny/src/genl_ctrl.c
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke.mehrtens@intel.com>2016-06-29 23:13:58 +0200
committerFelix Fietkau <nbd@nbd.name>2016-07-02 10:12:04 +0200
commitf28502a4857027490f0a5d7cc879457dd2b1cc6a (patch)
tree093d440d662b47c871c1af502183d066a4b03186 /package/libs/libnl-tiny/src/genl_ctrl.c
parentf576ff05a1523a0c61a3399087454034d4739f2c (diff)
downloadupstream-f28502a4857027490f0a5d7cc879457dd2b1cc6a.tar.gz
upstream-f28502a4857027490f0a5d7cc879457dd2b1cc6a.tar.bz2
upstream-f28502a4857027490f0a5d7cc879457dd2b1cc6a.zip
libnl-tiny: Generic Netlink multicast groups support
This adds this commit from normal libnl to libnl-tiny: https://github.com/tgraf/libnl/commit/2dbc1ca76c5b82c40749e609eb83877418abb006 commit 2dbc1ca76c5b82c40749e609eb83877418abb006 Author: dima <dima.ky@gmail.com> Date: Wed Oct 13 17:53:34 2010 +0300 Generic Netlink multicast groups support I have a patch against commit d378220c96c3c8b6f27dca33e7d8ba03318f9c2d extending libnl with a facility to receive generic netlink messages sent to multicast groups. Essentially it add one new function genl_ctrl_resolve_grp which prototype looks like this int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family_name, const char *grp_name) It resolves the family name and the group name to group id. Then the returned id can be used in nl_socket_add_membership to subscribe to multicast messages. Besides that it adds two more functions uint32_t nl_socket_get_peer_groups(struct nl_sock *sk) void nl_socket_set_peer_groups(struct nl_sock *sk, uint32_t groups) allowing to modify the socket peer groups field. So it's possible to multicast messages from the user space using the legacy interface. Looks like there is no way (or I was not able to find one?) to modify the netlink socket destination group from the user space, when the group id is greater then 32. Signed-off-by: Hauke Mehrtens <hauke.mehrtens@intel.com> Signed-off-by: Felix Fietkau <nbd@nbd.name> [cosmetic style fix]
Diffstat (limited to 'package/libs/libnl-tiny/src/genl_ctrl.c')
-rw-r--r--package/libs/libnl-tiny/src/genl_ctrl.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/package/libs/libnl-tiny/src/genl_ctrl.c b/package/libs/libnl-tiny/src/genl_ctrl.c
index 13016420d1..0045459b2f 100644
--- a/package/libs/libnl-tiny/src/genl_ctrl.c
+++ b/package/libs/libnl-tiny/src/genl_ctrl.c
@@ -45,6 +45,7 @@ static struct nla_policy ctrl_policy[CTRL_ATTR_MAX+1] = {
[CTRL_ATTR_HDRSIZE] = { .type = NLA_U32 },
[CTRL_ATTR_MAXATTR] = { .type = NLA_U32 },
[CTRL_ATTR_OPS] = { .type = NLA_NESTED },
+ [CTRL_ATTR_MCAST_GROUPS] = { .type = NLA_NESTED },
};
static struct nla_policy family_op_policy[CTRL_ATTR_OP_MAX+1] = {
@@ -52,6 +53,11 @@ static struct nla_policy family_op_policy[CTRL_ATTR_OP_MAX+1] = {
[CTRL_ATTR_OP_FLAGS] = { .type = NLA_U32 },
};
+static struct nla_policy family_grp_policy[CTRL_ATTR_MCAST_GRP_MAX+1] = {
+ [CTRL_ATTR_MCAST_GRP_NAME] = { .type = NLA_STRING },
+ [CTRL_ATTR_MCAST_GRP_ID] = { .type = NLA_U32 },
+};
+
static int ctrl_msg_parser(struct nl_cache_ops *ops, struct genl_cmd *cmd,
struct genl_info *info, void *arg)
{
@@ -127,6 +133,40 @@ static int ctrl_msg_parser(struct nl_cache_ops *ops, struct genl_cmd *cmd,
}
}
+ if (info->attrs[CTRL_ATTR_MCAST_GROUPS]) {
+ struct nlattr *nla, *nla_grps;
+ int remaining;
+
+ nla_grps = info->attrs[CTRL_ATTR_MCAST_GROUPS];
+ nla_for_each_nested(nla, nla_grps, remaining) {
+ struct nlattr *tb[CTRL_ATTR_MCAST_GRP_MAX+1];
+ int id;
+ const char * name;
+
+ err = nla_parse_nested(tb, CTRL_ATTR_MCAST_GRP_MAX, nla,
+ family_grp_policy);
+ if (err < 0)
+ goto errout;
+
+ if (tb[CTRL_ATTR_MCAST_GRP_ID] == NULL) {
+ err = -NLE_MISSING_ATTR;
+ goto errout;
+ }
+ id = nla_get_u32(tb[CTRL_ATTR_MCAST_GRP_ID]);
+
+ if (tb[CTRL_ATTR_MCAST_GRP_NAME] == NULL) {
+ err = -NLE_MISSING_ATTR;
+ goto errout;
+ }
+ name = nla_get_string(tb[CTRL_ATTR_MCAST_GRP_NAME]);
+
+ err = genl_family_add_grp(family, id, name);
+ if (err < 0)
+ goto errout;
+ }
+
+ }
+
err = pp->pp_cb((struct nl_object *) family, pp);
errout:
genl_family_put(family);
@@ -242,6 +282,44 @@ errout:
return err;
}
+static int genl_ctrl_grp_by_name(const struct genl_family *family,
+ const char *grp_name)
+{
+ struct genl_family_grp *grp;
+
+ nl_list_for_each_entry(grp, &family->gf_mc_grps, list) {
+ if (!strcmp(grp->name, grp_name)) {
+ return grp->id;
+ }
+ }
+
+ return -NLE_OBJ_NOTFOUND;
+}
+
+int genl_ctrl_resolve_grp(struct nl_sock *sk, const char *family_name,
+ const char *grp_name)
+{
+ struct nl_cache *cache;
+ struct genl_family *family;
+ int err;
+
+ if ((err = genl_ctrl_alloc_cache(sk, &cache)) < 0)
+ return err;
+
+ family = genl_ctrl_search_by_name(cache, family_name);
+ if (family == NULL) {
+ err = -NLE_OBJ_NOTFOUND;
+ goto errout;
+ }
+
+ err = genl_ctrl_grp_by_name(family, grp_name);
+ genl_family_put(family);
+errout:
+ nl_cache_free(cache);
+
+ return err;
+}
+
/** @} */
static struct genl_cmd genl_cmds[] = {