struct net_device

来源:互联网 发布:linux socket udp监听 编辑:程序博客网 时间:2024/05/16 10:20
struct net_device {
 char   name[IFNAMSIZ];
 struct hlist_node name_hlist;
 char    *ifalias;
 /*
  * I/O specific fields
  * FIXME: Merge these and struct ifmap into one
  */
 unsigned long  mem_end;
 unsigned long  mem_start;
 unsigned long  base_addr;
 int   irq;
 atomic_t  carrier_changes;
 /*
  * Some hardware also needs these fields (state,dev_list,
  * napi_list,unreg_list,close_list) but they are not
  * part of the usual set specified in Space.c.
  */
 unsigned long  state;
 struct list_head dev_list;
 struct list_head napi_list;
 struct list_head unreg_list;
 struct list_head close_list;
 struct list_head ptype_all;
 struct list_head ptype_specific;
 struct {
  struct list_head upper;
  struct list_head lower;
 } adj_list;
 struct {
  struct list_head upper;
  struct list_head lower;
 } all_adj_list;
 netdev_features_t features;
 netdev_features_t hw_features;
 netdev_features_t wanted_features;
 netdev_features_t vlan_features;
 netdev_features_t hw_enc_features;
 netdev_features_t mpls_features;
 netdev_features_t gso_partial_features;
 int   ifindex;
 int   group;
 struct net_device_stats stats;
 atomic_long_t  rx_dropped;
 atomic_long_t  tx_dropped;
 atomic_long_t  rx_nohandler;
#ifdef CONFIG_WIRELESS_EXT
 const struct iw_handler_def *wireless_handlers;
 struct iw_public_data *wireless_data;
#endif
 const struct net_device_ops *netdev_ops;
 const struct ethtool_ops *ethtool_ops;
#ifdef CONFIG_NET_SWITCHDEV
 const struct switchdev_ops *switchdev_ops;
#endif
#ifdef CONFIG_NET_L3_MASTER_DEV
 const struct l3mdev_ops *l3mdev_ops;
#endif
#if IS_ENABLED(CONFIG_IPV6)
 const struct ndisc_ops *ndisc_ops;
#endif
 const struct header_ops *header_ops;
 unsigned int  flags;
 unsigned int  priv_flags;
 unsigned short  gflags;
 unsigned short  padded;
 unsigned char  operstate;
 unsigned char  link_mode;
 unsigned char  if_port;
 unsigned char  dma;
 unsigned int  mtu;
 unsigned short  type;
 unsigned short  hard_header_len;
 unsigned short  min_header_len;
 unsigned short  needed_headroom;
 unsigned short  needed_tailroom;
 /* Interface address info. */
 unsigned char  perm_addr[MAX_ADDR_LEN];
 unsigned char  addr_assign_type;
 unsigned char  addr_len;
 unsigned short  neigh_priv_len;
 unsigned short          dev_id;
 unsigned short          dev_port;
 spinlock_t  addr_list_lock;
 unsigned char  name_assign_type;
 bool   uc_promisc;
 struct netdev_hw_addr_list uc;
 struct netdev_hw_addr_list mc;
 struct netdev_hw_addr_list dev_addrs;
#ifdef CONFIG_SYSFS
 struct kset  *queues_kset;
#endif
 unsigned int  promiscuity;
 unsigned int  allmulti;

