Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PACKET_INTERNAL_H__
0003 #define __PACKET_INTERNAL_H__
0004 
0005 #include <linux/refcount.h>
0006 
0007 struct packet_mclist {
0008     struct packet_mclist    *next;
0009     int         ifindex;
0010     int         count;
0011     unsigned short      type;
0012     unsigned short      alen;
0013     unsigned char       addr[MAX_ADDR_LEN];
0014 };
0015 
0016 /* kbdq - kernel block descriptor queue */
0017 struct tpacket_kbdq_core {
0018     struct pgv  *pkbdq;
0019     unsigned int    feature_req_word;
0020     unsigned int    hdrlen;
0021     unsigned char   reset_pending_on_curr_blk;
0022     unsigned char   delete_blk_timer;
0023     unsigned short  kactive_blk_num;
0024     unsigned short  blk_sizeof_priv;
0025 
0026     /* last_kactive_blk_num:
0027      * trick to see if user-space has caught up
0028      * in order to avoid refreshing timer when every single pkt arrives.
0029      */
0030     unsigned short  last_kactive_blk_num;
0031 
0032     char        *pkblk_start;
0033     char        *pkblk_end;
0034     int     kblk_size;
0035     unsigned int    max_frame_len;
0036     unsigned int    knum_blocks;
0037     uint64_t    knxt_seq_num;
0038     char        *prev;
0039     char        *nxt_offset;
0040     struct sk_buff  *skb;
0041 
0042     rwlock_t    blk_fill_in_prog_lock;
0043 
0044     /* Default is set to 8ms */
0045 #define DEFAULT_PRB_RETIRE_TOV  (8)
0046 
0047     unsigned short  retire_blk_tov;
0048     unsigned short  version;
0049     unsigned long   tov_in_jiffies;
0050 
0051     /* timer to retire an outstanding block */
0052     struct timer_list retire_blk_timer;
0053 };
0054 
0055 struct pgv {
0056     char *buffer;
0057 };
0058 
0059 struct packet_ring_buffer {
0060     struct pgv      *pg_vec;
0061 
0062     unsigned int        head;
0063     unsigned int        frames_per_block;
0064     unsigned int        frame_size;
0065     unsigned int        frame_max;
0066 
0067     unsigned int        pg_vec_order;
0068     unsigned int        pg_vec_pages;
0069     unsigned int        pg_vec_len;
0070 
0071     unsigned int __percpu   *pending_refcnt;
0072 
0073     union {
0074         unsigned long           *rx_owner_map;
0075         struct tpacket_kbdq_core    prb_bdqc;
0076     };
0077 };
0078 
0079 extern struct mutex fanout_mutex;
0080 #define PACKET_FANOUT_MAX   (1 << 16)
0081 
0082 struct packet_fanout {
0083     possible_net_t      net;
0084     unsigned int        num_members;
0085     u32         max_num_members;
0086     u16         id;
0087     u8          type;
0088     u8          flags;
0089     union {
0090         atomic_t        rr_cur;
0091         struct bpf_prog __rcu   *bpf_prog;
0092     };
0093     struct list_head    list;
0094     spinlock_t      lock;
0095     refcount_t      sk_ref;
0096     struct packet_type  prot_hook ____cacheline_aligned_in_smp;
0097     struct sock __rcu   *arr[];
0098 };
0099 
0100 struct packet_rollover {
0101     int         sock;
0102     atomic_long_t       num;
0103     atomic_long_t       num_huge;
0104     atomic_long_t       num_failed;
0105 #define ROLLOVER_HLEN   (L1_CACHE_BYTES / sizeof(u32))
0106     u32         history[ROLLOVER_HLEN] ____cacheline_aligned;
0107 } ____cacheline_aligned_in_smp;
0108 
0109 struct packet_sock {
0110     /* struct sock has to be the first member of packet_sock */
0111     struct sock     sk;
0112     struct packet_fanout    *fanout;
0113     union  tpacket_stats_u  stats;
0114     struct packet_ring_buffer   rx_ring;
0115     struct packet_ring_buffer   tx_ring;
0116     int         copy_thresh;
0117     spinlock_t      bind_lock;
0118     struct mutex        pg_vec_lock;
0119     unsigned int        running;    /* bind_lock must be held */
0120     unsigned int        auxdata:1,  /* writer must hold sock lock */
0121                 origdev:1,
0122                 has_vnet_hdr:1,
0123                 tp_loss:1,
0124                 tp_tx_has_off:1;
0125     int         pressure;
0126     int         ifindex;    /* bound device     */
0127     __be16          num;
0128     struct packet_rollover  *rollover;
0129     struct packet_mclist    *mclist;
0130     atomic_t        mapped;
0131     enum tpacket_versions   tp_version;
0132     unsigned int        tp_hdrlen;
0133     unsigned int        tp_reserve;
0134     unsigned int        tp_tstamp;
0135     struct completion   skb_completion;
0136     struct net_device __rcu *cached_dev;
0137     int         (*xmit)(struct sk_buff *skb);
0138     struct packet_type  prot_hook ____cacheline_aligned_in_smp;
0139     atomic_t        tp_drops ____cacheline_aligned_in_smp;
0140 };
0141 
0142 static inline struct packet_sock *pkt_sk(struct sock *sk)
0143 {
0144     return (struct packet_sock *)sk;
0145 }
0146 
0147 #endif