aboutsummaryrefslogtreecommitdiffstats
path: root/net/packet/af_packet.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-11 14:38:13 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-11 14:38:13 -0500
commitcb18eccff48ef3986d1072964590bce6fec705fb (patch)
tree777fb1d15e0281341e1e02c9803d989538d346f2 /net/packet/af_packet.c
parentc827ba4cb49a30ce581201fd0ba2be77cde412c7 (diff)
parent5ef213f6842277ee1df5659f59fac0ffc9beb411 (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6: (45 commits) [IPV4]: Restore multipath routing after rt_next changes. [XFRM] IPV6: Fix outbound RO transformation which is broken by IPsec tunnel patch. [NET]: Reorder fields of struct dst_entry [DECNET]: Convert decnet route to use the new dst_entry 'next' pointer [IPV6]: Convert ipv6 route to use the new dst_entry 'next' pointer [IPV4]: Convert ipv4 route to use the new dst_entry 'next' pointer [NET]: Introduce union in struct dst_entry to hold 'next' pointer [DECNET]: fix misannotation of linkinfo_dn [DECNET]: FRA_{DST,SRC} are le16 for decnet [UDP]: UDP can use sk_hash to speedup lookups [NET]: Fix whitespace errors. [NET] XFRM: Fix whitespace errors. [NET] X25: Fix whitespace errors. [NET] WANROUTER: Fix whitespace errors. [NET] UNIX: Fix whitespace errors. [NET] TIPC: Fix whitespace errors. [NET] SUNRPC: Fix whitespace errors. [NET] SCTP: Fix whitespace errors. [NET] SCHED: Fix whitespace errors. [NET] RXRPC: Fix whitespace errors. ...
Diffstat (limited to 'net/packet/af_packet.c')
-rw-r--r--net/packet/af_packet.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index a6fa48788e8..444550917bc 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -11,7 +11,7 @@
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Alan Cox, <gw4pts@gw4pts.ampr.org> 12 * Alan Cox, <gw4pts@gw4pts.ampr.org>
13 * 13 *
14 * Fixes: 14 * Fixes:
15 * Alan Cox : verify_area() now used correctly 15 * Alan Cox : verify_area() now used correctly
16 * Alan Cox : new skbuff lists, look ma no backlogs! 16 * Alan Cox : new skbuff lists, look ma no backlogs!
17 * Alan Cox : tidied skbuff lists. 17 * Alan Cox : tidied skbuff lists.
@@ -34,12 +34,12 @@
34 * Alexey Kuznetsov : Untied from IPv4 stack. 34 * Alexey Kuznetsov : Untied from IPv4 stack.
35 * Cyrus Durgin : Fixed kerneld for kmod. 35 * Cyrus Durgin : Fixed kerneld for kmod.
36 * Michal Ostrowski : Module initialization cleanup. 36 * Michal Ostrowski : Module initialization cleanup.
37 * Ulises Alonso : Frame number limit removal and 37 * Ulises Alonso : Frame number limit removal and
38 * packet_set_ring memory leak. 38 * packet_set_ring memory leak.
39 * Eric Biederman : Allow for > 8 byte hardware addresses. 39 * Eric Biederman : Allow for > 8 byte hardware addresses.
40 * The convention is that longer addresses 40 * The convention is that longer addresses
41 * will simply extend the hardware address 41 * will simply extend the hardware address
42 * byte arrays at the end of sockaddr_ll 42 * byte arrays at the end of sockaddr_ll
43 * and packet_mreq. 43 * and packet_mreq.
44 * 44 *
45 * This program is free software; you can redistribute it and/or 45 * This program is free software; you can redistribute it and/or
@@ -48,7 +48,7 @@
48 * 2 of the License, or (at your option) any later version. 48 * 2 of the License, or (at your option) any later version.
49 * 49 *
50 */ 50 */
51 51
52#include <linux/types.h> 52#include <linux/types.h>
53#include <linux/sched.h> 53#include <linux/sched.h>
54#include <linux/mm.h> 54#include <linux/mm.h>
@@ -124,7 +124,7 @@ Outgoing, dev->hard_header!=NULL
124 124
125Incoming, dev->hard_header==NULL 125Incoming, dev->hard_header==NULL
126 mac.raw -> UNKNOWN position. It is very likely, that it points to ll header. 126 mac.raw -> UNKNOWN position. It is very likely, that it points to ll header.
127 PPP makes it, that is wrong, because introduce assymetry 127 PPP makes it, that is wrong, because introduce assymetry
128 between rx and tx paths. 128 between rx and tx paths.
129 data -> data 129 data -> data
130 130
@@ -237,7 +237,7 @@ static inline char *packet_lookup_frame(struct packet_sock *po, unsigned int pos
237 frame_offset = position % po->frames_per_block; 237 frame_offset = position % po->frames_per_block;
238 238
239 frame = po->pg_vec[pg_vec_pos] + (frame_offset * po->frame_size); 239 frame = po->pg_vec[pg_vec_pos] + (frame_offset * po->frame_size);
240 240
241 return frame; 241 return frame;
242} 242}
243#endif 243#endif
@@ -280,7 +280,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev, struct
280 */ 280 */
281 281
282 sk = pt->af_packet_priv; 282 sk = pt->af_packet_priv;
283 283
284 /* 284 /*
285 * Yank back the headers [hope the device set this 285 * Yank back the headers [hope the device set this
286 * right or kerboom...] 286 * right or kerboom...]
@@ -336,7 +336,7 @@ oom:
336 * Output a raw packet to a device layer. This bypasses all the other 336 * Output a raw packet to a device layer. This bypasses all the other
337 * protocol layers and you must therefore supply it with a complete frame 337 * protocol layers and you must therefore supply it with a complete frame
338 */ 338 */
339 339
340static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock, 340static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
341 struct msghdr *msg, size_t len) 341 struct msghdr *msg, size_t len)
342{ 342{
@@ -346,9 +346,9 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
346 struct net_device *dev; 346 struct net_device *dev;
347 __be16 proto=0; 347 __be16 proto=0;
348 int err; 348 int err;
349 349
350 /* 350 /*
351 * Get and verify the address. 351 * Get and verify the address.
352 */ 352 */
353 353
354 if (saddr) 354 if (saddr)
@@ -362,7 +362,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
362 return(-ENOTCONN); /* SOCK_PACKET must be sent giving an address */ 362 return(-ENOTCONN); /* SOCK_PACKET must be sent giving an address */
363 363
364 /* 364 /*
365 * Find the device first to size check it 365 * Find the device first to size check it
366 */ 366 */
367 367
368 saddr->spkt_device[13] = 0; 368 saddr->spkt_device[13] = 0;
@@ -370,7 +370,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
370 err = -ENODEV; 370 err = -ENODEV;
371 if (dev == NULL) 371 if (dev == NULL)
372 goto out_unlock; 372 goto out_unlock;
373 373
374 err = -ENETDOWN; 374 err = -ENETDOWN;
375 if (!(dev->flags & IFF_UP)) 375 if (!(dev->flags & IFF_UP))
376 goto out_unlock; 376 goto out_unlock;
@@ -379,7 +379,7 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
379 * You may not queue a frame bigger than the mtu. This is the lowest level 379 * You may not queue a frame bigger than the mtu. This is the lowest level
380 * raw protocol and you must do your own fragmentation at this level. 380 * raw protocol and you must do your own fragmentation at this level.
381 */ 381 */
382 382
383 err = -EMSGSIZE; 383 err = -EMSGSIZE;
384 if (len > dev->mtu + dev->hard_header_len) 384 if (len > dev->mtu + dev->hard_header_len)
385 goto out_unlock; 385 goto out_unlock;
@@ -392,14 +392,14 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
392 * deal with the problem - do your own algorithmic backoffs. That's far 392 * deal with the problem - do your own algorithmic backoffs. That's far
393 * more flexible. 393 * more flexible.
394 */ 394 */
395 395
396 if (skb == NULL) 396 if (skb == NULL)
397 goto out_unlock; 397 goto out_unlock;
398 398
399 /* 399 /*
400 * Fill it in 400 * Fill it in
401 */ 401 */
402 402
403 /* FIXME: Save some space for broken drivers that write a 403 /* FIXME: Save some space for broken drivers that write a
404 * hard header at transmission time by themselves. PPP is the 404 * hard header at transmission time by themselves. PPP is the
405 * notable one here. This should really be fixed at the driver level. 405 * notable one here. This should really be fixed at the driver level.
@@ -641,7 +641,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
641 641
642 spin_lock(&sk->sk_receive_queue.lock); 642 spin_lock(&sk->sk_receive_queue.lock);
643 h = (struct tpacket_hdr *)packet_lookup_frame(po, po->head); 643 h = (struct tpacket_hdr *)packet_lookup_frame(po, po->head);
644 644
645 if (h->tp_status) 645 if (h->tp_status)
646 goto ring_is_full; 646 goto ring_is_full;
647 po->head = po->head != po->frame_max ? po->head+1 : 0; 647 po->head = po->head != po->frame_max ? po->head+1 : 0;
@@ -660,7 +660,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
660 h->tp_snaplen = snaplen; 660 h->tp_snaplen = snaplen;
661 h->tp_mac = macoff; 661 h->tp_mac = macoff;
662 h->tp_net = netoff; 662 h->tp_net = netoff;
663 if (skb->tstamp.off_sec == 0) { 663 if (skb->tstamp.off_sec == 0) {
664 __net_timestamp(skb); 664 __net_timestamp(skb);
665 sock_enable_timestamp(sk); 665 sock_enable_timestamp(sk);
666 } 666 }
@@ -700,7 +700,7 @@ drop_n_restore:
700 skb->len = skb_len; 700 skb->len = skb_len;
701 } 701 }
702drop: 702drop:
703 kfree_skb(skb); 703 kfree_skb(skb);
704 return 0; 704 return 0;
705 705
706ring_is_full: 706ring_is_full:
@@ -728,9 +728,9 @@ static int packet_sendmsg(struct kiocb *iocb, struct socket *sock,
728 int ifindex, err, reserve = 0; 728 int ifindex, err, reserve = 0;
729 729
730 /* 730 /*
731 * Get and verify the address. 731 * Get and verify the address.
732 */ 732 */
733 733
734 if (saddr == NULL) { 734 if (saddr == NULL) {
735 struct packet_sock *po = pkt_sk(sk); 735 struct packet_sock *po = pkt_sk(sk);
736 736
@@ -939,11 +939,11 @@ static int packet_bind_spkt(struct socket *sock, struct sockaddr *uaddr, int add
939 char name[15]; 939 char name[15];
940 struct net_device *dev; 940 struct net_device *dev;
941 int err = -ENODEV; 941 int err = -ENODEV;
942 942
943 /* 943 /*
944 * Check legality 944 * Check legality
945 */ 945 */
946 946
947 if (addr_len != sizeof(struct sockaddr)) 947 if (addr_len != sizeof(struct sockaddr))
948 return -EINVAL; 948 return -EINVAL;
949 strlcpy(name,uaddr->sa_data,sizeof(name)); 949 strlcpy(name,uaddr->sa_data,sizeof(name));
@@ -968,7 +968,7 @@ static int packet_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len
968 /* 968 /*
969 * Check legality 969 * Check legality
970 */ 970 */
971 971
972 if (addr_len < sizeof(struct sockaddr_ll)) 972 if (addr_len < sizeof(struct sockaddr_ll))
973 return -EINVAL; 973 return -EINVAL;
974 if (sll->sll_family != AF_PACKET) 974 if (sll->sll_family != AF_PACKET)
@@ -995,7 +995,7 @@ static struct proto packet_proto = {
995}; 995};
996 996
997/* 997/*
998 * Create a packet of type SOCK_PACKET. 998 * Create a packet of type SOCK_PACKET.
999 */ 999 */
1000 1000
1001static int packet_create(struct socket *sock, int protocol) 1001static int packet_create(struct socket *sock, int protocol)
@@ -1097,7 +1097,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
1097 skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err); 1097 skb=skb_recv_datagram(sk,flags,flags&MSG_DONTWAIT,&err);
1098 1098
1099 /* 1099 /*
1100 * An error occurred so return it. Because skb_recv_datagram() 1100 * An error occurred so return it. Because skb_recv_datagram()
1101 * handles the blocking we don't see and worry about blocking 1101 * handles the blocking we don't see and worry about blocking
1102 * retries. 1102 * retries.
1103 */ 1103 */
@@ -1358,7 +1358,7 @@ packet_setsockopt(struct socket *sock, int level, int optname, char __user *optv
1358 1358
1359 switch(optname) { 1359 switch(optname) {
1360#ifdef CONFIG_PACKET_MULTICAST 1360#ifdef CONFIG_PACKET_MULTICAST
1361 case PACKET_ADD_MEMBERSHIP: 1361 case PACKET_ADD_MEMBERSHIP:
1362 case PACKET_DROP_MEMBERSHIP: 1362 case PACKET_DROP_MEMBERSHIP:
1363 { 1363 {
1364 struct packet_mreq_max mreq; 1364 struct packet_mreq_max mreq;
@@ -1438,7 +1438,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
1438 1438
1439 if (len < 0) 1439 if (len < 0)
1440 return -EINVAL; 1440 return -EINVAL;
1441 1441
1442 switch(optname) { 1442 switch(optname) {
1443 case PACKET_STATISTICS: 1443 case PACKET_STATISTICS:
1444 if (len > sizeof(struct tpacket_stats)) 1444 if (len > sizeof(struct tpacket_stats))
@@ -1547,7 +1547,7 @@ static int packet_ioctl(struct socket *sock, unsigned int cmd,
1547 } 1547 }
1548 case SIOCGSTAMP: 1548 case SIOCGSTAMP:
1549 return sock_get_timestamp(sk, (struct timeval __user *)arg); 1549 return sock_get_timestamp(sk, (struct timeval __user *)arg);
1550 1550
1551#ifdef CONFIG_INET 1551#ifdef CONFIG_INET
1552 case SIOCADDRT: 1552 case SIOCADDRT:
1553 case SIOCDELRT: 1553 case SIOCDELRT:
@@ -1608,7 +1608,7 @@ static void packet_mm_open(struct vm_area_struct *vma)
1608 struct file *file = vma->vm_file; 1608 struct file *file = vma->vm_file;
1609 struct socket * sock = file->private_data; 1609 struct socket * sock = file->private_data;
1610 struct sock *sk = sock->sk; 1610 struct sock *sk = sock->sk;
1611 1611
1612 if (sk) 1612 if (sk)
1613 atomic_inc(&pkt_sk(sk)->mapped); 1613 atomic_inc(&pkt_sk(sk)->mapped);
1614} 1614}
@@ -1618,7 +1618,7 @@ static void packet_mm_close(struct vm_area_struct *vma)
1618 struct file *file = vma->vm_file; 1618 struct file *file = vma->vm_file;
1619 struct socket * sock = file->private_data; 1619 struct socket * sock = file->private_data;
1620 struct sock *sk = sock->sk; 1620 struct sock *sk = sock->sk;
1621 1621
1622 if (sk) 1622 if (sk)
1623 atomic_dec(&pkt_sk(sk)->mapped); 1623 atomic_dec(&pkt_sk(sk)->mapped);
1624} 1624}
@@ -1682,7 +1682,7 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
1682 int was_running, order = 0; 1682 int was_running, order = 0;
1683 __be16 num; 1683 __be16 num;
1684 int err = 0; 1684 int err = 0;
1685 1685
1686 if (req->tp_block_nr) { 1686 if (req->tp_block_nr) {
1687 int i, l; 1687 int i, l;
1688 1688
@@ -1744,7 +1744,7 @@ static int packet_set_ring(struct sock *sk, struct tpacket_req *req, int closing
1744 __sock_put(sk); 1744 __sock_put(sk);
1745 } 1745 }
1746 spin_unlock(&po->bind_lock); 1746 spin_unlock(&po->bind_lock);
1747 1747
1748 synchronize_net(); 1748 synchronize_net();
1749 1749
1750 err = -EBUSY; 1750 err = -EBUSY;
@@ -1861,7 +1861,7 @@ static const struct proto_ops packet_ops = {
1861 .connect = sock_no_connect, 1861 .connect = sock_no_connect,
1862 .socketpair = sock_no_socketpair, 1862 .socketpair = sock_no_socketpair,
1863 .accept = sock_no_accept, 1863 .accept = sock_no_accept,
1864 .getname = packet_getname, 1864 .getname = packet_getname,
1865 .poll = packet_poll, 1865 .poll = packet_poll,
1866 .ioctl = packet_ioctl, 1866 .ioctl = packet_ioctl,
1867 .listen = sock_no_listen, 1867 .listen = sock_no_listen,
@@ -1906,17 +1906,17 @@ static void *packet_seq_start(struct seq_file *seq, loff_t *pos)
1906static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1906static void *packet_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1907{ 1907{
1908 ++*pos; 1908 ++*pos;
1909 return (v == SEQ_START_TOKEN) 1909 return (v == SEQ_START_TOKEN)
1910 ? sk_head(&packet_sklist) 1910 ? sk_head(&packet_sklist)
1911 : sk_next((struct sock*)v) ; 1911 : sk_next((struct sock*)v) ;
1912} 1912}
1913 1913
1914static void packet_seq_stop(struct seq_file *seq, void *v) 1914static void packet_seq_stop(struct seq_file *seq, void *v)
1915{ 1915{
1916 read_unlock(&packet_sklist_lock); 1916 read_unlock(&packet_sklist_lock);
1917} 1917}
1918 1918
1919static int packet_seq_show(struct seq_file *seq, void *v) 1919static int packet_seq_show(struct seq_file *seq, void *v)
1920{ 1920{
1921 if (v == SEQ_START_TOKEN) 1921 if (v == SEQ_START_TOKEN)
1922 seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n"); 1922 seq_puts(seq, "sk RefCnt Type Proto Iface R Rmem User Inode\n");