xref: /linux/net/core/dev.h (revision 24b10e5f8e0d2bee1a10fc67011ea5d936c1a389)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 #ifndef _NET_CORE_DEV_H
3 #define _NET_CORE_DEV_H
4 
5 #include <linux/types.h>
6 
7 struct net;
8 struct net_device;
9 struct netdev_bpf;
10 struct netdev_phys_item_id;
11 struct netlink_ext_ack;
12 struct cpumask;
13 
14 /* Random bits of netdevice that don't need to be exposed */
15 #define FLOW_LIMIT_HISTORY	(1 << 7)  /* must be ^2 and !overflow buckets */
16 struct sd_flow_limit {
17 	u64			count;
18 	unsigned int		num_buckets;
19 	unsigned int		history_head;
20 	u16			history[FLOW_LIMIT_HISTORY];
21 	u8			buckets[];
22 };
23 
24 extern int netdev_flow_limit_table_len;
25 
26 #ifdef CONFIG_PROC_FS
27 int __init dev_proc_init(void);
28 #else
29 #define dev_proc_init() 0
30 #endif
31 
32 void linkwatch_init_dev(struct net_device *dev);
33 void linkwatch_run_queue(void);
34 
35 void dev_addr_flush(struct net_device *dev);
36 int dev_addr_init(struct net_device *dev);
37 void dev_addr_check(struct net_device *dev);
38 
39 /* sysctls not referred to from outside net/core/ */
40 extern int		netdev_budget;
41 extern unsigned int	netdev_budget_usecs;
42 extern unsigned int	sysctl_skb_defer_max;
43 extern int		netdev_tstamp_prequeue;
44 extern int		netdev_unregister_timeout_secs;
45 extern int		weight_p;
46 extern int		dev_weight_rx_bias;
47 extern int		dev_weight_tx_bias;
48 
49 /* rtnl helpers */
50 extern struct list_head net_todo_list;
51 void netdev_run_todo(void);
52 
53 /* netdev management, shared between various uAPI entry points */
54 struct netdev_name_node {
55 	struct hlist_node hlist;
56 	struct list_head list;
57 	struct net_device *dev;
58 	const char *name;
59 };
60 
61 int netdev_get_name(struct net *net, char *name, int ifindex);
62 int dev_change_name(struct net_device *dev, const char *newname);
63 
64 #define netdev_for_each_altname(dev, namenode)				\
65 	list_for_each_entry((namenode), &(dev)->name_node->list, list)
66 
67 int netdev_name_node_alt_create(struct net_device *dev, const char *name);
68 int netdev_name_node_alt_destroy(struct net_device *dev, const char *name);
69 
70 int dev_validate_mtu(struct net_device *dev, int mtu,
71 		     struct netlink_ext_ack *extack);
72 int dev_set_mtu_ext(struct net_device *dev, int mtu,
73 		    struct netlink_ext_ack *extack);
74 
75 int dev_get_phys_port_id(struct net_device *dev,
76 			 struct netdev_phys_item_id *ppid);
77 int dev_get_phys_port_name(struct net_device *dev,
78 			   char *name, size_t len);
79 
80 int dev_change_proto_down(struct net_device *dev, bool proto_down);
81 void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask,
82 				  u32 value);
83 
84 typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
85 int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
86 		      int fd, int expected_fd, u32 flags);
87 
88 int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len);
89 void dev_set_group(struct net_device *dev, int new_group);
90 int dev_change_carrier(struct net_device *dev, bool new_carrier);
91 
92 void __dev_set_rx_mode(struct net_device *dev);
93 
94 void __dev_notify_flags(struct net_device *dev, unsigned int old_flags,
95 			unsigned int gchanges, u32 portid,
96 			const struct nlmsghdr *nlh);
97 
98 void unregister_netdevice_many_notify(struct list_head *head,
99 				      u32 portid, const struct nlmsghdr *nlh);
100 
101 static inline void netif_set_gso_max_size(struct net_device *dev,
102 					  unsigned int size)
103 {
104 	/* dev->gso_max_size is read locklessly from sk_setup_caps() */
105 	WRITE_ONCE(dev->gso_max_size, size);
106 	if (size <= GSO_LEGACY_MAX_SIZE)
107 		WRITE_ONCE(dev->gso_ipv4_max_size, size);
108 }
109 
110 static inline void netif_set_gso_max_segs(struct net_device *dev,
111 					  unsigned int segs)
112 {
113 	/* dev->gso_max_segs is read locklessly from sk_setup_caps() */
114 	WRITE_ONCE(dev->gso_max_segs, segs);
115 }
116 
117 static inline void netif_set_gro_max_size(struct net_device *dev,
118 					  unsigned int size)
119 {
120 	/* This pairs with the READ_ONCE() in skb_gro_receive() */
121 	WRITE_ONCE(dev->gro_max_size, size);
122 	if (size <= GRO_LEGACY_MAX_SIZE)
123 		WRITE_ONCE(dev->gro_ipv4_max_size, size);
124 }
125 
126 static inline void netif_set_gso_ipv4_max_size(struct net_device *dev,
127 					       unsigned int size)
128 {
129 	/* dev->gso_ipv4_max_size is read locklessly from sk_setup_caps() */
130 	WRITE_ONCE(dev->gso_ipv4_max_size, size);
131 }
132 
133 static inline void netif_set_gro_ipv4_max_size(struct net_device *dev,
134 					       unsigned int size)
135 {
136 	/* This pairs with the READ_ONCE() in skb_gro_receive() */
137 	WRITE_ONCE(dev->gro_ipv4_max_size, size);
138 }
139 
140 int rps_cpumask_housekeeping(struct cpumask *mask);
141 
142 #if defined(CONFIG_DEBUG_NET) && defined(CONFIG_BPF_SYSCALL)
143 void xdp_do_check_flushed(struct napi_struct *napi);
144 #else
145 static inline void xdp_do_check_flushed(struct napi_struct *napi) { }
146 #endif
147 
148 struct napi_struct *napi_by_id(unsigned int napi_id);
149 #endif
150