aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2007-04-25 22:08:35 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:26:34 -0400
commitb529ccf2799c14346d1518e9bdf1f88f03643e99 (patch)
treef899a5a5d66d2ca21724c1871ee3afeda6c4a670
parent965ffea43d4ebe8cd7b9fee78d651268dd7d23c5 (diff)
[NETLINK]: Introduce nlmsg_hdr() helper
For the common "(struct nlmsghdr *)skb->data" sequence, so that we reduce the number of direct accesses to skb->data and for consistency with all the other cast skb member helpers. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/connector/connector.c2
-rw-r--r--drivers/scsi/scsi_netlink.c2
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--fs/ecryptfs/netlink.c4
-rw-r--r--include/linux/netlink.h5
-rw-r--r--kernel/audit.c6
-rw-r--r--kernel/taskstats.c4
-rw-r--r--net/decnet/netfilter/dn_rtmsg.c2
-rw-r--r--net/ipv4/fib_frontend.c2
-rw-r--r--net/ipv4/inet_diag.c2
-rw-r--r--net/ipv4/netfilter/ip_queue.c2
-rw-r--r--net/ipv6/netfilter/ip6_queue.c2
-rw-r--r--net/netlink/af_netlink.c2
-rw-r--r--net/tipc/netlink.c2
-rw-r--r--security/selinux/hooks.c2
15 files changed, 23 insertions, 18 deletions
diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index a905f7820331..7f9c4fb7e5b0 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -212,7 +212,7 @@ static void cn_rx_skb(struct sk_buff *__skb)
212 skb = skb_get(__skb); 212 skb = skb_get(__skb);
213 213
214 if (skb->len >= NLMSG_SPACE(0)) { 214 if (skb->len >= NLMSG_SPACE(0)) {
215 nlh = (struct nlmsghdr *)skb->data; 215 nlh = nlmsg_hdr(skb);
216 216
217 if (nlh->nlmsg_len < sizeof(struct cn_msg) || 217 if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
218 skb->len < nlh->nlmsg_len || 218 skb->len < nlh->nlmsg_len ||
diff --git a/drivers/scsi/scsi_netlink.c b/drivers/scsi/scsi_netlink.c
index 1b59b27e887f..45646a285244 100644
--- a/drivers/scsi/scsi_netlink.c
+++ b/drivers/scsi/scsi_netlink.c
@@ -50,7 +50,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
50 while (skb->len >= NLMSG_SPACE(0)) { 50 while (skb->len >= NLMSG_SPACE(0)) {
51 err = 0; 51 err = 0;
52 52
53 nlh = (struct nlmsghdr *) skb->data; 53 nlh = nlmsg_hdr(skb);
54 if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) || 54 if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) ||
55 (skb->len < nlh->nlmsg_len)) { 55 (skb->len < nlh->nlmsg_len)) {
56 printk(KERN_WARNING "%s: discarding partial skb\n", 56 printk(KERN_WARNING "%s: discarding partial skb\n",
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index ce0d14af33c8..10590cd7e9ed 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1081,7 +1081,7 @@ iscsi_if_rx(struct sock *sk, int len)
1081 struct nlmsghdr *nlh; 1081 struct nlmsghdr *nlh;
1082 struct iscsi_uevent *ev; 1082 struct iscsi_uevent *ev;
1083 1083
1084 nlh = (struct nlmsghdr *)skb->data; 1084 nlh = nlmsg_hdr(skb);
1085 if (nlh->nlmsg_len < sizeof(*nlh) || 1085 if (nlh->nlmsg_len < sizeof(*nlh) ||
1086 skb->len < nlh->nlmsg_len) { 1086 skb->len < nlh->nlmsg_len) {
1087 break; 1087 break;
diff --git a/fs/ecryptfs/netlink.c b/fs/ecryptfs/netlink.c
index e3aa2253c850..8405d216a5fc 100644
--- a/fs/ecryptfs/netlink.c
+++ b/fs/ecryptfs/netlink.c
@@ -97,7 +97,7 @@ out:
97 */ 97 */
98static int ecryptfs_process_nl_response(struct sk_buff *skb) 98static int ecryptfs_process_nl_response(struct sk_buff *skb)
99{ 99{
100 struct nlmsghdr *nlh = (struct nlmsghdr*)skb->data; 100 struct nlmsghdr *nlh = nlmsg_hdr(skb);
101 struct ecryptfs_message *msg = NLMSG_DATA(nlh); 101 struct ecryptfs_message *msg = NLMSG_DATA(nlh);
102 int rc; 102 int rc;
103 103
@@ -181,7 +181,7 @@ receive:
181 "rc = [%d]\n", rc); 181 "rc = [%d]\n", rc);
182 return; 182 return;
183 } 183 }
184 nlh = (struct nlmsghdr *)skb->data; 184 nlh = nlmsg_hdr(skb);
185 if (!NLMSG_OK(nlh, skb->len)) { 185 if (!NLMSG_OK(nlh, skb->len)) {
186 ecryptfs_printk(KERN_ERR, "Received corrupt netlink " 186 ecryptfs_printk(KERN_ERR, "Received corrupt netlink "
187 "message\n"); 187 "message\n");
diff --git a/include/linux/netlink.h b/include/linux/netlink.h
index 68a632b372ec..36629fff26d3 100644
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -138,6 +138,11 @@ struct nlattr
138#include <linux/capability.h> 138#include <linux/capability.h>
139#include <linux/skbuff.h> 139#include <linux/skbuff.h>
140 140
141static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
142{
143 return (struct nlmsghdr *)skb->data;
144}
145
141struct netlink_skb_parms 146struct netlink_skb_parms
142{ 147{
143 struct ucred creds; /* Skb credentials */ 148 struct ucred creds; /* Skb credentials */
diff --git a/kernel/audit.c b/kernel/audit.c
index ea8521417d13..80a7457dadbf 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -151,7 +151,7 @@ struct audit_buffer {
151 151
152static void audit_set_pid(struct audit_buffer *ab, pid_t pid) 152static void audit_set_pid(struct audit_buffer *ab, pid_t pid)
153{ 153{
154 struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data; 154 struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
155 nlh->nlmsg_pid = pid; 155 nlh->nlmsg_pid = pid;
156} 156}
157 157
@@ -750,7 +750,7 @@ static void audit_receive_skb(struct sk_buff *skb)
750 u32 rlen; 750 u32 rlen;
751 751
752 while (skb->len >= NLMSG_SPACE(0)) { 752 while (skb->len >= NLMSG_SPACE(0)) {
753 nlh = (struct nlmsghdr *)skb->data; 753 nlh = nlmsg_hdr(skb);
754 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) 754 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
755 return; 755 return;
756 rlen = NLMSG_ALIGN(nlh->nlmsg_len); 756 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
@@ -1268,7 +1268,7 @@ void audit_log_end(struct audit_buffer *ab)
1268 audit_log_lost("rate limit exceeded"); 1268 audit_log_lost("rate limit exceeded");
1269 } else { 1269 } else {
1270 if (audit_pid) { 1270 if (audit_pid) {
1271 struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data; 1271 struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
1272 nlh->nlmsg_len = ab->skb->len - NLMSG_SPACE(0); 1272 nlh->nlmsg_len = ab->skb->len - NLMSG_SPACE(0);
1273 skb_queue_tail(&audit_skb_queue, ab->skb); 1273 skb_queue_tail(&audit_skb_queue, ab->skb);
1274 ab->skb = NULL; 1274 ab->skb = NULL;
diff --git a/kernel/taskstats.c b/kernel/taskstats.c
index 4c3476fa058d..ad7d2392cb0e 100644
--- a/kernel/taskstats.c
+++ b/kernel/taskstats.c
@@ -102,7 +102,7 @@ static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
102 */ 102 */
103static int send_reply(struct sk_buff *skb, pid_t pid) 103static int send_reply(struct sk_buff *skb, pid_t pid)
104{ 104{
105 struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); 105 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
106 void *reply = genlmsg_data(genlhdr); 106 void *reply = genlmsg_data(genlhdr);
107 int rc; 107 int rc;
108 108
@@ -121,7 +121,7 @@ static int send_reply(struct sk_buff *skb, pid_t pid)
121static void send_cpu_listeners(struct sk_buff *skb, 121static void send_cpu_listeners(struct sk_buff *skb,
122 struct listener_list *listeners) 122 struct listener_list *listeners)
123{ 123{
124 struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); 124 struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
125 struct listener *s, *tmp; 125 struct listener *s, *tmp;
126 struct sk_buff *skb_next, *skb_cur = skb; 126 struct sk_buff *skb_next, *skb_cur = skb;
127 void *reply = genlmsg_data(genlhdr); 127 void *reply = genlmsg_data(genlhdr);
diff --git a/net/decnet/netfilter/dn_rtmsg.c b/net/decnet/netfilter/dn_rtmsg.c
index ceefd9dd0c92..9e8256a2361e 100644
--- a/net/decnet/netfilter/dn_rtmsg.c
+++ b/net/decnet/netfilter/dn_rtmsg.c
@@ -102,7 +102,7 @@ static unsigned int dnrmg_hook(unsigned int hook,
102 102
103static inline void dnrmg_receive_user_skb(struct sk_buff *skb) 103static inline void dnrmg_receive_user_skb(struct sk_buff *skb)
104{ 104{
105 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data; 105 struct nlmsghdr *nlh = nlmsg_hdr(skb);
106 106
107 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) 107 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
108 return; 108 return;
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
index cac06c43f004..3ff753c6f197 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -807,7 +807,7 @@ static void nl_fib_input(struct sock *sk, int len)
807 if (skb == NULL) 807 if (skb == NULL)
808 return; 808 return;
809 809
810 nlh = (struct nlmsghdr *)skb->data; 810 nlh = nlmsg_hdr(skb);
811 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len || 811 if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
812 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) { 812 nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) {
813 kfree_skb(skb); 813 kfree_skb(skb);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 37362cd1d07f..238999e6e871 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -847,7 +847,7 @@ static inline void inet_diag_rcv_skb(struct sk_buff *skb)
847{ 847{
848 if (skb->len >= NLMSG_SPACE(0)) { 848 if (skb->len >= NLMSG_SPACE(0)) {
849 int err; 849 int err;
850 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data; 850 struct nlmsghdr *nlh = nlmsg_hdr(skb);
851 851
852 if (nlh->nlmsg_len < sizeof(*nlh) || 852 if (nlh->nlmsg_len < sizeof(*nlh) ||
853 skb->len < nlh->nlmsg_len) 853 skb->len < nlh->nlmsg_len)
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c
index 15e0d2002235..17f7c988460c 100644
--- a/net/ipv4/netfilter/ip_queue.c
+++ b/net/ipv4/netfilter/ip_queue.c
@@ -497,7 +497,7 @@ ipq_rcv_skb(struct sk_buff *skb)
497 if (skblen < sizeof(*nlh)) 497 if (skblen < sizeof(*nlh))
498 return; 498 return;
499 499
500 nlh = (struct nlmsghdr *)skb->data; 500 nlh = nlmsg_hdr(skb);
501 nlmsglen = nlh->nlmsg_len; 501 nlmsglen = nlh->nlmsg_len;
502 if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen) 502 if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen)
503 return; 503 return;
diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
index 5cfce218c5e1..275e625e4977 100644
--- a/net/ipv6/netfilter/ip6_queue.c
+++ b/net/ipv6/netfilter/ip6_queue.c
@@ -487,7 +487,7 @@ ipq_rcv_skb(struct sk_buff *skb)
487 if (skblen < sizeof(*nlh)) 487 if (skblen < sizeof(*nlh))
488 return; 488 return;
489 489
490 nlh = (struct nlmsghdr *)skb->data; 490 nlh = nlmsg_hdr(skb);
491 nlmsglen = nlh->nlmsg_len; 491 nlmsglen = nlh->nlmsg_len;
492 if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen) 492 if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen)
493 return; 493 return;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 50dc5edb7752..04b72d3c1dea 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1471,7 +1471,7 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
1471 int err; 1471 int err;
1472 1472
1473 while (skb->len >= nlmsg_total_size(0)) { 1473 while (skb->len >= nlmsg_total_size(0)) {
1474 nlh = (struct nlmsghdr *) skb->data; 1474 nlh = nlmsg_hdr(skb);
1475 1475
1476 if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len) 1476 if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
1477 return 0; 1477 return 0;
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c
index b8e1edc2badc..4cdafa2d1d4d 100644
--- a/net/tipc/netlink.c
+++ b/net/tipc/netlink.c
@@ -57,7 +57,7 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
57 57
58 if (rep_buf) { 58 if (rep_buf) {
59 skb_push(rep_buf, hdr_space); 59 skb_push(rep_buf, hdr_space);
60 rep_nlh = (struct nlmsghdr *)rep_buf->data; 60 rep_nlh = nlmsg_hdr(rep_buf);
61 memcpy(rep_nlh, req_nlh, hdr_space); 61 memcpy(rep_nlh, req_nlh, hdr_space);
62 rep_nlh->nlmsg_len = rep_buf->len; 62 rep_nlh->nlmsg_len = rep_buf->len;
63 genlmsg_unicast(rep_buf, req_nlh->nlmsg_pid); 63 genlmsg_unicast(rep_buf, req_nlh->nlmsg_pid);
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index addb58501057..5f02b4be1917 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -3786,7 +3786,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
3786 err = -EINVAL; 3786 err = -EINVAL;
3787 goto out; 3787 goto out;
3788 } 3788 }
3789 nlh = (struct nlmsghdr *)skb->data; 3789 nlh = nlmsg_hdr(skb);
3790 3790
3791 err = selinux_nlmsg_lookup(isec->sclass, nlh->nlmsg_type, &perm); 3791 err = selinux_nlmsg_lookup(isec->sclass, nlh->nlmsg_type, &perm);
3792 if (err) { 3792 if (err) {