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

source code of linux/net/core/dev.h