Thread (90 messages) 90 messages, 8 authors, 2024-04-02

Re: [PATCH net-next v2 04/22] ovpn: add basic interface creation/destruction/management routines

From: Antonio Quartulli <antonio@openvpn.net>
Date: 2024-03-05 15:50:46


On 04/03/2024 22:33, Andrew Lunn wrote:
quoted
+int ovpn_struct_init(struct net_device *dev)
+{
+	struct ovpn_struct *ovpn = netdev_priv(dev);
+	int err;
+
+	memset(ovpn, 0, sizeof(*ovpn));
Probably not required. When a netdev is created, it should of zeroed
the priv.
ACK. There is a kvzalloc() involved.
quoted
+int ovpn_iface_create(const char *name, enum ovpn_mode mode, struct net *net)
+{
+	struct net_device *dev;
+	struct ovpn_struct *ovpn;
+	int ret;
+
+	dev = alloc_netdev(sizeof(struct ovpn_struct), name, NET_NAME_USER, ovpn_setup);
+
+	dev_net_set(dev, net);
+
+	ret = ovpn_struct_init(dev);
+	if (ret < 0)
+		goto err;
+
+	ovpn = netdev_priv(dev);
+	ovpn->mode = mode;
+
+	rtnl_lock();
+
+	ret = register_netdevice(dev);
+	if (ret < 0) {
+		netdev_dbg(dev, "cannot register interface %s: %d\n", dev->name, ret);
+		rtnl_unlock();
+		goto err;
+	}
+	rtnl_unlock();
+
+	return ret;
+
+err:
+	free_netdev(dev);
+	return ret;
+}
+
+void ovpn_iface_destruct(struct ovpn_struct *ovpn, bool unregister_netdev)
+{
+	ASSERT_RTNL();
+
+	netif_carrier_off(ovpn->dev);
You often see virtual devices turn their carrier off in there
probe/create function, because it is unclear what state it is in after
register_netdevice().
Are you suggesting to turn it off both here and in the create function?
Or should I remove the invocation above?

Regards,

-- 
Antonio Quartulli
OpenVPN Inc.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help