diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2007-03-10 13:56:08 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:24:43 -0400 |
commit | 797659fb4a4a511649cd71028141c32ad1698a12 (patch) | |
tree | 370361e706de99e3c176b343e9f2db5a1a9df2a3 | |
parent | 37e6636669b0b996681586facee8034f7f674f6a (diff) |
[PPPOE]: Introduce pppoe_hdr()
For consistency with all the other skb->nh.raw accessors.
Also do some really obvious simplifications in pppoe_recvmsg, well the
kfree_skb one is not so obvious, but free() and kfree() have the same behaviour
(hint :-) ).
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/net/pppoe.c | 22 | ||||
-rw-r--r-- | include/linux/if_pppox.h | 7 |
2 files changed, 15 insertions, 14 deletions
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c index ebfa2967cd68..3080a44b23ab 100644 --- a/drivers/net/pppoe.c +++ b/drivers/net/pppoe.c | |||
@@ -347,7 +347,7 @@ static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb) | |||
347 | struct pppox_sock *relay_po = NULL; | 347 | struct pppox_sock *relay_po = NULL; |
348 | 348 | ||
349 | if (sk->sk_state & PPPOX_BOUND) { | 349 | if (sk->sk_state & PPPOX_BOUND) { |
350 | struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw; | 350 | struct pppoe_hdr *ph = pppoe_hdr(skb); |
351 | int len = ntohs(ph->length); | 351 | int len = ntohs(ph->length); |
352 | skb_pull_rcsum(skb, sizeof(struct pppoe_hdr)); | 352 | skb_pull_rcsum(skb, sizeof(struct pppoe_hdr)); |
353 | if (pskb_trim_rcsum(skb, len)) | 353 | if (pskb_trim_rcsum(skb, len)) |
@@ -401,7 +401,7 @@ static int pppoe_rcv(struct sk_buff *skb, | |||
401 | if (!(skb = skb_share_check(skb, GFP_ATOMIC))) | 401 | if (!(skb = skb_share_check(skb, GFP_ATOMIC))) |
402 | goto out; | 402 | goto out; |
403 | 403 | ||
404 | ph = (struct pppoe_hdr *) skb->nh.raw; | 404 | ph = pppoe_hdr(skb); |
405 | 405 | ||
406 | po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source, dev->ifindex); | 406 | po = get_item((unsigned long) ph->sid, eth_hdr(skb)->h_source, dev->ifindex); |
407 | if (po != NULL) | 407 | if (po != NULL) |
@@ -433,7 +433,7 @@ static int pppoe_disc_rcv(struct sk_buff *skb, | |||
433 | if (!(skb = skb_share_check(skb, GFP_ATOMIC))) | 433 | if (!(skb = skb_share_check(skb, GFP_ATOMIC))) |
434 | goto out; | 434 | goto out; |
435 | 435 | ||
436 | ph = (struct pppoe_hdr *) skb->nh.raw; | 436 | ph = pppoe_hdr(skb); |
437 | if (ph->code != PADT_CODE) | 437 | if (ph->code != PADT_CODE) |
438 | goto abort; | 438 | goto abort; |
439 | 439 | ||
@@ -931,8 +931,6 @@ static int pppoe_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
931 | struct sock *sk = sock->sk; | 931 | struct sock *sk = sock->sk; |
932 | struct sk_buff *skb = NULL; | 932 | struct sk_buff *skb = NULL; |
933 | int error = 0; | 933 | int error = 0; |
934 | int len; | ||
935 | struct pppoe_hdr *ph = NULL; | ||
936 | 934 | ||
937 | if (sk->sk_state & PPPOX_BOUND) { | 935 | if (sk->sk_state & PPPOX_BOUND) { |
938 | error = -EIO; | 936 | error = -EIO; |
@@ -949,19 +947,15 @@ static int pppoe_recvmsg(struct kiocb *iocb, struct socket *sock, | |||
949 | m->msg_namelen = 0; | 947 | m->msg_namelen = 0; |
950 | 948 | ||
951 | if (skb) { | 949 | if (skb) { |
952 | error = 0; | 950 | struct pppoe_hdr *ph = pppoe_hdr(skb); |
953 | ph = (struct pppoe_hdr *) skb->nh.raw; | 951 | const int len = ntohs(ph->length); |
954 | len = ntohs(ph->length); | ||
955 | 952 | ||
956 | error = memcpy_toiovec(m->msg_iov, (unsigned char *) &ph->tag[0], len); | 953 | error = memcpy_toiovec(m->msg_iov, (unsigned char *) &ph->tag[0], len); |
957 | if (error < 0) | 954 | if (error == 0) |
958 | goto do_skb_free; | 955 | error = len; |
959 | error = len; | ||
960 | } | 956 | } |
961 | 957 | ||
962 | do_skb_free: | 958 | kfree_skb(skb); |
963 | if (skb) | ||
964 | kfree_skb(skb); | ||
965 | end: | 959 | end: |
966 | return error; | 960 | return error; |
967 | } | 961 | } |
diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h index e33ee763c052..7044f8ab30a0 100644 --- a/include/linux/if_pppox.h +++ b/include/linux/if_pppox.h | |||
@@ -112,6 +112,13 @@ struct pppoe_hdr { | |||
112 | } __attribute__ ((packed)); | 112 | } __attribute__ ((packed)); |
113 | 113 | ||
114 | #ifdef __KERNEL__ | 114 | #ifdef __KERNEL__ |
115 | #include <linux/skbuff.h> | ||
116 | |||
117 | static inline struct pppoe_hdr *pppoe_hdr(const struct sk_buff *skb) | ||
118 | { | ||
119 | return (struct pppoe_hdr *)skb->nh.raw; | ||
120 | } | ||
121 | |||
115 | struct pppoe_opt { | 122 | struct pppoe_opt { |
116 | struct net_device *dev; /* device associated with socket*/ | 123 | struct net_device *dev; /* device associated with socket*/ |
117 | int ifindex; /* ifindex of device associated with socket */ | 124 | int ifindex; /* ifindex of device associated with socket */ |