 /* Protocol-specific pointers */
#if IS_ENABLED(CONFIG_VLAN_8021Q)
 struct vlan_info __rcu *vlan_info;
#endif
#if IS_ENABLED(CONFIG_NET_DSA)
 struct dsa_switch_tree *dsa_ptr;
#endif
#if IS_ENABLED(CONFIG_TIPC)
 struct tipc_bearer __rcu *tipc_ptr;
#endif
 void    *atalk_ptr;
 struct in_device __rcu *ip_ptr;
 struct dn_dev __rcu     *dn_ptr;
 struct inet6_dev __rcu *ip6_ptr;
 void   *ax25_ptr;
 struct wireless_dev *ieee80211_ptr;
 struct wpan_dev  *ieee802154_ptr;
#if IS_ENABLED(CONFIG_MPLS_ROUTING)
 struct mpls_dev __rcu *mpls_ptr;
#endif
/*
 * Cache lines mostly used on receive path (including eth_type_trans())
 */
 unsigned long  last_rx;
 /* Interface address info used in eth_type_trans() */
 unsigned char  *dev_addr;
#ifdef CONFIG_SYSFS
 struct netdev_rx_queue *_rx;
 unsigned int  num_rx_queues;
 unsigned int  real_num_rx_queues;
#endif
 unsigned long  gro_flush_timeout;
 rx_handler_func_t __rcu *rx_handler;
 void __rcu  *rx_handler_data;
#ifdef CONFIG_NET_CLS_ACT
 struct tcf_proto __rcu  *ingress_cl_list;
#endif
 struct netdev_queue __rcu *ingress_queue;
#ifdef CONFIG_NETFILTER_INGRESS
 struct nf_hook_entry __rcu *nf_hooks_ingress;
#endif
 unsigned char  broadcast[MAX_ADDR_LEN];
#ifdef CONFIG_RFS_ACCEL
 struct cpu_rmap  *rx_cpu_rmap;
#endif
 struct hlist_node index_hlist;
/*
 * Cache lines mostly used on transmit path
 */
 struct netdev_queue *_tx ____cacheline_aligned_in_smp;
 unsigned int  num_tx_queues;
 unsigned int  real_num_tx_queues;
 struct Qdisc  *qdisc;
#ifdef CONFIG_NET_SCHED
 DECLARE_HASHTABLE (qdisc_hash, 4);
#endif
 unsigned long  tx_queue_len;
 spinlock_t  tx_global_lock;
 int   watchdog_timeo;
#ifdef CONFIG_XPS
 struct xps_dev_maps __rcu *xps_maps;
#endif
#ifdef CONFIG_NET_CLS_ACT
 struct tcf_proto __rcu  *egress_cl_list;
#endif
 /* These may be needed for future network-power-down code. */
 struct timer_list watchdog_timer;
 int __percpu  *pcpu_refcnt;
 struct list_head todo_list;
 struct list_head link_watch_list;
 enum { NETREG_UNINITIALIZED=0,
        NETREG_REGISTERED, /* completed register_netdevice */
        NETREG_UNREGISTERING, /* called unregister_netdevice */
        NETREG_UNREGISTERED, /* completed unregister todo */
        NETREG_RELEASED,  /* called free_netdev */
        NETREG_DUMMY,  /* dummy device for NAPI poll */
 } reg_state:8;
 bool dismantle;
 enum {
  RTNL_LINK_INITIALIZED,
  RTNL_LINK_INITIALIZING,
 } rtnl_link_state:16;
 void (*destructor)(struct net_device *dev);
#ifdef CONFIG_NETPOLL
 struct netpoll_info __rcu *npinfo;
#endif
 possible_net_t   nd_net;
 /* mid-layer private */
 union {
  void     *ml_priv;
  struct pcpu_lstats __percpu  *lstats;
  struct pcpu_sw_netstats __percpu *tstats;
  struct pcpu_dstats __percpu  *dstats;
  struct pcpu_vstats __percpu  *vstats;
 };
 struct garp_port __rcu *garp_port;
 struct mrp_port __rcu *mrp_port;
 struct device  dev;
 const struct attribute_group *sysfs_groups[4];
 const struct attribute_group *sysfs_rx_queue_group;
 const struct rtnl_link_ops *rtnl_link_ops;
 /* for setting kernel sock attribute on TCP connection setup */
#define GSO_MAX_SIZE  65536
 unsigned int  gso_max_size;
#define GSO_MAX_SEGS  65535
 u16   gso_max_segs;
#ifdef CONFIG_DCB
 const struct dcbnl_rtnl_ops *dcbnl_ops;
#endif
 u8   num_tc;
 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
 u8   prio_tc_map[TC_BITMASK + 1];
#if IS_ENABLED(CONFIG_FCOE)
 unsigned int  fcoe_ddp_xid;
#endif
#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
 struct netprio_map __rcu *priomap;
#endif
 struct phy_device *phydev;
 struct lock_class_key *qdisc_tx_busylock;
 struct lock_class_key *qdisc_running_key;
 bool   proto_down;
}
#######################################################
static inline void *netdev_priv(const struct net_device *dev)
{
 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
}
##########################################################
struct net_device_ops {
 int   (*ndo_init)(struct net_device *dev);
 void   (*ndo_uninit)(struct net_device *dev);
 int   (*ndo_open)(struct net_device *dev);
 int   (*ndo_stop)(struct net_device *dev);
 netdev_tx_t  (*ndo_start_xmit)(struct sk_buff *skb,
        struct net_device *dev);
 netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
            struct net_device *dev,
            netdev_features_t features);
 u16   (*ndo_select_queue)(struct net_device *dev,
          struct sk_buff *skb,
          void *accel_priv,
          select_queue_fallback_t fallback);
 void   (*ndo_change_rx_flags)(struct net_device *dev,
             int flags);
 void   (*ndo_set_rx_mode)(struct net_device *dev);
 int   (*ndo_set_mac_address)(struct net_device *dev,
             void *addr);
 int   (*ndo_validate_addr)(struct net_device *dev);
 int   (*ndo_do_ioctl)(struct net_device *dev,
             struct ifreq *ifr, int cmd);
 int   (*ndo_set_config)(struct net_device *dev,
               struct ifmap *map);
 int   (*ndo_change_mtu)(struct net_device *dev,
        int new_mtu);
 int   (*ndo_neigh_setup)(struct net_device *dev,
         struct neigh_parms *);
 void   (*ndo_tx_timeout) (struct net_device *dev);
 struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
           struct rtnl_link_stats64 *storage);
 bool   (*ndo_has_offload_stats)(int attr_id);
 int   (*ndo_get_offload_stats)(int attr_id,
        const struct net_device *dev,
        void *attr_data);
 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
 int   (*ndo_vlan_rx_add_vid)(struct net_device *dev,
             __be16 proto, u16 vid);
 int   (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
              __be16 proto, u16 vid);
