blob: dd3d72ce64b6102b4ab64c9654ddffb0145ae3d5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Pravin B Shelar012a5722013-08-19 11:23:07 -07002#ifndef __NET_VXLAN_H
3#define __NET_VXLAN_H 1
4
Jesse Gross5f352272014-12-23 22:37:26 -08005#include <linux/if_vlan.h>
Alexander Duyck86a98052016-06-16 12:20:44 -07006#include <net/udp_tunnel.h>
Thomas Grafee122c72015-07-21 10:43:58 +02007#include <net/dst_metadata.h>
Pravin B Shelar012a5722013-08-19 11:23:07 -07008
Jiri Benc828788a2016-02-02 18:09:13 +01009/* VXLAN protocol (RFC 7348) header:
Thomas Graf35114942015-01-15 03:53:55 +010010 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Jiri Benc828788a2016-02-02 18:09:13 +010011 * |R|R|R|R|I|R|R|R| Reserved |
Thomas Graf35114942015-01-15 03:53:55 +010012 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13 * | VXLAN Network Identifier (VNI) | Reserved |
14 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
15 *
Jiri Benc828788a2016-02-02 18:09:13 +010016 * I = VXLAN Network Identifier (VNI) present.
17 */
18struct vxlanhdr {
19 __be32 vx_flags;
20 __be32 vx_vni;
21};
22
23/* VXLAN header flags. */
Jiri Benc54bfd872016-02-16 21:58:58 +010024#define VXLAN_HF_VNI cpu_to_be32(BIT(27))
Jiri Benc828788a2016-02-02 18:09:13 +010025
26#define VXLAN_N_VID (1u << 24)
27#define VXLAN_VID_MASK (VXLAN_N_VID - 1)
Jiri Benc54bfd872016-02-16 21:58:58 +010028#define VXLAN_VNI_MASK cpu_to_be32(VXLAN_VID_MASK << 8)
Jiri Benc828788a2016-02-02 18:09:13 +010029#define VXLAN_HLEN (sizeof(struct udphdr) + sizeof(struct vxlanhdr))
30
31#define VNI_HASH_BITS 10
32#define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
33#define FDB_HASH_BITS 8
34#define FDB_HASH_SIZE (1<<FDB_HASH_BITS)
35
36/* Remote checksum offload for VXLAN (VXLAN_F_REMCSUM_[RT]X):
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * |R|R|R|R|I|R|R|R|R|R|C| Reserved |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | VXLAN Network Identifier (VNI) |O| Csum start |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 *
43 * C = Remote checksum offload bit. When set indicates that the
44 * remote checksum offload data is present.
45 *
46 * O = Offset bit. Indicates the checksum offset relative to
47 * checksum start.
48 *
49 * Csum start = Checksum start divided by two.
50 *
51 * http://tools.ietf.org/html/draft-herbert-vxlan-rco
52 */
53
54/* VXLAN-RCO header flags. */
Jiri Benc54bfd872016-02-16 21:58:58 +010055#define VXLAN_HF_RCO cpu_to_be32(BIT(21))
Jiri Benc828788a2016-02-02 18:09:13 +010056
57/* Remote checksum offload header option */
Jiri Benc54bfd872016-02-16 21:58:58 +010058#define VXLAN_RCO_MASK cpu_to_be32(0x7f) /* Last byte of vni field */
59#define VXLAN_RCO_UDP cpu_to_be32(0x80) /* Indicate UDP RCO (TCP when not set *) */
60#define VXLAN_RCO_SHIFT 1 /* Left shift of start */
Jiri Benc828788a2016-02-02 18:09:13 +010061#define VXLAN_RCO_SHIFT_MASK ((1 << VXLAN_RCO_SHIFT) - 1)
Jiri Benc54bfd872016-02-16 21:58:58 +010062#define VXLAN_MAX_REMCSUM_START (0x7f << VXLAN_RCO_SHIFT)
Jiri Benc828788a2016-02-02 18:09:13 +010063
64/*
65 * VXLAN Group Based Policy Extension (VXLAN_F_GBP):
66 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 * |G|R|R|R|I|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
68 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 * | VXLAN Network Identifier (VNI) | Reserved |
70 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 *
72 * G = Group Policy ID present.
73 *
Thomas Graf35114942015-01-15 03:53:55 +010074 * D = Don't Learn bit. When set, this bit indicates that the egress
75 * VTEP MUST NOT learn the source address of the encapsulated frame.
76 *
77 * A = Indicates that the group policy has already been applied to
78 * this packet. Policies MUST NOT be applied by devices when the
79 * A bit is set.
80 *
Jiri Benc828788a2016-02-02 18:09:13 +010081 * https://tools.ietf.org/html/draft-smith-vxlan-group-policy
Thomas Graf35114942015-01-15 03:53:55 +010082 */
83struct vxlanhdr_gbp {
Jiri Benc0e715d62016-02-02 18:09:11 +010084 u8 vx_flags;
Thomas Graf35114942015-01-15 03:53:55 +010085#ifdef __LITTLE_ENDIAN_BITFIELD
Jiri Benc0e715d62016-02-02 18:09:11 +010086 u8 reserved_flags1:3,
Thomas Graf35114942015-01-15 03:53:55 +010087 policy_applied:1,
88 reserved_flags2:2,
89 dont_learn:1,
90 reserved_flags3:1;
91#elif defined(__BIG_ENDIAN_BITFIELD)
Jiri Benc0e715d62016-02-02 18:09:11 +010092 u8 reserved_flags1:1,
Thomas Graf35114942015-01-15 03:53:55 +010093 dont_learn:1,
94 reserved_flags2:2,
95 policy_applied:1,
96 reserved_flags3:3;
97#else
98#error "Please fix <asm/byteorder.h>"
99#endif
100 __be16 policy_id;
101 __be32 vx_vni;
102};
103
Jiri Benc828788a2016-02-02 18:09:13 +0100104/* VXLAN-GBP header flags. */
Jiri Benc54bfd872016-02-16 21:58:58 +0100105#define VXLAN_HF_GBP cpu_to_be32(BIT(31))
Jiri Benc828788a2016-02-02 18:09:13 +0100106
Jiri Benc54bfd872016-02-16 21:58:58 +0100107#define VXLAN_GBP_USED_BITS (VXLAN_HF_GBP | cpu_to_be32(0xFFFFFF))
Thomas Graf35114942015-01-15 03:53:55 +0100108
109/* skb->mark mapping
110 *
111 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112 * |R|R|R|R|R|R|R|R|R|D|R|R|A|R|R|R| Group Policy ID |
113 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114 */
115#define VXLAN_GBP_DONT_LEARN (BIT(6) << 16)
116#define VXLAN_GBP_POLICY_APPLIED (BIT(3) << 16)
117#define VXLAN_GBP_ID_MASK (0xFFFF)
118
Jiri Bence1e53142016-04-05 14:47:13 +0200119/*
120 * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
121 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
122 * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
123 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
124 * | VXLAN Network Identifier (VNI) | Reserved |
125 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
126 *
127 * Ver = Version. Indicates VXLAN GPE protocol version.
128 *
129 * P = Next Protocol Bit. The P bit is set to indicate that the
130 * Next Protocol field is present.
131 *
132 * O = OAM Flag Bit. The O bit is set to indicate that the packet
133 * is an OAM packet.
134 *
135 * Next Protocol = This 8 bit field indicates the protocol header
136 * immediately following the VXLAN GPE header.
137 *
138 * https://tools.ietf.org/html/draft-ietf-nvo3-vxlan-gpe-01
139 */
140
141struct vxlanhdr_gpe {
142#if defined(__LITTLE_ENDIAN_BITFIELD)
143 u8 oam_flag:1,
144 reserved_flags1:1,
145 np_applied:1,
146 instance_applied:1,
147 version:2,
William Tuf1c8d372018-01-02 14:05:19 -0800148 reserved_flags2:2;
Jiri Bence1e53142016-04-05 14:47:13 +0200149#elif defined(__BIG_ENDIAN_BITFIELD)
150 u8 reserved_flags2:2,
151 version:2,
152 instance_applied:1,
153 np_applied:1,
154 reserved_flags1:1,
155 oam_flag:1;
156#endif
157 u8 reserved_flags3;
158 u8 reserved_flags4;
159 u8 next_protocol;
160 __be32 vx_vni;
161};
162
163/* VXLAN-GPE header flags. */
164#define VXLAN_HF_VER cpu_to_be32(BIT(29) | BIT(28))
165#define VXLAN_HF_NP cpu_to_be32(BIT(26))
166#define VXLAN_HF_OAM cpu_to_be32(BIT(24))
167
168#define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \
169 cpu_to_be32(0xff))
170
Thomas Graf35114942015-01-15 03:53:55 +0100171struct vxlan_metadata {
Thomas Graf35114942015-01-15 03:53:55 +0100172 u32 gbp;
173};
174
Pravin B Shelar012a5722013-08-19 11:23:07 -0700175/* per UDP socket information */
176struct vxlan_sock {
177 struct hlist_node hlist;
Pravin B Shelar012a5722013-08-19 11:23:07 -0700178 struct socket *sock;
Pravin B Shelar012a5722013-08-19 11:23:07 -0700179 struct hlist_head vni_list[VNI_HASH_SIZE];
Reshetova, Elena66af8462017-07-04 15:52:59 +0300180 refcount_t refcnt;
Tom Herbertdfd86452015-01-12 17:00:38 -0800181 u32 flags;
Pravin B Shelar012a5722013-08-19 11:23:07 -0700182};
183
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200184union vxlan_addr {
185 struct sockaddr_in sin;
186 struct sockaddr_in6 sin6;
187 struct sockaddr sa;
188};
189
190struct vxlan_rdst {
191 union vxlan_addr remote_ip;
192 __be16 remote_port;
Jiri Benc54bfd872016-02-16 21:58:58 +0100193 __be32 remote_vni;
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200194 u32 remote_ifindex;
195 struct list_head list;
196 struct rcu_head rcu;
Paolo Abeni0c1d70a2016-02-12 15:43:56 +0100197 struct dst_cache dst_cache;
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200198};
199
200struct vxlan_config {
201 union vxlan_addr remote_ip;
202 union vxlan_addr saddr;
Jiri Benc54bfd872016-02-16 21:58:58 +0100203 __be32 vni;
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200204 int remote_ifindex;
205 int mtu;
206 __be16 dst_port;
Jiri Benc0e715d62016-02-02 18:09:11 +0100207 u16 port_min;
208 u16 port_max;
209 u8 tos;
210 u8 ttl;
Daniel Borkmanne7f70af2016-03-09 03:00:03 +0100211 __be32 label;
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200212 u32 flags;
213 unsigned long age_interval;
214 unsigned int addrmax;
215 bool no_share;
216};
217
Jiri Benc69e76662017-07-02 19:00:57 +0200218struct vxlan_dev_node {
219 struct hlist_node hlist;
220 struct vxlan_dev *vxlan;
221};
222
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200223/* Pseudo network device */
224struct vxlan_dev {
Jiri Benc69e76662017-07-02 19:00:57 +0200225 struct vxlan_dev_node hlist4; /* vni hash table for IPv4 socket */
226#if IS_ENABLED(CONFIG_IPV6)
227 struct vxlan_dev_node hlist6; /* vni hash table for IPv6 socket */
228#endif
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200229 struct list_head next; /* vxlan's per namespace list */
pravin shelarc6fcc4f2016-10-28 09:59:15 -0700230 struct vxlan_sock __rcu *vn4_sock; /* listening socket for IPv4 */
Jiri Bencb1be00a2015-09-24 13:50:02 +0200231#if IS_ENABLED(CONFIG_IPV6)
pravin shelarc6fcc4f2016-10-28 09:59:15 -0700232 struct vxlan_sock __rcu *vn6_sock; /* listening socket for IPv6 */
Jiri Bencb1be00a2015-09-24 13:50:02 +0200233#endif
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200234 struct net_device *dev;
235 struct net *net; /* netns for packet i/o */
236 struct vxlan_rdst default_dst; /* default destination */
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200237
238 struct timer_list age_timer;
239 spinlock_t hash_lock;
240 unsigned int addrcnt;
Tom Herbert58ce31c2015-08-19 17:07:33 -0700241 struct gro_cells gro_cells;
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200242
243 struct vxlan_config cfg;
244
245 struct hlist_head fdb_head[FDB_HASH_SIZE];
246};
247
Tom Herbert359a0ea2014-06-04 17:20:29 -0700248#define VXLAN_F_LEARN 0x01
249#define VXLAN_F_PROXY 0x02
250#define VXLAN_F_RSC 0x04
251#define VXLAN_F_L2MISS 0x08
252#define VXLAN_F_L3MISS 0x10
253#define VXLAN_F_IPV6 0x20
Alexander Duyck6ceb31c2016-02-19 11:26:31 -0800254#define VXLAN_F_UDP_ZERO_CSUM_TX 0x40
Tom Herbert359a0ea2014-06-04 17:20:29 -0700255#define VXLAN_F_UDP_ZERO_CSUM6_TX 0x80
256#define VXLAN_F_UDP_ZERO_CSUM6_RX 0x100
Tom Herbertdfd86452015-01-12 17:00:38 -0800257#define VXLAN_F_REMCSUM_TX 0x200
258#define VXLAN_F_REMCSUM_RX 0x400
Thomas Graf35114942015-01-15 03:53:55 +0100259#define VXLAN_F_GBP 0x800
Tom Herbert0ace2ca2015-02-10 16:30:32 -0800260#define VXLAN_F_REMCSUM_NOPARTIAL 0x1000
Thomas Grafee122c72015-07-21 10:43:58 +0200261#define VXLAN_F_COLLECT_METADATA 0x2000
Jiri Bence1e53142016-04-05 14:47:13 +0200262#define VXLAN_F_GPE 0x4000
Matthias Schiffer0f22a3c2017-06-19 10:03:58 +0200263#define VXLAN_F_IPV6_LINKLOCAL 0x8000
Hangbin Liu72f6d712018-04-17 14:11:28 +0800264#define VXLAN_F_TTL_INHERIT 0x10000
Tom Herbert359a0ea2014-06-04 17:20:29 -0700265
Simon Hormand299ce12015-03-12 11:00:10 +0900266/* Flags that are used in the receive path. These flags must match in
Tom Herbertaf33c1a2015-01-20 11:23:05 -0800267 * order for a socket to be shareable
268 */
269#define VXLAN_F_RCV_FLAGS (VXLAN_F_GBP | \
Jiri Bence1e53142016-04-05 14:47:13 +0200270 VXLAN_F_GPE | \
Tom Herbertaf33c1a2015-01-20 11:23:05 -0800271 VXLAN_F_UDP_ZERO_CSUM6_RX | \
Tom Herbert0ace2ca2015-02-10 16:30:32 -0800272 VXLAN_F_REMCSUM_RX | \
Thomas Grafee122c72015-07-21 10:43:58 +0200273 VXLAN_F_REMCSUM_NOPARTIAL | \
Alexei Starovoitovda8b43c2015-08-04 22:51:07 -0700274 VXLAN_F_COLLECT_METADATA)
Thomas Grafac5132d2015-01-15 03:53:56 +0100275
Jiri Bence1e53142016-04-05 14:47:13 +0200276/* Flags that can be set together with VXLAN_F_GPE. */
277#define VXLAN_F_ALLOWED_GPE (VXLAN_F_GPE | \
278 VXLAN_F_IPV6 | \
Matthias Schiffer0f22a3c2017-06-19 10:03:58 +0200279 VXLAN_F_IPV6_LINKLOCAL | \
Jiri Bence1e53142016-04-05 14:47:13 +0200280 VXLAN_F_UDP_ZERO_CSUM_TX | \
281 VXLAN_F_UDP_ZERO_CSUM6_TX | \
282 VXLAN_F_UDP_ZERO_CSUM6_RX | \
283 VXLAN_F_COLLECT_METADATA)
284
Thomas Graf0dfbdf42015-07-21 10:44:02 +0200285struct net_device *vxlan_dev_create(struct net *net, const char *name,
286 u8 name_assign_type, struct vxlan_config *conf);
287
Jesse Gross5f352272014-12-23 22:37:26 -0800288static inline netdev_features_t vxlan_features_check(struct sk_buff *skb,
289 netdev_features_t features)
Joe Stringer11bf7822014-11-17 16:24:54 -0800290{
Jesse Gross5f352272014-12-23 22:37:26 -0800291 u8 l4_hdr = 0;
292
293 if (!skb->encapsulation)
294 return features;
295
296 switch (vlan_get_protocol(skb)) {
297 case htons(ETH_P_IP):
298 l4_hdr = ip_hdr(skb)->protocol;
299 break;
300 case htons(ETH_P_IPV6):
301 l4_hdr = ipv6_hdr(skb)->nexthdr;
302 break;
303 default:
Luis de Bethencourt5ef7e0b2018-01-16 15:03:32 +0000304 return features;
Jesse Gross5f352272014-12-23 22:37:26 -0800305 }
306
307 if ((l4_hdr == IPPROTO_UDP) &&
Joe Stringer11bf7822014-11-17 16:24:54 -0800308 (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
309 skb->inner_protocol != htons(ETH_P_TEB) ||
310 (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
Alexander Duyckaf67eb9e2016-05-02 09:25:16 -0700311 sizeof(struct udphdr) + sizeof(struct vxlanhdr)) ||
312 (skb->ip_summed != CHECKSUM_NONE &&
313 !can_checksum_protocol(features, inner_eth_hdr(skb)->h_proto))))
Tom Herberta1882222015-12-14 11:19:43 -0800314 return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
Joe Stringer11bf7822014-11-17 16:24:54 -0800315
Jesse Gross5f352272014-12-23 22:37:26 -0800316 return features;
Joe Stringer11bf7822014-11-17 16:24:54 -0800317}
Joe Stringer23e62de2014-11-13 16:38:12 -0800318
Joseph Gasparakise6cd9882013-10-24 06:27:10 +0000319/* IP header + UDP + VXLAN + Ethernet header */
320#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
321/* IPv6 header + UDP + VXLAN + Ethernet header */
322#define VXLAN6_HEADROOM (40 + 8 + 8 + 14)
323
Jiri Bencd4ac05f2016-02-16 21:58:57 +0100324static inline struct vxlanhdr *vxlan_hdr(struct sk_buff *skb)
325{
326 return (struct vxlanhdr *)(udp_hdr(skb) + 1);
327}
328
Jiri Benc54bfd872016-02-16 21:58:58 +0100329static inline __be32 vxlan_vni(__be32 vni_field)
330{
331#if defined(__BIG_ENDIAN)
Jiri Benc5692d7e2016-03-21 17:39:18 +0100332 return (__force __be32)((__force u32)vni_field >> 8);
Jiri Benc54bfd872016-02-16 21:58:58 +0100333#else
Jiri Benc5692d7e2016-03-21 17:39:18 +0100334 return (__force __be32)((__force u32)(vni_field & VXLAN_VNI_MASK) << 8);
Jiri Benc54bfd872016-02-16 21:58:58 +0100335#endif
336}
337
338static inline __be32 vxlan_vni_field(__be32 vni)
339{
340#if defined(__BIG_ENDIAN)
Jiri Benc5692d7e2016-03-21 17:39:18 +0100341 return (__force __be32)((__force u32)vni << 8);
Jiri Benc54bfd872016-02-16 21:58:58 +0100342#else
Jiri Benc5692d7e2016-03-21 17:39:18 +0100343 return (__force __be32)((__force u32)vni >> 8);
Jiri Benc54bfd872016-02-16 21:58:58 +0100344#endif
345}
346
Jiri Benc54bfd872016-02-16 21:58:58 +0100347static inline size_t vxlan_rco_start(__be32 vni_field)
348{
349 return be32_to_cpu(vni_field & VXLAN_RCO_MASK) << VXLAN_RCO_SHIFT;
350}
351
352static inline size_t vxlan_rco_offset(__be32 vni_field)
353{
354 return (vni_field & VXLAN_RCO_UDP) ?
355 offsetof(struct udphdr, check) :
356 offsetof(struct tcphdr, check);
357}
358
359static inline __be32 vxlan_compute_rco(unsigned int start, unsigned int offset)
360{
361 __be32 vni_field = cpu_to_be32(start >> VXLAN_RCO_SHIFT);
362
363 if (offset == offsetof(struct udphdr, check))
364 vni_field |= VXLAN_RCO_UDP;
365 return vni_field;
366}
367
Jiri Benc705cc622015-08-20 13:56:28 +0200368static inline unsigned short vxlan_get_sk_family(struct vxlan_sock *vs)
369{
370 return vs->sock->sk->sk_family;
371}
Jiri Benc48e92c42015-08-25 18:36:50 +0200372
Ido Schimmelcca45e02018-10-17 08:53:10 +0000373#if IS_ENABLED(CONFIG_IPV6)
374
375static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
376{
377 if (ipa->sa.sa_family == AF_INET6)
378 return ipv6_addr_any(&ipa->sin6.sin6_addr);
379 else
380 return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
381}
382
383static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
384{
385 if (ipa->sa.sa_family == AF_INET6)
386 return ipv6_addr_is_multicast(&ipa->sin6.sin6_addr);
387 else
388 return IN_MULTICAST(ntohl(ipa->sin.sin_addr.s_addr));
389}
390
391#else /* !IS_ENABLED(CONFIG_IPV6) */
392
393static inline bool vxlan_addr_any(const union vxlan_addr *ipa)
394{
395 return ipa->sin.sin_addr.s_addr == htonl(INADDR_ANY);
396}
397
398static inline bool vxlan_addr_multicast(const union vxlan_addr *ipa)
399{
400 return IN_MULTICAST(ntohl(ipa->sin.sin_addr.s_addr));
401}
402
403#endif /* IS_ENABLED(CONFIG_IPV6) */
404
Jiri Benc48e92c42015-08-25 18:36:50 +0200405#endif