Lines Matching +full:route +full:- +full:ptp

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2012-2013 Vyatta Inc.
64 /* per-network namespace private data for this module */
94 return vs->flags & VXLAN_F_COLLECT_METADATA || in vxlan_collect_metadata()
102 if (a->sa.sa_family != b->sa.sa_family) in vxlan_addr_equal()
104 if (a->sa.sa_family == AF_INET6) in vxlan_addr_equal()
105 return ipv6_addr_equal(&a->sin6.sin6_addr, &b->sin6.sin6_addr); in vxlan_addr_equal()
107 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; in vxlan_addr_equal()
113 ip->sin6.sin6_addr = nla_get_in6_addr(nla); in vxlan_nla_get_addr()
114 ip->sa.sa_family = AF_INET6; in vxlan_nla_get_addr()
117 ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); in vxlan_nla_get_addr()
118 ip->sa.sa_family = AF_INET; in vxlan_nla_get_addr()
121 return -EAFNOSUPPORT; in vxlan_nla_get_addr()
128 if (ip->sa.sa_family == AF_INET6) in vxlan_nla_put_addr()
129 return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); in vxlan_nla_put_addr()
131 return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); in vxlan_nla_put_addr()
139 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; in vxlan_addr_equal()
145 return -EAFNOSUPPORT; in vxlan_nla_get_addr()
147 ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); in vxlan_nla_get_addr()
148 ip->sa.sa_family = AF_INET; in vxlan_nla_get_addr()
151 return -EAFNOSUPPORT; in vxlan_nla_get_addr()
158 return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); in vxlan_nla_put_addr()
165 return &vs->vni_list[hash_32((__force u32)vni, VNI_HASH_BITS)]; in vni_head()
173 return &vn->sock_list[hash_32(ntohs(port), PORT_HASH_BITS)]; in vs_head()
177 * Guaranteed to be non-NULL because remotes are never deleted.
181 if (rcu_access_pointer(fdb->nh)) in first_remote_rcu()
183 return list_entry_rcu(fdb->remotes.next, struct vxlan_rdst, list); in first_remote_rcu()
188 if (rcu_access_pointer(fdb->nh)) in first_remote_rtnl()
190 return list_first_entry(&fdb->remotes, struct vxlan_rdst, list); in first_remote_rtnl()
195 * non-default VRF).
205 if (inet_sk(vs->sock->sk)->inet_sport == port && in vxlan_find_sock()
207 vs->flags == flags && in vxlan_find_sock()
208 vs->sock->sk->sk_bound_dev_if == ifindex) in vxlan_find_sock()
220 if (vs->flags & VXLAN_F_COLLECT_METADATA) in vxlan_vs_find_vni()
224 if (node->vxlan->default_dst.remote_vni != vni) in vxlan_vs_find_vni()
228 const struct vxlan_config *cfg = &node->vxlan->cfg; in vxlan_vs_find_vni()
230 if ((cfg->flags & VXLAN_F_IPV6_LINKLOCAL) && in vxlan_vs_find_vni()
231 cfg->remote_ifindex != ifindex) in vxlan_vs_find_vni()
235 return node->vxlan; in vxlan_vs_find_vni()
272 return -EMSGSIZE; in vxlan_fdb_info()
280 nh = rcu_dereference(fdb->nh); in vxlan_fdb_info()
283 nh_id = nh->id; in vxlan_fdb_info()
289 send_ip = !vxlan_addr_any(&rdst->remote_ip); in vxlan_fdb_info()
290 ndm->ndm_family = send_ip ? rdst->remote_ip.sa.sa_family : AF_INET; in vxlan_fdb_info()
292 ndm->ndm_family = nh_family; in vxlan_fdb_info()
294 send_eth = !is_zero_ether_addr(fdb->eth_addr); in vxlan_fdb_info()
296 ndm->ndm_family = AF_BRIDGE; in vxlan_fdb_info()
297 ndm->ndm_state = fdb->state; in vxlan_fdb_info()
298 ndm->ndm_ifindex = vxlan->dev->ifindex; in vxlan_fdb_info()
299 ndm->ndm_flags = fdb->flags; in vxlan_fdb_info()
300 if (rdst && rdst->offloaded) in vxlan_fdb_info()
301 ndm->ndm_flags |= NTF_OFFLOADED; in vxlan_fdb_info()
302 ndm->ndm_type = RTN_UNICAST; in vxlan_fdb_info()
304 if (!net_eq(dev_net(vxlan->dev), vxlan->net) && in vxlan_fdb_info()
306 peernet2id(dev_net(vxlan->dev), vxlan->net))) in vxlan_fdb_info()
309 if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr)) in vxlan_fdb_info()
316 &rdst->remote_ip)) in vxlan_fdb_info()
319 if (rdst->remote_port && in vxlan_fdb_info()
320 rdst->remote_port != vxlan->cfg.dst_port && in vxlan_fdb_info()
321 nla_put_be16(skb, NDA_PORT, rdst->remote_port)) in vxlan_fdb_info()
323 if (rdst->remote_vni != vxlan->default_dst.remote_vni && in vxlan_fdb_info()
324 nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni))) in vxlan_fdb_info()
326 if (rdst->remote_ifindex && in vxlan_fdb_info()
327 nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex)) in vxlan_fdb_info()
331 if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->vni && in vxlan_fdb_info()
333 be32_to_cpu(fdb->vni))) in vxlan_fdb_info()
336 ci.ndm_used = jiffies_to_clock_t(now - fdb->used); in vxlan_fdb_info()
338 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated); in vxlan_fdb_info()
349 return -EMSGSIZE; in vxlan_fdb_info()
367 struct net *net = dev_net(vxlan->dev); in __vxlan_fdb_notify()
369 int err = -ENOBUFS; in __vxlan_fdb_notify()
377 /* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */ in __vxlan_fdb_notify()
378 WARN_ON(err == -EMSGSIZE); in __vxlan_fdb_notify()
396 fdb_info->info.dev = vxlan->dev; in vxlan_fdb_switchdev_notifier_info()
397 fdb_info->info.extack = extack; in vxlan_fdb_switchdev_notifier_info()
398 fdb_info->remote_ip = rd->remote_ip; in vxlan_fdb_switchdev_notifier_info()
399 fdb_info->remote_port = rd->remote_port; in vxlan_fdb_switchdev_notifier_info()
400 fdb_info->remote_vni = rd->remote_vni; in vxlan_fdb_switchdev_notifier_info()
401 fdb_info->remote_ifindex = rd->remote_ifindex; in vxlan_fdb_switchdev_notifier_info()
402 memcpy(fdb_info->eth_addr, fdb->eth_addr, ETH_ALEN); in vxlan_fdb_switchdev_notifier_info()
403 fdb_info->vni = fdb->vni; in vxlan_fdb_switchdev_notifier_info()
404 fdb_info->offloaded = rd->offloaded; in vxlan_fdb_switchdev_notifier_info()
405 fdb_info->added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER; in vxlan_fdb_switchdev_notifier_info()
424 ret = call_switchdev_notifiers(notifier_type, vxlan->dev, in vxlan_fdb_switchdev_call_notifiers()
499 return jhash_2words(key, vni, vxlan_salt) & (FDB_HASH_SIZE - 1); in eth_vni_hash()
504 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) in fdb_head_index()
514 return &vxlan->fdb_head[fdb_head_index(vxlan, mac, vni)]; in vxlan_fdb_head()
525 if (ether_addr_equal(mac, f->eth_addr)) { in __vxlan_find_mac()
526 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) { in __vxlan_find_mac()
527 if (vni == f->vni) in __vxlan_find_mac()
544 if (f && f->used != jiffies) in vxlan_find_mac()
545 f->used = jiffies; in vxlan_find_mac()
550 /* caller should hold vxlan->hash_lock */
557 list_for_each_entry(rd, &f->remotes, list) { in vxlan_fdb_find_rdst()
558 if (vxlan_addr_equal(&rd->remote_ip, ip) && in vxlan_fdb_find_rdst()
559 rd->remote_port == port && in vxlan_fdb_find_rdst()
560 rd->remote_vni == vni && in vxlan_fdb_find_rdst()
561 rd->remote_ifindex == ifindex) in vxlan_fdb_find_rdst()
579 return -EINVAL; in vxlan_fdb_find_uc()
587 rc = -ENOENT; in vxlan_fdb_find_uc()
610 rc = nb->notifier_call(nb, SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE, in vxlan_fdb_notify_one()
626 return -EINVAL; in vxlan_fdb_replay()
630 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
631 hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist) { in vxlan_fdb_replay()
632 if (f->vni == vni) { in vxlan_fdb_replay()
633 list_for_each_entry(rdst, &f->remotes, list) { in vxlan_fdb_replay()
642 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
647 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
664 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_clear_offload()
665 hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist) in vxlan_fdb_clear_offload()
666 if (f->vni == vni) in vxlan_fdb_clear_offload()
667 list_for_each_entry(rdst, &f->remotes, list) in vxlan_fdb_clear_offload()
668 rdst->offloaded = false; in vxlan_fdb_clear_offload()
669 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_clear_offload()
686 rd = list_first_entry_or_null(&f->remotes, struct vxlan_rdst, list); in vxlan_fdb_replace()
691 dst_cache_reset(&rd->dst_cache); in vxlan_fdb_replace()
692 rd->remote_ip = *ip; in vxlan_fdb_replace()
693 rd->remote_port = port; in vxlan_fdb_replace()
694 rd->remote_vni = vni; in vxlan_fdb_replace()
695 rd->remote_ifindex = ifindex; in vxlan_fdb_replace()
696 rd->offloaded = false; in vxlan_fdb_replace()
713 return -ENOBUFS; in vxlan_fdb_append()
715 if (dst_cache_init(&rd->dst_cache, GFP_ATOMIC)) { in vxlan_fdb_append()
717 return -ENOBUFS; in vxlan_fdb_append()
720 rd->remote_ip = *ip; in vxlan_fdb_append()
721 rd->remote_port = port; in vxlan_fdb_append()
722 rd->offloaded = false; in vxlan_fdb_append()
723 rd->remote_vni = vni; in vxlan_fdb_append()
724 rd->remote_ifindex = ifindex; in vxlan_fdb_append()
726 list_add_tail_rcu(&rd->list, &f->remotes); in vxlan_fdb_append()
741 if (skb->remcsum_offload) in vxlan_gro_remcsum()
744 if (!NAPI_GRO_CB(skb)->csum_valid) in vxlan_gro_remcsum()
753 skb->remcsum_offload = 1; in vxlan_gro_remcsum()
784 flags = vh->vx_flags; in vxlan_gro_receive()
786 if ((flags & VXLAN_HF_RCO) && (vs->flags & VXLAN_F_REMCSUM_RX)) { in vxlan_gro_receive()
788 vh->vx_vni, &grc, in vxlan_gro_receive()
789 !!(vs->flags & in vxlan_gro_receive()
799 if (!NAPI_GRO_CB(p)->same_flow) in vxlan_gro_receive()
802 vh2 = (struct vxlanhdr *)(p->data + off_vx); in vxlan_gro_receive()
803 if (vh->vx_flags != vh2->vx_flags || in vxlan_gro_receive()
804 vh->vx_vni != vh2->vx_vni) { in vxlan_gro_receive()
805 NAPI_GRO_CB(p)->same_flow = 0; in vxlan_gro_receive()
821 /* Sets 'skb->inner_mac_header' since we are always called with in vxlan_gro_complete()
822 * 'skb->encapsulation' set. in vxlan_gro_complete()
836 f->state = state; in vxlan_fdb_alloc()
837 f->flags = ndm_flags; in vxlan_fdb_alloc()
838 f->updated = f->used = jiffies; in vxlan_fdb_alloc()
839 f->vni = src_vni; in vxlan_fdb_alloc()
840 f->nh = NULL; in vxlan_fdb_alloc()
841 RCU_INIT_POINTER(f->vdev, vxlan); in vxlan_fdb_alloc()
842 INIT_LIST_HEAD(&f->nh_list); in vxlan_fdb_alloc()
843 INIT_LIST_HEAD(&f->remotes); in vxlan_fdb_alloc()
844 memcpy(f->eth_addr, mac, ETH_ALEN); in vxlan_fdb_alloc()
852 ++vxlan->addrcnt; in vxlan_fdb_insert()
853 hlist_add_head_rcu(&f->hlist, in vxlan_fdb_insert()
860 struct nexthop *old_nh = rtnl_dereference(fdb->nh); in vxlan_fdb_nh_update()
862 int err = -EINVAL; in vxlan_fdb_nh_update()
864 if (old_nh && old_nh->id == nhid) in vxlan_fdb_nh_update()
867 nh = nexthop_find_by_id(vxlan->net, nhid); in vxlan_fdb_nh_update()
890 switch (vxlan->default_dst.remote_ip.sa.sa_family) { in vxlan_fdb_nh_update()
893 err = -EAFNOSUPPORT; in vxlan_fdb_nh_update()
900 err = -EAFNOSUPPORT; in vxlan_fdb_nh_update()
908 list_del_rcu(&fdb->nh_list); in vxlan_fdb_nh_update()
911 rcu_assign_pointer(fdb->nh, nh); in vxlan_fdb_nh_update()
912 list_add_tail_rcu(&fdb->nh_list, &nh->fdb_list); in vxlan_fdb_nh_update()
932 if (vxlan->cfg.addrmax && in vxlan_fdb_create()
933 vxlan->addrcnt >= vxlan->cfg.addrmax) in vxlan_fdb_create()
934 return -ENOSPC; in vxlan_fdb_create()
936 netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip); in vxlan_fdb_create()
939 return -ENOMEM; in vxlan_fdb_create()
962 nh = rcu_dereference_raw(f->nh); in __vxlan_fdb_free()
964 rcu_assign_pointer(f->nh, NULL); in __vxlan_fdb_free()
965 rcu_assign_pointer(f->vdev, NULL); in __vxlan_fdb_free()
969 list_for_each_entry_safe(rd, nd, &f->remotes, list) { in __vxlan_fdb_free()
970 dst_cache_destroy(&rd->dst_cache); in __vxlan_fdb_free()
988 netdev_dbg(vxlan->dev, "delete %pM\n", f->eth_addr); in vxlan_fdb_destroy()
990 --vxlan->addrcnt; in vxlan_fdb_destroy()
992 if (rcu_access_pointer(f->nh)) in vxlan_fdb_destroy()
996 list_for_each_entry(rd, &f->remotes, list) in vxlan_fdb_destroy()
1001 hlist_del_rcu(&f->hlist); in vxlan_fdb_destroy()
1002 list_del_rcu(&f->nh_list); in vxlan_fdb_destroy()
1003 call_rcu(&f->rcu, vxlan_fdb_free); in vxlan_fdb_destroy()
1010 dst_cache_destroy(&rd->dst_cache); in vxlan_dst_free()
1030 if (nhid && !rcu_access_pointer(f->nh)) { in vxlan_fdb_update_existing()
1033 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1039 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1046 !(f->flags & NTF_VXLAN_ADDED_BY_USER)) { in vxlan_fdb_update_existing()
1047 if (f->state != state) { in vxlan_fdb_update_existing()
1048 f->state = state; in vxlan_fdb_update_existing()
1049 f->updated = jiffies; in vxlan_fdb_update_existing()
1052 if (f->flags != fdb_flags) { in vxlan_fdb_update_existing()
1053 f->flags = fdb_flags; in vxlan_fdb_update_existing()
1054 f->updated = jiffies; in vxlan_fdb_update_existing()
1061 if (!(is_multicast_ether_addr(f->eth_addr) || in vxlan_fdb_update_existing()
1062 is_zero_ether_addr(f->eth_addr))) { in vxlan_fdb_update_existing()
1073 NL_SET_ERR_MSG(extack, "Cannot replace non-unicast fdb entries"); in vxlan_fdb_update_existing()
1074 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1078 (is_multicast_ether_addr(f->eth_addr) || in vxlan_fdb_update_existing()
1079 is_zero_ether_addr(f->eth_addr))) { in vxlan_fdb_update_existing()
1088 f->used = jiffies; in vxlan_fdb_update_existing()
1108 list_del_rcu(&rd->list); in vxlan_fdb_update_existing()
1109 call_rcu(&rd->rcu, vxlan_dst_free); in vxlan_fdb_update_existing()
1129 return -EOPNOTSUPP; in vxlan_fdb_update_create()
1131 netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip); in vxlan_fdb_update_create()
1150 /* Add new entry to forwarding table -- assumes lock held */
1164 netdev_dbg(vxlan->dev, in vxlan_fdb_update()
1166 return -EEXIST; in vxlan_fdb_update()
1174 return -ENOENT; in vxlan_fdb_update()
1186 list_del_rcu(&rd->list); in vxlan_fdb_dst_destroy()
1188 call_rcu(&rd->rcu, vxlan_dst_free); in vxlan_fdb_dst_destroy()
1195 struct net *net = dev_net(vxlan->dev); in vxlan_fdb_parse()
1200 return -EINVAL; in vxlan_fdb_parse()
1207 union vxlan_addr *remote = &vxlan->default_dst.remote_ip; in vxlan_fdb_parse()
1209 if (remote->sa.sa_family == AF_INET) { in vxlan_fdb_parse()
1210 ip->sin.sin_addr.s_addr = htonl(INADDR_ANY); in vxlan_fdb_parse()
1211 ip->sa.sa_family = AF_INET; in vxlan_fdb_parse()
1214 ip->sin6.sin6_addr = in6addr_any; in vxlan_fdb_parse()
1215 ip->sa.sa_family = AF_INET6; in vxlan_fdb_parse()
1222 return -EINVAL; in vxlan_fdb_parse()
1225 *port = vxlan->cfg.dst_port; in vxlan_fdb_parse()
1230 return -EINVAL; in vxlan_fdb_parse()
1233 *vni = vxlan->default_dst.remote_vni; in vxlan_fdb_parse()
1238 return -EINVAL; in vxlan_fdb_parse()
1241 *src_vni = vxlan->default_dst.remote_vni; in vxlan_fdb_parse()
1248 return -EINVAL; in vxlan_fdb_parse()
1252 return -EADDRNOTAVAIL; in vxlan_fdb_parse()
1272 /* struct net *net = dev_net(vxlan->dev); */ in vxlan_fdb_add()
1280 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_REACHABLE))) { in vxlan_fdb_add()
1282 ndm->ndm_state); in vxlan_fdb_add()
1283 return -EINVAL; in vxlan_fdb_add()
1287 return -EINVAL; in vxlan_fdb_add()
1294 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family) in vxlan_fdb_add()
1295 return -EAFNOSUPPORT; in vxlan_fdb_add()
1298 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_add()
1299 err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags, in vxlan_fdb_add()
1301 ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER, in vxlan_fdb_add()
1303 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_add()
1315 int err = -ENOENT; in __vxlan_fdb_delete()
1330 if (rd && !list_is_singular(&f->remotes)) { in __vxlan_fdb_delete()
1360 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete()
1363 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete()
1381 hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) { in vxlan_fdb_dump()
1384 if (rcu_access_pointer(f->nh)) { in vxlan_fdb_dump()
1385 if (*idx < cb->args[2]) in vxlan_fdb_dump()
1388 NETLINK_CB(cb->skb).portid, in vxlan_fdb_dump()
1389 cb->nlh->nlmsg_seq, in vxlan_fdb_dump()
1401 list_for_each_entry_rcu(rd, &f->remotes, list) { in vxlan_fdb_dump()
1402 if (*idx < cb->args[2]) in vxlan_fdb_dump()
1406 NETLINK_CB(cb->skb).portid, in vxlan_fdb_dump()
1407 cb->nlh->nlmsg_seq, in vxlan_fdb_dump()
1439 vni = vxlan->default_dst.remote_vni; in vxlan_fdb_get()
1446 err = -ENOENT; in vxlan_fdb_get()
1470 if (src_ip->sa.sa_family == AF_INET6 && in vxlan_snoop()
1471 (ipv6_addr_type(&src_ip->sin6.sin6_addr) & IPV6_ADDR_LINKLOCAL)) in vxlan_snoop()
1479 if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && in vxlan_snoop()
1480 rdst->remote_ifindex == ifindex)) in vxlan_snoop()
1484 if (f->state & (NUD_PERMANENT | NUD_NOARP)) in vxlan_snoop()
1488 if (rcu_access_pointer(f->nh)) in vxlan_snoop()
1494 src_mac, &rdst->remote_ip.sa, &src_ip->sa); in vxlan_snoop()
1496 rdst->remote_ip = *src_ip; in vxlan_snoop()
1497 f->updated = jiffies; in vxlan_snoop()
1503 spin_lock(&vxlan->hash_lock[hash_index]); in vxlan_snoop()
1510 vxlan->cfg.dst_port, in vxlan_snoop()
1512 vxlan->default_dst.remote_vni, in vxlan_snoop()
1514 spin_unlock(&vxlan->hash_lock[hash_index]); in vxlan_snoop()
1528 unsigned short family = dev->default_dst.remote_ip.sa.sa_family; in vxlan_group_used()
1530 sock4 = rtnl_dereference(dev->vn4_sock); in vxlan_group_used()
1535 if (family == AF_INET && sock4 && refcount_read(&sock4->refcnt) == 1) in vxlan_group_used()
1538 sock6 = rtnl_dereference(dev->vn6_sock); in vxlan_group_used()
1539 if (family == AF_INET6 && sock6 && refcount_read(&sock6->refcnt) == 1) in vxlan_group_used()
1543 list_for_each_entry(vxlan, &vn->vxlan_list, next) { in vxlan_group_used()
1544 if (!netif_running(vxlan->dev) || vxlan == dev) in vxlan_group_used()
1548 rtnl_dereference(vxlan->vn4_sock) != sock4) in vxlan_group_used()
1552 rtnl_dereference(vxlan->vn6_sock) != sock6) in vxlan_group_used()
1556 if (!vxlan_addr_equal(&vxlan->default_dst.remote_ip, in vxlan_group_used()
1557 &dev->default_dst.remote_ip)) in vxlan_group_used()
1560 if (vxlan->default_dst.remote_ifindex != in vxlan_group_used()
1561 dev->default_dst.remote_ifindex) in vxlan_group_used()
1576 if (!refcount_dec_and_test(&vs->refcnt)) in __vxlan_sock_release_prep()
1579 vn = net_generic(sock_net(vs->sock->sk), vxlan_net_id); in __vxlan_sock_release_prep()
1580 spin_lock(&vn->sock_lock); in __vxlan_sock_release_prep()
1581 hlist_del_rcu(&vs->hlist); in __vxlan_sock_release_prep()
1582 udp_tunnel_notify_del_rx_port(vs->sock, in __vxlan_sock_release_prep()
1583 (vs->flags & VXLAN_F_GPE) ? in __vxlan_sock_release_prep()
1586 spin_unlock(&vn->sock_lock); in __vxlan_sock_release_prep()
1593 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); in vxlan_sock_release()
1595 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); in vxlan_sock_release()
1597 RCU_INIT_POINTER(vxlan->vn6_sock, NULL); in vxlan_sock_release()
1600 RCU_INIT_POINTER(vxlan->vn4_sock, NULL); in vxlan_sock_release()
1606 udp_tunnel_sock_release(sock4->sock); in vxlan_sock_release()
1612 udp_tunnel_sock_release(sock6->sock); in vxlan_sock_release()
1624 union vxlan_addr *ip = &vxlan->default_dst.remote_ip; in vxlan_igmp_join()
1625 int ifindex = vxlan->default_dst.remote_ifindex; in vxlan_igmp_join()
1626 int ret = -EINVAL; in vxlan_igmp_join()
1628 if (ip->sa.sa_family == AF_INET) { in vxlan_igmp_join()
1629 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); in vxlan_igmp_join()
1631 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, in vxlan_igmp_join()
1635 sk = sock4->sock->sk; in vxlan_igmp_join()
1641 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); in vxlan_igmp_join()
1643 sk = sock6->sock->sk; in vxlan_igmp_join()
1645 ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex, in vxlan_igmp_join()
1646 &ip->sin6.sin6_addr); in vxlan_igmp_join()
1658 union vxlan_addr *ip = &vxlan->default_dst.remote_ip; in vxlan_igmp_leave()
1659 int ifindex = vxlan->default_dst.remote_ifindex; in vxlan_igmp_leave()
1660 int ret = -EINVAL; in vxlan_igmp_leave()
1662 if (ip->sa.sa_family == AF_INET) { in vxlan_igmp_leave()
1663 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); in vxlan_igmp_leave()
1665 .imr_multiaddr.s_addr = ip->sin.sin_addr.s_addr, in vxlan_igmp_leave()
1669 sk = sock4->sock->sk; in vxlan_igmp_leave()
1675 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); in vxlan_igmp_leave()
1677 sk = sock6->sock->sk; in vxlan_igmp_leave()
1679 ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex, in vxlan_igmp_leave()
1680 &ip->sin6.sin6_addr); in vxlan_igmp_leave()
1693 if (!(unparsed->vx_flags & VXLAN_HF_RCO) || skb->remcsum_offload) in vxlan_remcsum()
1696 start = vxlan_rco_start(unparsed->vx_vni); in vxlan_remcsum()
1697 offset = start + vxlan_rco_offset(unparsed->vx_vni); in vxlan_remcsum()
1705 unparsed->vx_flags &= ~VXLAN_HF_RCO; in vxlan_remcsum()
1706 unparsed->vx_vni &= VXLAN_VNI_MASK; in vxlan_remcsum()
1717 if (!(unparsed->vx_flags & VXLAN_HF_GBP)) in vxlan_parse_gbp_hdr()
1720 md->gbp = ntohs(gbp->policy_id); in vxlan_parse_gbp_hdr()
1724 tun_dst->u.tun_info.key.tun_flags |= TUNNEL_VXLAN_OPT; in vxlan_parse_gbp_hdr()
1725 tun_dst->u.tun_info.options_len = sizeof(*md); in vxlan_parse_gbp_hdr()
1727 if (gbp->dont_learn) in vxlan_parse_gbp_hdr()
1728 md->gbp |= VXLAN_GBP_DONT_LEARN; in vxlan_parse_gbp_hdr()
1730 if (gbp->policy_applied) in vxlan_parse_gbp_hdr()
1731 md->gbp |= VXLAN_GBP_POLICY_APPLIED; in vxlan_parse_gbp_hdr()
1733 /* In flow-based mode, GBP is carried in dst_metadata */ in vxlan_parse_gbp_hdr()
1735 skb->mark = md->gbp; in vxlan_parse_gbp_hdr()
1737 unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS; in vxlan_parse_gbp_hdr()
1747 if (!gpe->np_applied) in vxlan_parse_gpe_hdr()
1752 if (gpe->version != 0) in vxlan_parse_gpe_hdr()
1758 if (gpe->oam_flag) in vxlan_parse_gpe_hdr()
1761 *protocol = tun_p_to_eth_p(gpe->next_protocol); in vxlan_parse_gpe_hdr()
1765 unparsed->vx_flags &= ~VXLAN_GPE_USED_BITS; in vxlan_parse_gpe_hdr()
1774 u32 ifindex = skb->dev->ifindex; in vxlan_set_mac()
1777 skb->protocol = eth_type_trans(skb, vxlan->dev); in vxlan_set_mac()
1781 if (ether_addr_equal(eth_hdr(skb)->h_source, vxlan->dev->dev_addr)) in vxlan_set_mac()
1786 saddr.sin.sin_addr.s_addr = ip_hdr(skb)->saddr; in vxlan_set_mac()
1790 saddr.sin6.sin6_addr = ipv6_hdr(skb)->saddr; in vxlan_set_mac()
1795 if ((vxlan->cfg.flags & VXLAN_F_LEARN) && in vxlan_set_mac()
1796 vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, ifindex, vni)) in vxlan_set_mac()
1816 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", in vxlan_ecn_decapsulate()
1817 &((struct iphdr *)oiph)->saddr, in vxlan_ecn_decapsulate()
1818 ((struct iphdr *)oiph)->tos); in vxlan_ecn_decapsulate()
1820 net_info_ratelimited("non-ECT from %pI6\n", in vxlan_ecn_decapsulate()
1821 &((struct ipv6hdr *)oiph)->saddr); in vxlan_ecn_decapsulate()
1846 netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", in vxlan_rcv()
1847 ntohl(vxlan_hdr(skb)->vx_flags), in vxlan_rcv()
1848 ntohl(vxlan_hdr(skb)->vx_vni)); in vxlan_rcv()
1859 vni = vxlan_vni(vxlan_hdr(skb)->vx_vni); in vxlan_rcv()
1861 vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni); in vxlan_rcv()
1868 if (vs->flags & VXLAN_F_GPE) { in vxlan_rcv()
1869 if (!vxlan_parse_gpe_hdr(&unparsed, &protocol, skb, vs->flags)) in vxlan_rcv()
1875 !net_eq(vxlan->net, dev_net(vxlan->dev)))) in vxlan_rcv()
1878 if (vs->flags & VXLAN_F_REMCSUM_RX) in vxlan_rcv()
1879 if (unlikely(!vxlan_remcsum(&unparsed, skb, vs->flags))) in vxlan_rcv()
1891 md = ip_tunnel_info_opts(&tun_dst->u.tun_info); in vxlan_rcv()
1898 if (vs->flags & VXLAN_F_GBP) in vxlan_rcv()
1899 vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md); in vxlan_rcv()
1921 skb->dev = vxlan->dev; in vxlan_rcv()
1922 skb->pkt_type = PACKET_HOST; in vxlan_rcv()
1929 ++vxlan->dev->stats.rx_frame_errors; in vxlan_rcv()
1930 ++vxlan->dev->stats.rx_errors; in vxlan_rcv()
1936 if (unlikely(!(vxlan->dev->flags & IFF_UP))) { in vxlan_rcv()
1938 atomic_long_inc(&vxlan->dev->rx_dropped); in vxlan_rcv()
1942 dev_sw_netstats_rx_add(vxlan->dev, skb->len); in vxlan_rcv()
1943 gro_cells_receive(&vxlan->gro_cells, skb); in vxlan_rcv()
1964 return -EINVAL; in vxlan_err_lookup()
1968 if (!(hdr->vx_flags & VXLAN_HF_VNI)) in vxlan_err_lookup()
1969 return -EINVAL; in vxlan_err_lookup()
1973 return -ENOENT; in vxlan_err_lookup()
1975 vni = vxlan_vni(hdr->vx_vni); in vxlan_err_lookup()
1976 vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni); in vxlan_err_lookup()
1978 return -ENOENT; in vxlan_err_lookup()
1991 if (dev->flags & IFF_NOARP) in arp_reduce()
1995 dev->stats.tx_dropped++; in arp_reduce()
2000 if ((parp->ar_hrd != htons(ARPHRD_ETHER) && in arp_reduce()
2001 parp->ar_hrd != htons(ARPHRD_IEEE802)) || in arp_reduce()
2002 parp->ar_pro != htons(ETH_P_IP) || in arp_reduce()
2003 parp->ar_op != htons(ARPOP_REQUEST) || in arp_reduce()
2004 parp->ar_hln != dev->addr_len || in arp_reduce()
2005 parp->ar_pln != 4) in arp_reduce()
2009 arpptr += dev->addr_len; /* sha */ in arp_reduce()
2012 arpptr += dev->addr_len; /* tha */ in arp_reduce()
2025 if (!(n->nud_state & NUD_CONNECTED)) { in arp_reduce()
2030 f = vxlan_find_mac(vxlan, n->ha, vni); in arp_reduce()
2031 if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { in arp_reduce()
2032 /* bridge-local neighbor */ in arp_reduce()
2038 n->ha, sha); in arp_reduce()
2047 reply->ip_summed = CHECKSUM_UNNECESSARY; in arp_reduce()
2048 reply->pkt_type = PACKET_HOST; in arp_reduce()
2051 dev->stats.rx_dropped++; in arp_reduce()
2052 } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { in arp_reduce()
2069 struct net_device *dev = request->dev; in vxlan_na_create()
2078 if (dev == NULL || !pskb_may_pull(request, request->len)) in vxlan_na_create()
2082 sizeof(*na) + na_olen + dev->needed_tailroom; in vxlan_na_create()
2087 reply->protocol = htons(ETH_P_IPV6); in vxlan_na_create()
2088 reply->dev = dev; in vxlan_na_create()
2089 skb_reserve(reply, LL_RESERVED_SPACE(request->dev)); in vxlan_na_create()
2095 daddr = eth_hdr(request)->h_source; in vxlan_na_create()
2096 ns_olen = request->len - skb_network_offset(request) - in vxlan_na_create()
2097 sizeof(struct ipv6hdr) - sizeof(*ns); in vxlan_na_create()
2098 for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) { in vxlan_na_create()
2099 if (!ns->opt[i + 1]) { in vxlan_na_create()
2103 if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) { in vxlan_na_create()
2104 daddr = ns->opt + i + sizeof(struct nd_opt_hdr); in vxlan_na_create()
2110 ether_addr_copy(eth_hdr(reply)->h_dest, daddr); in vxlan_na_create()
2111 ether_addr_copy(eth_hdr(reply)->h_source, n->ha); in vxlan_na_create()
2112 eth_hdr(reply)->h_proto = htons(ETH_P_IPV6); in vxlan_na_create()
2113 reply->protocol = htons(ETH_P_IPV6); in vxlan_na_create()
2123 pip6->version = 6; in vxlan_na_create()
2124 pip6->priority = ipv6_hdr(request)->priority; in vxlan_na_create()
2125 pip6->nexthdr = IPPROTO_ICMPV6; in vxlan_na_create()
2126 pip6->hop_limit = 255; in vxlan_na_create()
2127 pip6->daddr = ipv6_hdr(request)->saddr; in vxlan_na_create()
2128 pip6->saddr = *(struct in6_addr *)n->primary_key; in vxlan_na_create()
2135 na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT; in vxlan_na_create()
2136 na->icmph.icmp6_router = isrouter; in vxlan_na_create()
2137 na->icmph.icmp6_override = 1; in vxlan_na_create()
2138 na->icmph.icmp6_solicited = 1; in vxlan_na_create()
2139 na->target = ns->target; in vxlan_na_create()
2140 ether_addr_copy(&na->opt[2], n->ha); in vxlan_na_create()
2141 na->opt[0] = ND_OPT_TARGET_LL_ADDR; in vxlan_na_create()
2142 na->opt[1] = na_olen >> 3; in vxlan_na_create()
2144 na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr, in vxlan_na_create()
2145 &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6, in vxlan_na_create()
2148 pip6->payload_len = htons(sizeof(*na)+na_olen); in vxlan_na_create()
2152 reply->ip_summed = CHECKSUM_UNNECESSARY; in vxlan_na_create()
2171 daddr = &iphdr->daddr; in neigh_reduce()
2175 ipv6_addr_is_multicast(&msg->target)) in neigh_reduce()
2178 n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev); in neigh_reduce()
2184 if (!(n->nud_state & NUD_CONNECTED)) { in neigh_reduce()
2189 f = vxlan_find_mac(vxlan, n->ha, vni); in neigh_reduce()
2190 if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { in neigh_reduce()
2191 /* bridge-local neighbor */ in neigh_reduce()
2197 !!(f ? f->flags & NTF_ROUTER : 0)); in neigh_reduce()
2205 dev->stats.rx_dropped++; in neigh_reduce()
2207 } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { in neigh_reduce()
2209 .sin6.sin6_addr = msg->target, in neigh_reduce()
2227 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) in route_shortcircuit()
2231 switch (ntohs(eth_hdr(skb)->h_proto)) { in route_shortcircuit()
2239 n = neigh_lookup(&arp_tbl, &pip->daddr, dev); in route_shortcircuit()
2240 if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { in route_shortcircuit()
2242 .sin.sin_addr.s_addr = pip->daddr, in route_shortcircuit()
2260 n = neigh_lookup(ipv6_stub->nd_tbl, &pip6->daddr, dev); in route_shortcircuit()
2261 if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { in route_shortcircuit()
2263 .sin6.sin6_addr = pip6->daddr, in route_shortcircuit()
2281 diff = !ether_addr_equal(eth_hdr(skb)->h_dest, n->ha); in route_shortcircuit()
2283 memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, in route_shortcircuit()
2284 dev->addr_len); in route_shortcircuit()
2285 memcpy(eth_hdr(skb)->h_dest, n->ha, dev->addr_len); in route_shortcircuit()
2299 if (!md->gbp) in vxlan_build_gbp_hdr()
2303 vxh->vx_flags |= VXLAN_HF_GBP; in vxlan_build_gbp_hdr()
2305 if (md->gbp & VXLAN_GBP_DONT_LEARN) in vxlan_build_gbp_hdr()
2306 gbp->dont_learn = 1; in vxlan_build_gbp_hdr()
2308 if (md->gbp & VXLAN_GBP_POLICY_APPLIED) in vxlan_build_gbp_hdr()
2309 gbp->policy_applied = 1; in vxlan_build_gbp_hdr()
2311 gbp->policy_id = htons(md->gbp & VXLAN_GBP_ID_MASK); in vxlan_build_gbp_hdr()
2319 gpe->np_applied = 1; in vxlan_build_gpe_hdr()
2320 gpe->next_protocol = tun_p_from_eth_p(protocol); in vxlan_build_gpe_hdr()
2321 if (!gpe->next_protocol) in vxlan_build_gpe_hdr()
2322 return -EPFNOSUPPORT; in vxlan_build_gpe_hdr()
2338 skb->ip_summed == CHECKSUM_PARTIAL) { in vxlan_build_skb()
2343 (skb->csum_offset == offsetof(struct udphdr, check) || in vxlan_build_skb()
2344 skb->csum_offset == offsetof(struct tcphdr, check))) in vxlan_build_skb()
2348 min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len in vxlan_build_skb()
2361 vxh->vx_flags = VXLAN_HF_VNI; in vxlan_build_skb()
2362 vxh->vx_vni = vxlan_vni_field(vni); in vxlan_build_skb()
2367 start = skb_checksum_start_offset(skb) - sizeof(struct vxlanhdr); in vxlan_build_skb()
2368 vxh->vx_vni |= vxlan_compute_rco(start, skb->csum_offset); in vxlan_build_skb()
2369 vxh->vx_flags |= VXLAN_HF_RCO; in vxlan_build_skb()
2372 skb->ip_summed = CHECKSUM_NONE; in vxlan_build_skb()
2373 skb->encapsulation = 0; in vxlan_build_skb()
2380 err = vxlan_build_gpe_hdr(vxh, vxflags, skb->protocol); in vxlan_build_skb()
2383 inner_protocol = skb->protocol; in vxlan_build_skb()
2402 return ERR_PTR(-EIO); in vxlan_get_route()
2415 fl4.flowi4_mark = skb->mark; in vxlan_get_route()
2422 rt = ip_route_output_key(vxlan->net, &fl4); in vxlan_get_route()
2424 if (rt->dst.dev == dev) { in vxlan_get_route()
2425 netdev_dbg(dev, "circular route to %pI4\n", &daddr); in vxlan_get_route()
2427 return ERR_PTR(-ELOOP); in vxlan_get_route()
2432 dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); in vxlan_get_route()
2434 netdev_dbg(dev, "no route to %pI4\n", &daddr); in vxlan_get_route()
2435 return ERR_PTR(-ENETUNREACH); in vxlan_get_route()
2457 return ERR_PTR(-EIO); in vxlan6_get_route()
2472 fl6.flowi6_mark = skb->mark; in vxlan6_get_route()
2477 ndst = ipv6_stub->ipv6_dst_lookup_flow(vxlan->net, sock6->sock->sk, in vxlan6_get_route()
2480 netdev_dbg(dev, "no route to %pI6\n", daddr); in vxlan6_get_route()
2481 return ERR_PTR(-ENETUNREACH); in vxlan6_get_route()
2484 if (unlikely(ndst->dev == dev)) { in vxlan6_get_route()
2485 netdev_dbg(dev, "circular route to %pI6\n", daddr); in vxlan6_get_route()
2487 return ERR_PTR(-ELOOP); in vxlan6_get_route()
2504 union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip; in vxlan_encap_bypass()
2506 int len = skb->len; in vxlan_encap_bypass()
2508 tx_stats = this_cpu_ptr(src_vxlan->dev->tstats); in vxlan_encap_bypass()
2509 rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats); in vxlan_encap_bypass()
2510 skb->pkt_type = PACKET_HOST; in vxlan_encap_bypass()
2511 skb->encapsulation = 0; in vxlan_encap_bypass()
2512 skb->dev = dst_vxlan->dev; in vxlan_encap_bypass()
2515 if (remote_ip->sa.sa_family == AF_INET) { in vxlan_encap_bypass()
2526 dev = skb->dev; in vxlan_encap_bypass()
2527 if (unlikely(!(dev->flags & IFF_UP))) { in vxlan_encap_bypass()
2532 if ((dst_vxlan->cfg.flags & VXLAN_F_LEARN) && snoop) in vxlan_encap_bypass()
2533 vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source, 0, vni); in vxlan_encap_bypass()
2535 u64_stats_update_begin(&tx_stats->syncp); in vxlan_encap_bypass()
2536 tx_stats->tx_packets++; in vxlan_encap_bypass()
2537 tx_stats->tx_bytes += len; in vxlan_encap_bypass()
2538 u64_stats_update_end(&tx_stats->syncp); in vxlan_encap_bypass()
2541 u64_stats_update_begin(&rx_stats->syncp); in vxlan_encap_bypass()
2542 rx_stats->rx_packets++; in vxlan_encap_bypass()
2543 rx_stats->rx_bytes += len; in vxlan_encap_bypass()
2544 u64_stats_update_end(&rx_stats->syncp); in vxlan_encap_bypass()
2547 dev->stats.rx_dropped++; in vxlan_encap_bypass()
2560 /* IPv6 rt-flags are checked against RTF_LOCAL, but the value of in encap_bypass_if_local()
2562 * we can use RTCF_LOCAL which works for ipv4 and ipv6 route entry. in encap_bypass_if_local()
2572 dst_vxlan = vxlan_find_vni(vxlan->net, dst_ifindex, vni, in encap_bypass_if_local()
2573 daddr->sa.sa_family, dst_port, in encap_bypass_if_local()
2574 vxlan->cfg.flags); in encap_bypass_if_local()
2576 dev->stats.tx_errors++; in encap_bypass_if_local()
2579 return -ENOENT; in encap_bypass_if_local()
2606 u32 flags = vxlan->cfg.flags; in vxlan_xmit_one()
2608 bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev)); in vxlan_xmit_one()
2613 dst = &rdst->remote_ip; in vxlan_xmit_one()
2616 /* short-circuited back to local bridge */ in vxlan_xmit_one()
2624 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; in vxlan_xmit_one()
2625 vni = (rdst->remote_vni) ? : default_vni; in vxlan_xmit_one()
2626 ifindex = rdst->remote_ifindex; in vxlan_xmit_one()
2627 local_ip = vxlan->cfg.saddr; in vxlan_xmit_one()
2628 dst_cache = &rdst->dst_cache; in vxlan_xmit_one()
2629 md->gbp = skb->mark; in vxlan_xmit_one()
2633 ttl = vxlan->cfg.ttl; in vxlan_xmit_one()
2638 tos = vxlan->cfg.tos; in vxlan_xmit_one()
2642 if (dst->sa.sa_family == AF_INET) in vxlan_xmit_one()
2646 label = vxlan->cfg.label; in vxlan_xmit_one()
2650 dev->name); in vxlan_xmit_one()
2655 remote_ip.sin.sin_addr.s_addr = info->key.u.ipv4.dst; in vxlan_xmit_one()
2656 local_ip.sin.sin_addr.s_addr = info->key.u.ipv4.src; in vxlan_xmit_one()
2658 remote_ip.sin6.sin6_addr = info->key.u.ipv6.dst; in vxlan_xmit_one()
2659 local_ip.sin6.sin6_addr = info->key.u.ipv6.src; in vxlan_xmit_one()
2662 dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; in vxlan_xmit_one()
2663 vni = tunnel_id_to_key32(info->key.tun_id); in vxlan_xmit_one()
2665 dst_cache = &info->dst_cache; in vxlan_xmit_one()
2666 if (info->key.tun_flags & TUNNEL_VXLAN_OPT) { in vxlan_xmit_one()
2667 if (info->options_len < sizeof(*md)) in vxlan_xmit_one()
2671 ttl = info->key.ttl; in vxlan_xmit_one()
2672 tos = info->key.tos; in vxlan_xmit_one()
2673 label = info->key.label; in vxlan_xmit_one()
2674 udp_sum = !!(info->key.tun_flags & TUNNEL_CSUM); in vxlan_xmit_one()
2676 src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, in vxlan_xmit_one()
2677 vxlan->cfg.port_max, true); in vxlan_xmit_one()
2680 if (dst->sa.sa_family == AF_INET) { in vxlan_xmit_one()
2681 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); in vxlan_xmit_one()
2686 ifindex = sock4->sock->sk->sk_bound_dev_if; in vxlan_xmit_one()
2689 dst->sin.sin_addr.s_addr, in vxlan_xmit_one()
2702 &rt->dst, rt->rt_flags); in vxlan_xmit_one()
2706 if (vxlan->cfg.df == VXLAN_DF_SET) { in vxlan_xmit_one()
2708 } else if (vxlan->cfg.df == VXLAN_DF_INHERIT) { in vxlan_xmit_one()
2711 if (ntohs(eth->h_proto) == ETH_P_IPV6 || in vxlan_xmit_one()
2712 (ntohs(eth->h_proto) == ETH_P_IP && in vxlan_xmit_one()
2713 old_iph->frag_off & htons(IP_DF))) in vxlan_xmit_one()
2716 } else if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) { in vxlan_xmit_one()
2720 ndst = &rt->dst; in vxlan_xmit_one()
2731 info->key.u.ipv4.src = src.s_addr; in vxlan_xmit_one()
2732 info->key.u.ipv4.dst = dst.s_addr; in vxlan_xmit_one()
2740 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); in vxlan_xmit_one()
2746 udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, local_ip.sin.sin_addr.s_addr, in vxlan_xmit_one()
2747 dst->sin.sin_addr.s_addr, tos, ttl, df, in vxlan_xmit_one()
2751 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock); in vxlan_xmit_one()
2754 ifindex = sock6->sock->sk->sk_bound_dev_if; in vxlan_xmit_one()
2757 label, &dst->sin6.sin6_addr, in vxlan_xmit_one()
2768 u32 rt6i_flags = ((struct rt6_info *)ndst)->rt6i_flags; in vxlan_xmit_one()
2787 info->key.u.ipv6.src = src; in vxlan_xmit_one()
2788 info->key.u.ipv6.dst = dst; in vxlan_xmit_one()
2804 udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev, in vxlan_xmit_one()
2806 &dst->sin6.sin6_addr, tos, ttl, in vxlan_xmit_one()
2815 dev->stats.tx_dropped++; in vxlan_xmit_one()
2821 if (err == -ELOOP) in vxlan_xmit_one()
2822 dev->stats.collisions++; in vxlan_xmit_one()
2823 else if (err == -ENETUNREACH) in vxlan_xmit_one()
2824 dev->stats.tx_carrier_errors++; in vxlan_xmit_one()
2826 dev->stats.tx_errors++; in vxlan_xmit_one()
2842 nh = rcu_dereference(f->nh); in vxlan_xmit_nh()
2858 dev->stats.tx_dropped++; in vxlan_xmit_nh()
2882 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) { in vxlan_xmit()
2883 if (info && info->mode & IP_TUNNEL_INFO_BRIDGE && in vxlan_xmit()
2884 info->mode & IP_TUNNEL_INFO_TX) { in vxlan_xmit()
2885 vni = tunnel_id_to_key32(info->key.tun_id); in vxlan_xmit()
2887 if (info && info->mode & IP_TUNNEL_INFO_TX) in vxlan_xmit()
2895 if (vxlan->cfg.flags & VXLAN_F_PROXY) { in vxlan_xmit()
2897 if (ntohs(eth->h_proto) == ETH_P_ARP) in vxlan_xmit()
2900 else if (ntohs(eth->h_proto) == ETH_P_IPV6 && in vxlan_xmit()
2903 ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { in vxlan_xmit()
2906 if (m->icmph.icmp6_code == 0 && in vxlan_xmit()
2907 m->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) in vxlan_xmit()
2914 f = vxlan_find_mac(vxlan, eth->h_dest, vni); in vxlan_xmit()
2917 if (f && (f->flags & NTF_ROUTER) && (vxlan->cfg.flags & VXLAN_F_RSC) && in vxlan_xmit()
2918 (ntohs(eth->h_proto) == ETH_P_IP || in vxlan_xmit()
2919 ntohs(eth->h_proto) == ETH_P_IPV6)) { in vxlan_xmit()
2922 f = vxlan_find_mac(vxlan, eth->h_dest, vni); in vxlan_xmit()
2928 if ((vxlan->cfg.flags & VXLAN_F_L2MISS) && in vxlan_xmit()
2929 !is_multicast_ether_addr(eth->h_dest)) in vxlan_xmit()
2930 vxlan_fdb_miss(vxlan, eth->h_dest); in vxlan_xmit()
2932 dev->stats.tx_dropped++; in vxlan_xmit()
2938 if (rcu_access_pointer(f->nh)) { in vxlan_xmit()
2940 (vni ? : vxlan->default_dst.remote_vni), did_rsc); in vxlan_xmit()
2942 list_for_each_entry_rcu(rdst, &f->remotes, list) { in vxlan_xmit()
2969 if (!netif_running(vxlan->dev)) in vxlan_cleanup()
2975 spin_lock(&vxlan->hash_lock[h]); in vxlan_cleanup()
2976 hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { in vxlan_cleanup()
2981 if (f->state & (NUD_PERMANENT | NUD_NOARP)) in vxlan_cleanup()
2984 if (f->flags & NTF_EXT_LEARNED) in vxlan_cleanup()
2987 timeout = f->used + vxlan->cfg.age_interval * HZ; in vxlan_cleanup()
2989 netdev_dbg(vxlan->dev, in vxlan_cleanup()
2991 f->eth_addr); in vxlan_cleanup()
2992 f->state = NUD_STALE; in vxlan_cleanup()
2997 spin_unlock(&vxlan->hash_lock[h]); in vxlan_cleanup()
3000 mod_timer(&vxlan->age_timer, next_timer); in vxlan_cleanup()
3005 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in vxlan_vs_del_dev()
3007 spin_lock(&vn->sock_lock); in vxlan_vs_del_dev()
3008 hlist_del_init_rcu(&vxlan->hlist4.hlist); in vxlan_vs_del_dev()
3010 hlist_del_init_rcu(&vxlan->hlist6.hlist); in vxlan_vs_del_dev()
3012 spin_unlock(&vn->sock_lock); in vxlan_vs_del_dev()
3018 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in vxlan_vs_add_dev()
3019 __be32 vni = vxlan->default_dst.remote_vni; in vxlan_vs_add_dev()
3021 node->vxlan = vxlan; in vxlan_vs_add_dev()
3022 spin_lock(&vn->sock_lock); in vxlan_vs_add_dev()
3023 hlist_add_head_rcu(&node->hlist, vni_head(vs, vni)); in vxlan_vs_add_dev()
3024 spin_unlock(&vn->sock_lock); in vxlan_vs_add_dev()
3033 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); in vxlan_init()
3034 if (!dev->tstats) in vxlan_init()
3035 return -ENOMEM; in vxlan_init()
3037 err = gro_cells_init(&vxlan->gro_cells, dev); in vxlan_init()
3039 free_percpu(dev->tstats); in vxlan_init()
3051 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete_default()
3055 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete_default()
3062 gro_cells_destroy(&vxlan->gro_cells); in vxlan_uninit()
3064 vxlan_fdb_delete_default(vxlan, vxlan->cfg.vni); in vxlan_uninit()
3066 free_percpu(dev->tstats); in vxlan_uninit()
3079 if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip)) { in vxlan_open()
3081 if (ret == -EADDRINUSE) in vxlan_open()
3089 if (vxlan->cfg.age_interval) in vxlan_open()
3090 mod_timer(&vxlan->age_timer, jiffies + FDB_AGE_INTERVAL); in vxlan_open()
3103 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_flush()
3104 hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { in vxlan_flush()
3107 if (!do_all && (f->state & (NUD_PERMANENT | NUD_NOARP))) in vxlan_flush()
3110 if (is_zero_ether_addr(f->eth_addr) && in vxlan_flush()
3111 f->vni == vxlan->cfg.vni) in vxlan_flush()
3115 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_flush()
3123 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in vxlan_stop()
3126 if (vxlan_addr_multicast(&vxlan->default_dst.remote_ip) && in vxlan_stop()
3130 del_timer_sync(&vxlan->age_timer); in vxlan_stop()
3146 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_change_mtu()
3147 struct net_device *lowerdev = __dev_get_by_index(vxlan->net, in vxlan_change_mtu()
3148 dst->remote_ifindex); in vxlan_change_mtu()
3149 bool use_ipv6 = !!(vxlan->cfg.flags & VXLAN_F_IPV6); in vxlan_change_mtu()
3151 /* This check is different than dev->max_mtu, because it looks at in vxlan_change_mtu()
3152 * the lowerdev->mtu, rather than the static dev->max_mtu in vxlan_change_mtu()
3155 int max_mtu = lowerdev->mtu - in vxlan_change_mtu()
3158 return -EINVAL; in vxlan_change_mtu()
3161 dev->mtu = new_mtu; in vxlan_change_mtu()
3171 sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, in vxlan_fill_metadata_dst()
3172 vxlan->cfg.port_max, true); in vxlan_fill_metadata_dst()
3173 dport = info->key.tp_dst ? : vxlan->cfg.dst_port; in vxlan_fill_metadata_dst()
3176 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); in vxlan_fill_metadata_dst()
3179 rt = vxlan_get_route(vxlan, dev, sock4, skb, 0, info->key.tos, in vxlan_fill_metadata_dst()
3180 info->key.u.ipv4.dst, in vxlan_fill_metadata_dst()
3181 &info->key.u.ipv4.src, dport, sport, in vxlan_fill_metadata_dst()
3182 &info->dst_cache, info); in vxlan_fill_metadata_dst()
3188 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock); in vxlan_fill_metadata_dst()
3191 ndst = vxlan6_get_route(vxlan, dev, sock6, skb, 0, info->key.tos, in vxlan_fill_metadata_dst()
3192 info->key.label, &info->key.u.ipv6.dst, in vxlan_fill_metadata_dst()
3193 &info->key.u.ipv6.src, dport, sport, in vxlan_fill_metadata_dst()
3194 &info->dst_cache, info); in vxlan_fill_metadata_dst()
3199 return -EPFNOSUPPORT; in vxlan_fill_metadata_dst()
3202 info->key.tp_src = sport; in vxlan_fill_metadata_dst()
3203 info->key.tp_dst = dport; in vxlan_fill_metadata_dst()
3253 spin_lock(&vn->sock_lock); in vxlan_offload_rx_ports()
3255 hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist) { in vxlan_offload_rx_ports()
3258 if (vs->flags & VXLAN_F_GPE) in vxlan_offload_rx_ports()
3264 udp_tunnel_push_rx_port(dev, vs->sock, type); in vxlan_offload_rx_ports()
3266 udp_tunnel_drop_rx_port(dev, vs->sock, type); in vxlan_offload_rx_ports()
3269 spin_unlock(&vn->sock_lock); in vxlan_offload_rx_ports()
3281 dev->needs_free_netdev = true; in vxlan_setup()
3284 dev->features |= NETIF_F_LLTX; in vxlan_setup()
3285 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; in vxlan_setup()
3286 dev->features |= NETIF_F_RXCSUM; in vxlan_setup()
3287 dev->features |= NETIF_F_GSO_SOFTWARE; in vxlan_setup()
3289 dev->vlan_features = dev->features; in vxlan_setup()
3290 dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXCSUM; in vxlan_setup()
3291 dev->hw_features |= NETIF_F_GSO_SOFTWARE; in vxlan_setup()
3293 dev->priv_flags |= IFF_NO_QUEUE; in vxlan_setup()
3295 /* MTU range: 68 - 65535 */ in vxlan_setup()
3296 dev->min_mtu = ETH_MIN_MTU; in vxlan_setup()
3297 dev->max_mtu = ETH_MAX_MTU; in vxlan_setup()
3299 INIT_LIST_HEAD(&vxlan->next); in vxlan_setup()
3301 timer_setup(&vxlan->age_timer, vxlan_cleanup, TIMER_DEFERRABLE); in vxlan_setup()
3303 vxlan->dev = dev; in vxlan_setup()
3306 spin_lock_init(&vxlan->hash_lock[h]); in vxlan_setup()
3307 INIT_HLIST_HEAD(&vxlan->fdb_head[h]); in vxlan_setup()
3313 dev->priv_flags &= ~IFF_TX_SKB_SHARING; in vxlan_ether_setup()
3314 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; in vxlan_ether_setup()
3315 dev->netdev_ops = &vxlan_netdev_ether_ops; in vxlan_ether_setup()
3320 dev->header_ops = NULL; in vxlan_raw_setup()
3321 dev->type = ARPHRD_NONE; in vxlan_raw_setup()
3322 dev->hard_header_len = 0; in vxlan_raw_setup()
3323 dev->addr_len = 0; in vxlan_raw_setup()
3324 dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in vxlan_raw_setup()
3325 dev->netdev_ops = &vxlan_netdev_raw_ops; in vxlan_raw_setup()
3367 return -EINVAL; in vxlan_validate()
3373 return -EADDRNOTAVAIL; in vxlan_validate()
3383 return -EINVAL; in vxlan_validate()
3390 return -EINVAL; in vxlan_validate()
3399 return -ERANGE; in vxlan_validate()
3407 if (ntohs(p->high) < ntohs(p->low)) { in vxlan_validate()
3410 return -EINVAL; in vxlan_validate()
3420 return -EINVAL; in vxlan_validate()
3430 strlcpy(drvinfo->version, VXLAN_VERSION, sizeof(drvinfo->version)); in vxlan_get_drvinfo()
3431 strlcpy(drvinfo->driver, "vxlan", sizeof(drvinfo->driver)); in vxlan_get_drvinfo()
3438 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_get_link_ksettings()
3439 struct net_device *lowerdev = __dev_get_by_index(vxlan->net, in vxlan_get_link_ksettings()
3440 dst->remote_ifindex); in vxlan_get_link_ksettings()
3443 cmd->base.duplex = DUPLEX_UNKNOWN; in vxlan_get_link_ksettings()
3444 cmd->base.port = PORT_OTHER; in vxlan_get_link_ksettings()
3445 cmd->base.speed = SPEED_UNKNOWN; in vxlan_get_link_ksettings()
3501 return ERR_PTR(-ENOMEM); in vxlan_socket_create()
3504 INIT_HLIST_HEAD(&vs->vni_list[h]); in vxlan_socket_create()
3512 vs->sock = sock; in vxlan_socket_create()
3513 refcount_set(&vs->refcnt, 1); in vxlan_socket_create()
3514 vs->flags = (flags & VXLAN_F_RCV_FLAGS); in vxlan_socket_create()
3516 spin_lock(&vn->sock_lock); in vxlan_socket_create()
3517 hlist_add_head_rcu(&vs->hlist, vs_head(net, port)); in vxlan_socket_create()
3519 (vs->flags & VXLAN_F_GPE) ? in vxlan_socket_create()
3522 spin_unlock(&vn->sock_lock); in vxlan_socket_create()
3541 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in __vxlan_sock_add()
3546 if (vxlan->cfg.remote_ifindex) in __vxlan_sock_add()
3548 vxlan->net, vxlan->cfg.remote_ifindex); in __vxlan_sock_add()
3550 if (!vxlan->cfg.no_share) { in __vxlan_sock_add()
3551 spin_lock(&vn->sock_lock); in __vxlan_sock_add()
3552 vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET, in __vxlan_sock_add()
3553 vxlan->cfg.dst_port, vxlan->cfg.flags, in __vxlan_sock_add()
3555 if (vs && !refcount_inc_not_zero(&vs->refcnt)) { in __vxlan_sock_add()
3556 spin_unlock(&vn->sock_lock); in __vxlan_sock_add()
3557 return -EBUSY; in __vxlan_sock_add()
3559 spin_unlock(&vn->sock_lock); in __vxlan_sock_add()
3562 vs = vxlan_socket_create(vxlan->net, ipv6, in __vxlan_sock_add()
3563 vxlan->cfg.dst_port, vxlan->cfg.flags, in __vxlan_sock_add()
3569 rcu_assign_pointer(vxlan->vn6_sock, vs); in __vxlan_sock_add()
3570 node = &vxlan->hlist6; in __vxlan_sock_add()
3574 rcu_assign_pointer(vxlan->vn4_sock, vs); in __vxlan_sock_add()
3575 node = &vxlan->hlist4; in __vxlan_sock_add()
3583 bool metadata = vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA; in vxlan_sock_add()
3584 bool ipv6 = vxlan->cfg.flags & VXLAN_F_IPV6 || metadata; in vxlan_sock_add()
3588 RCU_INIT_POINTER(vxlan->vn4_sock, NULL); in vxlan_sock_add()
3590 RCU_INIT_POINTER(vxlan->vn6_sock, NULL); in vxlan_sock_add()
3593 if (ret < 0 && ret != -EAFNOSUPPORT) in vxlan_sock_add()
3613 if (conf->flags & VXLAN_F_GPE) { in vxlan_config_validate()
3616 * case, the other side of the PtP link will have to be in vxlan_config_validate()
3619 if ((conf->flags & ~VXLAN_F_ALLOWED_GPE) || in vxlan_config_validate()
3620 !(conf->flags & VXLAN_F_COLLECT_METADATA)) { in vxlan_config_validate()
3623 return -EINVAL; in vxlan_config_validate()
3627 if (!conf->remote_ip.sa.sa_family && !conf->saddr.sa.sa_family) { in vxlan_config_validate()
3629 conf->remote_ip.sa.sa_family = AF_INET; in vxlan_config_validate()
3630 conf->saddr.sa.sa_family = AF_INET; in vxlan_config_validate()
3631 } else if (!conf->remote_ip.sa.sa_family) { in vxlan_config_validate()
3632 conf->remote_ip.sa.sa_family = conf->saddr.sa.sa_family; in vxlan_config_validate()
3633 } else if (!conf->saddr.sa.sa_family) { in vxlan_config_validate()
3634 conf->saddr.sa.sa_family = conf->remote_ip.sa.sa_family; in vxlan_config_validate()
3637 if (conf->saddr.sa.sa_family != conf->remote_ip.sa.sa_family) { in vxlan_config_validate()
3640 return -EINVAL; in vxlan_config_validate()
3643 if (vxlan_addr_multicast(&conf->saddr)) { in vxlan_config_validate()
3645 return -EINVAL; in vxlan_config_validate()
3648 if (conf->saddr.sa.sa_family == AF_INET6) { in vxlan_config_validate()
3652 return -EPFNOSUPPORT; in vxlan_config_validate()
3655 conf->flags |= VXLAN_F_IPV6; in vxlan_config_validate()
3657 if (!(conf->flags & VXLAN_F_COLLECT_METADATA)) { in vxlan_config_validate()
3659 ipv6_addr_type(&conf->saddr.sin6.sin6_addr); in vxlan_config_validate()
3661 ipv6_addr_type(&conf->remote_ip.sin6.sin6_addr); in vxlan_config_validate()
3668 return -EINVAL; in vxlan_config_validate()
3671 conf->flags |= VXLAN_F_IPV6_LINKLOCAL; in vxlan_config_validate()
3677 return -EINVAL; in vxlan_config_validate()
3680 conf->flags &= ~VXLAN_F_IPV6_LINKLOCAL; in vxlan_config_validate()
3685 if (conf->label && !use_ipv6) { in vxlan_config_validate()
3688 return -EINVAL; in vxlan_config_validate()
3691 if (conf->remote_ifindex) { in vxlan_config_validate()
3694 lowerdev = __dev_get_by_index(src_net, conf->remote_ifindex); in vxlan_config_validate()
3698 return -ENODEV; in vxlan_config_validate()
3704 if (idev && idev->cnf.disable_ipv6) { in vxlan_config_validate()
3707 return -EPERM; in vxlan_config_validate()
3714 if (vxlan_addr_multicast(&conf->remote_ip)) { in vxlan_config_validate()
3718 return -EINVAL; in vxlan_config_validate()
3722 if (conf->flags & VXLAN_F_IPV6_LINKLOCAL) { in vxlan_config_validate()
3724 "Local interface required for link-local local/remote addresses"); in vxlan_config_validate()
3725 return -EINVAL; in vxlan_config_validate()
3732 if (!conf->dst_port) { in vxlan_config_validate()
3733 if (conf->flags & VXLAN_F_GPE) in vxlan_config_validate()
3734 conf->dst_port = htons(4790); /* IANA VXLAN-GPE port */ in vxlan_config_validate()
3736 conf->dst_port = htons(vxlan_port); in vxlan_config_validate()
3739 if (!conf->age_interval) in vxlan_config_validate()
3740 conf->age_interval = FDB_AGE_DEFAULT; in vxlan_config_validate()
3742 list_for_each_entry(tmp, &vn->vxlan_list, next) { in vxlan_config_validate()
3746 if (tmp->cfg.vni != conf->vni) in vxlan_config_validate()
3748 if (tmp->cfg.dst_port != conf->dst_port) in vxlan_config_validate()
3750 if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) != in vxlan_config_validate()
3751 (conf->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6))) in vxlan_config_validate()
3754 if ((conf->flags & VXLAN_F_IPV6_LINKLOCAL) && in vxlan_config_validate()
3755 tmp->cfg.remote_ifindex != conf->remote_ifindex) in vxlan_config_validate()
3760 return -EEXIST; in vxlan_config_validate()
3773 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_config_apply()
3775 bool use_ipv6 = !!(conf->flags & VXLAN_F_IPV6); in vxlan_config_apply()
3779 if (conf->flags & VXLAN_F_GPE) in vxlan_config_apply()
3784 if (conf->mtu) in vxlan_config_apply()
3785 dev->mtu = conf->mtu; in vxlan_config_apply()
3787 vxlan->net = src_net; in vxlan_config_apply()
3790 dst->remote_vni = conf->vni; in vxlan_config_apply()
3792 memcpy(&dst->remote_ip, &conf->remote_ip, sizeof(conf->remote_ip)); in vxlan_config_apply()
3795 dst->remote_ifindex = conf->remote_ifindex; in vxlan_config_apply()
3797 dev->gso_max_size = lowerdev->gso_max_size; in vxlan_config_apply()
3798 dev->gso_max_segs = lowerdev->gso_max_segs; in vxlan_config_apply()
3800 needed_headroom = lowerdev->hard_header_len; in vxlan_config_apply()
3801 needed_headroom += lowerdev->needed_headroom; in vxlan_config_apply()
3803 dev->needed_tailroom = lowerdev->needed_tailroom; in vxlan_config_apply()
3805 max_mtu = lowerdev->mtu - (use_ipv6 ? VXLAN6_HEADROOM : in vxlan_config_apply()
3810 if (!changelink && !conf->mtu) in vxlan_config_apply()
3811 dev->mtu = max_mtu; in vxlan_config_apply()
3814 if (dev->mtu > max_mtu) in vxlan_config_apply()
3815 dev->mtu = max_mtu; in vxlan_config_apply()
3817 if (use_ipv6 || conf->flags & VXLAN_F_COLLECT_METADATA) in vxlan_config_apply()
3821 dev->needed_headroom = needed_headroom; in vxlan_config_apply()
3823 memcpy(&vxlan->cfg, conf, sizeof(*conf)); in vxlan_config_apply()
3855 dst = &vxlan->default_dst; in __vxlan_dev_create()
3860 dev->ethtool_ops = &vxlan_ethtool_ops; in __vxlan_dev_create()
3863 if (!vxlan_addr_any(&dst->remote_ip)) { in __vxlan_dev_create()
3865 &dst->remote_ip, in __vxlan_dev_create()
3867 vxlan->cfg.dst_port, in __vxlan_dev_create()
3868 dst->remote_vni, in __vxlan_dev_create()
3869 dst->remote_vni, in __vxlan_dev_create()
3870 dst->remote_ifindex, in __vxlan_dev_create()
3881 if (dst->remote_ifindex) { in __vxlan_dev_create()
3882 remote_dev = __dev_get_by_index(net, dst->remote_ifindex); in __vxlan_dev_create()
3884 err = -ENODEV; in __vxlan_dev_create()
3898 vxlan_fdb_insert(vxlan, all_zeros_mac, dst->remote_vni, f); in __vxlan_dev_create()
3911 list_add(&vxlan->next, &vn->vxlan_list); in __vxlan_dev_create()
3913 dst->remote_dev = remote_dev; in __vxlan_dev_create()
3944 return -EOPNOTSUPP; in vxlan_nl2flag()
3948 flags = conf->flags | mask; in vxlan_nl2flag()
3950 flags = conf->flags | mask; in vxlan_nl2flag()
3952 flags = conf->flags & ~mask; in vxlan_nl2flag()
3954 conf->flags = flags; in vxlan_nl2flag()
3970 memcpy(conf, &vxlan->cfg, sizeof(*conf)); in vxlan_nl2conf()
3975 if (changelink && (vni != conf->vni)) { in vxlan_nl2conf()
3977 return -EOPNOTSUPP; in vxlan_nl2conf()
3979 conf->vni = cpu_to_be32(nla_get_u32(data[IFLA_VXLAN_ID])); in vxlan_nl2conf()
3983 if (changelink && (conf->remote_ip.sa.sa_family != AF_INET)) { in vxlan_nl2conf()
3985 return -EOPNOTSUPP; in vxlan_nl2conf()
3988 conf->remote_ip.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_GROUP]); in vxlan_nl2conf()
3989 conf->remote_ip.sa.sa_family = AF_INET; in vxlan_nl2conf()
3993 return -EPFNOSUPPORT; in vxlan_nl2conf()
3996 if (changelink && (conf->remote_ip.sa.sa_family != AF_INET6)) { in vxlan_nl2conf()
3998 return -EOPNOTSUPP; in vxlan_nl2conf()
4001 conf->remote_ip.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_GROUP6]); in vxlan_nl2conf()
4002 conf->remote_ip.sa.sa_family = AF_INET6; in vxlan_nl2conf()
4006 if (changelink && (conf->saddr.sa.sa_family != AF_INET)) { in vxlan_nl2conf()
4008 return -EOPNOTSUPP; in vxlan_nl2conf()
4011 conf->saddr.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_LOCAL]); in vxlan_nl2conf()
4012 conf->saddr.sa.sa_family = AF_INET; in vxlan_nl2conf()
4016 return -EPFNOSUPPORT; in vxlan_nl2conf()
4019 if (changelink && (conf->saddr.sa.sa_family != AF_INET6)) { in vxlan_nl2conf()
4021 return -EOPNOTSUPP; in vxlan_nl2conf()
4025 conf->saddr.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_LOCAL6]); in vxlan_nl2conf()
4026 conf->saddr.sa.sa_family = AF_INET6; in vxlan_nl2conf()
4030 conf->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]); in vxlan_nl2conf()
4033 conf->tos = nla_get_u8(data[IFLA_VXLAN_TOS]); in vxlan_nl2conf()
4036 conf->ttl = nla_get_u8(data[IFLA_VXLAN_TTL]); in vxlan_nl2conf()
4048 conf->label = nla_get_be32(data[IFLA_VXLAN_LABEL]) & in vxlan_nl2conf()
4059 conf->flags |= VXLAN_F_LEARN; in vxlan_nl2conf()
4063 conf->age_interval = nla_get_u32(data[IFLA_VXLAN_AGEING]); in vxlan_nl2conf()
4101 return -EOPNOTSUPP; in vxlan_nl2conf()
4103 conf->addrmax = nla_get_u32(data[IFLA_VXLAN_LIMIT]); in vxlan_nl2conf()
4118 conf->port_min = ntohs(p->low); in vxlan_nl2conf()
4119 conf->port_max = ntohs(p->high); in vxlan_nl2conf()
4123 return -EOPNOTSUPP; in vxlan_nl2conf()
4131 return -EOPNOTSUPP; in vxlan_nl2conf()
4133 conf->dst_port = nla_get_be16(data[IFLA_VXLAN_PORT]); in vxlan_nl2conf()
4140 return -EOPNOTSUPP; in vxlan_nl2conf()
4143 conf->flags |= VXLAN_F_UDP_ZERO_CSUM_TX; in vxlan_nl2conf()
4205 return -EOPNOTSUPP; in vxlan_nl2conf()
4207 conf->mtu = nla_get_u32(tb[IFLA_MTU]); in vxlan_nl2conf()
4211 conf->df = nla_get_u8(data[IFLA_VXLAN_DF]); in vxlan_nl2conf()
4240 dst = &vxlan->default_dst; in vxlan_changelink()
4245 err = vxlan_config_validate(vxlan->net, &conf, &lowerdev, in vxlan_changelink()
4250 if (dst->remote_dev == lowerdev) in vxlan_changelink()
4253 err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev, in vxlan_changelink()
4259 if (!vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip)) { in vxlan_changelink()
4262 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4268 vxlan->cfg.dst_port, in vxlan_changelink()
4273 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4274 netdev_adjacent_change_abort(dst->remote_dev, in vxlan_changelink()
4279 if (!vxlan_addr_any(&dst->remote_ip)) in vxlan_changelink()
4281 dst->remote_ip, in vxlan_changelink()
4282 vxlan->cfg.dst_port, in vxlan_changelink()
4283 dst->remote_vni, in vxlan_changelink()
4284 dst->remote_vni, in vxlan_changelink()
4285 dst->remote_ifindex, in vxlan_changelink()
4287 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4290 if (conf.age_interval != vxlan->cfg.age_interval) in vxlan_changelink()
4291 mod_timer(&vxlan->age_timer, jiffies); in vxlan_changelink()
4293 netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev); in vxlan_changelink()
4294 if (lowerdev && lowerdev != dst->remote_dev) in vxlan_changelink()
4295 dst->remote_dev = lowerdev; in vxlan_changelink()
4296 vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); in vxlan_changelink()
4306 list_del(&vxlan->next); in vxlan_dellink()
4308 if (vxlan->default_dst.remote_dev) in vxlan_dellink()
4309 netdev_upper_dev_unlink(vxlan->default_dst.remote_dev, dev); in vxlan_dellink()
4345 const struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_fill_info()
4347 .low = htons(vxlan->cfg.port_min), in vxlan_fill_info()
4348 .high = htons(vxlan->cfg.port_max), in vxlan_fill_info()
4351 if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(dst->remote_vni))) in vxlan_fill_info()
4354 if (!vxlan_addr_any(&dst->remote_ip)) { in vxlan_fill_info()
4355 if (dst->remote_ip.sa.sa_family == AF_INET) { in vxlan_fill_info()
4357 dst->remote_ip.sin.sin_addr.s_addr)) in vxlan_fill_info()
4362 &dst->remote_ip.sin6.sin6_addr)) in vxlan_fill_info()
4368 if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) in vxlan_fill_info()
4371 if (!vxlan_addr_any(&vxlan->cfg.saddr)) { in vxlan_fill_info()
4372 if (vxlan->cfg.saddr.sa.sa_family == AF_INET) { in vxlan_fill_info()
4374 vxlan->cfg.saddr.sin.sin_addr.s_addr)) in vxlan_fill_info()
4379 &vxlan->cfg.saddr.sin6.sin6_addr)) in vxlan_fill_info()
4385 if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->cfg.ttl) || in vxlan_fill_info()
4387 !!(vxlan->cfg.flags & VXLAN_F_TTL_INHERIT)) || in vxlan_fill_info()
4388 nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->cfg.tos) || in vxlan_fill_info()
4389 nla_put_u8(skb, IFLA_VXLAN_DF, vxlan->cfg.df) || in vxlan_fill_info()
4390 nla_put_be32(skb, IFLA_VXLAN_LABEL, vxlan->cfg.label) || in vxlan_fill_info()
4392 !!(vxlan->cfg.flags & VXLAN_F_LEARN)) || in vxlan_fill_info()
4394 !!(vxlan->cfg.flags & VXLAN_F_PROXY)) || in vxlan_fill_info()
4396 !!(vxlan->cfg.flags & VXLAN_F_RSC)) || in vxlan_fill_info()
4398 !!(vxlan->cfg.flags & VXLAN_F_L2MISS)) || in vxlan_fill_info()
4400 !!(vxlan->cfg.flags & VXLAN_F_L3MISS)) || in vxlan_fill_info()
4402 !!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) || in vxlan_fill_info()
4403 nla_put_u32(skb, IFLA_VXLAN_AGEING, vxlan->cfg.age_interval) || in vxlan_fill_info()
4404 nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->cfg.addrmax) || in vxlan_fill_info()
4405 nla_put_be16(skb, IFLA_VXLAN_PORT, vxlan->cfg.dst_port) || in vxlan_fill_info()
4407 !(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM_TX)) || in vxlan_fill_info()
4409 !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_TX)) || in vxlan_fill_info()
4411 !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_RX)) || in vxlan_fill_info()
4413 !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_TX)) || in vxlan_fill_info()
4415 !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_RX))) in vxlan_fill_info()
4421 if (vxlan->cfg.flags & VXLAN_F_GBP && in vxlan_fill_info()
4425 if (vxlan->cfg.flags & VXLAN_F_GPE && in vxlan_fill_info()
4429 if (vxlan->cfg.flags & VXLAN_F_REMCSUM_NOPARTIAL && in vxlan_fill_info()
4436 return -EMSGSIZE; in vxlan_fill_info()
4443 return vxlan->net; in vxlan_get_link_net()
4501 list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) { in vxlan_handle_lowerdev_unregister()
4502 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_handle_lowerdev_unregister()
4510 if (dst->remote_ifindex == dev->ifindex) in vxlan_handle_lowerdev_unregister()
4511 vxlan_dellink(vxlan->dev, &list_kill); in vxlan_handle_lowerdev_unregister()
4524 if (!dev->udp_tunnel_nic_info) in vxlan_netdevice_event()
4528 if (!dev->udp_tunnel_nic_info) in vxlan_netdevice_event()
4551 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_offloaded_set()
4553 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_offloaded_set()
4555 f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_offloaded_set()
4559 rdst = vxlan_fdb_find_rdst(f, &fdb_info->remote_ip, in vxlan_fdb_offloaded_set()
4560 fdb_info->remote_port, in vxlan_fdb_offloaded_set()
4561 fdb_info->remote_vni, in vxlan_fdb_offloaded_set()
4562 fdb_info->remote_ifindex); in vxlan_fdb_offloaded_set()
4566 rdst->offloaded = fdb_info->offloaded; in vxlan_fdb_offloaded_set()
4569 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_offloaded_set()
4581 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_add()
4582 extack = switchdev_notifier_info_to_extack(&fdb_info->info); in vxlan_fdb_external_learn_add()
4584 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_add()
4585 err = vxlan_fdb_update(vxlan, fdb_info->eth_addr, &fdb_info->remote_ip, in vxlan_fdb_external_learn_add()
4588 fdb_info->remote_port, in vxlan_fdb_external_learn_add()
4589 fdb_info->vni, in vxlan_fdb_external_learn_add()
4590 fdb_info->remote_vni, in vxlan_fdb_external_learn_add()
4591 fdb_info->remote_ifindex, in vxlan_fdb_external_learn_add()
4594 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_add()
4608 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_del()
4609 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_del()
4611 f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_del()
4613 err = -ENOENT; in vxlan_fdb_external_learn_del()
4614 else if (f->flags & NTF_EXT_LEARNED) in vxlan_fdb_external_learn_del()
4615 err = __vxlan_fdb_delete(vxlan, fdb_info->eth_addr, in vxlan_fdb_external_learn_del()
4616 fdb_info->remote_ip, in vxlan_fdb_external_learn_del()
4617 fdb_info->remote_port, in vxlan_fdb_external_learn_del()
4618 fdb_info->vni, in vxlan_fdb_external_learn_del()
4619 fdb_info->remote_vni, in vxlan_fdb_external_learn_del()
4620 fdb_info->remote_ifindex, in vxlan_fdb_external_learn_del()
4623 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_del()
4646 fdb_info->offloaded = true; in vxlan_switchdev_event()
4656 fdb_info->offloaded = false; in vxlan_switchdev_event()
4675 list_for_each_entry_rcu(fdb, &nh->fdb_list, nh_list) { in vxlan_fdb_nh_flush()
4676 vxlan = rcu_dereference(fdb->vdev); in vxlan_fdb_nh_flush()
4678 hash_index = fdb_head_index(vxlan, fdb->eth_addr, in vxlan_fdb_nh_flush()
4679 vxlan->default_dst.remote_vni); in vxlan_fdb_nh_flush()
4680 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_nh_flush()
4681 if (!hlist_unhashed(&fdb->hlist)) in vxlan_fdb_nh_flush()
4683 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_nh_flush()
4710 INIT_LIST_HEAD(&vn->vxlan_list); in vxlan_init_net()
4711 spin_lock_init(&vn->sock_lock); in vxlan_init_net()
4714 INIT_HLIST_HEAD(&vn->sock_list[h]); in vxlan_init_net()
4727 if (dev->rtnl_link_ops == &vxlan_link_ops) in vxlan_destroy_tunnels()
4730 list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) { in vxlan_destroy_tunnels()
4731 /* If vxlan->dev is in the same netns, it has already been added in vxlan_destroy_tunnels()
4734 if (!net_eq(dev_net(vxlan->dev), net)) in vxlan_destroy_tunnels()
4735 unregister_netdevice_queue(vxlan->dev, head); in vxlan_destroy_tunnels()
4739 WARN_ON_ONCE(!hlist_empty(&vn->sock_list[h])); in vxlan_destroy_tunnels()