[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>
This commit is contained in:
Arnaldo Carvalho de Melo 2007-04-25 19:08:35 -07:00 committed by David S. Miller
parent 965ffea43d
commit b529ccf279
15 changed files with 23 additions and 18 deletions

View file

@ -212,7 +212,7 @@ static void cn_rx_skb(struct sk_buff *__skb)
skb = skb_get(__skb); skb = skb_get(__skb);
if (skb->len >= NLMSG_SPACE(0)) { if (skb->len >= NLMSG_SPACE(0)) {
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < sizeof(struct cn_msg) || if (nlh->nlmsg_len < sizeof(struct cn_msg) ||
skb->len < nlh->nlmsg_len || skb->len < nlh->nlmsg_len ||

View file

@ -50,7 +50,7 @@ scsi_nl_rcv_msg(struct sk_buff *skb)
while (skb->len >= NLMSG_SPACE(0)) { while (skb->len >= NLMSG_SPACE(0)) {
err = 0; err = 0;
nlh = (struct nlmsghdr *) skb->data; nlh = nlmsg_hdr(skb);
if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) || if ((nlh->nlmsg_len < (sizeof(*nlh) + sizeof(*hdr))) ||
(skb->len < nlh->nlmsg_len)) { (skb->len < nlh->nlmsg_len)) {
printk(KERN_WARNING "%s: discarding partial skb\n", printk(KERN_WARNING "%s: discarding partial skb\n",

View file

@ -1081,7 +1081,7 @@ iscsi_if_rx(struct sock *sk, int len)
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
struct iscsi_uevent *ev; struct iscsi_uevent *ev;
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < sizeof(*nlh) || if (nlh->nlmsg_len < sizeof(*nlh) ||
skb->len < nlh->nlmsg_len) { skb->len < nlh->nlmsg_len) {
break; break;

View file

@ -97,7 +97,7 @@ out:
*/ */
static int ecryptfs_process_nl_response(struct sk_buff *skb) static int ecryptfs_process_nl_response(struct sk_buff *skb)
{ {
struct nlmsghdr *nlh = (struct nlmsghdr*)skb->data; struct nlmsghdr *nlh = nlmsg_hdr(skb);
struct ecryptfs_message *msg = NLMSG_DATA(nlh); struct ecryptfs_message *msg = NLMSG_DATA(nlh);
int rc; int rc;
@ -181,7 +181,7 @@ receive:
"rc = [%d]\n", rc); "rc = [%d]\n", rc);
return; return;
} }
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
if (!NLMSG_OK(nlh, skb->len)) { if (!NLMSG_OK(nlh, skb->len)) {
ecryptfs_printk(KERN_ERR, "Received corrupt netlink " ecryptfs_printk(KERN_ERR, "Received corrupt netlink "
"message\n"); "message\n");

View file

@ -138,6 +138,11 @@ struct nlattr
#include <linux/capability.h> #include <linux/capability.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
{
return (struct nlmsghdr *)skb->data;
}
struct netlink_skb_parms struct netlink_skb_parms
{ {
struct ucred creds; /* Skb credentials */ struct ucred creds; /* Skb credentials */

View file

@ -151,7 +151,7 @@ struct audit_buffer {
static void audit_set_pid(struct audit_buffer *ab, pid_t pid) static void audit_set_pid(struct audit_buffer *ab, pid_t pid)
{ {
struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data; struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
nlh->nlmsg_pid = pid; nlh->nlmsg_pid = pid;
} }
@ -750,7 +750,7 @@ static void audit_receive_skb(struct sk_buff *skb)
u32 rlen; u32 rlen;
while (skb->len >= NLMSG_SPACE(0)) { while (skb->len >= NLMSG_SPACE(0)) {
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
return; return;
rlen = NLMSG_ALIGN(nlh->nlmsg_len); rlen = NLMSG_ALIGN(nlh->nlmsg_len);
@ -1268,7 +1268,7 @@ void audit_log_end(struct audit_buffer *ab)
audit_log_lost("rate limit exceeded"); audit_log_lost("rate limit exceeded");
} else { } else {
if (audit_pid) { if (audit_pid) {
struct nlmsghdr *nlh = (struct nlmsghdr *)ab->skb->data; struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
nlh->nlmsg_len = ab->skb->len - NLMSG_SPACE(0); nlh->nlmsg_len = ab->skb->len - NLMSG_SPACE(0);
skb_queue_tail(&audit_skb_queue, ab->skb); skb_queue_tail(&audit_skb_queue, ab->skb);
ab->skb = NULL; ab->skb = NULL;

View file

@ -102,7 +102,7 @@ static int prepare_reply(struct genl_info *info, u8 cmd, struct sk_buff **skbp,
*/ */
static int send_reply(struct sk_buff *skb, pid_t pid) static int send_reply(struct sk_buff *skb, pid_t pid)
{ {
struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
void *reply = genlmsg_data(genlhdr); void *reply = genlmsg_data(genlhdr);
int rc; int rc;
@ -121,7 +121,7 @@ static int send_reply(struct sk_buff *skb, pid_t pid)
static void send_cpu_listeners(struct sk_buff *skb, static void send_cpu_listeners(struct sk_buff *skb,
struct listener_list *listeners) struct listener_list *listeners)
{ {
struct genlmsghdr *genlhdr = nlmsg_data((struct nlmsghdr *)skb->data); struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
struct listener *s, *tmp; struct listener *s, *tmp;
struct sk_buff *skb_next, *skb_cur = skb; struct sk_buff *skb_next, *skb_cur = skb;
void *reply = genlmsg_data(genlhdr); void *reply = genlmsg_data(genlhdr);

View file

@ -102,7 +102,7 @@ static unsigned int dnrmg_hook(unsigned int hook,
static inline void dnrmg_receive_user_skb(struct sk_buff *skb) static inline void dnrmg_receive_user_skb(struct sk_buff *skb)
{ {
struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data; struct nlmsghdr *nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len) if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
return; return;

View file

@ -807,7 +807,7 @@ static void nl_fib_input(struct sock *sk, int len)
if (skb == NULL) if (skb == NULL)
return; return;
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len || if (skb->len < NLMSG_SPACE(0) || skb->len < nlh->nlmsg_len ||
nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) { nlh->nlmsg_len < NLMSG_LENGTH(sizeof(*frn))) {
kfree_skb(skb); kfree_skb(skb);

View file

@ -847,7 +847,7 @@ static inline void inet_diag_rcv_skb(struct sk_buff *skb)
{ {
if (skb->len >= NLMSG_SPACE(0)) { if (skb->len >= NLMSG_SPACE(0)) {
int err; int err;
struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data; struct nlmsghdr *nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < sizeof(*nlh) || if (nlh->nlmsg_len < sizeof(*nlh) ||
skb->len < nlh->nlmsg_len) skb->len < nlh->nlmsg_len)

View file

@ -497,7 +497,7 @@ ipq_rcv_skb(struct sk_buff *skb)
if (skblen < sizeof(*nlh)) if (skblen < sizeof(*nlh))
return; return;
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
nlmsglen = nlh->nlmsg_len; nlmsglen = nlh->nlmsg_len;
if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen) if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen)
return; return;

View file

@ -487,7 +487,7 @@ ipq_rcv_skb(struct sk_buff *skb)
if (skblen < sizeof(*nlh)) if (skblen < sizeof(*nlh))
return; return;
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
nlmsglen = nlh->nlmsg_len; nlmsglen = nlh->nlmsg_len;
if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen) if (nlmsglen < sizeof(*nlh) || skblen < nlmsglen)
return; return;

View file

@ -1471,7 +1471,7 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
int err; int err;
while (skb->len >= nlmsg_total_size(0)) { while (skb->len >= nlmsg_total_size(0)) {
nlh = (struct nlmsghdr *) skb->data; nlh = nlmsg_hdr(skb);
if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len) if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
return 0; return 0;

View file

@ -57,7 +57,7 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
if (rep_buf) { if (rep_buf) {
skb_push(rep_buf, hdr_space); skb_push(rep_buf, hdr_space);
rep_nlh = (struct nlmsghdr *)rep_buf->data; rep_nlh = nlmsg_hdr(rep_buf);
memcpy(rep_nlh, req_nlh, hdr_space); memcpy(rep_nlh, req_nlh, hdr_space);
rep_nlh->nlmsg_len = rep_buf->len; rep_nlh->nlmsg_len = rep_buf->len;
genlmsg_unicast(rep_buf, req_nlh->nlmsg_pid); genlmsg_unicast(rep_buf, req_nlh->nlmsg_pid);

View file

@ -3786,7 +3786,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
err = -EINVAL; err = -EINVAL;
goto out; goto out;
} }
nlh = (struct nlmsghdr *)skb->data; nlh = nlmsg_hdr(skb);
err = selinux_nlmsg_lookup(isec->sclass, nlh->nlmsg_type, &perm); err = selinux_nlmsg_lookup(isec->sclass, nlh->nlmsg_type, &perm);
if (err) { if (err) {