#ifdef CONFIG_NET_POLL_CONTROLLER
 void                    (*ndo_poll_controller)(struct net_device *dev);
 int   (*ndo_netpoll_setup)(struct net_device *dev,
           struct netpoll_info *info);
 void   (*ndo_netpoll_cleanup)(struct net_device *dev);
#endif
#ifdef CONFIG_NET_RX_BUSY_POLL
 int   (*ndo_busy_poll)(struct napi_struct *dev);
#endif
 int   (*ndo_set_vf_mac)(struct net_device *dev,
        int queue, u8 *mac);
 int   (*ndo_set_vf_vlan)(struct net_device *dev,
         int queue, u16 vlan,
         u8 qos, __be16 proto);
 int   (*ndo_set_vf_rate)(struct net_device *dev,
         int vf, int min_tx_rate,
         int max_tx_rate);
 int   (*ndo_set_vf_spoofchk)(struct net_device *dev,
             int vf, bool setting);
 int   (*ndo_set_vf_trust)(struct net_device *dev,
          int vf, bool setting);
 int   (*ndo_get_vf_config)(struct net_device *dev,
           int vf,
           struct ifla_vf_info *ivf);
 int   (*ndo_set_vf_link_state)(struct net_device *dev,
        int vf, int link_state);
 int   (*ndo_get_vf_stats)(struct net_device *dev,
          int vf,
          struct ifla_vf_stats
          *vf_stats);
 int   (*ndo_set_vf_port)(struct net_device *dev,
         int vf,
         struct nlattr *port[]);
 int   (*ndo_get_vf_port)(struct net_device *dev,
         int vf, struct sk_buff *skb);
 int   (*ndo_set_vf_guid)(struct net_device *dev,
         int vf, u64 guid,
         int guid_type);
 int   (*ndo_set_vf_rss_query_en)(
         struct net_device *dev,
         int vf, bool setting);
 int   (*ndo_setup_tc)(struct net_device *dev,
      u32 handle,
      __be16 protocol,
      struct tc_to_netdev *tc);
#if IS_ENABLED(CONFIG_FCOE)
 int   (*ndo_fcoe_enable)(struct net_device *dev);
 int   (*ndo_fcoe_disable)(struct net_device *dev);
 int   (*ndo_fcoe_ddp_setup)(struct net_device *dev,
            u16 xid,
            struct scatterlist *sgl,
            unsigned int sgc);
 int   (*ndo_fcoe_ddp_done)(struct net_device *dev,
           u16 xid);
 int   (*ndo_fcoe_ddp_target)(struct net_device *dev,
             u16 xid,
             struct scatterlist *sgl,
             unsigned int sgc);
 int   (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
       struct netdev_fcoe_hbainfo *hbainfo);
#endif
#if IS_ENABLED(CONFIG_LIBFCOE)
#define NETDEV_FCOE_WWNN 0
#define NETDEV_FCOE_WWPN 1
 int   (*ndo_fcoe_get_wwn)(struct net_device *dev,
          u64 *wwn, int type);
#endif
#ifdef CONFIG_RFS_ACCEL
 int   (*ndo_rx_flow_steer)(struct net_device *dev,
           const struct sk_buff *skb,
           u16 rxq_index,
           u32 flow_id);
#endif
 int   (*ndo_add_slave)(struct net_device *dev,
       struct net_device *slave_dev);
 int   (*ndo_del_slave)(struct net_device *dev,
       struct net_device *slave_dev);
 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
          netdev_features_t features);
 int   (*ndo_set_features)(struct net_device *dev,
          netdev_features_t features);
 int   (*ndo_neigh_construct)(struct net_device *dev,
             struct neighbour *n);
 void   (*ndo_neigh_destroy)(struct net_device *dev,
           struct neighbour *n);
 int   (*ndo_fdb_add)(struct ndmsg *ndm,
            struct nlattr *tb[],
            struct net_device *dev,
            const unsigned char *addr,
            u16 vid,
            u16 flags);
 int   (*ndo_fdb_del)(struct ndmsg *ndm,
            struct nlattr *tb[],
            struct net_device *dev,
            const unsigned char *addr,
            u16 vid);
 int   (*ndo_fdb_dump)(struct sk_buff *skb,
      struct netlink_callback *cb,
      struct net_device *dev,
      struct net_device *filter_dev,
      int *idx);
 int   (*ndo_bridge_setlink)(struct net_device *dev,
            struct nlmsghdr *nlh,
            u16 flags);
 int   (*ndo_bridge_getlink)(struct sk_buff *skb,
            u32 pid, u32 seq,
            struct net_device *dev,
            u32 filter_mask,
            int nlflags);
 int   (*ndo_bridge_dellink)(struct net_device *dev,
            struct nlmsghdr *nlh,
            u16 flags);
 int   (*ndo_change_carrier)(struct net_device *dev,
            bool new_carrier);
 int   (*ndo_get_phys_port_id)(struct net_device *dev,
       struct netdev_phys_item_id *ppid);
 int   (*ndo_get_phys_port_name)(struct net_device *dev,
         char *name, size_t len);
 void   (*ndo_udp_tunnel_add)(struct net_device *dev,
            struct udp_tunnel_info *ti);
 void   (*ndo_udp_tunnel_del)(struct net_device *dev,
            struct udp_tunnel_info *ti);
 void*   (*ndo_dfwd_add_station)(struct net_device *pdev,
       struct net_device *dev);
 void   (*ndo_dfwd_del_station)(struct net_device *pdev,
       void *priv);
 netdev_tx_t  (*ndo_dfwd_start_xmit) (struct sk_buff *skb,
       struct net_device *dev,
       void *priv);
 int   (*ndo_get_lock_subclass)(struct net_device *dev);
 int   (*ndo_set_tx_maxrate)(struct net_device *dev,
            int queue_index,
            u32 maxrate);
 int   (*ndo_get_iflink)(const struct net_device *dev);
 int   (*ndo_change_proto_down)(struct net_device *dev,
        bool proto_down);
 int   (*ndo_fill_metadata_dst)(struct net_device *dev,
             struct sk_buff *skb);
 void   (*ndo_set_rx_headroom)(struct net_device *dev,
             int needed_headroom);
 int   (*ndo_xdp)(struct net_device *dev,
        struct netdev_xdp *xdp);
}
##################################################

simnetdevs=alloc_netdev(sizeof(struct simnetpriv), "eth%d", NET_NAME_UNKNOWN, simnetinit);
#################################################
netdev_get_tx_queue(netdev,0)->trans_start = jiffies;


原创粉丝点击