diff options
author | Johannes Berg <johannes.berg@intel.com> | 2013-11-19 09:19:39 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-11-19 16:39:06 -0500 |
commit | 2a94fe48f32ccf7321450a2cc07f2b724a444e5b (patch) | |
tree | e5a066d8f83d8822d448421019a4503f361295f9 /net/ieee802154 | |
parent | 68eb55031da7c967d954e5f9415cd05f4abdb692 (diff) |
genetlink: make multicast groups const, prevent abuse
Register generic netlink multicast groups as an array with
the family and give them contiguous group IDs. Then instead
of passing the global group ID to the various functions that
send messages, pass the ID relative to the family - for most
families that's just 0 because the only have one group.
This avoids the list_head and ID in each group, adding a new
field for the mcast group ID offset to the family.
At the same time, this allows us to prevent abusing groups
again like the quota and dropmon code did, since we can now
check that a family only uses a group it owns.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ieee802154')
-rw-r--r-- | net/ieee802154/ieee802154.h | 6 | ||||
-rw-r--r-- | net/ieee802154/netlink.c | 26 | ||||
-rw-r--r-- | net/ieee802154/nl-mac.c | 22 |
3 files changed, 20 insertions, 34 deletions
diff --git a/net/ieee802154/ieee802154.h b/net/ieee802154/ieee802154.h index 14d5dab4436f..cee4425b9956 100644 --- a/net/ieee802154/ieee802154.h +++ b/net/ieee802154/ieee802154.h | |||
@@ -54,8 +54,10 @@ int ieee802154_dump_phy(struct sk_buff *skb, struct netlink_callback *cb); | |||
54 | int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info); | 54 | int ieee802154_add_iface(struct sk_buff *skb, struct genl_info *info); |
55 | int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info); | 55 | int ieee802154_del_iface(struct sk_buff *skb, struct genl_info *info); |
56 | 56 | ||
57 | extern struct genl_multicast_group ieee802154_coord_mcgrp; | 57 | enum ieee802154_mcgrp_ids { |
58 | extern struct genl_multicast_group ieee802154_beacon_mcgrp; | 58 | IEEE802154_COORD_MCGRP, |
59 | IEEE802154_BEACON_MCGRP, | ||
60 | }; | ||
59 | 61 | ||
60 | int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info); | 62 | int ieee802154_associate_req(struct sk_buff *skb, struct genl_info *info); |
61 | int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info); | 63 | int ieee802154_associate_resp(struct sk_buff *skb, struct genl_info *info); |
diff --git a/net/ieee802154/netlink.c b/net/ieee802154/netlink.c index 5172f467a383..43f1b2bf469f 100644 --- a/net/ieee802154/netlink.c +++ b/net/ieee802154/netlink.c | |||
@@ -125,25 +125,17 @@ static const struct genl_ops ieee8021154_ops[] = { | |||
125 | ieee802154_dump_iface), | 125 | ieee802154_dump_iface), |
126 | }; | 126 | }; |
127 | 127 | ||
128 | int __init ieee802154_nl_init(void) | 128 | static const struct genl_multicast_group ieee802154_mcgrps[] = { |
129 | { | 129 | [IEEE802154_COORD_MCGRP] = { .name = IEEE802154_MCAST_COORD_NAME, }, |
130 | int rc; | 130 | [IEEE802154_BEACON_MCGRP] = { .name = IEEE802154_MCAST_BEACON_NAME, }, |
131 | 131 | }; | |
132 | rc = genl_register_family_with_ops(&nl802154_family, ieee8021154_ops); | ||
133 | if (rc) | ||
134 | return rc; | ||
135 | 132 | ||
136 | rc = genl_register_mc_group(&nl802154_family, &ieee802154_coord_mcgrp); | ||
137 | if (rc) | ||
138 | goto fail; | ||
139 | 133 | ||
140 | rc = genl_register_mc_group(&nl802154_family, &ieee802154_beacon_mcgrp); | 134 | int __init ieee802154_nl_init(void) |
141 | if (rc) | 135 | { |
142 | goto fail; | 136 | return genl_register_family_with_ops_groups(&nl802154_family, |
143 | return 0; | 137 | ieee8021154_ops, |
144 | fail: | 138 | ieee802154_mcgrps); |
145 | genl_unregister_family(&nl802154_family); | ||
146 | return rc; | ||
147 | } | 139 | } |
148 | 140 | ||
149 | void __exit ieee802154_nl_exit(void) | 141 | void __exit ieee802154_nl_exit(void) |
diff --git a/net/ieee802154/nl-mac.c b/net/ieee802154/nl-mac.c index 28d493032132..ba5c1e002f37 100644 --- a/net/ieee802154/nl-mac.c +++ b/net/ieee802154/nl-mac.c | |||
@@ -39,14 +39,6 @@ | |||
39 | 39 | ||
40 | #include "ieee802154.h" | 40 | #include "ieee802154.h" |
41 | 41 | ||
42 | struct genl_multicast_group ieee802154_coord_mcgrp = { | ||
43 | .name = IEEE802154_MCAST_COORD_NAME, | ||
44 | }; | ||
45 | |||
46 | struct genl_multicast_group ieee802154_beacon_mcgrp = { | ||
47 | .name = IEEE802154_MCAST_BEACON_NAME, | ||
48 | }; | ||
49 | |||
50 | int ieee802154_nl_assoc_indic(struct net_device *dev, | 42 | int ieee802154_nl_assoc_indic(struct net_device *dev, |
51 | struct ieee802154_addr *addr, u8 cap) | 43 | struct ieee802154_addr *addr, u8 cap) |
52 | { | 44 | { |
@@ -72,7 +64,7 @@ int ieee802154_nl_assoc_indic(struct net_device *dev, | |||
72 | nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap)) | 64 | nla_put_u8(msg, IEEE802154_ATTR_CAPABILITY, cap)) |
73 | goto nla_put_failure; | 65 | goto nla_put_failure; |
74 | 66 | ||
75 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 67 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
76 | 68 | ||
77 | nla_put_failure: | 69 | nla_put_failure: |
78 | nlmsg_free(msg); | 70 | nlmsg_free(msg); |
@@ -98,7 +90,7 @@ int ieee802154_nl_assoc_confirm(struct net_device *dev, u16 short_addr, | |||
98 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || | 90 | nla_put_u16(msg, IEEE802154_ATTR_SHORT_ADDR, short_addr) || |
99 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | 91 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) |
100 | goto nla_put_failure; | 92 | goto nla_put_failure; |
101 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 93 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
102 | 94 | ||
103 | nla_put_failure: | 95 | nla_put_failure: |
104 | nlmsg_free(msg); | 96 | nlmsg_free(msg); |
@@ -133,7 +125,7 @@ int ieee802154_nl_disassoc_indic(struct net_device *dev, | |||
133 | } | 125 | } |
134 | if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason)) | 126 | if (nla_put_u8(msg, IEEE802154_ATTR_REASON, reason)) |
135 | goto nla_put_failure; | 127 | goto nla_put_failure; |
136 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 128 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
137 | 129 | ||
138 | nla_put_failure: | 130 | nla_put_failure: |
139 | nlmsg_free(msg); | 131 | nlmsg_free(msg); |
@@ -157,7 +149,7 @@ int ieee802154_nl_disassoc_confirm(struct net_device *dev, u8 status) | |||
157 | dev->dev_addr) || | 149 | dev->dev_addr) || |
158 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | 150 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) |
159 | goto nla_put_failure; | 151 | goto nla_put_failure; |
160 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 152 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
161 | 153 | ||
162 | nla_put_failure: | 154 | nla_put_failure: |
163 | nlmsg_free(msg); | 155 | nlmsg_free(msg); |
@@ -183,7 +175,7 @@ int ieee802154_nl_beacon_indic(struct net_device *dev, | |||
183 | nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) || | 175 | nla_put_u16(msg, IEEE802154_ATTR_COORD_SHORT_ADDR, coord_addr) || |
184 | nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid)) | 176 | nla_put_u16(msg, IEEE802154_ATTR_COORD_PAN_ID, panid)) |
185 | goto nla_put_failure; | 177 | goto nla_put_failure; |
186 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 178 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
187 | 179 | ||
188 | nla_put_failure: | 180 | nla_put_failure: |
189 | nlmsg_free(msg); | 181 | nlmsg_free(msg); |
@@ -214,7 +206,7 @@ int ieee802154_nl_scan_confirm(struct net_device *dev, | |||
214 | (edl && | 206 | (edl && |
215 | nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl))) | 207 | nla_put(msg, IEEE802154_ATTR_ED_LIST, 27, edl))) |
216 | goto nla_put_failure; | 208 | goto nla_put_failure; |
217 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 209 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
218 | 210 | ||
219 | nla_put_failure: | 211 | nla_put_failure: |
220 | nlmsg_free(msg); | 212 | nlmsg_free(msg); |
@@ -238,7 +230,7 @@ int ieee802154_nl_start_confirm(struct net_device *dev, u8 status) | |||
238 | dev->dev_addr) || | 230 | dev->dev_addr) || |
239 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) | 231 | nla_put_u8(msg, IEEE802154_ATTR_STATUS, status)) |
240 | goto nla_put_failure; | 232 | goto nla_put_failure; |
241 | return ieee802154_nl_mcast(msg, ieee802154_coord_mcgrp.id); | 233 | return ieee802154_nl_mcast(msg, IEEE802154_COORD_MCGRP); |
242 | 234 | ||
243 | nla_put_failure: | 235 | nla_put_failure: |
244 | nlmsg_free(msg); | 236 | nlmsg_free(msg); |