diff options
author | Thomas Graf <tgraf@suug.ch> | 2006-11-14 22:46:02 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-12-03 00:22:42 -0500 |
commit | 17c157c889f4b07258af6bfec9e4e9dcf3c00178 (patch) | |
tree | f17be049a40b5742ca7e67094d6a7063146568d5 | |
parent | 81878d27fdd297a33f3cfcf29483fe1abaf26dec (diff) |
[GENL]: Add genlmsg_put_reply() to simplify building reply headers
By modyfing genlmsg_put() to take a genl_family and by adding
genlmsg_put_reply() the process of constructing the netlink
and generic netlink headers is simplified.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Paul Moore <paul.moore@hp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/genetlink.h | 31 | ||||
-rw-r--r-- | kernel/taskstats.c | 8 | ||||
-rw-r--r-- | net/netlabel/netlabel_cipso_v4.c | 17 | ||||
-rw-r--r-- | net/netlabel/netlabel_mgmt.c | 34 | ||||
-rw-r--r-- | net/netlabel/netlabel_unlabeled.c | 8 | ||||
-rw-r--r-- | net/netlabel/netlabel_user.h | 31 | ||||
-rw-r--r-- | net/netlink/genetlink.c | 17 |
7 files changed, 51 insertions, 95 deletions
diff --git a/include/net/genetlink.h b/include/net/genetlink.h index 797c18b5041f..7fd131c9a8cc 100644 --- a/include/net/genetlink.h +++ b/include/net/genetlink.h | |||
@@ -79,34 +79,51 @@ extern struct sock *genl_sock; | |||
79 | * @skb: socket buffer holding the message | 79 | * @skb: socket buffer holding the message |
80 | * @pid: netlink pid the message is addressed to | 80 | * @pid: netlink pid the message is addressed to |
81 | * @seq: sequence number (usually the one of the sender) | 81 | * @seq: sequence number (usually the one of the sender) |
82 | * @type: netlink message type | 82 | * @family: generic netlink family |
83 | * @hdrlen: length of the user specific header | ||
84 | * @flags netlink message flags | 83 | * @flags netlink message flags |
85 | * @cmd: generic netlink command | 84 | * @cmd: generic netlink command |
86 | * @version: version | ||
87 | * | 85 | * |
88 | * Returns pointer to user specific header | 86 | * Returns pointer to user specific header |
89 | */ | 87 | */ |
90 | static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, | 88 | static inline void *genlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, |
91 | int type, int hdrlen, int flags, | 89 | struct genl_family *family, int flags, u8 cmd) |
92 | u8 cmd, u8 version) | ||
93 | { | 90 | { |
94 | struct nlmsghdr *nlh; | 91 | struct nlmsghdr *nlh; |
95 | struct genlmsghdr *hdr; | 92 | struct genlmsghdr *hdr; |
96 | 93 | ||
97 | nlh = nlmsg_put(skb, pid, seq, type, GENL_HDRLEN + hdrlen, flags); | 94 | nlh = nlmsg_put(skb, pid, seq, family->id, GENL_HDRLEN + |
95 | family->hdrsize, flags); | ||
98 | if (nlh == NULL) | 96 | if (nlh == NULL) |
99 | return NULL; | 97 | return NULL; |
100 | 98 | ||
101 | hdr = nlmsg_data(nlh); | 99 | hdr = nlmsg_data(nlh); |
102 | hdr->cmd = cmd; | 100 | hdr->cmd = cmd; |
103 | hdr->version = version; | 101 | hdr->version = family->version; |
104 | hdr->reserved = 0; | 102 | hdr->reserved = 0; |
105 | 103 | ||
106 | return (char *) hdr + GENL_HDRLEN; | 104 | return (char *) hdr + GENL_HDRLEN; |
107 | } | 105 | } |
108 | 106 | ||
109 | /** | 107 | /** |
108 | * genlmsg_put_reply - Add generic netlink header to a reply message | ||
109 | * @skb: socket buffer holding the message | ||
110 | * @info: receiver info | ||
111 | * @family: generic netlink family | ||
112 | * @flags: netlink message flags | ||
113 | * @cmd: generic netlink command | ||
114 | * | ||
115 | * Returns pointer to user specific header | ||
116 | */ | ||
117 | static inline void *genlmsg_put_reply(struct sk_buff *skb, | ||
118 | struct genl_info *info, | ||
119 | struct genl_family *family, | ||
120 | int flags, u8 cmd) | ||
121 | { | ||
122 | return genlmsg_put(skb, info->snd_pid, info->snd_seq, family, | ||
123 | flags, cmd); | ||
124 | } | ||
125 | |||
126 | /** | ||
110 | * genlmsg_end - Finalize a generic netlink message | 127 | * genlmsg_end - Finalize a generic netlink message |
111 | * @skb: socket buffer the message is stored in | 128 | * @skb: socket buffer the message is stored in |
112 | * @hdr: user specific header | 129 | * @hdr: user specific header |
diff --git a/kernel/taskstats.c b/kernel/taskstats.c index faa5239813ce..d3d28919d4b4 100644 --- a/kernel/taskstats.c +++ b/kernel/taskstats.c | |||
@@ -85,13 +85,9 @@ static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp, | |||
85 | int seq = get_cpu_var(taskstats_seqnum)++; | 85 | int seq = get_cpu_var(taskstats_seqnum)++; |
86 | put_cpu_var(taskstats_seqnum); | 86 | put_cpu_var(taskstats_seqnum); |
87 | 87 | ||
88 | reply = genlmsg_put(skb, 0, seq, | 88 | reply = genlmsg_put(skb, 0, seq, &family, 0, cmd); |
89 | family.id, 0, 0, | ||
90 | cmd, family.version); | ||
91 | } else | 89 | } else |
92 | reply = genlmsg_put(skb, info->snd_pid, info->snd_seq, | 90 | reply = genlmsg_put_reply(skb, info, &family, 0, cmd); |
93 | family.id, 0, 0, | ||
94 | cmd, family.version); | ||
95 | if (reply == NULL) { | 91 | if (reply == NULL) { |
96 | nlmsg_free(skb); | 92 | nlmsg_free(skb); |
97 | return -EINVAL; | 93 | return -EINVAL; |
diff --git a/net/netlabel/netlabel_cipso_v4.c b/net/netlabel/netlabel_cipso_v4.c index 52628878524c..fe9851fac85d 100644 --- a/net/netlabel/netlabel_cipso_v4.c +++ b/net/netlabel/netlabel_cipso_v4.c | |||
@@ -457,12 +457,8 @@ list_start: | |||
457 | ret_val = -ENOMEM; | 457 | ret_val = -ENOMEM; |
458 | goto list_failure; | 458 | goto list_failure; |
459 | } | 459 | } |
460 | data = netlbl_netlink_hdr_put(ans_skb, | 460 | data = genlmsg_put_reply(ans_skb, info, &netlbl_cipsov4_gnl_family, |
461 | info->snd_pid, | 461 | 0, NLBL_CIPSOV4_C_LIST); |
462 | info->snd_seq, | ||
463 | netlbl_cipsov4_gnl_family.id, | ||
464 | 0, | ||
465 | NLBL_CIPSOV4_C_LIST); | ||
466 | if (data == NULL) { | 462 | if (data == NULL) { |
467 | ret_val = -ENOMEM; | 463 | ret_val = -ENOMEM; |
468 | goto list_failure; | 464 | goto list_failure; |
@@ -607,12 +603,9 @@ static int netlbl_cipsov4_listall_cb(struct cipso_v4_doi *doi_def, void *arg) | |||
607 | struct netlbl_cipsov4_doiwalk_arg *cb_arg = arg; | 603 | struct netlbl_cipsov4_doiwalk_arg *cb_arg = arg; |
608 | void *data; | 604 | void *data; |
609 | 605 | ||
610 | data = netlbl_netlink_hdr_put(cb_arg->skb, | 606 | data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).pid, |
611 | NETLINK_CB(cb_arg->nl_cb->skb).pid, | 607 | cb_arg->seq, &netlbl_cipsov4_gnl_family, |
612 | cb_arg->seq, | 608 | NLM_F_MULTI, NLBL_CIPSOV4_C_LISTALL); |
613 | netlbl_cipsov4_gnl_family.id, | ||
614 | NLM_F_MULTI, | ||
615 | NLBL_CIPSOV4_C_LISTALL); | ||
616 | if (data == NULL) | 609 | if (data == NULL) |
617 | goto listall_cb_failure; | 610 | goto listall_cb_failure; |
618 | 611 | ||
diff --git a/net/netlabel/netlabel_mgmt.c b/net/netlabel/netlabel_mgmt.c index 784693735e0d..e8c80f33f3d7 100644 --- a/net/netlabel/netlabel_mgmt.c +++ b/net/netlabel/netlabel_mgmt.c | |||
@@ -188,12 +188,9 @@ static int netlbl_mgmt_listall_cb(struct netlbl_dom_map *entry, void *arg) | |||
188 | struct netlbl_domhsh_walk_arg *cb_arg = arg; | 188 | struct netlbl_domhsh_walk_arg *cb_arg = arg; |
189 | void *data; | 189 | void *data; |
190 | 190 | ||
191 | data = netlbl_netlink_hdr_put(cb_arg->skb, | 191 | data = genlmsg_put(cb_arg->skb, NETLINK_CB(cb_arg->nl_cb->skb).pid, |
192 | NETLINK_CB(cb_arg->nl_cb->skb).pid, | 192 | cb_arg->seq, &netlbl_mgmt_gnl_family, |
193 | cb_arg->seq, | 193 | NLM_F_MULTI, NLBL_MGMT_C_LISTALL); |
194 | netlbl_mgmt_gnl_family.id, | ||
195 | NLM_F_MULTI, | ||
196 | NLBL_MGMT_C_LISTALL); | ||
197 | if (data == NULL) | 194 | if (data == NULL) |
198 | goto listall_cb_failure; | 195 | goto listall_cb_failure; |
199 | 196 | ||
@@ -359,12 +356,8 @@ static int netlbl_mgmt_listdef(struct sk_buff *skb, struct genl_info *info) | |||
359 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 356 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
360 | if (ans_skb == NULL) | 357 | if (ans_skb == NULL) |
361 | return -ENOMEM; | 358 | return -ENOMEM; |
362 | data = netlbl_netlink_hdr_put(ans_skb, | 359 | data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family, |
363 | info->snd_pid, | 360 | 0, NLBL_MGMT_C_LISTDEF); |
364 | info->snd_seq, | ||
365 | netlbl_mgmt_gnl_family.id, | ||
366 | 0, | ||
367 | NLBL_MGMT_C_LISTDEF); | ||
368 | if (data == NULL) | 361 | if (data == NULL) |
369 | goto listdef_failure; | 362 | goto listdef_failure; |
370 | 363 | ||
@@ -422,12 +415,9 @@ static int netlbl_mgmt_protocols_cb(struct sk_buff *skb, | |||
422 | int ret_val = -ENOMEM; | 415 | int ret_val = -ENOMEM; |
423 | void *data; | 416 | void *data; |
424 | 417 | ||
425 | data = netlbl_netlink_hdr_put(skb, | 418 | data = genlmsg_put(skb, NETLINK_CB(cb->skb).pid, cb->nlh->nlmsg_seq, |
426 | NETLINK_CB(cb->skb).pid, | 419 | &netlbl_mgmt_gnl_family, NLM_F_MULTI, |
427 | cb->nlh->nlmsg_seq, | 420 | NLBL_MGMT_C_PROTOCOLS); |
428 | netlbl_mgmt_gnl_family.id, | ||
429 | NLM_F_MULTI, | ||
430 | NLBL_MGMT_C_PROTOCOLS); | ||
431 | if (data == NULL) | 421 | if (data == NULL) |
432 | goto protocols_cb_failure; | 422 | goto protocols_cb_failure; |
433 | 423 | ||
@@ -495,12 +485,8 @@ static int netlbl_mgmt_version(struct sk_buff *skb, struct genl_info *info) | |||
495 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 485 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
496 | if (ans_skb == NULL) | 486 | if (ans_skb == NULL) |
497 | return -ENOMEM; | 487 | return -ENOMEM; |
498 | data = netlbl_netlink_hdr_put(ans_skb, | 488 | data = genlmsg_put_reply(ans_skb, info, &netlbl_mgmt_gnl_family, |
499 | info->snd_pid, | 489 | 0, NLBL_MGMT_C_VERSION); |
500 | info->snd_seq, | ||
501 | netlbl_mgmt_gnl_family.id, | ||
502 | 0, | ||
503 | NLBL_MGMT_C_VERSION); | ||
504 | if (data == NULL) | 490 | if (data == NULL) |
505 | goto version_failure; | 491 | goto version_failure; |
506 | 492 | ||
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c index 57dd07b51be6..a1d4ae51db04 100644 --- a/net/netlabel/netlabel_unlabeled.c +++ b/net/netlabel/netlabel_unlabeled.c | |||
@@ -141,12 +141,8 @@ static int netlbl_unlabel_list(struct sk_buff *skb, struct genl_info *info) | |||
141 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 141 | ans_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
142 | if (ans_skb == NULL) | 142 | if (ans_skb == NULL) |
143 | goto list_failure; | 143 | goto list_failure; |
144 | data = netlbl_netlink_hdr_put(ans_skb, | 144 | data = genlmsg_put_reply(ans_skb, info, &netlbl_unlabel_gnl_family, |
145 | info->snd_pid, | 145 | 0, NLBL_UNLABEL_C_LIST); |
146 | info->snd_seq, | ||
147 | netlbl_unlabel_gnl_family.id, | ||
148 | 0, | ||
149 | NLBL_UNLABEL_C_LIST); | ||
150 | if (data == NULL) { | 146 | if (data == NULL) { |
151 | ret_val = -ENOMEM; | 147 | ret_val = -ENOMEM; |
152 | goto list_failure; | 148 | goto list_failure; |
diff --git a/net/netlabel/netlabel_user.h b/net/netlabel/netlabel_user.h index 47967ef32964..6d7f4ab46c2b 100644 --- a/net/netlabel/netlabel_user.h +++ b/net/netlabel/netlabel_user.h | |||
@@ -42,37 +42,6 @@ | |||
42 | /* NetLabel NETLINK helper functions */ | 42 | /* NetLabel NETLINK helper functions */ |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * netlbl_netlink_hdr_put - Write the NETLINK buffers into a sk_buff | ||
46 | * @skb: the packet | ||
47 | * @pid: the PID of the receipient | ||
48 | * @seq: the sequence number | ||
49 | * @type: the generic NETLINK message family type | ||
50 | * @cmd: command | ||
51 | * | ||
52 | * Description: | ||
53 | * Write both a NETLINK nlmsghdr structure and a Generic NETLINK genlmsghdr | ||
54 | * struct to the packet. Returns a pointer to the start of the payload buffer | ||
55 | * on success or NULL on failure. | ||
56 | * | ||
57 | */ | ||
58 | static inline void *netlbl_netlink_hdr_put(struct sk_buff *skb, | ||
59 | u32 pid, | ||
60 | u32 seq, | ||
61 | int type, | ||
62 | int flags, | ||
63 | u8 cmd) | ||
64 | { | ||
65 | return genlmsg_put(skb, | ||
66 | pid, | ||
67 | seq, | ||
68 | type, | ||
69 | 0, | ||
70 | flags, | ||
71 | cmd, | ||
72 | NETLBL_PROTO_VERSION); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * netlbl_netlink_auditinfo - Fetch the audit information from a NETLINK msg | 45 | * netlbl_netlink_auditinfo - Fetch the audit information from a NETLINK msg |
77 | * @skb: the packet | 46 | * @skb: the packet |
78 | * @audit_info: NetLabel audit information | 47 | * @audit_info: NetLabel audit information |
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c index 0249a56a9aad..8903ef93db5b 100644 --- a/net/netlink/genetlink.c +++ b/net/netlink/genetlink.c | |||
@@ -384,6 +384,13 @@ static void genl_rcv(struct sock *sk, int len) | |||
384 | * Controller | 384 | * Controller |
385 | **************************************************************************/ | 385 | **************************************************************************/ |
386 | 386 | ||
387 | static struct genl_family genl_ctrl = { | ||
388 | .id = GENL_ID_CTRL, | ||
389 | .name = "nlctrl", | ||
390 | .version = 0x1, | ||
391 | .maxattr = CTRL_ATTR_MAX, | ||
392 | }; | ||
393 | |||
387 | static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq, | 394 | static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq, |
388 | u32 flags, struct sk_buff *skb, u8 cmd) | 395 | u32 flags, struct sk_buff *skb, u8 cmd) |
389 | { | 396 | { |
@@ -392,8 +399,7 @@ static int ctrl_fill_info(struct genl_family *family, u32 pid, u32 seq, | |||
392 | void *hdr; | 399 | void *hdr; |
393 | int idx = 1; | 400 | int idx = 1; |
394 | 401 | ||
395 | hdr = genlmsg_put(skb, pid, seq, GENL_ID_CTRL, 0, flags, cmd, | 402 | hdr = genlmsg_put(skb, pid, seq, &genl_ctrl, flags, cmd); |
396 | family->version); | ||
397 | if (hdr == NULL) | 403 | if (hdr == NULL) |
398 | return -1; | 404 | return -1; |
399 | 405 | ||
@@ -562,13 +568,6 @@ static struct genl_ops genl_ctrl_ops = { | |||
562 | .policy = ctrl_policy, | 568 | .policy = ctrl_policy, |
563 | }; | 569 | }; |
564 | 570 | ||
565 | static struct genl_family genl_ctrl = { | ||
566 | .id = GENL_ID_CTRL, | ||
567 | .name = "nlctrl", | ||
568 | .version = 0x1, | ||
569 | .maxattr = CTRL_ATTR_MAX, | ||
570 | }; | ||
571 | |||
572 | static int __init genl_init(void) | 571 | static int __init genl_init(void) |
573 | { | 572 | { |
574 | int i, err; | 573 | int i, err; |