Commit 184f489e authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

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: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f406c8b9
...@@ -158,10 +158,16 @@ struct packet_mreq_max { ...@@ -158,10 +158,16 @@ struct packet_mreq_max {
unsigned char mr_address[MAX_ADDR_LEN]; unsigned char mr_address[MAX_ADDR_LEN];
}; };
union tpacket_uhdr {
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
struct tpacket3_hdr *h3;
void *raw;
};
static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u, static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,
int closing, int tx_ring); int closing, int tx_ring);
#define V3_ALIGNMENT (8) #define V3_ALIGNMENT (8)
#define BLK_HDR_LEN (ALIGN(sizeof(struct tpacket_block_desc), V3_ALIGNMENT)) #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,11 +296,7 @@ static inline __pure struct page *pgv_to_page(void *addr)
static void __packet_set_status(struct packet_sock *po, void *frame, int status) static void __packet_set_status(struct packet_sock *po, void *frame, int status)
{ {
union { union tpacket_uhdr h;
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
void *raw;
} h;
h.raw = frame; h.raw = frame;
switch (po->tp_version) { switch (po->tp_version) {
...@@ -317,11 +319,7 @@ static void __packet_set_status(struct packet_sock *po, void *frame, int status) ...@@ -317,11 +319,7 @@ static void __packet_set_status(struct packet_sock *po, void *frame, int status)
static int __packet_get_status(struct packet_sock *po, void *frame) static int __packet_get_status(struct packet_sock *po, void *frame)
{ {
union { union tpacket_uhdr h;
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
void *raw;
} h;
smp_rmb(); smp_rmb();
...@@ -347,11 +345,7 @@ static void *packet_lookup_frame(struct packet_sock *po, ...@@ -347,11 +345,7 @@ static void *packet_lookup_frame(struct packet_sock *po,
int status) int status)
{ {
unsigned int pg_vec_pos, frame_offset; unsigned int pg_vec_pos, frame_offset;
union { union tpacket_uhdr h;
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
void *raw;
} h;
pg_vec_pos = position / rb->frames_per_block; pg_vec_pos = position / rb->frames_per_block;
frame_offset = position % rb->frames_per_block; frame_offset = position % rb->frames_per_block;
...@@ -1669,12 +1663,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, ...@@ -1669,12 +1663,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
struct sock *sk; struct sock *sk;
struct packet_sock *po; struct packet_sock *po;
struct sockaddr_ll *sll; struct sockaddr_ll *sll;
union { union tpacket_uhdr h;
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
struct tpacket3_hdr *h3;
void *raw;
} h;
u8 *skb_head = skb->data; u8 *skb_head = skb->data;
int skb_len = skb->len; int skb_len = skb->len;
unsigned int snaplen, res; unsigned int snaplen, res;
...@@ -1909,11 +1898,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb, ...@@ -1909,11 +1898,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
void *frame, struct net_device *dev, int size_max, void *frame, struct net_device *dev, int size_max,
__be16 proto, unsigned char *addr, int hlen) __be16 proto, unsigned char *addr, int hlen)
{ {
union { union tpacket_uhdr ph;
struct tpacket_hdr *h1;
struct tpacket2_hdr *h2;
void *raw;
} ph;
int to_write, offset, len, tp_len, nr_frags, len_max; int to_write, offset, len, tp_len, nr_frags, len_max;
struct socket *sock = po->sk.sk_socket; struct socket *sock = po->sk.sk_socket;
struct page *page; struct page *page;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment