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