~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/dsa/tag_trailer.c

Version: ~ [ linux-5.15-rc5 ] ~ [ linux-5.14.11 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.72 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.152 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.210 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.250 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.286 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.288 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * net/dsa/tag_trailer.c - Trailer tag format handling
  3  * Copyright (c) 2008-2009 Marvell Semiconductor
  4  *
  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  */
 10 
 11 #include <linux/etherdevice.h>
 12 #include <linux/list.h>
 13 #include <linux/slab.h>
 14 #include "dsa_priv.h"
 15 
 16 static netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev)
 17 {
 18         struct dsa_slave_priv *p = netdev_priv(dev);
 19         struct sk_buff *nskb;
 20         int padlen;
 21         u8 *trailer;
 22 
 23         dev->stats.tx_packets++;
 24         dev->stats.tx_bytes += skb->len;
 25 
 26         /*
 27          * We have to make sure that the trailer ends up as the very
 28          * last 4 bytes of the packet.  This means that we have to pad
 29          * the packet to the minimum ethernet frame size, if necessary,
 30          * before adding the trailer.
 31          */
 32         padlen = 0;
 33         if (skb->len < 60)
 34                 padlen = 60 - skb->len;
 35 
 36         nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
 37         if (nskb == NULL) {
 38                 kfree_skb(skb);
 39                 return NETDEV_TX_OK;
 40         }
 41         skb_reserve(nskb, NET_IP_ALIGN);
 42 
 43         skb_reset_mac_header(nskb);
 44         skb_set_network_header(nskb, skb_network_header(skb) - skb->head);
 45         skb_set_transport_header(nskb, skb_transport_header(skb) - skb->head);
 46         skb_copy_and_csum_dev(skb, skb_put(nskb, skb->len));
 47         kfree_skb(skb);
 48 
 49         if (padlen) {
 50                 u8 *pad = skb_put(nskb, padlen);
 51                 memset(pad, 0, padlen);
 52         }
 53 
 54         trailer = skb_put(nskb, 4);
 55         trailer[0] = 0x80;
 56         trailer[1] = 1 << p->port;
 57         trailer[2] = 0x10;
 58         trailer[3] = 0x00;
 59 
 60         nskb->dev = p->parent->dst->master_netdev;
 61         dev_queue_xmit(nskb);
 62 
 63         return NETDEV_TX_OK;
 64 }
 65 
 66 static int trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 67                        struct packet_type *pt, struct net_device *orig_dev)
 68 {
 69         struct dsa_switch_tree *dst = dev->dsa_ptr;
 70         struct dsa_switch *ds;
 71         u8 *trailer;
 72         int source_port;
 73 
 74         if (unlikely(dst == NULL))
 75                 goto out_drop;
 76         ds = dst->ds[0];
 77 
 78         skb = skb_unshare(skb, GFP_ATOMIC);
 79         if (skb == NULL)
 80                 goto out;
 81 
 82         if (skb_linearize(skb))
 83                 goto out_drop;
 84 
 85         trailer = skb_tail_pointer(skb) - 4;
 86         if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
 87             (trailer[3] & 0xef) != 0x00 || trailer[3] != 0x00)
 88                 goto out_drop;
 89 
 90         source_port = trailer[1] & 7;
 91         if (source_port >= DSA_MAX_PORTS || ds->ports[source_port] == NULL)
 92                 goto out_drop;
 93 
 94         pskb_trim_rcsum(skb, skb->len - 4);
 95 
 96         skb->dev = ds->ports[source_port];
 97         skb_push(skb, ETH_HLEN);
 98         skb->pkt_type = PACKET_HOST;
 99         skb->protocol = eth_type_trans(skb, skb->dev);
100 
101         skb->dev->stats.rx_packets++;
102         skb->dev->stats.rx_bytes += skb->len;
103 
104         netif_receive_skb(skb);
105 
106         return 0;
107 
108 out_drop:
109         kfree_skb(skb);
110 out:
111         return 0;
112 }
113 
114 const struct dsa_device_ops trailer_netdev_ops = {
115         .xmit   = trailer_xmit,
116         .rcv    = trailer_rcv,
117 };
118 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp