~ [ 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 <net/dsa.h>
 15 #include "dsa_priv.h"
 16 
 17 static struct sk_buff *trailer_xmit(struct sk_buff *skb, struct net_device *dev)
 18 {
 19         struct dsa_slave_priv *p = netdev_priv(dev);
 20         struct sk_buff *nskb;
 21         int padlen;
 22         u8 *trailer;
 23 
 24         /*
 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.
 29          */
 30         padlen = 0;
 31         if (skb->len < 60)
 32                 padlen = 60 - skb->len;
 33 
 34         nskb = alloc_skb(NET_IP_ALIGN + skb->len + padlen + 4, GFP_ATOMIC);
 35         if (nskb == NULL) {
 36                 kfree_skb(skb);
 37                 return NULL;
 38         }
 39         skb_reserve(nskb, NET_IP_ALIGN);
 40 
 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);
 46 
 47         if (padlen) {
 48                 u8 *pad = skb_put(nskb, padlen);
 49                 memset(pad, 0, padlen);
 50         }
 51 
 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;
 57 
 58         return nskb;
 59 }
 60 
 61 static struct sk_buff *trailer_rcv(struct sk_buff *skb, struct net_device *dev,
 62                                    struct packet_type *pt,
 63                                    struct net_device *orig_dev)
 64 {
 65         struct dsa_switch_tree *dst = dev->dsa_ptr;
 66         struct dsa_switch *ds;
 67         u8 *trailer;
 68         int source_port;
 69 
 70         ds = dst->cpu_switch;
 71 
 72         if (skb_linearize(skb))
 73                 goto out_drop;
 74 
 75         trailer = skb_tail_pointer(skb) - 4;
 76         if (trailer[0] != 0x80 || (trailer[1] & 0xf8) != 0x00 ||
 77             (trailer[2] & 0xef) != 0x00 || trailer[3] != 0x00)
 78                 goto out_drop;
 79 
 80         source_port = trailer[1] & 7;
 81         if (source_port >= ds->num_ports || !ds->ports[source_port].netdev)
 82                 goto out_drop;
 83 
 84         pskb_trim_rcsum(skb, skb->len - 4);
 85 
 86         skb->dev = ds->ports[source_port].netdev;
 87 
 88         return skb;
 89 
 90 out_drop:
 91         return NULL;
 92 }
 93 
 94 const struct dsa_device_ops trailer_netdev_ops = {
 95         .xmit   = trailer_xmit,
 96         .rcv    = trailer_rcv,
 97 };
 98 

~ [ 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