aboutsummaryrefslogtreecommitdiffstats
path: root/net/packet
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-04-15 21:57:46 -0400
committerDavid S. Miller <davem@davemloft.net>2013-04-16 16:43:34 -0400
commit184f489e9b8c40b4dd4883d3f1364f7786c8755c (patch)
tree0cb73f7297e1ef2685fcec6310d530ea2993d19e /net/packet
parentf406c8b9693f2f71ef2caeb0b68521a7d22d00f0 (diff)
packet: minor: add generic tpacket_uhdr to access packet headers
There is no need to add a dozen unions each time at the start of the function. So, do this once and use it instead. Thus, we can remove some duplicate code and make it more readable. Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/packet')
-rw-r--r--net/packet/af_packet.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 77d71f84758c..e566b793f07c 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -158,10 +158,16 @@ struct packet_mreq_max {
158 unsigned char mr_address[MAX_ADDR_LEN]; 158 unsigned char mr_address[MAX_ADDR_LEN];
159}; 159};
160 160
161union tpacket_uhdr {
162 struct tpacket_hdr *h1;
163 struct tpacket2_hdr *h2;
164 struct tpacket3_hdr *h3;
165 void *raw;
166};
167
161static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, 168static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
162 int closing, int tx_ring); 169 int closing, int tx_ring);
163 170
164
165#define V3_ALIGNMENT (8) 171#define V3_ALIGNMENT (8)
166 172
167#define BLK_HDR_LEN (ALIGN(sizeof(struct tpacket_block_desc), V3_ALIGNMENT)) 173#define BLK_HDR_LEN (ALIGN(sizeof(struct tpacket_block_desc), V3_ALIGNMENT))
@@ -290,11 +296,7 @@ static inline __pure struct page *pgv_to_page(void *addr)
290 296
291static void __packet_set_status(struct packet_sock *po, void *frame, int status) 297static void __packet_set_status(struct packet_sock *po, void *frame, int status)
292{ 298{
293 union { 299 union tpacket_uhdr h;
294 struct tpacket_hdr *h1;
295 struct tpacket2_hdr *h2;
296 void *raw;
297 } h;
298 300
299 h.raw = frame; 301 h.raw = frame;
300 switch (po->tp_version) { 302 switch (po->tp_version) {
@@ -317,11 +319,7 @@ static void __packet_set_status(struct packet_sock *po, void *frame, int status)
317 319
318static int __packet_get_status(struct packet_sock *po, void *frame) 320static int __packet_get_status(struct packet_sock *po, void *frame)
319{ 321{
320 union { 322 union tpacket_uhdr h;
321 struct tpacket_hdr *h1;
322 struct tpacket2_hdr *h2;
323 void *raw;
324 } h;
325 323
326 smp_rmb(); 324 smp_rmb();
327 325
@@ -347,11 +345,7 @@ static void *packet_lookup_frame(struct packet_sock *po,
347 int status) 345 int status)
348{ 346{
349 unsigned int pg_vec_pos, frame_offset; 347 unsigned int pg_vec_pos, frame_offset;
350 union { 348 union tpacket_uhdr h;
351 struct tpacket_hdr *h1;
352 struct tpacket2_hdr *h2;
353 void *raw;
354 } h;
355 349
356 pg_vec_pos = position / rb->frames_per_block; 350 pg_vec_pos = position / rb->frames_per_block;
357 frame_offset = position % rb->frames_per_block; 351 frame_offset = position % rb->frames_per_block;
@@ -1669,12 +1663,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
1669 struct sock *sk; 1663 struct sock *sk;
1670 struct packet_sock *po; 1664 struct packet_sock *po;
1671 struct sockaddr_ll *sll; 1665 struct sockaddr_ll *sll;
1672 union { 1666 union tpacket_uhdr h;
1673 struct tpacket_hdr *h1;
1674 struct tpacket2_hdr *h2;
1675 struct tpacket3_hdr *h3;
1676 void *raw;
1677 } h;
1678 u8 *skb_head = skb->data; 1667 u8 *skb_head = skb->data;
1679 int skb_len = skb->len; 1668 int skb_len = skb->len;
1680 unsigned int snaplen, res; 1669 unsigned int snaplen, res;
@@ -1909,11 +1898,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
1909 void *frame, struct net_device *dev, int size_max, 1898 void *frame, struct net_device *dev, int size_max,
1910 __be16 proto, unsigned char *addr, int hlen) 1899 __be16 proto, unsigned char *addr, int hlen)
1911{ 1900{
1912 union { 1901 union tpacket_uhdr ph;
1913 struct tpacket_hdr *h1;
1914 struct tpacket2_hdr *h2;
1915 void *raw;
1916 } ph;
1917 int to_write, offset, len, tp_len, nr_frags, len_max; 1902 int to_write, offset, len, tp_len, nr_frags, len_max;
1918 struct socket *sock = po->sk.sk_socket; 1903 struct socket *sock = po->sk.sk_socket;
1919 struct page *page; 1904 struct page *page;