]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/dsa/tag_hellcreek.c
ax25: Fix UAF bugs in ax25 timers
[mirror_ubuntu-jammy-kernel.git] / net / dsa / tag_hellcreek.c
CommitLineData
01ef09ca
KK
1// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/*
3 * net/dsa/tag_hellcreek.c - Hirschmann Hellcreek switch tag format handling
4 *
5 * Copyright (C) 2019,2020 Linutronix GmbH
6 * Author Kurt Kanzenbach <kurt@linutronix.de>
7 *
8 * Based on tag_ksz.c.
9 */
10
8551fad6 11#include <linux/skbuff.h>
01ef09ca
KK
12#include <net/dsa.h>
13
14#include "dsa_priv.h"
15
16#define HELLCREEK_TAG_LEN 1
17
18static struct sk_buff *hellcreek_xmit(struct sk_buff *skb,
19 struct net_device *dev)
20{
21 struct dsa_port *dp = dsa_slave_to_port(dev);
22 u8 *tag;
23
24 /* Tag encoding */
25 tag = skb_put(skb, HELLCREEK_TAG_LEN);
26 *tag = BIT(dp->index);
27
28 return skb;
29}
30
31static struct sk_buff *hellcreek_rcv(struct sk_buff *skb,
29a097b7 32 struct net_device *dev)
01ef09ca
KK
33{
34 /* Tag decoding */
35 u8 *tag = skb_tail_pointer(skb) - HELLCREEK_TAG_LEN;
36 unsigned int port = tag[0] & 0x03;
37
38 skb->dev = dsa_master_find_slave(dev, 0, port);
39 if (!skb->dev) {
40 netdev_warn(dev, "Failed to get source port: %d\n", port);
41 return NULL;
42 }
43
44 pskb_trim_rcsum(skb, skb->len - HELLCREEK_TAG_LEN);
45
bea79078 46 dsa_default_offload_fwd_mark(skb);
01ef09ca
KK
47
48 return skb;
49}
50
51static const struct dsa_device_ops hellcreek_netdev_ops = {
52 .name = "hellcreek",
53 .proto = DSA_TAG_PROTO_HELLCREEK,
54 .xmit = hellcreek_xmit,
55 .rcv = hellcreek_rcv,
4e500251 56 .needed_tailroom = HELLCREEK_TAG_LEN,
01ef09ca
KK
57};
58
59MODULE_LICENSE("Dual MIT/GPL");
60MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_HELLCREEK);
61
62module_dsa_tag_driver(hellcreek_netdev_ops);