netfilter: expect: Make sure the max_expected limit is effective
[linux-2.6/btrfs-unstable.git] / net / dsa / tag_trailer.c
blob74c948512550f71649d62446b0c2e60bd88004f9
1 /*
2 * net/dsa/tag_trailer.c - Trailer tag format handling
3 * Copyright (c) 2008-2009 Marvell Semiconductor
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
11 #include <linux/etherdevice.h>
12 #include <linux/list.h>
13 #include <linux/slab.h>
14 #include <net/dsa.h>
15 #include "dsa_priv.h"
17 static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
19 struct dsa_slave_priv *p = netdev_priv(dev);
20 struct sk_buff *nskb;
21 int padlen;
22 u8 *trailer;
25 * We have to make sure that the trailer ends up as the very
26 * last 4 bytes of the packet. This means that we have to pad
27 * the packet to the minimum ethernet frame size, if necessary,
28 * before adding the trailer.
30 padlen = 0;
31 if (skb->len < 60)
32 padlen = 60 - skb->len;
34 nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
35 if (nskb == NULL) {
36 kfree_skb(skb);
37 return NULL;
39 skb_reserve(nskb, NET_IP_ALIGN);
41 skb_reset_mac_header(nskb);
42 skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
43 skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
44 skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
45 kfree_skb(skb);
47 if (padlen) {
48 u8 *pad = skb_put(nskb, padlen);
49 memset(pad, 0, padlen);
52 trailer = skb_put(nskb, 4);
53 trailer[0] = 0x80;
54 trailer[1] = 1 << p->dp->index;
55 trailer[2] = 0x10;
56 trailer[3] = 0x00;
58 return nskb;
61 static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
62 struct packet_type *pt, struct net_device *orig_dev)
64 struct dsa_switch_tree *dst = dev->dsa_ptr;
65 struct dsa_switch *ds;
66 u8 *trailer;
67 int source_port;
69 if (unlikely(dst == NULL))
70 goto out_drop;
71 ds = dst->cpu_switch;
73 skb = skb_unshare(skb, GFP_ATOMIC);
74 if (skb == NULL)
75 goto out;
77 if (skb_linearize(skb))
78 goto out_drop;
80 trailer = skb_tail_pointer(skb) - 4;
81 if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
82 (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
83 goto out_drop;
85 source_port = trailer[1] & 7;
86 if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
87 goto out_drop;
89 pskb_trim_rcsum(skb, skb->len - 4);
91 skb->dev = ds->ports[source_port].netdev;
92 skb_push(skb, ETH_HLEN);
93 skb->pkt_type = PACKET_HOST;
94 skb->protocol = eth_type_trans(skb, skb->dev);
96 skb->dev->stats.rx_packets++;
97 skb->dev->stats.rx_bytes += skb->len;
99 netif_receive_skb(skb);
101 return 0;
103 out_drop:
104 kfree_skb(skb);
105 out:
106 return 0;
109 const struct dsa_device_ops trailer_netdev_ops = {
110 .xmit = trailer_xmit,
111 .rcv = trailer_rcv,