0001
0002 #ifndef __LINUX_IF_PACKET_H
0003 #define __LINUX_IF_PACKET_H
0004
0005 #include <asm/byteorder.h>
0006 #include <linux/types.h>
0007
0008 struct sockaddr_pkt {
0009 unsigned short spkt_family;
0010 unsigned char spkt_device[14];
0011 __be16 spkt_protocol;
0012 };
0013
0014 struct sockaddr_ll {
0015 unsigned short sll_family;
0016 __be16 sll_protocol;
0017 int sll_ifindex;
0018 unsigned short sll_hatype;
0019 unsigned char sll_pkttype;
0020 unsigned char sll_halen;
0021 unsigned char sll_addr[8];
0022 };
0023
0024
0025
0026 #define PACKET_HOST 0
0027 #define PACKET_BROADCAST 1
0028 #define PACKET_MULTICAST 2
0029 #define PACKET_OTHERHOST 3
0030 #define PACKET_OUTGOING 4
0031 #define PACKET_LOOPBACK 5
0032 #define PACKET_USER 6
0033 #define PACKET_KERNEL 7
0034
0035 #define PACKET_FASTROUTE 6
0036
0037
0038
0039 #define PACKET_ADD_MEMBERSHIP 1
0040 #define PACKET_DROP_MEMBERSHIP 2
0041 #define PACKET_RECV_OUTPUT 3
0042
0043 #define PACKET_RX_RING 5
0044 #define PACKET_STATISTICS 6
0045 #define PACKET_COPY_THRESH 7
0046 #define PACKET_AUXDATA 8
0047 #define PACKET_ORIGDEV 9
0048 #define PACKET_VERSION 10
0049 #define PACKET_HDRLEN 11
0050 #define PACKET_RESERVE 12
0051 #define PACKET_TX_RING 13
0052 #define PACKET_LOSS 14
0053 #define PACKET_VNET_HDR 15
0054 #define PACKET_TX_TIMESTAMP 16
0055 #define PACKET_TIMESTAMP 17
0056 #define PACKET_FANOUT 18
0057 #define PACKET_TX_HAS_OFF 19
0058 #define PACKET_QDISC_BYPASS 20
0059 #define PACKET_ROLLOVER_STATS 21
0060 #define PACKET_FANOUT_DATA 22
0061 #define PACKET_IGNORE_OUTGOING 23
0062
0063 #define PACKET_FANOUT_HASH 0
0064 #define PACKET_FANOUT_LB 1
0065 #define PACKET_FANOUT_CPU 2
0066 #define PACKET_FANOUT_ROLLOVER 3
0067 #define PACKET_FANOUT_RND 4
0068 #define PACKET_FANOUT_QM 5
0069 #define PACKET_FANOUT_CBPF 6
0070 #define PACKET_FANOUT_EBPF 7
0071 #define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
0072 #define PACKET_FANOUT_FLAG_UNIQUEID 0x2000
0073 #define PACKET_FANOUT_FLAG_DEFRAG 0x8000
0074
0075 struct tpacket_stats {
0076 unsigned int tp_packets;
0077 unsigned int tp_drops;
0078 };
0079
0080 struct tpacket_stats_v3 {
0081 unsigned int tp_packets;
0082 unsigned int tp_drops;
0083 unsigned int tp_freeze_q_cnt;
0084 };
0085
0086 struct tpacket_rollover_stats {
0087 __aligned_u64 tp_all;
0088 __aligned_u64 tp_huge;
0089 __aligned_u64 tp_failed;
0090 };
0091
0092 union tpacket_stats_u {
0093 struct tpacket_stats stats1;
0094 struct tpacket_stats_v3 stats3;
0095 };
0096
0097 struct tpacket_auxdata {
0098 __u32 tp_status;
0099 __u32 tp_len;
0100 __u32 tp_snaplen;
0101 __u16 tp_mac;
0102 __u16 tp_net;
0103 __u16 tp_vlan_tci;
0104 __u16 tp_vlan_tpid;
0105 };
0106
0107
0108 #define TP_STATUS_KERNEL 0
0109 #define TP_STATUS_USER (1 << 0)
0110 #define TP_STATUS_COPY (1 << 1)
0111 #define TP_STATUS_LOSING (1 << 2)
0112 #define TP_STATUS_CSUMNOTREADY (1 << 3)
0113 #define TP_STATUS_VLAN_VALID (1 << 4)
0114 #define TP_STATUS_BLK_TMO (1 << 5)
0115 #define TP_STATUS_VLAN_TPID_VALID (1 << 6)
0116 #define TP_STATUS_CSUM_VALID (1 << 7)
0117
0118
0119 #define TP_STATUS_AVAILABLE 0
0120 #define TP_STATUS_SEND_REQUEST (1 << 0)
0121 #define TP_STATUS_SENDING (1 << 1)
0122 #define TP_STATUS_WRONG_FORMAT (1 << 2)
0123
0124
0125 #define TP_STATUS_TS_SOFTWARE (1 << 29)
0126 #define TP_STATUS_TS_SYS_HARDWARE (1 << 30)
0127 #define TP_STATUS_TS_RAW_HARDWARE (1U << 31)
0128
0129
0130 #define TP_FT_REQ_FILL_RXHASH 0x1
0131
0132 struct tpacket_hdr {
0133 unsigned long tp_status;
0134 unsigned int tp_len;
0135 unsigned int tp_snaplen;
0136 unsigned short tp_mac;
0137 unsigned short tp_net;
0138 unsigned int tp_sec;
0139 unsigned int tp_usec;
0140 };
0141
0142 #define TPACKET_ALIGNMENT 16
0143 #define TPACKET_ALIGN(x) (((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1))
0144 #define TPACKET_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + sizeof(struct sockaddr_ll))
0145
0146 struct tpacket2_hdr {
0147 __u32 tp_status;
0148 __u32 tp_len;
0149 __u32 tp_snaplen;
0150 __u16 tp_mac;
0151 __u16 tp_net;
0152 __u32 tp_sec;
0153 __u32 tp_nsec;
0154 __u16 tp_vlan_tci;
0155 __u16 tp_vlan_tpid;
0156 __u8 tp_padding[4];
0157 };
0158
0159 struct tpacket_hdr_variant1 {
0160 __u32 tp_rxhash;
0161 __u32 tp_vlan_tci;
0162 __u16 tp_vlan_tpid;
0163 __u16 tp_padding;
0164 };
0165
0166 struct tpacket3_hdr {
0167 __u32 tp_next_offset;
0168 __u32 tp_sec;
0169 __u32 tp_nsec;
0170 __u32 tp_snaplen;
0171 __u32 tp_len;
0172 __u32 tp_status;
0173 __u16 tp_mac;
0174 __u16 tp_net;
0175
0176 union {
0177 struct tpacket_hdr_variant1 hv1;
0178 };
0179 __u8 tp_padding[8];
0180 };
0181
0182 struct tpacket_bd_ts {
0183 unsigned int ts_sec;
0184 union {
0185 unsigned int ts_usec;
0186 unsigned int ts_nsec;
0187 };
0188 };
0189
0190 struct tpacket_hdr_v1 {
0191 __u32 block_status;
0192 __u32 num_pkts;
0193 __u32 offset_to_first_pkt;
0194
0195
0196
0197
0198 __u32 blk_len;
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209 __aligned_u64 seq_num;
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236 struct tpacket_bd_ts ts_first_pkt, ts_last_pkt;
0237 };
0238
0239 union tpacket_bd_header_u {
0240 struct tpacket_hdr_v1 bh1;
0241 };
0242
0243 struct tpacket_block_desc {
0244 __u32 version;
0245 __u32 offset_to_priv;
0246 union tpacket_bd_header_u hdr;
0247 };
0248
0249 #define TPACKET2_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll))
0250 #define TPACKET3_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket3_hdr)) + sizeof(struct sockaddr_ll))
0251
0252 enum tpacket_versions {
0253 TPACKET_V1,
0254 TPACKET_V2,
0255 TPACKET_V3
0256 };
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271 struct tpacket_req {
0272 unsigned int tp_block_size;
0273 unsigned int tp_block_nr;
0274 unsigned int tp_frame_size;
0275 unsigned int tp_frame_nr;
0276 };
0277
0278 struct tpacket_req3 {
0279 unsigned int tp_block_size;
0280 unsigned int tp_block_nr;
0281 unsigned int tp_frame_size;
0282 unsigned int tp_frame_nr;
0283 unsigned int tp_retire_blk_tov;
0284 unsigned int tp_sizeof_priv;
0285 unsigned int tp_feature_req_word;
0286 };
0287
0288 union tpacket_req_u {
0289 struct tpacket_req req;
0290 struct tpacket_req3 req3;
0291 };
0292
0293 struct packet_mreq {
0294 int mr_ifindex;
0295 unsigned short mr_type;
0296 unsigned short mr_alen;
0297 unsigned char mr_address[8];
0298 };
0299
0300 struct fanout_args {
0301 #if defined(__LITTLE_ENDIAN_BITFIELD)
0302 __u16 id;
0303 __u16 type_flags;
0304 #else
0305 __u16 type_flags;
0306 __u16 id;
0307 #endif
0308 __u32 max_num_members;
0309 };
0310
0311 #define PACKET_MR_MULTICAST 0
0312 #define PACKET_MR_PROMISC 1
0313 #define PACKET_MR_ALLMULTI 2
0314 #define PACKET_MR_UNICAST 3
0315
0316 #endif