dev.h (3378B)
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 7struct net; 8struct net_device; 9struct netdev_bpf; 10struct netdev_phys_item_id; 11struct netlink_ext_ack; 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 */ 15struct 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 23extern int netdev_flow_limit_table_len; 24 25#ifdef CONFIG_PROC_FS 26int __init dev_proc_init(void); 27#else 28#define dev_proc_init() 0 29#endif 30 31void linkwatch_init_dev(struct net_device *dev); 32void linkwatch_forget_dev(struct net_device *dev); 33void linkwatch_run_queue(void); 34 35void dev_addr_flush(struct net_device *dev); 36int dev_addr_init(struct net_device *dev); 37void dev_addr_check(struct net_device *dev); 38 39/* sysctls not referred to from outside net/core/ */ 40extern int netdev_budget; 41extern unsigned int netdev_budget_usecs; 42extern unsigned int sysctl_skb_defer_max; 43extern int netdev_tstamp_prequeue; 44extern int netdev_unregister_timeout_secs; 45extern int weight_p; 46extern int dev_weight_rx_bias; 47extern int dev_weight_tx_bias; 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}; 60 61int netdev_get_name(struct net *net, char *name, int ifindex); 62int dev_change_name(struct net_device *dev, const char *newname); 63 64int netdev_name_node_alt_create(struct net_device *dev, const char *name); 65int netdev_name_node_alt_destroy(struct net_device *dev, const char *name); 66 67int dev_validate_mtu(struct net_device *dev, int mtu, 68 struct netlink_ext_ack *extack); 69int dev_set_mtu_ext(struct net_device *dev, int mtu, 70 struct netlink_ext_ack *extack); 71 72int dev_get_phys_port_id(struct net_device *dev, 73 struct netdev_phys_item_id *ppid); 74int dev_get_phys_port_name(struct net_device *dev, 75 char *name, size_t len); 76 77int dev_change_proto_down(struct net_device *dev, bool proto_down); 78void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask, 79 u32 value); 80 81typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf); 82int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, 83 int fd, int expected_fd, u32 flags); 84 85int dev_change_tx_queue_len(struct net_device *dev, unsigned long new_len); 86void dev_set_group(struct net_device *dev, int new_group); 87int dev_change_carrier(struct net_device *dev, bool new_carrier); 88 89void __dev_set_rx_mode(struct net_device *dev); 90 91static inline void netif_set_gso_max_size(struct net_device *dev, 92 unsigned int size) 93{ 94 /* dev->gso_max_size is read locklessly from sk_setup_caps() */ 95 WRITE_ONCE(dev->gso_max_size, size); 96} 97 98static inline void netif_set_gso_max_segs(struct net_device *dev, 99 unsigned int segs) 100{ 101 /* dev->gso_max_segs is read locklessly from sk_setup_caps() */ 102 WRITE_ONCE(dev->gso_max_segs, segs); 103} 104 105static inline void netif_set_gro_max_size(struct net_device *dev, 106 unsigned int size) 107{ 108 /* This pairs with the READ_ONCE() in skb_gro_receive() */ 109 WRITE_ONCE(dev->gro_max_size, size); 110} 111 112#endif