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

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (c) 2012-2013 Vyatta Inc.
70 return vs->flags & VXLAN_F_COLLECT_METADATA || in vxlan_collect_metadata()
76 * non-default VRF).
86 if (inet_sk(vs->sock->sk)->inet_sport == port && in vxlan_find_sock()
88 vs->flags == flags && in vxlan_find_sock()
89 vs->sock->sk->sk_bound_dev_if == ifindex) in vxlan_find_sock()
103 if (vs->flags & VXLAN_F_COLLECT_METADATA && in vxlan_vs_find_vni()
104 !(vs->flags & VXLAN_F_VNIFILTER)) in vxlan_vs_find_vni()
108 if (!node->vxlan) in vxlan_vs_find_vni()
111 if (node->vxlan->cfg.flags & VXLAN_F_VNIFILTER) { in vxlan_vs_find_vni()
112 vnode = vxlan_vnifilter_lookup(node->vxlan, vni); in vxlan_vs_find_vni()
115 } else if (node->vxlan->default_dst.remote_vni != vni) { in vxlan_vs_find_vni()
120 const struct vxlan_config *cfg = &node->vxlan->cfg; in vxlan_vs_find_vni()
122 if ((cfg->flags & VXLAN_F_IPV6_LINKLOCAL) && in vxlan_vs_find_vni()
123 cfg->remote_ifindex != ifindex) in vxlan_vs_find_vni()
129 return node->vxlan; in vxlan_vs_find_vni()
166 return -EMSGSIZE; in vxlan_fdb_info()
174 nh = rcu_dereference(fdb->nh); in vxlan_fdb_info()
177 nh_id = nh->id; in vxlan_fdb_info()
183 send_ip = !vxlan_addr_any(&rdst->remote_ip); in vxlan_fdb_info()
184 ndm->ndm_family = send_ip ? rdst->remote_ip.sa.sa_family : AF_INET; in vxlan_fdb_info()
186 ndm->ndm_family = nh_family; in vxlan_fdb_info()
188 send_eth = !is_zero_ether_addr(fdb->eth_addr); in vxlan_fdb_info()
190 ndm->ndm_family = AF_BRIDGE; in vxlan_fdb_info()
191 ndm->ndm_state = fdb->state; in vxlan_fdb_info()
192 ndm->ndm_ifindex = vxlan->dev->ifindex; in vxlan_fdb_info()
193 ndm->ndm_flags = fdb->flags; in vxlan_fdb_info()
194 if (rdst && rdst->offloaded) in vxlan_fdb_info()
195 ndm->ndm_flags |= NTF_OFFLOADED; in vxlan_fdb_info()
196 ndm->ndm_type = RTN_UNICAST; in vxlan_fdb_info()
198 if (!net_eq(dev_net(vxlan->dev), vxlan->net) && in vxlan_fdb_info()
200 peernet2id(dev_net(vxlan->dev), vxlan->net))) in vxlan_fdb_info()
203 if (send_eth && nla_put(skb, NDA_LLADDR, ETH_ALEN, &fdb->eth_addr)) in vxlan_fdb_info()
210 &rdst->remote_ip)) in vxlan_fdb_info()
213 if (rdst->remote_port && in vxlan_fdb_info()
214 rdst->remote_port != vxlan->cfg.dst_port && in vxlan_fdb_info()
215 nla_put_be16(skb, NDA_PORT, rdst->remote_port)) in vxlan_fdb_info()
217 if (rdst->remote_vni != vxlan->default_dst.remote_vni && in vxlan_fdb_info()
218 nla_put_u32(skb, NDA_VNI, be32_to_cpu(rdst->remote_vni))) in vxlan_fdb_info()
220 if (rdst->remote_ifindex && in vxlan_fdb_info()
221 nla_put_u32(skb, NDA_IFINDEX, rdst->remote_ifindex)) in vxlan_fdb_info()
225 if ((vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) && fdb->vni && in vxlan_fdb_info()
227 be32_to_cpu(fdb->vni))) in vxlan_fdb_info()
230 ci.ndm_used = jiffies_to_clock_t(now - fdb->used); in vxlan_fdb_info()
232 ci.ndm_updated = jiffies_to_clock_t(now - fdb->updated); in vxlan_fdb_info()
243 return -EMSGSIZE; in vxlan_fdb_info()
261 struct net *net = dev_net(vxlan->dev); in __vxlan_fdb_notify()
263 int err = -ENOBUFS; in __vxlan_fdb_notify()
271 /* -EMSGSIZE implies BUG in vxlan_nlmsg_size() */ in __vxlan_fdb_notify()
272 WARN_ON(err == -EMSGSIZE); in __vxlan_fdb_notify()
289 fdb_info->info.dev = vxlan->dev; in vxlan_fdb_switchdev_notifier_info()
290 fdb_info->info.extack = extack; in vxlan_fdb_switchdev_notifier_info()
291 fdb_info->remote_ip = rd->remote_ip; in vxlan_fdb_switchdev_notifier_info()
292 fdb_info->remote_port = rd->remote_port; in vxlan_fdb_switchdev_notifier_info()
293 fdb_info->remote_vni = rd->remote_vni; in vxlan_fdb_switchdev_notifier_info()
294 fdb_info->remote_ifindex = rd->remote_ifindex; in vxlan_fdb_switchdev_notifier_info()
295 memcpy(fdb_info->eth_addr, fdb->eth_addr, ETH_ALEN); in vxlan_fdb_switchdev_notifier_info()
296 fdb_info->vni = fdb->vni; in vxlan_fdb_switchdev_notifier_info()
297 fdb_info->offloaded = rd->offloaded; in vxlan_fdb_switchdev_notifier_info()
298 fdb_info->added_by_user = fdb->flags & NTF_VXLAN_ADDED_BY_USER; in vxlan_fdb_switchdev_notifier_info()
317 ret = call_switchdev_notifiers(notifier_type, vxlan->dev, in vxlan_fdb_switchdev_call_notifiers()
392 return jhash_2words(key, vni, vxlan_salt) & (FDB_HASH_SIZE - 1); in eth_vni_hash()
397 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) in fdb_head_index()
407 return &vxlan->fdb_head[fdb_head_index(vxlan, mac, vni)]; in vxlan_fdb_head()
418 if (ether_addr_equal(mac, f->eth_addr)) { in __vxlan_find_mac()
419 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) { in __vxlan_find_mac()
420 if (vni == f->vni) in __vxlan_find_mac()
437 if (f && f->used != jiffies) in vxlan_find_mac()
438 f->used = jiffies; in vxlan_find_mac()
443 /* caller should hold vxlan->hash_lock */
450 list_for_each_entry(rd, &f->remotes, list) { in vxlan_fdb_find_rdst()
451 if (vxlan_addr_equal(&rd->remote_ip, ip) && in vxlan_fdb_find_rdst()
452 rd->remote_port == port && in vxlan_fdb_find_rdst()
453 rd->remote_vni == vni && in vxlan_fdb_find_rdst()
454 rd->remote_ifindex == ifindex) in vxlan_fdb_find_rdst()
472 return -EINVAL; in vxlan_fdb_find_uc()
480 rc = -ENOENT; in vxlan_fdb_find_uc()
503 rc = nb->notifier_call(nb, SWITCHDEV_VXLAN_FDB_ADD_TO_DEVICE, in vxlan_fdb_notify_one()
519 return -EINVAL; in vxlan_fdb_replay()
523 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
524 hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist) { in vxlan_fdb_replay()
525 if (f->vni == vni) { in vxlan_fdb_replay()
526 list_for_each_entry(rdst, &f->remotes, list) { in vxlan_fdb_replay()
535 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
540 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_replay()
557 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_clear_offload()
558 hlist_for_each_entry(f, &vxlan->fdb_head[h], hlist) in vxlan_fdb_clear_offload()
559 if (f->vni == vni) in vxlan_fdb_clear_offload()
560 list_for_each_entry(rdst, &f->remotes, list) in vxlan_fdb_clear_offload()
561 rdst->offloaded = false; in vxlan_fdb_clear_offload()
562 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_fdb_clear_offload()
579 rd = list_first_entry_or_null(&f->remotes, struct vxlan_rdst, list); in vxlan_fdb_replace()
584 dst_cache_reset(&rd->dst_cache); in vxlan_fdb_replace()
585 rd->remote_ip = *ip; in vxlan_fdb_replace()
586 rd->remote_port = port; in vxlan_fdb_replace()
587 rd->remote_vni = vni; in vxlan_fdb_replace()
588 rd->remote_ifindex = ifindex; in vxlan_fdb_replace()
589 rd->offloaded = false; in vxlan_fdb_replace()
606 return -ENOMEM; in vxlan_fdb_append()
608 if (dst_cache_init(&rd->dst_cache, GFP_ATOMIC)) { in vxlan_fdb_append()
610 return -ENOMEM; in vxlan_fdb_append()
613 rd->remote_ip = *ip; in vxlan_fdb_append()
614 rd->remote_port = port; in vxlan_fdb_append()
615 rd->offloaded = false; in vxlan_fdb_append()
616 rd->remote_vni = vni; in vxlan_fdb_append()
617 rd->remote_ifindex = ifindex; in vxlan_fdb_append()
619 list_add_tail_rcu(&rd->list, &f->remotes); in vxlan_fdb_append()
630 if (!gpe->np_applied) in vxlan_parse_gpe_proto()
635 if (gpe->version != 0) in vxlan_parse_gpe_proto()
641 if (gpe->oam_flag) in vxlan_parse_gpe_proto()
644 *protocol = tun_p_to_eth_p(gpe->next_protocol); in vxlan_parse_gpe_proto()
660 if (skb->remcsum_offload) in vxlan_gro_remcsum()
663 if (!NAPI_GRO_CB(skb)->csum_valid) in vxlan_gro_remcsum()
672 skb->remcsum_offload = 1; in vxlan_gro_remcsum()
698 flags = vh->vx_flags; in vxlan_gro_prepare_receive()
700 if ((flags & VXLAN_HF_RCO) && (vs->flags & VXLAN_F_REMCSUM_RX)) { in vxlan_gro_prepare_receive()
702 vh->vx_vni, grc, in vxlan_gro_prepare_receive()
703 !!(vs->flags & in vxlan_gro_prepare_receive()
713 if (!NAPI_GRO_CB(p)->same_flow) in vxlan_gro_prepare_receive()
716 vh2 = (struct vxlanhdr *)(p->data + off_vx); in vxlan_gro_prepare_receive()
717 if (vh->vx_flags != vh2->vx_flags || in vxlan_gro_prepare_receive()
718 vh->vx_vni != vh2->vx_vni) { in vxlan_gro_prepare_receive()
719 NAPI_GRO_CB(p)->same_flow = 0; in vxlan_gro_prepare_receive()
761 pp = call_gro_receive(ptype->callbacks.gro_receive, head, skb); in vxlan_gpe_gro_receive()
771 /* Sets 'skb->inner_mac_header' since we are always called with in vxlan_gro_complete()
772 * 'skb->encapsulation' set. in vxlan_gro_complete()
779 struct vxlanhdr *vh = (struct vxlanhdr *)(skb->data + nhoff); in vxlan_gpe_gro_complete()
781 int err = -ENOSYS; in vxlan_gpe_gro_complete()
788 err = ptype->callbacks.gro_complete(skb, nhoff + sizeof(struct vxlanhdr)); in vxlan_gpe_gro_complete()
801 f->state = state; in vxlan_fdb_alloc()
802 f->flags = ndm_flags; in vxlan_fdb_alloc()
803 f->updated = f->used = jiffies; in vxlan_fdb_alloc()
804 f->vni = src_vni; in vxlan_fdb_alloc()
805 f->nh = NULL; in vxlan_fdb_alloc()
806 RCU_INIT_POINTER(f->vdev, vxlan); in vxlan_fdb_alloc()
807 INIT_LIST_HEAD(&f->nh_list); in vxlan_fdb_alloc()
808 INIT_LIST_HEAD(&f->remotes); in vxlan_fdb_alloc()
809 memcpy(f->eth_addr, mac, ETH_ALEN); in vxlan_fdb_alloc()
817 ++vxlan->addrcnt; in vxlan_fdb_insert()
818 hlist_add_head_rcu(&f->hlist, in vxlan_fdb_insert()
825 struct nexthop *old_nh = rtnl_dereference(fdb->nh); in vxlan_fdb_nh_update()
827 int err = -EINVAL; in vxlan_fdb_nh_update()
829 if (old_nh && old_nh->id == nhid) in vxlan_fdb_nh_update()
832 nh = nexthop_find_by_id(vxlan->net, nhid); in vxlan_fdb_nh_update()
854 switch (vxlan->default_dst.remote_ip.sa.sa_family) { in vxlan_fdb_nh_update()
857 err = -EAFNOSUPPORT; in vxlan_fdb_nh_update()
864 err = -EAFNOSUPPORT; in vxlan_fdb_nh_update()
871 list_del_rcu(&fdb->nh_list); in vxlan_fdb_nh_update()
874 rcu_assign_pointer(fdb->nh, nh); in vxlan_fdb_nh_update()
875 list_add_tail_rcu(&fdb->nh_list, &nh->fdb_list); in vxlan_fdb_nh_update()
895 if (vxlan->cfg.addrmax && in vxlan_fdb_create()
896 vxlan->addrcnt >= vxlan->cfg.addrmax) in vxlan_fdb_create()
897 return -ENOSPC; in vxlan_fdb_create()
899 netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip); in vxlan_fdb_create()
902 return -ENOMEM; in vxlan_fdb_create()
925 nh = rcu_dereference_raw(f->nh); in __vxlan_fdb_free()
927 rcu_assign_pointer(f->nh, NULL); in __vxlan_fdb_free()
928 rcu_assign_pointer(f->vdev, NULL); in __vxlan_fdb_free()
932 list_for_each_entry_safe(rd, nd, &f->remotes, list) { in __vxlan_fdb_free()
933 dst_cache_destroy(&rd->dst_cache); in __vxlan_fdb_free()
951 netdev_dbg(vxlan->dev, "delete %pM\n", f->eth_addr); in vxlan_fdb_destroy()
953 --vxlan->addrcnt; in vxlan_fdb_destroy()
955 if (rcu_access_pointer(f->nh)) in vxlan_fdb_destroy()
959 list_for_each_entry(rd, &f->remotes, list) in vxlan_fdb_destroy()
964 hlist_del_rcu(&f->hlist); in vxlan_fdb_destroy()
965 list_del_rcu(&f->nh_list); in vxlan_fdb_destroy()
966 call_rcu(&f->rcu, vxlan_fdb_free); in vxlan_fdb_destroy()
973 dst_cache_destroy(&rd->dst_cache); in vxlan_dst_free()
993 if (nhid && !rcu_access_pointer(f->nh)) { in vxlan_fdb_update_existing()
996 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1002 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1009 !(f->flags & NTF_VXLAN_ADDED_BY_USER)) { in vxlan_fdb_update_existing()
1010 if (f->state != state) { in vxlan_fdb_update_existing()
1011 f->state = state; in vxlan_fdb_update_existing()
1012 f->updated = jiffies; in vxlan_fdb_update_existing()
1015 if (f->flags != fdb_flags) { in vxlan_fdb_update_existing()
1016 f->flags = fdb_flags; in vxlan_fdb_update_existing()
1017 f->updated = jiffies; in vxlan_fdb_update_existing()
1024 if (!(is_multicast_ether_addr(f->eth_addr) || in vxlan_fdb_update_existing()
1025 is_zero_ether_addr(f->eth_addr))) { in vxlan_fdb_update_existing()
1036 NL_SET_ERR_MSG(extack, "Cannot replace non-unicast fdb entries"); in vxlan_fdb_update_existing()
1037 return -EOPNOTSUPP; in vxlan_fdb_update_existing()
1041 (is_multicast_ether_addr(f->eth_addr) || in vxlan_fdb_update_existing()
1042 is_zero_ether_addr(f->eth_addr))) { in vxlan_fdb_update_existing()
1051 f->used = jiffies; in vxlan_fdb_update_existing()
1071 list_del_rcu(&rd->list); in vxlan_fdb_update_existing()
1072 call_rcu(&rd->rcu, vxlan_dst_free); in vxlan_fdb_update_existing()
1092 return -EOPNOTSUPP; in vxlan_fdb_update_create()
1094 netdev_dbg(vxlan->dev, "add %pM -> %pIS\n", mac, ip); in vxlan_fdb_update_create()
1113 /* Add new entry to forwarding table -- assumes lock held */
1127 netdev_dbg(vxlan->dev, in vxlan_fdb_update()
1129 return -EEXIST; in vxlan_fdb_update()
1137 return -ENOENT; in vxlan_fdb_update()
1149 list_del_rcu(&rd->list); in vxlan_fdb_dst_destroy()
1151 call_rcu(&rd->rcu, vxlan_dst_free); in vxlan_fdb_dst_destroy()
1159 struct net *net = dev_net(vxlan->dev); in vxlan_fdb_parse()
1165 return -EINVAL; in vxlan_fdb_parse()
1175 union vxlan_addr *remote = &vxlan->default_dst.remote_ip; in vxlan_fdb_parse()
1177 if (remote->sa.sa_family == AF_INET) { in vxlan_fdb_parse()
1178 ip->sin.sin_addr.s_addr = htonl(INADDR_ANY); in vxlan_fdb_parse()
1179 ip->sa.sa_family = AF_INET; in vxlan_fdb_parse()
1182 ip->sin6.sin6_addr = in6addr_any; in vxlan_fdb_parse()
1183 ip->sa.sa_family = AF_INET6; in vxlan_fdb_parse()
1191 return -EINVAL; in vxlan_fdb_parse()
1195 *port = vxlan->cfg.dst_port; in vxlan_fdb_parse()
1201 return -EINVAL; in vxlan_fdb_parse()
1205 *vni = vxlan->default_dst.remote_vni; in vxlan_fdb_parse()
1211 return -EINVAL; in vxlan_fdb_parse()
1215 *src_vni = vxlan->default_dst.remote_vni; in vxlan_fdb_parse()
1223 return -EINVAL; in vxlan_fdb_parse()
1229 return -EADDRNOTAVAIL; in vxlan_fdb_parse()
1250 /* struct net *net = dev_net(vxlan->dev); */ in vxlan_fdb_add()
1258 if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_REACHABLE))) { in vxlan_fdb_add()
1260 ndm->ndm_state); in vxlan_fdb_add()
1261 return -EINVAL; in vxlan_fdb_add()
1265 return -EINVAL; in vxlan_fdb_add()
1272 if (vxlan->default_dst.remote_ip.sa.sa_family != ip.sa.sa_family) in vxlan_fdb_add()
1273 return -EAFNOSUPPORT; in vxlan_fdb_add()
1276 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_add()
1277 err = vxlan_fdb_update(vxlan, addr, &ip, ndm->ndm_state, flags, in vxlan_fdb_add()
1279 ndm->ndm_flags | NTF_VXLAN_ADDED_BY_USER, in vxlan_fdb_add()
1281 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_add()
1293 int err = -ENOENT; in __vxlan_fdb_delete()
1308 if (rd && !list_is_singular(&f->remotes)) { in __vxlan_fdb_delete()
1339 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete()
1342 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete()
1360 hlist_for_each_entry_rcu(f, &vxlan->fdb_head[h], hlist) { in vxlan_fdb_dump()
1363 if (rcu_access_pointer(f->nh)) { in vxlan_fdb_dump()
1364 if (*idx < cb->args[2]) in vxlan_fdb_dump()
1367 NETLINK_CB(cb->skb).portid, in vxlan_fdb_dump()
1368 cb->nlh->nlmsg_seq, in vxlan_fdb_dump()
1380 list_for_each_entry_rcu(rd, &f->remotes, list) { in vxlan_fdb_dump()
1381 if (*idx < cb->args[2]) in vxlan_fdb_dump()
1385 NETLINK_CB(cb->skb).portid, in vxlan_fdb_dump()
1386 cb->nlh->nlmsg_seq, in vxlan_fdb_dump()
1418 vni = vxlan->default_dst.remote_vni; in vxlan_fdb_get()
1425 err = -ENOENT; in vxlan_fdb_get()
1448 /* Ignore packets from invalid src-address */ in vxlan_snoop()
1453 if (src_ip->sa.sa_family == AF_INET6 && in vxlan_snoop()
1454 (ipv6_addr_type(&src_ip->sin6.sin6_addr) & IPV6_ADDR_LINKLOCAL)) in vxlan_snoop()
1462 if (likely(vxlan_addr_equal(&rdst->remote_ip, src_ip) && in vxlan_snoop()
1463 rdst->remote_ifindex == ifindex)) in vxlan_snoop()
1467 if (f->state & (NUD_PERMANENT | NUD_NOARP)) in vxlan_snoop()
1471 if (rcu_access_pointer(f->nh)) in vxlan_snoop()
1477 src_mac, &rdst->remote_ip.sa, &src_ip->sa); in vxlan_snoop()
1479 rdst->remote_ip = *src_ip; in vxlan_snoop()
1480 f->updated = jiffies; in vxlan_snoop()
1486 spin_lock(&vxlan->hash_lock[hash_index]); in vxlan_snoop()
1493 vxlan->cfg.dst_port, in vxlan_snoop()
1495 vxlan->default_dst.remote_vni, in vxlan_snoop()
1497 spin_unlock(&vxlan->hash_lock[hash_index]); in vxlan_snoop()
1509 if (!refcount_dec_and_test(&vs->refcnt)) in __vxlan_sock_release_prep()
1512 vn = net_generic(sock_net(vs->sock->sk), vxlan_net_id); in __vxlan_sock_release_prep()
1513 spin_lock(&vn->sock_lock); in __vxlan_sock_release_prep()
1514 hlist_del_rcu(&vs->hlist); in __vxlan_sock_release_prep()
1515 udp_tunnel_notify_del_rx_port(vs->sock, in __vxlan_sock_release_prep()
1516 (vs->flags & VXLAN_F_GPE) ? in __vxlan_sock_release_prep()
1519 spin_unlock(&vn->sock_lock); in __vxlan_sock_release_prep()
1526 struct vxlan_sock *sock4 = rtnl_dereference(vxlan->vn4_sock); in vxlan_sock_release()
1528 struct vxlan_sock *sock6 = rtnl_dereference(vxlan->vn6_sock); in vxlan_sock_release()
1530 RCU_INIT_POINTER(vxlan->vn6_sock, NULL); in vxlan_sock_release()
1533 RCU_INIT_POINTER(vxlan->vn4_sock, NULL); in vxlan_sock_release()
1536 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) in vxlan_sock_release()
1542 udp_tunnel_sock_release(sock4->sock); in vxlan_sock_release()
1548 udp_tunnel_sock_release(sock6->sock); in vxlan_sock_release()
1559 if (!(unparsed->vx_flags & VXLAN_HF_RCO) || skb->remcsum_offload) in vxlan_remcsum()
1562 start = vxlan_rco_start(unparsed->vx_vni); in vxlan_remcsum()
1563 offset = start + vxlan_rco_offset(unparsed->vx_vni); in vxlan_remcsum()
1571 unparsed->vx_flags &= ~VXLAN_HF_RCO; in vxlan_remcsum()
1572 unparsed->vx_vni &= VXLAN_VNI_MASK; in vxlan_remcsum()
1583 if (!(unparsed->vx_flags & VXLAN_HF_GBP)) in vxlan_parse_gbp_hdr()
1586 md->gbp = ntohs(gbp->policy_id); in vxlan_parse_gbp_hdr()
1591 tun_dst->u.tun_info.key.tun_flags); in vxlan_parse_gbp_hdr()
1592 tun_dst->u.tun_info.options_len = sizeof(*md); in vxlan_parse_gbp_hdr()
1594 if (gbp->dont_learn) in vxlan_parse_gbp_hdr()
1595 md->gbp |= VXLAN_GBP_DONT_LEARN; in vxlan_parse_gbp_hdr()
1597 if (gbp->policy_applied) in vxlan_parse_gbp_hdr()
1598 md->gbp |= VXLAN_GBP_POLICY_APPLIED; in vxlan_parse_gbp_hdr()
1600 /* In flow-based mode, GBP is carried in dst_metadata */ in vxlan_parse_gbp_hdr()
1602 skb->mark = md->gbp; in vxlan_parse_gbp_hdr()
1604 unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS; in vxlan_parse_gbp_hdr()
1612 u32 ifindex = skb->dev->ifindex; in vxlan_set_mac()
1615 skb->protocol = eth_type_trans(skb, vxlan->dev); in vxlan_set_mac()
1619 if (ether_addr_equal(eth_hdr(skb)->h_source, vxlan->dev->dev_addr)) in vxlan_set_mac()
1624 saddr.sin.sin_addr.s_addr = ip_hdr(skb)->saddr; in vxlan_set_mac()
1628 saddr.sin6.sin6_addr = ipv6_hdr(skb)->saddr; in vxlan_set_mac()
1633 if ((vxlan->cfg.flags & VXLAN_F_LEARN) && in vxlan_set_mac()
1634 vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, ifindex, vni)) in vxlan_set_mac()
1654 net_info_ratelimited("non-ECT from %pI4 with TOS=%#x\n", in vxlan_ecn_decapsulate()
1655 &((struct iphdr *)oiph)->saddr, in vxlan_ecn_decapsulate()
1656 ((struct iphdr *)oiph)->tos); in vxlan_ecn_decapsulate()
1658 net_info_ratelimited("non-ECT from %pI6\n", in vxlan_ecn_decapsulate()
1659 &((struct ipv6hdr *)oiph)->saddr); in vxlan_ecn_decapsulate()
1686 netdev_dbg(skb->dev, "invalid vxlan flags=%#x vni=%#x\n", in vxlan_rcv()
1687 ntohl(vxlan_hdr(skb)->vx_flags), in vxlan_rcv()
1688 ntohl(vxlan_hdr(skb)->vx_vni)); in vxlan_rcv()
1699 vni = vxlan_vni(vxlan_hdr(skb)->vx_vni); in vxlan_rcv()
1701 vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni, &vninode); in vxlan_rcv()
1708 if (vs->flags & VXLAN_F_GPE) { in vxlan_rcv()
1716 !net_eq(vxlan->net, dev_net(vxlan->dev)))) in vxlan_rcv()
1719 if (vs->flags & VXLAN_F_REMCSUM_RX) in vxlan_rcv()
1720 if (unlikely(!vxlan_remcsum(&unparsed, skb, vs->flags))) in vxlan_rcv()
1734 md = ip_tunnel_info_opts(&tun_dst->u.tun_info); in vxlan_rcv()
1741 if (vs->flags & VXLAN_F_GBP) in vxlan_rcv()
1742 vxlan_parse_gbp_hdr(&unparsed, skb, vs->flags, md); in vxlan_rcv()
1764 skb->dev = vxlan->dev; in vxlan_rcv()
1765 skb->pkt_type = PACKET_HOST; in vxlan_rcv()
1768 /* Save offset of outer header relative to skb->head, in vxlan_rcv()
1770 * and might change skb->head. in vxlan_rcv()
1772 nh = skb_network_header(skb) - skb->head; in vxlan_rcv()
1777 DEV_STATS_INC(vxlan->dev, rx_length_errors); in vxlan_rcv()
1778 DEV_STATS_INC(vxlan->dev, rx_errors); in vxlan_rcv()
1785 oiph = skb->head + nh; in vxlan_rcv()
1788 DEV_STATS_INC(vxlan->dev, rx_frame_errors); in vxlan_rcv()
1789 DEV_STATS_INC(vxlan->dev, rx_errors); in vxlan_rcv()
1797 if (unlikely(!(vxlan->dev->flags & IFF_UP))) { in vxlan_rcv()
1799 dev_core_stats_rx_dropped_inc(vxlan->dev); in vxlan_rcv()
1805 dev_sw_netstats_rx_add(vxlan->dev, skb->len); in vxlan_rcv()
1806 vxlan_vnifilter_count(vxlan, vni, vninode, VXLAN_VNI_STATS_RX, skb->len); in vxlan_rcv()
1807 gro_cells_receive(&vxlan->gro_cells, skb); in vxlan_rcv()
1828 return -EINVAL; in vxlan_err_lookup()
1832 if (!(hdr->vx_flags & VXLAN_HF_VNI)) in vxlan_err_lookup()
1833 return -EINVAL; in vxlan_err_lookup()
1837 return -ENOENT; in vxlan_err_lookup()
1839 vni = vxlan_vni(hdr->vx_vni); in vxlan_err_lookup()
1840 vxlan = vxlan_vs_find_vni(vs, skb->dev->ifindex, vni, NULL); in vxlan_err_lookup()
1842 return -ENOENT; in vxlan_err_lookup()
1855 if (dev->flags & IFF_NOARP) in arp_reduce()
1866 if ((parp->ar_hrd != htons(ARPHRD_ETHER) && in arp_reduce()
1867 parp->ar_hrd != htons(ARPHRD_IEEE802)) || in arp_reduce()
1868 parp->ar_pro != htons(ETH_P_IP) || in arp_reduce()
1869 parp->ar_op != htons(ARPOP_REQUEST) || in arp_reduce()
1870 parp->ar_hln != dev->addr_len || in arp_reduce()
1871 parp->ar_pln != 4) in arp_reduce()
1875 arpptr += dev->addr_len; /* sha */ in arp_reduce()
1878 arpptr += dev->addr_len; /* tha */ in arp_reduce()
1891 if (!(READ_ONCE(n->nud_state) & NUD_CONNECTED)) { in arp_reduce()
1896 f = vxlan_find_mac(vxlan, n->ha, vni); in arp_reduce()
1897 if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { in arp_reduce()
1898 /* bridge-local neighbor */ in arp_reduce()
1904 n->ha, sha); in arp_reduce()
1913 reply->ip_summed = CHECKSUM_UNNECESSARY; in arp_reduce()
1914 reply->pkt_type = PACKET_HOST; in arp_reduce()
1922 } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { in arp_reduce()
1939 struct net_device *dev = request->dev; in vxlan_na_create()
1948 if (dev == NULL || !pskb_may_pull(request, request->len)) in vxlan_na_create()
1952 sizeof(*na) + na_olen + dev->needed_tailroom; in vxlan_na_create()
1957 reply->protocol = htons(ETH_P_IPV6); in vxlan_na_create()
1958 reply->dev = dev; in vxlan_na_create()
1959 skb_reserve(reply, LL_RESERVED_SPACE(request->dev)); in vxlan_na_create()
1965 daddr = eth_hdr(request)->h_source; in vxlan_na_create()
1966 ns_olen = request->len - skb_network_offset(request) - in vxlan_na_create()
1967 sizeof(struct ipv6hdr) - sizeof(*ns); in vxlan_na_create()
1968 for (i = 0; i < ns_olen-1; i += (ns->opt[i+1]<<3)) { in vxlan_na_create()
1969 if (!ns->opt[i + 1]) { in vxlan_na_create()
1973 if (ns->opt[i] == ND_OPT_SOURCE_LL_ADDR) { in vxlan_na_create()
1974 daddr = ns->opt + i + sizeof(struct nd_opt_hdr); in vxlan_na_create()
1980 ether_addr_copy(eth_hdr(reply)->h_dest, daddr); in vxlan_na_create()
1981 ether_addr_copy(eth_hdr(reply)->h_source, n->ha); in vxlan_na_create()
1982 eth_hdr(reply)->h_proto = htons(ETH_P_IPV6); in vxlan_na_create()
1983 reply->protocol = htons(ETH_P_IPV6); in vxlan_na_create()
1993 pip6->version = 6; in vxlan_na_create()
1994 pip6->priority = ipv6_hdr(request)->priority; in vxlan_na_create()
1995 pip6->nexthdr = IPPROTO_ICMPV6; in vxlan_na_create()
1996 pip6->hop_limit = 255; in vxlan_na_create()
1997 pip6->daddr = ipv6_hdr(request)->saddr; in vxlan_na_create()
1998 pip6->saddr = *(struct in6_addr *)n->primary_key; in vxlan_na_create()
2005 na->icmph.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT; in vxlan_na_create()
2006 na->icmph.icmp6_router = isrouter; in vxlan_na_create()
2007 na->icmph.icmp6_override = 1; in vxlan_na_create()
2008 na->icmph.icmp6_solicited = 1; in vxlan_na_create()
2009 na->target = ns->target; in vxlan_na_create()
2010 ether_addr_copy(&na->opt[2], n->ha); in vxlan_na_create()
2011 na->opt[0] = ND_OPT_TARGET_LL_ADDR; in vxlan_na_create()
2012 na->opt[1] = na_olen >> 3; in vxlan_na_create()
2014 na->icmph.icmp6_cksum = csum_ipv6_magic(&pip6->saddr, in vxlan_na_create()
2015 &pip6->daddr, sizeof(*na)+na_olen, IPPROTO_ICMPV6, in vxlan_na_create()
2018 pip6->payload_len = htons(sizeof(*na)+na_olen); in vxlan_na_create()
2022 reply->ip_summed = CHECKSUM_UNNECESSARY; in vxlan_na_create()
2042 daddr = &iphdr->daddr; in neigh_reduce()
2046 ipv6_addr_is_multicast(&msg->target)) in neigh_reduce()
2049 n = neigh_lookup(ipv6_stub->nd_tbl, &msg->target, dev); in neigh_reduce()
2055 if (!(READ_ONCE(n->nud_state) & NUD_CONNECTED)) { in neigh_reduce()
2060 f = vxlan_find_mac(vxlan, n->ha, vni); in neigh_reduce()
2061 if (f && vxlan_addr_any(&(first_remote_rcu(f)->remote_ip))) { in neigh_reduce()
2062 /* bridge-local neighbor */ in neigh_reduce()
2068 !!(f ? f->flags & NTF_ROUTER : 0)); in neigh_reduce()
2080 } else if (vxlan->cfg.flags & VXLAN_F_L3MISS) { in neigh_reduce()
2082 .sin6.sin6_addr = msg->target, in neigh_reduce()
2101 if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) in route_shortcircuit()
2105 switch (ntohs(eth_hdr(skb)->h_proto)) { in route_shortcircuit()
2113 n = neigh_lookup(&arp_tbl, &pip->daddr, dev); in route_shortcircuit()
2114 if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { in route_shortcircuit()
2116 .sin.sin_addr.s_addr = pip->daddr, in route_shortcircuit()
2134 n = neigh_lookup(ipv6_stub->nd_tbl, &pip6->daddr, dev); in route_shortcircuit()
2135 if (!n && (vxlan->cfg.flags & VXLAN_F_L3MISS)) { in route_shortcircuit()
2137 .sin6.sin6_addr = pip6->daddr, in route_shortcircuit()
2155 diff = !ether_addr_equal(eth_hdr(skb)->h_dest, n->ha); in route_shortcircuit()
2157 memcpy(eth_hdr(skb)->h_source, eth_hdr(skb)->h_dest, in route_shortcircuit()
2158 dev->addr_len); in route_shortcircuit()
2159 memcpy(eth_hdr(skb)->h_dest, n->ha, dev->addr_len); in route_shortcircuit()
2172 gpe->np_applied = 1; in vxlan_build_gpe_hdr()
2173 gpe->next_protocol = tun_p_from_eth_p(protocol); in vxlan_build_gpe_hdr()
2174 if (!gpe->next_protocol) in vxlan_build_gpe_hdr()
2175 return -EPFNOSUPPORT; in vxlan_build_gpe_hdr()
2191 skb->ip_summed == CHECKSUM_PARTIAL) { in vxlan_build_skb()
2196 (skb->csum_offset == offsetof(struct udphdr, check) || in vxlan_build_skb()
2197 skb->csum_offset == offsetof(struct tcphdr, check))) in vxlan_build_skb()
2201 min_headroom = LL_RESERVED_SPACE(dst->dev) + dst->header_len in vxlan_build_skb()
2214 vxh->vx_flags = VXLAN_HF_VNI; in vxlan_build_skb()
2215 vxh->vx_vni = vxlan_vni_field(vni); in vxlan_build_skb()
2220 start = skb_checksum_start_offset(skb) - sizeof(struct vxlanhdr); in vxlan_build_skb()
2221 vxh->vx_vni |= vxlan_compute_rco(start, skb->csum_offset); in vxlan_build_skb()
2222 vxh->vx_flags |= VXLAN_HF_RCO; in vxlan_build_skb()
2225 skb->ip_summed = CHECKSUM_NONE; in vxlan_build_skb()
2226 skb->encapsulation = 0; in vxlan_build_skb()
2233 err = vxlan_build_gpe_hdr(vxh, skb->protocol); in vxlan_build_skb()
2236 inner_protocol = skb->protocol; in vxlan_build_skb()
2249 union vxlan_addr *remote_ip = &dst_vxlan->default_dst.remote_ip; in vxlan_encap_bypass()
2251 int len = skb->len; in vxlan_encap_bypass()
2253 skb->pkt_type = PACKET_HOST; in vxlan_encap_bypass()
2254 skb->encapsulation = 0; in vxlan_encap_bypass()
2255 skb->dev = dst_vxlan->dev; in vxlan_encap_bypass()
2258 if (remote_ip->sa.sa_family == AF_INET) { in vxlan_encap_bypass()
2269 dev = skb->dev; in vxlan_encap_bypass()
2270 if (unlikely(!(dev->flags & IFF_UP))) { in vxlan_encap_bypass()
2275 if ((dst_vxlan->cfg.flags & VXLAN_F_LEARN) && snoop) in vxlan_encap_bypass()
2276 vxlan_snoop(dev, &loopback, eth_hdr(skb)->h_source, 0, vni); in vxlan_encap_bypass()
2278 dev_sw_netstats_tx_add(src_vxlan->dev, 1, len); in vxlan_encap_bypass()
2282 dev_sw_netstats_rx_add(dst_vxlan->dev, len); in vxlan_encap_bypass()
2302 /* IPv6 rt-flags are checked against RTF_LOCAL, but the value of in encap_bypass_if_local()
2304 * we can use RTCF_LOCAL which works for ipv4 and ipv6 route entry. in encap_bypass_if_local()
2311 vxlan->cfg.flags & VXLAN_F_LOCALBYPASS) { in encap_bypass_if_local()
2315 dst_vxlan = vxlan_find_vni(vxlan->net, dst_ifindex, vni, in encap_bypass_if_local()
2317 vxlan->cfg.flags); in encap_bypass_if_local()
2324 return -ENOENT; in encap_bypass_if_local()
2344 unsigned int pkt_len = skb->len; in vxlan_xmit_one()
2351 u32 flags = vxlan->cfg.flags; in vxlan_xmit_one()
2354 bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev)); in vxlan_xmit_one()
2358 no_eth_encap = flags & VXLAN_F_GPE && skb->protocol != htons(ETH_P_TEB); in vxlan_xmit_one()
2371 if (vxlan_addr_any(&rdst->remote_ip)) { in vxlan_xmit_one()
2373 /* short-circuited back to local bridge */ in vxlan_xmit_one()
2381 addr_family = vxlan->cfg.saddr.sa.sa_family; in vxlan_xmit_one()
2382 dst_port = rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; in vxlan_xmit_one()
2383 vni = (rdst->remote_vni) ? : default_vni; in vxlan_xmit_one()
2384 ifindex = rdst->remote_ifindex; in vxlan_xmit_one()
2387 key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; in vxlan_xmit_one()
2388 key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; in vxlan_xmit_one()
2390 key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr; in vxlan_xmit_one()
2391 key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr; in vxlan_xmit_one()
2394 dst_cache = &rdst->dst_cache; in vxlan_xmit_one()
2395 md->gbp = skb->mark; in vxlan_xmit_one()
2399 ttl = vxlan->cfg.ttl; in vxlan_xmit_one()
2400 if (!ttl && vxlan_addr_multicast(&rdst->remote_ip)) in vxlan_xmit_one()
2403 tos = vxlan->cfg.tos; in vxlan_xmit_one()
2414 switch (vxlan->cfg.label_policy) { in vxlan_xmit_one()
2416 key.label = vxlan->cfg.label; in vxlan_xmit_one()
2429 dev->name); in vxlan_xmit_one()
2432 pkey = &info->key; in vxlan_xmit_one()
2434 dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; in vxlan_xmit_one()
2435 vni = tunnel_id_to_key32(info->key.tun_id); in vxlan_xmit_one()
2437 dst_cache = &info->dst_cache; in vxlan_xmit_one()
2438 if (test_bit(IP_TUNNEL_VXLAN_OPT_BIT, info->key.tun_flags)) { in vxlan_xmit_one()
2439 if (info->options_len < sizeof(*md)) in vxlan_xmit_one()
2443 ttl = info->key.ttl; in vxlan_xmit_one()
2444 tos = info->key.tos; in vxlan_xmit_one()
2445 udp_sum = test_bit(IP_TUNNEL_CSUM_BIT, info->key.tun_flags); in vxlan_xmit_one()
2447 src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, in vxlan_xmit_one()
2448 vxlan->cfg.port_max, true); in vxlan_xmit_one()
2452 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); in vxlan_xmit_one()
2458 ifindex = sock4->sock->sk->sk_bound_dev_if; in vxlan_xmit_one()
2460 rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, ifindex, in vxlan_xmit_one()
2472 &rt->dst, rt->rt_flags); in vxlan_xmit_one()
2476 if (vxlan->cfg.df == VXLAN_DF_SET) { in vxlan_xmit_one()
2478 } else if (vxlan->cfg.df == VXLAN_DF_INHERIT) { in vxlan_xmit_one()
2481 if (ntohs(eth->h_proto) == ETH_P_IPV6 || in vxlan_xmit_one()
2482 (ntohs(eth->h_proto) == ETH_P_IP && in vxlan_xmit_one()
2483 old_iph->frag_off & htons(IP_DF))) in vxlan_xmit_one()
2487 info->key.tun_flags)) { in vxlan_xmit_one()
2491 ndst = &rt->dst; in vxlan_xmit_one()
2504 unclone->key.u.ipv4.src = pkey->u.ipv4.dst; in vxlan_xmit_one()
2505 unclone->key.u.ipv4.dst = saddr; in vxlan_xmit_one()
2513 ttl = ttl ? : ip4_dst_hoplimit(&rt->dst); in vxlan_xmit_one()
2519 udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr, in vxlan_xmit_one()
2520 pkey->u.ipv4.dst, tos, ttl, df, in vxlan_xmit_one()
2524 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock); in vxlan_xmit_one()
2528 ifindex = sock6->sock->sk->sk_bound_dev_if; in vxlan_xmit_one()
2530 ndst = udp_tunnel6_dst_lookup(skb, dev, vxlan->net, sock6->sock, in vxlan_xmit_one()
2541 u32 rt6i_flags = dst_rt6_info(ndst)->rt6i_flags; in vxlan_xmit_one()
2563 unclone->key.u.ipv6.src = pkey->u.ipv6.dst; in vxlan_xmit_one()
2564 unclone->key.u.ipv6.dst = saddr; in vxlan_xmit_one()
2580 udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev, in vxlan_xmit_one()
2581 &saddr, &pkey->u.ipv6.dst, tos, ttl, in vxlan_xmit_one()
2582 pkey->label, src_port, dst_port, !udp_sum); in vxlan_xmit_one()
2598 if (err == -ELOOP) in vxlan_xmit_one()
2600 else if (err == -ENETUNREACH) in vxlan_xmit_one()
2620 nh = rcu_dereference(f->nh); in vxlan_xmit_nh()
2663 if (vxlan->cfg.saddr.sa.sa_family != nh_rdst.remote_ip.sa.sa_family) in vxlan_xmit_nhid()
2702 if (vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA) { in vxlan_xmit()
2703 if (info && info->mode & IP_TUNNEL_INFO_BRIDGE && in vxlan_xmit()
2704 info->mode & IP_TUNNEL_INFO_TX) { in vxlan_xmit()
2705 vni = tunnel_id_to_key32(info->key.tun_id); in vxlan_xmit()
2706 nhid = info->key.nhid; in vxlan_xmit()
2708 if (info && info->mode & IP_TUNNEL_INFO_TX) in vxlan_xmit()
2716 if (vxlan->cfg.flags & VXLAN_F_PROXY) { in vxlan_xmit()
2718 if (ntohs(eth->h_proto) == ETH_P_ARP) in vxlan_xmit()
2721 else if (ntohs(eth->h_proto) == ETH_P_IPV6 && in vxlan_xmit()
2724 ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { in vxlan_xmit()
2727 if (m->icmph.icmp6_code == 0 && in vxlan_xmit()
2728 m->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) in vxlan_xmit()
2737 if (vxlan->cfg.flags & VXLAN_F_MDB) { in vxlan_xmit()
2753 f = vxlan_find_mac(vxlan, eth->h_dest, vni); in vxlan_xmit()
2756 if (f && (f->flags & NTF_ROUTER) && (vxlan->cfg.flags & VXLAN_F_RSC) && in vxlan_xmit()
2757 (ntohs(eth->h_proto) == ETH_P_IP || in vxlan_xmit()
2758 ntohs(eth->h_proto) == ETH_P_IPV6)) { in vxlan_xmit()
2761 f = vxlan_find_mac(vxlan, eth->h_dest, vni); in vxlan_xmit()
2767 if ((vxlan->cfg.flags & VXLAN_F_L2MISS) && in vxlan_xmit()
2768 !is_multicast_ether_addr(eth->h_dest)) in vxlan_xmit()
2769 vxlan_fdb_miss(vxlan, eth->h_dest); in vxlan_xmit()
2779 if (rcu_access_pointer(f->nh)) { in vxlan_xmit()
2781 (vni ? : vxlan->default_dst.remote_vni), did_rsc); in vxlan_xmit()
2783 list_for_each_entry_rcu(rdst, &f->remotes, list) { in vxlan_xmit()
2810 if (!netif_running(vxlan->dev)) in vxlan_cleanup()
2816 spin_lock(&vxlan->hash_lock[h]); in vxlan_cleanup()
2817 hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { in vxlan_cleanup()
2822 if (f->state & (NUD_PERMANENT | NUD_NOARP)) in vxlan_cleanup()
2825 if (f->flags & NTF_EXT_LEARNED) in vxlan_cleanup()
2828 timeout = f->used + vxlan->cfg.age_interval * HZ; in vxlan_cleanup()
2830 netdev_dbg(vxlan->dev, in vxlan_cleanup()
2832 f->eth_addr); in vxlan_cleanup()
2833 f->state = NUD_STALE; in vxlan_cleanup()
2838 spin_unlock(&vxlan->hash_lock[h]); in vxlan_cleanup()
2841 mod_timer(&vxlan->age_timer, next_timer); in vxlan_cleanup()
2846 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in vxlan_vs_del_dev()
2848 spin_lock(&vn->sock_lock); in vxlan_vs_del_dev()
2849 hlist_del_init_rcu(&vxlan->hlist4.hlist); in vxlan_vs_del_dev()
2851 hlist_del_init_rcu(&vxlan->hlist6.hlist); in vxlan_vs_del_dev()
2853 spin_unlock(&vn->sock_lock); in vxlan_vs_del_dev()
2859 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in vxlan_vs_add_dev()
2860 __be32 vni = vxlan->default_dst.remote_vni; in vxlan_vs_add_dev()
2862 node->vxlan = vxlan; in vxlan_vs_add_dev()
2863 spin_lock(&vn->sock_lock); in vxlan_vs_add_dev()
2864 hlist_add_head_rcu(&node->hlist, vni_head(vs, vni)); in vxlan_vs_add_dev()
2865 spin_unlock(&vn->sock_lock); in vxlan_vs_add_dev()
2874 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) in vxlan_init()
2877 err = gro_cells_init(&vxlan->gro_cells, dev); in vxlan_init()
2889 gro_cells_destroy(&vxlan->gro_cells); in vxlan_init()
2891 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) in vxlan_init()
2901 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete_default()
2905 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_delete_default()
2914 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) in vxlan_uninit()
2917 gro_cells_destroy(&vxlan->gro_cells); in vxlan_uninit()
2919 vxlan_fdb_delete_default(vxlan, vxlan->cfg.vni); in vxlan_uninit()
2938 if (vxlan->cfg.age_interval) in vxlan_open()
2939 mod_timer(&vxlan->age_timer, jiffies + FDB_AGE_INTERVAL); in vxlan_open()
2960 return is_zero_ether_addr(f->eth_addr) && f->vni == vxlan->cfg.vni; in vxlan_fdb_is_default_entry()
2965 struct nexthop *nh = rtnl_dereference(f->nh); in vxlan_fdb_nhid_matches()
2967 return nh && nh->id == nhid; in vxlan_fdb_nhid_matches()
2974 if (desc->state_mask && (f->state & desc->state_mask) != desc->state) in vxlan_fdb_flush_matches()
2977 if (desc->flags_mask && (f->flags & desc->flags_mask) != desc->flags) in vxlan_fdb_flush_matches()
2980 if (desc->ignore_default_entry && vxlan_fdb_is_default_entry(f, vxlan)) in vxlan_fdb_flush_matches()
2983 if (desc->src_vni && f->vni != desc->src_vni) in vxlan_fdb_flush_matches()
2986 if (desc->nhid && !vxlan_fdb_nhid_matches(f, desc->nhid)) in vxlan_fdb_flush_matches()
2995 return desc->vni || desc->port || desc->dst_ip.sa.sa_family; in vxlan_fdb_flush_should_match_remotes()
3002 if (desc->vni && rd->remote_vni != desc->vni) in vxlan_fdb_flush_remote_matches()
3005 if (desc->port && rd->remote_port != desc->port) in vxlan_fdb_flush_remote_matches()
3008 if (desc->dst_ip.sa.sa_family && in vxlan_fdb_flush_remote_matches()
3009 !vxlan_addr_equal(&rd->remote_ip, &desc->dst_ip)) in vxlan_fdb_flush_remote_matches()
3023 list_for_each_entry_safe(rd, tmp, &f->remotes, list) { in vxlan_fdb_flush_match_remotes()
3031 *p_destroy_fdb = remotes_flushed && list_empty(&f->remotes); in vxlan_fdb_flush_match_remotes()
3044 spin_lock_bh(&vxlan->hash_lock[h]); in vxlan_flush()
3045 hlist_for_each_safe(p, n, &vxlan->fdb_head[h]) { in vxlan_flush()
3064 spin_unlock_bh(&vxlan->hash_lock[h]); in vxlan_flush()
3094 ndm_flags = ndm->ndm_flags & ~VXLAN_FDB_FLUSH_IGNORED_NDM_FLAGS; in vxlan_fdb_delete_bulk()
3103 return -EINVAL; in vxlan_fdb_delete_bulk()
3105 if (ndm->ndm_state & ~VXLAN_FDB_FLUSH_ALLOWED_NDM_STATES) { in vxlan_fdb_delete_bulk()
3107 return -EINVAL; in vxlan_fdb_delete_bulk()
3110 desc.state = ndm->ndm_state; in vxlan_fdb_delete_bulk()
3161 del_timer_sync(&vxlan->age_timer); in vxlan_stop()
3177 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_change_mtu()
3178 struct net_device *lowerdev = __dev_get_by_index(vxlan->net, in vxlan_change_mtu()
3179 dst->remote_ifindex); in vxlan_change_mtu()
3181 /* This check is different than dev->max_mtu, because it looks at in vxlan_change_mtu()
3182 * the lowerdev->mtu, rather than the static dev->max_mtu in vxlan_change_mtu()
3185 int max_mtu = lowerdev->mtu - vxlan_headroom(vxlan->cfg.flags); in vxlan_change_mtu()
3187 return -EINVAL; in vxlan_change_mtu()
3190 WRITE_ONCE(dev->mtu, new_mtu); in vxlan_change_mtu()
3200 sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, in vxlan_fill_metadata_dst()
3201 vxlan->cfg.port_max, true); in vxlan_fill_metadata_dst()
3202 dport = info->key.tp_dst ? : vxlan->cfg.dst_port; in vxlan_fill_metadata_dst()
3205 struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); in vxlan_fill_metadata_dst()
3209 return -EIO; in vxlan_fill_metadata_dst()
3211 rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, 0, in vxlan_fill_metadata_dst()
3212 &info->key.u.ipv4.src, in vxlan_fill_metadata_dst()
3213 &info->key, in vxlan_fill_metadata_dst()
3214 sport, dport, info->key.tos, in vxlan_fill_metadata_dst()
3215 &info->dst_cache); in vxlan_fill_metadata_dst()
3221 struct vxlan_sock *sock6 = rcu_dereference(vxlan->vn6_sock); in vxlan_fill_metadata_dst()
3225 return -EIO; in vxlan_fill_metadata_dst()
3227 ndst = udp_tunnel6_dst_lookup(skb, dev, vxlan->net, sock6->sock, in vxlan_fill_metadata_dst()
3228 0, &info->key.u.ipv6.src, in vxlan_fill_metadata_dst()
3229 &info->key, in vxlan_fill_metadata_dst()
3230 sport, dport, info->key.tos, in vxlan_fill_metadata_dst()
3231 &info->dst_cache); in vxlan_fill_metadata_dst()
3236 return -EPFNOSUPPORT; in vxlan_fill_metadata_dst()
3239 info->key.tp_src = sport; in vxlan_fill_metadata_dst()
3240 info->key.tp_dst = dport; in vxlan_fill_metadata_dst()
3293 spin_lock(&vn->sock_lock); in vxlan_offload_rx_ports()
3295 hlist_for_each_entry_rcu(vs, &vn->sock_list[i], hlist) { in vxlan_offload_rx_ports()
3298 if (vs->flags & VXLAN_F_GPE) in vxlan_offload_rx_ports()
3304 udp_tunnel_push_rx_port(dev, vs->sock, type); in vxlan_offload_rx_ports()
3306 udp_tunnel_drop_rx_port(dev, vs->sock, type); in vxlan_offload_rx_ports()
3309 spin_unlock(&vn->sock_lock); in vxlan_offload_rx_ports()
3321 dev->needs_free_netdev = true; in vxlan_setup()
3324 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST; in vxlan_setup()
3325 dev->features |= NETIF_F_RXCSUM; in vxlan_setup()
3326 dev->features |= NETIF_F_GSO_SOFTWARE; in vxlan_setup()
3328 dev->vlan_features = dev->features; in vxlan_setup()
3329 dev->hw_features |= NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_FRAGLIST; in vxlan_setup()
3330 dev->hw_features |= NETIF_F_RXCSUM; in vxlan_setup()
3331 dev->hw_features |= NETIF_F_GSO_SOFTWARE; in vxlan_setup()
3333 dev->priv_flags |= IFF_NO_QUEUE; in vxlan_setup()
3334 dev->change_proto_down = true; in vxlan_setup()
3335 dev->lltx = true; in vxlan_setup()
3337 /* MTU range: 68 - 65535 */ in vxlan_setup()
3338 dev->min_mtu = ETH_MIN_MTU; in vxlan_setup()
3339 dev->max_mtu = ETH_MAX_MTU; in vxlan_setup()
3341 dev->pcpu_stat_type = NETDEV_PCPU_STAT_TSTATS; in vxlan_setup()
3342 INIT_LIST_HEAD(&vxlan->next); in vxlan_setup()
3344 timer_setup(&vxlan->age_timer, vxlan_cleanup, TIMER_DEFERRABLE); in vxlan_setup()
3346 vxlan->dev = dev; in vxlan_setup()
3349 spin_lock_init(&vxlan->hash_lock[h]); in vxlan_setup()
3350 INIT_HLIST_HEAD(&vxlan->fdb_head[h]); in vxlan_setup()
3356 dev->priv_flags &= ~IFF_TX_SKB_SHARING; in vxlan_ether_setup()
3357 dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; in vxlan_ether_setup()
3358 dev->netdev_ops = &vxlan_netdev_ether_ops; in vxlan_ether_setup()
3363 dev->header_ops = NULL; in vxlan_raw_setup()
3364 dev->type = ARPHRD_NONE; in vxlan_raw_setup()
3365 dev->hard_header_len = 0; in vxlan_raw_setup()
3366 dev->addr_len = 0; in vxlan_raw_setup()
3367 dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in vxlan_raw_setup()
3368 dev->netdev_ops = &vxlan_netdev_raw_ops; in vxlan_raw_setup()
3414 return -EINVAL; in vxlan_validate()
3420 return -EADDRNOTAVAIL; in vxlan_validate()
3430 return -EINVAL; in vxlan_validate()
3437 return -EINVAL; in vxlan_validate()
3446 return -ERANGE; in vxlan_validate()
3454 if (ntohs(p->high) < ntohs(p->low)) { in vxlan_validate()
3457 return -EINVAL; in vxlan_validate()
3467 return -EINVAL; in vxlan_validate()
3477 strscpy(drvinfo->version, VXLAN_VERSION, sizeof(drvinfo->version)); in vxlan_get_drvinfo()
3478 strscpy(drvinfo->driver, "vxlan", sizeof(drvinfo->driver)); in vxlan_get_drvinfo()
3485 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_get_link_ksettings()
3486 struct net_device *lowerdev = __dev_get_by_index(vxlan->net, in vxlan_get_link_ksettings()
3487 dst->remote_ifindex); in vxlan_get_link_ksettings()
3490 cmd->base.duplex = DUPLEX_UNKNOWN; in vxlan_get_link_ksettings()
3491 cmd->base.port = PORT_OTHER; in vxlan_get_link_ksettings()
3492 cmd->base.speed = SPEED_UNKNOWN; in vxlan_get_link_ksettings()
3532 udp_allow_gso(sock->sk); in vxlan_create_sock()
3549 return ERR_PTR(-ENOMEM); in vxlan_socket_create()
3552 INIT_HLIST_HEAD(&vs->vni_list[h]); in vxlan_socket_create()
3560 vs->sock = sock; in vxlan_socket_create()
3561 refcount_set(&vs->refcnt, 1); in vxlan_socket_create()
3562 vs->flags = (flags & VXLAN_F_RCV_FLAGS); in vxlan_socket_create()
3564 spin_lock(&vn->sock_lock); in vxlan_socket_create()
3565 hlist_add_head_rcu(&vs->hlist, vs_head(net, port)); in vxlan_socket_create()
3567 (vs->flags & VXLAN_F_GPE) ? in vxlan_socket_create()
3570 spin_unlock(&vn->sock_lock); in vxlan_socket_create()
3579 if (vs->flags & VXLAN_F_GPE) { in vxlan_socket_create()
3594 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); in __vxlan_sock_add()
3595 bool metadata = vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA; in __vxlan_sock_add()
3600 if (vxlan->cfg.remote_ifindex) in __vxlan_sock_add()
3602 vxlan->net, vxlan->cfg.remote_ifindex); in __vxlan_sock_add()
3604 if (!vxlan->cfg.no_share) { in __vxlan_sock_add()
3605 spin_lock(&vn->sock_lock); in __vxlan_sock_add()
3606 vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET, in __vxlan_sock_add()
3607 vxlan->cfg.dst_port, vxlan->cfg.flags, in __vxlan_sock_add()
3609 if (vs && !refcount_inc_not_zero(&vs->refcnt)) { in __vxlan_sock_add()
3610 spin_unlock(&vn->sock_lock); in __vxlan_sock_add()
3611 return -EBUSY; in __vxlan_sock_add()
3613 spin_unlock(&vn->sock_lock); in __vxlan_sock_add()
3616 vs = vxlan_socket_create(vxlan->net, ipv6, in __vxlan_sock_add()
3617 vxlan->cfg.dst_port, vxlan->cfg.flags, in __vxlan_sock_add()
3623 rcu_assign_pointer(vxlan->vn6_sock, vs); in __vxlan_sock_add()
3624 node = &vxlan->hlist6; in __vxlan_sock_add()
3628 rcu_assign_pointer(vxlan->vn4_sock, vs); in __vxlan_sock_add()
3629 node = &vxlan->hlist4; in __vxlan_sock_add()
3632 if (metadata && (vxlan->cfg.flags & VXLAN_F_VNIFILTER)) in __vxlan_sock_add()
3642 bool metadata = vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA; in vxlan_sock_add()
3643 bool ipv6 = vxlan->cfg.flags & VXLAN_F_IPV6 || metadata; in vxlan_sock_add()
3647 RCU_INIT_POINTER(vxlan->vn4_sock, NULL); in vxlan_sock_add()
3649 RCU_INIT_POINTER(vxlan->vn6_sock, NULL); in vxlan_sock_add()
3652 if (ret < 0 && ret != -EAFNOSUPPORT) in vxlan_sock_add()
3669 list_for_each_entry(tmp, &vn->vxlan_list, next) { in vxlan_vni_in_use()
3672 if (tmp->cfg.flags & VXLAN_F_VNIFILTER) { in vxlan_vni_in_use()
3675 } else if (tmp->cfg.vni != vni) { in vxlan_vni_in_use()
3678 if (tmp->cfg.dst_port != conf->dst_port) in vxlan_vni_in_use()
3680 if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) != in vxlan_vni_in_use()
3681 (conf->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6))) in vxlan_vni_in_use()
3684 if ((conf->flags & VXLAN_F_IPV6_LINKLOCAL) && in vxlan_vni_in_use()
3685 tmp->cfg.remote_ifindex != conf->remote_ifindex) in vxlan_vni_in_use()
3688 return -EEXIST; in vxlan_vni_in_use()
3701 if (conf->flags & VXLAN_F_GPE) { in vxlan_config_validate()
3704 * case, the other side of the PtP link will have to be in vxlan_config_validate()
3707 if ((conf->flags & ~VXLAN_F_ALLOWED_GPE) || in vxlan_config_validate()
3708 !(conf->flags & VXLAN_F_COLLECT_METADATA)) { in vxlan_config_validate()
3711 return -EINVAL; in vxlan_config_validate()
3715 if (!conf->remote_ip.sa.sa_family && !conf->saddr.sa.sa_family) { in vxlan_config_validate()
3717 conf->remote_ip.sa.sa_family = AF_INET; in vxlan_config_validate()
3718 conf->saddr.sa.sa_family = AF_INET; in vxlan_config_validate()
3719 } else if (!conf->remote_ip.sa.sa_family) { in vxlan_config_validate()
3720 conf->remote_ip.sa.sa_family = conf->saddr.sa.sa_family; in vxlan_config_validate()
3721 } else if (!conf->saddr.sa.sa_family) { in vxlan_config_validate()
3722 conf->saddr.sa.sa_family = conf->remote_ip.sa.sa_family; in vxlan_config_validate()
3725 if (conf->saddr.sa.sa_family != conf->remote_ip.sa.sa_family) { in vxlan_config_validate()
3728 return -EINVAL; in vxlan_config_validate()
3731 if (vxlan_addr_multicast(&conf->saddr)) { in vxlan_config_validate()
3733 return -EINVAL; in vxlan_config_validate()
3736 if (conf->saddr.sa.sa_family == AF_INET6) { in vxlan_config_validate()
3740 return -EPFNOSUPPORT; in vxlan_config_validate()
3743 conf->flags |= VXLAN_F_IPV6; in vxlan_config_validate()
3745 if (!(conf->flags & VXLAN_F_COLLECT_METADATA)) { in vxlan_config_validate()
3747 ipv6_addr_type(&conf->saddr.sin6.sin6_addr); in vxlan_config_validate()
3749 ipv6_addr_type(&conf->remote_ip.sin6.sin6_addr); in vxlan_config_validate()
3756 return -EINVAL; in vxlan_config_validate()
3759 conf->flags |= VXLAN_F_IPV6_LINKLOCAL; in vxlan_config_validate()
3765 return -EINVAL; in vxlan_config_validate()
3768 conf->flags &= ~VXLAN_F_IPV6_LINKLOCAL; in vxlan_config_validate()
3773 if (conf->label && !use_ipv6) { in vxlan_config_validate()
3776 return -EINVAL; in vxlan_config_validate()
3779 if (conf->label_policy && !use_ipv6) { in vxlan_config_validate()
3782 return -EINVAL; in vxlan_config_validate()
3785 if (conf->remote_ifindex) { in vxlan_config_validate()
3788 lowerdev = __dev_get_by_index(src_net, conf->remote_ifindex); in vxlan_config_validate()
3792 return -ENODEV; in vxlan_config_validate()
3799 if (idev && idev->cnf.disable_ipv6) { in vxlan_config_validate()
3802 return -EPERM; in vxlan_config_validate()
3809 if (vxlan_addr_multicast(&conf->remote_ip)) { in vxlan_config_validate()
3813 return -EINVAL; in vxlan_config_validate()
3817 if (conf->flags & VXLAN_F_IPV6_LINKLOCAL) { in vxlan_config_validate()
3819 "Local interface required for link-local local/remote addresses"); in vxlan_config_validate()
3820 return -EINVAL; in vxlan_config_validate()
3827 if (!conf->dst_port) { in vxlan_config_validate()
3828 if (conf->flags & VXLAN_F_GPE) in vxlan_config_validate()
3829 conf->dst_port = htons(IANA_VXLAN_GPE_UDP_PORT); in vxlan_config_validate()
3831 conf->dst_port = htons(vxlan_port); in vxlan_config_validate()
3834 if (!conf->age_interval) in vxlan_config_validate()
3835 conf->age_interval = FDB_AGE_DEFAULT; in vxlan_config_validate()
3837 if (vxlan_vni_in_use(src_net, old, conf, conf->vni)) { in vxlan_config_validate()
3840 return -EEXIST; in vxlan_config_validate()
3853 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_config_apply()
3856 u32 flags = conf->flags; in vxlan_config_apply()
3864 if (conf->mtu) in vxlan_config_apply()
3865 dev->mtu = conf->mtu; in vxlan_config_apply()
3867 vxlan->net = src_net; in vxlan_config_apply()
3870 dst->remote_vni = conf->vni; in vxlan_config_apply()
3872 memcpy(&dst->remote_ip, &conf->remote_ip, sizeof(conf->remote_ip)); in vxlan_config_apply()
3875 dst->remote_ifindex = conf->remote_ifindex; in vxlan_config_apply()
3879 needed_headroom = lowerdev->hard_header_len; in vxlan_config_apply()
3880 needed_headroom += lowerdev->needed_headroom; in vxlan_config_apply()
3882 dev->needed_tailroom = lowerdev->needed_tailroom; in vxlan_config_apply()
3884 max_mtu = lowerdev->mtu - vxlan_headroom(flags); in vxlan_config_apply()
3888 if (!changelink && !conf->mtu) in vxlan_config_apply()
3889 dev->mtu = max_mtu; in vxlan_config_apply()
3892 if (dev->mtu > max_mtu) in vxlan_config_apply()
3893 dev->mtu = max_mtu; in vxlan_config_apply()
3898 dev->needed_headroom = needed_headroom; in vxlan_config_apply()
3900 memcpy(&vxlan->cfg, conf, sizeof(*conf)); in vxlan_config_apply()
3932 dst = &vxlan->default_dst; in __vxlan_dev_create()
3937 dev->ethtool_ops = &vxlan_ethtool_ops; in __vxlan_dev_create()
3940 if (!vxlan_addr_any(&dst->remote_ip)) { in __vxlan_dev_create()
3942 &dst->remote_ip, in __vxlan_dev_create()
3944 vxlan->cfg.dst_port, in __vxlan_dev_create()
3945 dst->remote_vni, in __vxlan_dev_create()
3946 dst->remote_vni, in __vxlan_dev_create()
3947 dst->remote_ifindex, in __vxlan_dev_create()
3958 if (dst->remote_ifindex) { in __vxlan_dev_create()
3959 remote_dev = __dev_get_by_index(net, dst->remote_ifindex); in __vxlan_dev_create()
3961 err = -ENODEV; in __vxlan_dev_create()
3975 vxlan_fdb_insert(vxlan, all_zeros_mac, dst->remote_vni, f); in __vxlan_dev_create()
3988 list_add(&vxlan->next, &vn->vxlan_list); in __vxlan_dev_create()
3990 dst->remote_dev = remote_dev; in __vxlan_dev_create()
4021 return -EOPNOTSUPP; in vxlan_nl2flag()
4025 flags = conf->flags | mask; in vxlan_nl2flag()
4027 flags = conf->flags | mask; in vxlan_nl2flag()
4029 flags = conf->flags & ~mask; in vxlan_nl2flag()
4031 conf->flags = flags; in vxlan_nl2flag()
4047 memcpy(conf, &vxlan->cfg, sizeof(*conf)); in vxlan_nl2conf()
4052 if (changelink && (vni != conf->vni)) { in vxlan_nl2conf()
4054 return -EOPNOTSUPP; in vxlan_nl2conf()
4056 conf->vni = cpu_to_be32(nla_get_u32(data[IFLA_VXLAN_ID])); in vxlan_nl2conf()
4060 if (changelink && (conf->remote_ip.sa.sa_family != AF_INET)) { in vxlan_nl2conf()
4062 return -EOPNOTSUPP; in vxlan_nl2conf()
4065 conf->remote_ip.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_GROUP]); in vxlan_nl2conf()
4066 conf->remote_ip.sa.sa_family = AF_INET; in vxlan_nl2conf()
4070 return -EPFNOSUPPORT; in vxlan_nl2conf()
4073 if (changelink && (conf->remote_ip.sa.sa_family != AF_INET6)) { in vxlan_nl2conf()
4075 return -EOPNOTSUPP; in vxlan_nl2conf()
4078 conf->remote_ip.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_GROUP6]); in vxlan_nl2conf()
4079 conf->remote_ip.sa.sa_family = AF_INET6; in vxlan_nl2conf()
4083 if (changelink && (conf->saddr.sa.sa_family != AF_INET)) { in vxlan_nl2conf()
4085 return -EOPNOTSUPP; in vxlan_nl2conf()
4088 conf->saddr.sin.sin_addr.s_addr = nla_get_in_addr(data[IFLA_VXLAN_LOCAL]); in vxlan_nl2conf()
4089 conf->saddr.sa.sa_family = AF_INET; in vxlan_nl2conf()
4093 return -EPFNOSUPPORT; in vxlan_nl2conf()
4096 if (changelink && (conf->saddr.sa.sa_family != AF_INET6)) { in vxlan_nl2conf()
4098 return -EOPNOTSUPP; in vxlan_nl2conf()
4102 conf->saddr.sin6.sin6_addr = nla_get_in6_addr(data[IFLA_VXLAN_LOCAL6]); in vxlan_nl2conf()
4103 conf->saddr.sa.sa_family = AF_INET6; in vxlan_nl2conf()
4107 conf->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]); in vxlan_nl2conf()
4110 conf->tos = nla_get_u8(data[IFLA_VXLAN_TOS]); in vxlan_nl2conf()
4113 conf->ttl = nla_get_u8(data[IFLA_VXLAN_TTL]); in vxlan_nl2conf()
4125 conf->label = nla_get_be32(data[IFLA_VXLAN_LABEL]) & in vxlan_nl2conf()
4128 conf->label_policy = nla_get_u32(data[IFLA_VXLAN_LABEL_POLICY]); in vxlan_nl2conf()
4138 conf->flags |= VXLAN_F_LEARN; in vxlan_nl2conf()
4142 conf->age_interval = nla_get_u32(data[IFLA_VXLAN_AGEING]); in vxlan_nl2conf()
4180 return -EOPNOTSUPP; in vxlan_nl2conf()
4182 conf->addrmax = nla_get_u32(data[IFLA_VXLAN_LIMIT]); in vxlan_nl2conf()
4197 conf->port_min = ntohs(p->low); in vxlan_nl2conf()
4198 conf->port_max = ntohs(p->high); in vxlan_nl2conf()
4202 return -EOPNOTSUPP; in vxlan_nl2conf()
4210 return -EOPNOTSUPP; in vxlan_nl2conf()
4212 conf->dst_port = nla_get_be16(data[IFLA_VXLAN_PORT]); in vxlan_nl2conf()
4219 return -EOPNOTSUPP; in vxlan_nl2conf()
4222 conf->flags |= VXLAN_F_UDP_ZERO_CSUM_TX; in vxlan_nl2conf()
4233 conf->flags |= VXLAN_F_LOCALBYPASS; in vxlan_nl2conf()
4295 return -EOPNOTSUPP; in vxlan_nl2conf()
4297 conf->mtu = nla_get_u32(tb[IFLA_MTU]); in vxlan_nl2conf()
4301 conf->df = nla_get_u8(data[IFLA_VXLAN_DF]); in vxlan_nl2conf()
4310 if ((conf->flags & VXLAN_F_VNIFILTER) && in vxlan_nl2conf()
4311 !(conf->flags & VXLAN_F_COLLECT_METADATA)) { in vxlan_nl2conf()
4314 return -EINVAL; in vxlan_nl2conf()
4345 dst = &vxlan->default_dst; in vxlan_changelink()
4350 err = vxlan_config_validate(vxlan->net, &conf, &lowerdev, in vxlan_changelink()
4355 if (dst->remote_dev == lowerdev) in vxlan_changelink()
4358 err = netdev_adjacent_change_prepare(dst->remote_dev, lowerdev, dev, in vxlan_changelink()
4364 if (!vxlan_addr_equal(&conf.remote_ip, &dst->remote_ip)) { in vxlan_changelink()
4367 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4373 vxlan->cfg.dst_port, in vxlan_changelink()
4378 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4379 netdev_adjacent_change_abort(dst->remote_dev, in vxlan_changelink()
4384 if (!vxlan_addr_any(&dst->remote_ip)) in vxlan_changelink()
4386 dst->remote_ip, in vxlan_changelink()
4387 vxlan->cfg.dst_port, in vxlan_changelink()
4388 dst->remote_vni, in vxlan_changelink()
4389 dst->remote_vni, in vxlan_changelink()
4390 dst->remote_ifindex, in vxlan_changelink()
4392 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_changelink()
4397 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER) { in vxlan_changelink()
4398 err = vxlan_vnilist_update_group(vxlan, &dst->remote_ip, in vxlan_changelink()
4401 netdev_adjacent_change_abort(dst->remote_dev, in vxlan_changelink()
4408 if (conf.age_interval != vxlan->cfg.age_interval) in vxlan_changelink()
4409 mod_timer(&vxlan->age_timer, jiffies); in vxlan_changelink()
4411 netdev_adjacent_change_commit(dst->remote_dev, lowerdev, dev); in vxlan_changelink()
4412 if (lowerdev && lowerdev != dst->remote_dev) in vxlan_changelink()
4413 dst->remote_dev = lowerdev; in vxlan_changelink()
4414 vxlan_config_apply(dev, &conf, lowerdev, vxlan->net, true); in vxlan_changelink()
4428 list_del(&vxlan->next); in vxlan_dellink()
4430 if (vxlan->default_dst.remote_dev) in vxlan_dellink()
4431 netdev_upper_dev_unlink(vxlan->default_dst.remote_dev, dev); in vxlan_dellink()
4473 const struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_fill_info()
4475 .low = htons(vxlan->cfg.port_min), in vxlan_fill_info()
4476 .high = htons(vxlan->cfg.port_max), in vxlan_fill_info()
4479 if (nla_put_u32(skb, IFLA_VXLAN_ID, be32_to_cpu(dst->remote_vni))) in vxlan_fill_info()
4482 if (!vxlan_addr_any(&dst->remote_ip)) { in vxlan_fill_info()
4483 if (dst->remote_ip.sa.sa_family == AF_INET) { in vxlan_fill_info()
4485 dst->remote_ip.sin.sin_addr.s_addr)) in vxlan_fill_info()
4490 &dst->remote_ip.sin6.sin6_addr)) in vxlan_fill_info()
4496 if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex)) in vxlan_fill_info()
4499 if (!vxlan_addr_any(&vxlan->cfg.saddr)) { in vxlan_fill_info()
4500 if (vxlan->cfg.saddr.sa.sa_family == AF_INET) { in vxlan_fill_info()
4502 vxlan->cfg.saddr.sin.sin_addr.s_addr)) in vxlan_fill_info()
4507 &vxlan->cfg.saddr.sin6.sin6_addr)) in vxlan_fill_info()
4513 if (nla_put_u8(skb, IFLA_VXLAN_TTL, vxlan->cfg.ttl) || in vxlan_fill_info()
4515 !!(vxlan->cfg.flags & VXLAN_F_TTL_INHERIT)) || in vxlan_fill_info()
4516 nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->cfg.tos) || in vxlan_fill_info()
4517 nla_put_u8(skb, IFLA_VXLAN_DF, vxlan->cfg.df) || in vxlan_fill_info()
4518 nla_put_be32(skb, IFLA_VXLAN_LABEL, vxlan->cfg.label) || in vxlan_fill_info()
4519 nla_put_u32(skb, IFLA_VXLAN_LABEL_POLICY, vxlan->cfg.label_policy) || in vxlan_fill_info()
4521 !!(vxlan->cfg.flags & VXLAN_F_LEARN)) || in vxlan_fill_info()
4523 !!(vxlan->cfg.flags & VXLAN_F_PROXY)) || in vxlan_fill_info()
4525 !!(vxlan->cfg.flags & VXLAN_F_RSC)) || in vxlan_fill_info()
4527 !!(vxlan->cfg.flags & VXLAN_F_L2MISS)) || in vxlan_fill_info()
4529 !!(vxlan->cfg.flags & VXLAN_F_L3MISS)) || in vxlan_fill_info()
4531 !!(vxlan->cfg.flags & VXLAN_F_COLLECT_METADATA)) || in vxlan_fill_info()
4532 nla_put_u32(skb, IFLA_VXLAN_AGEING, vxlan->cfg.age_interval) || in vxlan_fill_info()
4533 nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->cfg.addrmax) || in vxlan_fill_info()
4534 nla_put_be16(skb, IFLA_VXLAN_PORT, vxlan->cfg.dst_port) || in vxlan_fill_info()
4536 !(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM_TX)) || in vxlan_fill_info()
4538 !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_TX)) || in vxlan_fill_info()
4540 !!(vxlan->cfg.flags & VXLAN_F_UDP_ZERO_CSUM6_RX)) || in vxlan_fill_info()
4542 !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_TX)) || in vxlan_fill_info()
4544 !!(vxlan->cfg.flags & VXLAN_F_REMCSUM_RX)) || in vxlan_fill_info()
4546 !!(vxlan->cfg.flags & VXLAN_F_LOCALBYPASS))) in vxlan_fill_info()
4552 if (vxlan->cfg.flags & VXLAN_F_GBP && in vxlan_fill_info()
4556 if (vxlan->cfg.flags & VXLAN_F_GPE && in vxlan_fill_info()
4560 if (vxlan->cfg.flags & VXLAN_F_REMCSUM_NOPARTIAL && in vxlan_fill_info()
4564 if (vxlan->cfg.flags & VXLAN_F_VNIFILTER && in vxlan_fill_info()
4566 !!(vxlan->cfg.flags & VXLAN_F_VNIFILTER))) in vxlan_fill_info()
4572 return -EMSGSIZE; in vxlan_fill_info()
4579 return READ_ONCE(vxlan->net); in vxlan_get_link_net()
4637 list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) { in vxlan_handle_lowerdev_unregister()
4638 struct vxlan_rdst *dst = &vxlan->default_dst; in vxlan_handle_lowerdev_unregister()
4646 if (dst->remote_ifindex == dev->ifindex) in vxlan_handle_lowerdev_unregister()
4647 vxlan_dellink(vxlan->dev, &list_kill); in vxlan_handle_lowerdev_unregister()
4682 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_offloaded_set()
4684 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_offloaded_set()
4686 f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_offloaded_set()
4690 rdst = vxlan_fdb_find_rdst(f, &fdb_info->remote_ip, in vxlan_fdb_offloaded_set()
4691 fdb_info->remote_port, in vxlan_fdb_offloaded_set()
4692 fdb_info->remote_vni, in vxlan_fdb_offloaded_set()
4693 fdb_info->remote_ifindex); in vxlan_fdb_offloaded_set()
4697 rdst->offloaded = fdb_info->offloaded; in vxlan_fdb_offloaded_set()
4700 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_offloaded_set()
4712 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_add()
4713 extack = switchdev_notifier_info_to_extack(&fdb_info->info); in vxlan_fdb_external_learn_add()
4715 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_add()
4716 err = vxlan_fdb_update(vxlan, fdb_info->eth_addr, &fdb_info->remote_ip, in vxlan_fdb_external_learn_add()
4719 fdb_info->remote_port, in vxlan_fdb_external_learn_add()
4720 fdb_info->vni, in vxlan_fdb_external_learn_add()
4721 fdb_info->remote_vni, in vxlan_fdb_external_learn_add()
4722 fdb_info->remote_ifindex, in vxlan_fdb_external_learn_add()
4725 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_add()
4739 hash_index = fdb_head_index(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_del()
4740 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_del()
4742 f = vxlan_find_mac(vxlan, fdb_info->eth_addr, fdb_info->vni); in vxlan_fdb_external_learn_del()
4744 err = -ENOENT; in vxlan_fdb_external_learn_del()
4745 else if (f->flags & NTF_EXT_LEARNED) in vxlan_fdb_external_learn_del()
4746 err = __vxlan_fdb_delete(vxlan, fdb_info->eth_addr, in vxlan_fdb_external_learn_del()
4747 fdb_info->remote_ip, in vxlan_fdb_external_learn_del()
4748 fdb_info->remote_port, in vxlan_fdb_external_learn_del()
4749 fdb_info->vni, in vxlan_fdb_external_learn_del()
4750 fdb_info->remote_vni, in vxlan_fdb_external_learn_del()
4751 fdb_info->remote_ifindex, in vxlan_fdb_external_learn_del()
4754 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_external_learn_del()
4777 fdb_info->offloaded = true; in vxlan_switchdev_event()
4787 fdb_info->offloaded = false; in vxlan_switchdev_event()
4806 list_for_each_entry_rcu(fdb, &nh->fdb_list, nh_list) { in vxlan_fdb_nh_flush()
4807 vxlan = rcu_dereference(fdb->vdev); in vxlan_fdb_nh_flush()
4809 hash_index = fdb_head_index(vxlan, fdb->eth_addr, in vxlan_fdb_nh_flush()
4810 vxlan->default_dst.remote_vni); in vxlan_fdb_nh_flush()
4811 spin_lock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_nh_flush()
4812 if (!hlist_unhashed(&fdb->hlist)) in vxlan_fdb_nh_flush()
4814 spin_unlock_bh(&vxlan->hash_lock[hash_index]); in vxlan_fdb_nh_flush()
4828 nh = nexthop_find_by_id(info->net, info->id); in vxlan_nexthop_event()
4842 INIT_LIST_HEAD(&vn->vxlan_list); in vxlan_init_net()
4843 spin_lock_init(&vn->sock_lock); in vxlan_init_net()
4844 vn->nexthop_notifier_block.notifier_call = vxlan_nexthop_event; in vxlan_init_net()
4847 INIT_HLIST_HEAD(&vn->sock_list[h]); in vxlan_init_net()
4849 return register_nexthop_notifier(net, &vn->nexthop_notifier_block, in vxlan_init_net()
4858 list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) in vxlan_destroy_tunnels()
4859 vxlan_dellink(vxlan->dev, dev_to_kill); in vxlan_destroy_tunnels()
4871 __unregister_nexthop_notifier(net, &vn->nexthop_notifier_block); in vxlan_exit_batch_rtnl()
4883 WARN_ON_ONCE(!hlist_empty(&vn->sock_list[h])); in vxlan_exit_net()