]>
Commit | Line | Data |
---|---|---|
2ad7bf36 MB |
1 | /* |
2 | * Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com> | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License as | |
6 | * published by the Free Software Foundation; either version 2 of | |
7 | * the License, or (at your option) any later version. | |
8 | * | |
9 | */ | |
10 | #ifndef __IPVLAN_H | |
11 | #define __IPVLAN_H | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/types.h> | |
15 | #include <linux/module.h> | |
16 | #include <linux/init.h> | |
17 | #include <linux/rculist.h> | |
18 | #include <linux/notifier.h> | |
19 | #include <linux/netdevice.h> | |
20 | #include <linux/etherdevice.h> | |
21 | #include <linux/if_arp.h> | |
22 | #include <linux/if_link.h> | |
23 | #include <linux/if_vlan.h> | |
24 | #include <linux/ip.h> | |
25 | #include <linux/inetdevice.h> | |
26 | #include <net/rtnetlink.h> | |
27 | #include <net/gre.h> | |
28 | #include <net/route.h> | |
29 | #include <net/addrconf.h> | |
30 | ||
31 | #define IPVLAN_DRV "ipvlan" | |
32 | #define IPV_DRV_VER "0.1" | |
33 | ||
34 | #define IPVLAN_HASH_SIZE (1 << BITS_PER_BYTE) | |
35 | #define IPVLAN_HASH_MASK (IPVLAN_HASH_SIZE - 1) | |
36 | ||
37 | #define IPVLAN_MAC_FILTER_BITS 8 | |
38 | #define IPVLAN_MAC_FILTER_SIZE (1 << IPVLAN_MAC_FILTER_BITS) | |
39 | #define IPVLAN_MAC_FILTER_MASK (IPVLAN_MAC_FILTER_SIZE - 1) | |
40 | ||
41 | typedef enum { | |
42 | IPVL_IPV6 = 0, | |
43 | IPVL_ICMPV6, | |
44 | IPVL_IPV4, | |
45 | IPVL_ARP, | |
46 | } ipvl_hdr_type; | |
47 | ||
48 | struct ipvl_pcpu_stats { | |
49 | u64 rx_pkts; | |
50 | u64 rx_bytes; | |
51 | u64 rx_mcast; | |
52 | u64 tx_pkts; | |
53 | u64 tx_bytes; | |
54 | struct u64_stats_sync syncp; | |
55 | u32 rx_errs; | |
56 | u32 tx_drps; | |
57 | }; | |
58 | ||
59 | struct ipvl_port; | |
60 | ||
61 | struct ipvl_dev { | |
62 | struct net_device *dev; | |
63 | struct list_head pnode; | |
64 | struct ipvl_port *port; | |
65 | struct net_device *phy_dev; | |
66 | struct list_head addrs; | |
67 | int ipv4cnt; | |
68 | int ipv6cnt; | |
69 | struct ipvl_pcpu_stats *pcpu_stats; | |
70 | DECLARE_BITMAP(mac_filters, IPVLAN_MAC_FILTER_SIZE); | |
71 | netdev_features_t sfeatures; | |
72 | u32 msg_enable; | |
73 | u16 mtu_adj; | |
74 | }; | |
75 | ||
76 | struct ipvl_addr { | |
77 | struct ipvl_dev *master; /* Back pointer to master */ | |
78 | union { | |
79 | struct in6_addr ip6; /* IPv6 address on logical interface */ | |
80 | struct in_addr ip4; /* IPv4 address on logical interface */ | |
81 | } ipu; | |
82 | #define ip6addr ipu.ip6 | |
83 | #define ip4addr ipu.ip4 | |
84 | struct hlist_node hlnode; /* Hash-table linkage */ | |
85 | struct list_head anode; /* logical-interface linkage */ | |
86 | struct rcu_head rcu; | |
87 | ipvl_hdr_type atype; | |
88 | }; | |
89 | ||
90 | struct ipvl_port { | |
91 | struct net_device *dev; | |
92 | struct hlist_head hlhead[IPVLAN_HASH_SIZE]; | |
93 | struct list_head ipvlans; | |
94 | struct rcu_head rcu; | |
95 | int count; | |
96 | u16 mode; | |
97 | }; | |
98 | ||
99 | static inline struct ipvl_port *ipvlan_port_get_rcu(const struct net_device *d) | |
100 | { | |
101 | return rcu_dereference(d->rx_handler_data); | |
102 | } | |
103 | ||
104 | static inline struct ipvl_port *ipvlan_port_get_rtnl(const struct net_device *d) | |
105 | { | |
106 | return rtnl_dereference(d->rx_handler_data); | |
107 | } | |
108 | ||
109 | static inline bool ipvlan_dev_master(struct net_device *d) | |
110 | { | |
111 | return d->priv_flags & IFF_IPVLAN_MASTER; | |
112 | } | |
113 | ||
114 | static inline bool ipvlan_dev_slave(struct net_device *d) | |
115 | { | |
116 | return d->priv_flags & IFF_IPVLAN_SLAVE; | |
117 | } | |
118 | ||
119 | void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev); | |
120 | void ipvlan_set_port_mode(struct ipvl_port *port, u32 nval); | |
121 | void ipvlan_init_secret(void); | |
122 | unsigned int ipvlan_mac_hash(const unsigned char *addr); | |
123 | rx_handler_result_t ipvlan_handle_frame(struct sk_buff **pskb); | |
124 | int ipvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev); | |
125 | void ipvlan_ht_addr_add(struct ipvl_dev *ipvlan, struct ipvl_addr *addr); | |
126 | bool ipvlan_addr_busy(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6); | |
127 | struct ipvl_addr *ipvlan_ht_addr_lookup(const struct ipvl_port *port, | |
128 | const void *iaddr, bool is_v6); | |
129 | void ipvlan_ht_addr_del(struct ipvl_addr *addr, bool sync); | |
130 | #endif /* __IPVLAN_H */ |