Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (c) 2007-2012 Nicira, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "datapath.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "vport-internal_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "vport-netdev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static void dp_detach_port_notify(struct vport *vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 	struct sk_buff *notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	struct datapath *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	dp = vport->dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	notify = ovs_vport_cmd_build_info(vport, ovs_dp_get_net(dp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 					  0, 0, OVS_VPORT_CMD_DEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	ovs_dp_detach_port(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	if (IS_ERR(notify)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 		genl_set_err(&dp_vport_genl_family, ovs_dp_get_net(dp), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 			     0, PTR_ERR(notify));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	genlmsg_multicast_netns(&dp_vport_genl_family,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 				ovs_dp_get_net(dp), notify, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 				0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) void ovs_dp_notify_wq(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	struct ovs_net *ovs_net = container_of(work, struct ovs_net, dp_notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	struct datapath *dp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	ovs_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	list_for_each_entry(dp, &ovs_net->dps, list_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 		for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 			struct vport *vport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 			struct hlist_node *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 			hlist_for_each_entry_safe(vport, n, &dp->ports[i], dp_hash_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 				if (vport->ops->type == OVS_VPORT_TYPE_INTERNAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 				if (!(netif_is_ovs_port(vport->dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 					dp_detach_port_notify(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	ovs_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int dp_device_event(struct notifier_block *unused, unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 			   void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	struct ovs_net *ovs_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	struct vport *vport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	if (!ovs_is_internal_dev(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		vport = ovs_netdev_get_vport(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	if (!vport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	if (event == NETDEV_UNREGISTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		/* upper_dev_unlink and decrement promisc immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 		ovs_netdev_detach_dev(vport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 		/* schedule vport destroy, dev_put and genl notification */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		ovs_net = net_generic(dev_net(dev), ovs_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		queue_work(system_wq, &ovs_net->dp_notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct notifier_block ovs_dp_device_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	.notifier_call = dp_device_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };