From 8dea78da5cee153b8af9c07a2745f6c55057fe12 Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Thu, 17 Jan 2013 16:15:55 -0500 Subject: Patched in Tegra support. --- net/netlink/genetlink.c | 153 +++++++++++++----------------------------------- 1 file changed, 40 insertions(+), 113 deletions(-) (limited to 'net/netlink/genetlink.c') diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index f2aabb6f410..482fa571b4e 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c @@ -33,14 +33,6 @@ void genl_unlock(void) } EXPORT_SYMBOL(genl_unlock); -#ifdef CONFIG_LOCKDEP -int lockdep_genl_is_held(void) -{ - return lockdep_is_held(&genl_mutex); -} -EXPORT_SYMBOL(lockdep_genl_is_held); -#endif - #define GENL_FAM_TAB_SIZE 16 #define GENL_FAM_TAB_MASK (GENL_FAM_TAB_SIZE - 1) @@ -106,7 +98,7 @@ static struct genl_ops *genl_get_cmd(u8 cmd, struct genl_family *family) /* Of course we are going to have problems once we hit * 2^16 alive types, but that can only happen by year 2K */ -static u16 genl_generate_id(void) +static inline u16 genl_generate_id(void) { static u16 id_gen_idx = GENL_MIN_ID; int i; @@ -498,37 +490,6 @@ int genl_unregister_family(struct genl_family *family) } EXPORT_SYMBOL(genl_unregister_family); -/** - * genlmsg_put - Add generic netlink header to netlink message - * @skb: socket buffer holding the message - * @portid: netlink portid the message is addressed to - * @seq: sequence number (usually the one of the sender) - * @family: generic netlink family - * @flags: netlink message flags - * @cmd: generic netlink command - * - * Returns pointer to user specific header - */ -void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, - struct genl_family *family, int flags, u8 cmd) -{ - struct nlmsghdr *nlh; - struct genlmsghdr *hdr; - - nlh = nlmsg_put(skb, portid, seq, family->id, GENL_HDRLEN + - family->hdrsize, flags); - if (nlh == NULL) - return NULL; - - hdr = nlmsg_data(nlh); - hdr->cmd = cmd; - hdr->version = family->version; - hdr->reserved = 0; - - return (char *) hdr + GENL_HDRLEN; -} -EXPORT_SYMBOL(genlmsg_put); - static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) { struct genl_ops *ops; @@ -555,7 +516,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) return -EOPNOTSUPP; if ((ops->flags & GENL_ADMIN_PERM) && - !capable(CAP_NET_ADMIN)) + security_netlink_recv(skb, CAP_NET_ADMIN)) return -EPERM; if (nlh->nlmsg_flags & NLM_F_DUMP) { @@ -563,13 +524,8 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) return -EOPNOTSUPP; genl_unlock(); - { - struct netlink_dump_control c = { - .dump = ops->dumpit, - .done = ops->done, - }; - err = netlink_dump_start(net->genl_sock, skb, nlh, &c); - } + err = netlink_dump_start(net->genl_sock, skb, nlh, + ops->dumpit, ops->done, 0); genl_lock(); return err; } @@ -585,7 +541,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) } info.snd_seq = nlh->nlmsg_seq; - info.snd_portid = NETLINK_CB(skb).portid; + info.snd_pid = NETLINK_CB(skb).pid; info.nlhdr = nlh; info.genlhdr = nlmsg_data(nlh); info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN; @@ -626,21 +582,20 @@ static struct genl_family genl_ctrl = { .netnsok = true, }; -static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq, +static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq, u32 flags, struct sk_buff *skb, u8 cmd) { void *hdr; - hdr = genlmsg_put(skb, portid, seq, &genl_ctrl, flags, cmd); + hdr = genlmsg_put(skb, pid, seq, &genl_ctrl, flags, cmd); if (hdr == NULL) return -1; - if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, family->name) || - nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, family->id) || - nla_put_u32(skb, CTRL_ATTR_VERSION, family->version) || - nla_put_u32(skb, CTRL_ATTR_HDRSIZE, family->hdrsize) || - nla_put_u32(skb, CTRL_ATTR_MAXATTR, family->maxattr)) - goto nla_put_failure; + NLA_PUT_STRING(skb, CTRL_ATTR_FAMILY_NAME, family->name); + NLA_PUT_U16(skb, CTRL_ATTR_FAMILY_ID, family->id); + NLA_PUT_U32(skb, CTRL_ATTR_VERSION, family->version); + NLA_PUT_U32(skb, CTRL_ATTR_HDRSIZE, family->hdrsize); + NLA_PUT_U32(skb, CTRL_ATTR_MAXATTR, family->maxattr); if (!list_empty(&family->ops_list)) { struct nlattr *nla_ops; @@ -658,9 +613,8 @@ static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq, if (nest == NULL) goto nla_put_failure; - if (nla_put_u32(skb, CTRL_ATTR_OP_ID, ops->cmd) || - nla_put_u32(skb, CTRL_ATTR_OP_FLAGS, ops->flags)) - goto nla_put_failure; + NLA_PUT_U32(skb, CTRL_ATTR_OP_ID, ops->cmd); + NLA_PUT_U32(skb, CTRL_ATTR_OP_FLAGS, ops->flags); nla_nest_end(skb, nest); } @@ -684,10 +638,9 @@ static int ctrl_fill_info(struct genl_family *family, u32 portid, u32 seq, if (nest == NULL) goto nla_put_failure; - if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id) || - nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME, - grp->name)) - goto nla_put_failure; + NLA_PUT_U32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id); + NLA_PUT_STRING(skb, CTRL_ATTR_MCAST_GRP_NAME, + grp->name); nla_nest_end(skb, nest); } @@ -701,7 +654,7 @@ nla_put_failure: return -EMSGSIZE; } -static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid, +static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 pid, u32 seq, u32 flags, struct sk_buff *skb, u8 cmd) { @@ -709,13 +662,12 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid, struct nlattr *nla_grps; struct nlattr *nest; - hdr = genlmsg_put(skb, portid, seq, &genl_ctrl, flags, cmd); + hdr = genlmsg_put(skb, pid, seq, &genl_ctrl, flags, cmd); if (hdr == NULL) return -1; - if (nla_put_string(skb, CTRL_ATTR_FAMILY_NAME, grp->family->name) || - nla_put_u16(skb, CTRL_ATTR_FAMILY_ID, grp->family->id)) - goto nla_put_failure; + NLA_PUT_STRING(skb, CTRL_ATTR_FAMILY_NAME, grp->family->name); + NLA_PUT_U16(skb, CTRL_ATTR_FAMILY_ID, grp->family->id); nla_grps = nla_nest_start(skb, CTRL_ATTR_MCAST_GROUPS); if (nla_grps == NULL) @@ -725,10 +677,9 @@ static int ctrl_fill_mcgrp_info(struct genl_multicast_group *grp, u32 portid, if (nest == NULL) goto nla_put_failure; - if (nla_put_u32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id) || - nla_put_string(skb, CTRL_ATTR_MCAST_GRP_NAME, - grp->name)) - goto nla_put_failure; + NLA_PUT_U32(skb, CTRL_ATTR_MCAST_GRP_ID, grp->id); + NLA_PUT_STRING(skb, CTRL_ATTR_MCAST_GRP_NAME, + grp->name); nla_nest_end(skb, nest); nla_nest_end(skb, nla_grps); @@ -756,7 +707,7 @@ static int ctrl_dumpfamily(struct sk_buff *skb, struct netlink_callback *cb) continue; if (++n < fams_to_skip) continue; - if (ctrl_fill_info(rt, NETLINK_CB(cb->skb).portid, + if (ctrl_fill_info(rt, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, NLM_F_MULTI, skb, CTRL_CMD_NEWFAMILY) < 0) goto errout; @@ -773,7 +724,7 @@ errout: } static struct sk_buff *ctrl_build_family_msg(struct genl_family *family, - u32 portid, int seq, u8 cmd) + u32 pid, int seq, u8 cmd) { struct sk_buff *skb; int err; @@ -782,7 +733,7 @@ static struct sk_buff *ctrl_build_family_msg(struct genl_family *family, if (skb == NULL) return ERR_PTR(-ENOBUFS); - err = ctrl_fill_info(family, portid, seq, 0, skb, cmd); + err = ctrl_fill_info(family, pid, seq, 0, skb, cmd); if (err < 0) { nlmsg_free(skb); return ERR_PTR(err); @@ -792,7 +743,7 @@ static struct sk_buff *ctrl_build_family_msg(struct genl_family *family, } static struct sk_buff *ctrl_build_mcgrp_msg(struct genl_multicast_group *grp, - u32 portid, int seq, u8 cmd) + u32 pid, int seq, u8 cmd) { struct sk_buff *skb; int err; @@ -801,7 +752,7 @@ static struct sk_buff *ctrl_build_mcgrp_msg(struct genl_multicast_group *grp, if (skb == NULL) return ERR_PTR(-ENOBUFS); - err = ctrl_fill_mcgrp_info(grp, portid, seq, 0, skb, cmd); + err = ctrl_fill_mcgrp_info(grp, pid, seq, 0, skb, cmd); if (err < 0) { nlmsg_free(skb); return ERR_PTR(err); @@ -833,15 +784,6 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info) name = nla_data(info->attrs[CTRL_ATTR_FAMILY_NAME]); res = genl_family_find_byname(name); -#ifdef CONFIG_MODULES - if (res == NULL) { - genl_unlock(); - request_module("net-pf-%d-proto-%d-family-%s", - PF_NETLINK, NETLINK_GENERIC, name); - genl_lock(); - res = genl_family_find_byname(name); - } -#endif err = -ENOENT; } @@ -853,7 +795,7 @@ static int ctrl_getfamily(struct sk_buff *skb, struct genl_info *info) return -ENOENT; } - msg = ctrl_build_family_msg(res, info->snd_portid, info->snd_seq, + msg = ctrl_build_family_msg(res, info->snd_pid, info->snd_seq, CTRL_CMD_NEWFAMILY); if (IS_ERR(msg)) return PTR_ERR(msg); @@ -915,14 +857,10 @@ static struct genl_multicast_group notify_grp = { static int __net_init genl_pernet_init(struct net *net) { - struct netlink_kernel_cfg cfg = { - .input = genl_rcv, - .cb_mutex = &genl_mutex, - .flags = NL_CFG_F_NONROOT_RECV, - }; - /* we'll bump the group number right afterwards */ - net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC, &cfg); + net->genl_sock = netlink_kernel_create(net, NETLINK_GENERIC, 0, + genl_rcv, &genl_mutex, + THIS_MODULE); if (!net->genl_sock && net_eq(net, &init_net)) panic("GENL: Cannot initialize generic netlink\n"); @@ -955,6 +893,8 @@ static int __init genl_init(void) if (err < 0) goto problem; + netlink_set_nonroot(NETLINK_GENERIC, NL_NONROOT_RECV); + err = register_pernet_subsys(&genl_pernet_ops); if (err) goto problem; @@ -971,7 +911,7 @@ problem: subsys_initcall(genl_init); -static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group, +static int genlmsg_mcast(struct sk_buff *skb, u32 pid, unsigned long group, gfp_t flags) { struct sk_buff *tmp; @@ -986,7 +926,7 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group, goto error; } err = nlmsg_multicast(prev->genl_sock, tmp, - portid, group, flags); + pid, group, flags); if (err) goto error; } @@ -994,28 +934,15 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group, prev = net; } - return nlmsg_multicast(prev->genl_sock, skb, portid, group, flags); + return nlmsg_multicast(prev->genl_sock, skb, pid, group, flags); error: kfree_skb(skb); return err; } -int genlmsg_multicast_allns(struct sk_buff *skb, u32 portid, unsigned int group, +int genlmsg_multicast_allns(struct sk_buff *skb, u32 pid, unsigned int group, gfp_t flags) { - return genlmsg_mcast(skb, portid, group, flags); + return genlmsg_mcast(skb, pid, group, flags); } EXPORT_SYMBOL(genlmsg_multicast_allns); - -void genl_notify(struct sk_buff *skb, struct net *net, u32 portid, u32 group, - struct nlmsghdr *nlh, gfp_t flags) -{ - struct sock *sk = net->genl_sock; - int report = 0; - - if (nlh) - report = nlmsg_report(nlh); - - nlmsg_notify(sk, skb, portid, group, report, flags); -} -EXPORT_SYMBOL(genl_notify); -- cgit v1.2.2