forked from iqiyi/dpvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvlan.h
130 lines (111 loc) · 3.7 KB
/
vlan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2017 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/*
* dpvs VLAN (802.1q) implementation.
*
* [email protected], May 2017, initial.
*/
#ifndef __DPVS_VLAN_H__
#define __DPVS_VLAN_H__
#include <linux/if_ether.h>
#include "common.h"
#include "list.h"
#include "netif.h"
#define VLAN_ID_MAX 4096
#define VLAN_ID_MASK 0x0fff
#define VLAN_HLEN 4
#define VLAN_ETH_DATA_LEN 1500
#define mbuf_vlan_tag_get_id(m) htons(((m)->vlan_tci & VLAN_ID_MASK))
/* VLANs info for real device */
struct vlan_info {
struct netif_port *real_dev;
struct hlist_head *vlan_dev_hash;
uint16_t vlan_dev_num;
rte_rwlock_t vlan_lock;
rte_atomic32_t refcnt;
};
struct vlan_stats {
uint64_t rx_packets;
uint64_t rx_bytes;
uint64_t rx_multicast;
uint64_t tx_packets;
uint64_t tx_bytes;
uint64_t rx_errors;
uint64_t tx_dropped;
};
/**
* struct vlan_dev_priv - vlan netif device specific info
* NOTES:
* 1. about priority mapping
* but mbuf has no fields to save priority and
* dpvs has no QoS module.
* 2. refcnt for vlan_dev_priv ?
* it's a part of netif_port, if refcnt needed
* then add to netif_port.
*/
struct vlan_dev_priv {
struct hlist_node hlist; /* node of real_dev.vlan_dev_hash */
__be16 vlan_proto; /* now ETH_P_8021Q */
__be16 vlan_id;
uint16_t flags;
struct netif_port *dev;
struct netif_port *real_dev;
/* per-CPU statistics
* RTE_DEFINE_PER_LCORE cannot be used inside struct */
struct vlan_stats lcore_stats[RTE_MAX_LCORE];
};
/**
* from linux kernel.
*
* struct vlan_ethhdr - vlan ethernet header (ethhdr + vlan_hdr)
* @h_dest: destination ethernet address
* @h_source: source ethernet address
* @h_vlan_proto: ethernet protocol
* @h_vlan_TCI: priority and VLAN ID
* @h_vlan_encapsulated_proto: packet type ID or len
*/
struct vlan_ethhdr {
unsigned char h_dest[ETH_ALEN];
unsigned char h_source[ETH_ALEN];
__be16 h_vlan_proto;
__be16 h_vlan_TCI;
__be16 h_vlan_encapsulated_proto;
};
int vlan_add_dev(struct netif_port *real_dev, const char *ifname,
__be16 vlan_proto, __be16 vlan_id);
int vlan_del_dev(struct netif_port *real_dev, __be16 vlan_proto,
__be16 vlan_id);
struct netif_port *vlan_find_dev(const struct netif_port *real_dev,
__be16 vlan_proto, __be16 vlan_id);
int vlan_rcv(struct rte_mbuf *mbuf, struct netif_port *rdev);
int vlan_init(void);
static inline int vlan_insert_tag(struct rte_mbuf *mbuf,
__be16 proto, __be16 id)
{
struct vlan_ethhdr *veth;
char *data;
if (rte_pktmbuf_headroom(mbuf) < VLAN_HLEN)
return EDPVS_NOROOM;
veth = (struct vlan_ethhdr *)rte_pktmbuf_prepend(mbuf, VLAN_HLEN);
data = rte_pktmbuf_mtod(mbuf, char *);
memmove(data, data + VLAN_HLEN, 2 * ETH_ALEN);
veth->h_vlan_proto = proto;
veth->h_vlan_TCI = id;
return EDPVS_OK;
}
#endif /* __DPVS_VLAN_H__ */