| Nicholas Flintham | 1e3d311 | 2013-04-10 10:48:38 +0100 | [diff] [blame^] | 1 | #ifndef __LINUX_IF_PACKET_H |
| 2 | #define __LINUX_IF_PACKET_H |
| 3 | |
| 4 | #include <linux/types.h> |
| 5 | |
| 6 | struct sockaddr_pkt { |
| 7 | unsigned short spkt_family; |
| 8 | unsigned char spkt_device[14]; |
| 9 | __be16 spkt_protocol; |
| 10 | }; |
| 11 | |
| 12 | struct sockaddr_ll { |
| 13 | unsigned short sll_family; |
| 14 | __be16 sll_protocol; |
| 15 | int sll_ifindex; |
| 16 | unsigned short sll_hatype; |
| 17 | unsigned char sll_pkttype; |
| 18 | unsigned char sll_halen; |
| 19 | unsigned char sll_addr[8]; |
| 20 | }; |
| 21 | |
| 22 | |
| 23 | #define PACKET_HOST 0 |
| 24 | #define PACKET_BROADCAST 1 |
| 25 | #define PACKET_MULTICAST 2 |
| 26 | #define PACKET_OTHERHOST 3 |
| 27 | #define PACKET_OUTGOING 4 |
| 28 | #define PACKET_LOOPBACK 5 |
| 29 | #define PACKET_FASTROUTE 6 |
| 30 | |
| 31 | |
| 32 | #define PACKET_ADD_MEMBERSHIP 1 |
| 33 | #define PACKET_DROP_MEMBERSHIP 2 |
| 34 | #define PACKET_RECV_OUTPUT 3 |
| 35 | #define PACKET_RX_RING 5 |
| 36 | #define PACKET_STATISTICS 6 |
| 37 | #define PACKET_COPY_THRESH 7 |
| 38 | #define PACKET_AUXDATA 8 |
| 39 | #define PACKET_ORIGDEV 9 |
| 40 | #define PACKET_VERSION 10 |
| 41 | #define PACKET_HDRLEN 11 |
| 42 | #define PACKET_RESERVE 12 |
| 43 | #define PACKET_TX_RING 13 |
| 44 | #define PACKET_LOSS 14 |
| 45 | #define PACKET_VNET_HDR 15 |
| 46 | #define PACKET_TX_TIMESTAMP 16 |
| 47 | #define PACKET_TIMESTAMP 17 |
| 48 | #define PACKET_FANOUT 18 |
| 49 | |
| 50 | #define PACKET_FANOUT_HASH 0 |
| 51 | #define PACKET_FANOUT_LB 1 |
| 52 | #define PACKET_FANOUT_CPU 2 |
| 53 | #define PACKET_FANOUT_FLAG_DEFRAG 0x8000 |
| 54 | |
| 55 | struct tpacket_stats { |
| 56 | unsigned int tp_packets; |
| 57 | unsigned int tp_drops; |
| 58 | }; |
| 59 | |
| 60 | struct tpacket_stats_v3 { |
| 61 | unsigned int tp_packets; |
| 62 | unsigned int tp_drops; |
| 63 | unsigned int tp_freeze_q_cnt; |
| 64 | }; |
| 65 | |
| 66 | union tpacket_stats_u { |
| 67 | struct tpacket_stats stats1; |
| 68 | struct tpacket_stats_v3 stats3; |
| 69 | }; |
| 70 | |
| 71 | struct tpacket_auxdata { |
| 72 | __u32 tp_status; |
| 73 | __u32 tp_len; |
| 74 | __u32 tp_snaplen; |
| 75 | __u16 tp_mac; |
| 76 | __u16 tp_net; |
| 77 | __u16 tp_vlan_tci; |
| 78 | __u16 tp_padding; |
| 79 | }; |
| 80 | |
| 81 | #define TP_STATUS_KERNEL 0x0 |
| 82 | #define TP_STATUS_USER 0x1 |
| 83 | #define TP_STATUS_COPY 0x2 |
| 84 | #define TP_STATUS_LOSING 0x4 |
| 85 | #define TP_STATUS_CSUMNOTREADY 0x8 |
| 86 | #define TP_STATUS_VLAN_VALID 0x10 |
| 87 | #define TP_STATUS_BLK_TMO 0x20 |
| 88 | |
| 89 | #define TP_STATUS_AVAILABLE 0x0 |
| 90 | #define TP_STATUS_SEND_REQUEST 0x1 |
| 91 | #define TP_STATUS_SENDING 0x2 |
| 92 | #define TP_STATUS_WRONG_FORMAT 0x4 |
| 93 | |
| 94 | #define TP_FT_REQ_FILL_RXHASH 0x1 |
| 95 | |
| 96 | struct tpacket_hdr { |
| 97 | unsigned long tp_status; |
| 98 | unsigned int tp_len; |
| 99 | unsigned int tp_snaplen; |
| 100 | unsigned short tp_mac; |
| 101 | unsigned short tp_net; |
| 102 | unsigned int tp_sec; |
| 103 | unsigned int tp_usec; |
| 104 | }; |
| 105 | |
| 106 | #define TPACKET_ALIGNMENT 16 |
| 107 | #define TPACKET_ALIGN(x) (((x)+TPACKET_ALIGNMENT-1)&~(TPACKET_ALIGNMENT-1)) |
| 108 | #define TPACKET_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket_hdr)) + sizeof(struct sockaddr_ll)) |
| 109 | |
| 110 | struct tpacket2_hdr { |
| 111 | __u32 tp_status; |
| 112 | __u32 tp_len; |
| 113 | __u32 tp_snaplen; |
| 114 | __u16 tp_mac; |
| 115 | __u16 tp_net; |
| 116 | __u32 tp_sec; |
| 117 | __u32 tp_nsec; |
| 118 | __u16 tp_vlan_tci; |
| 119 | __u16 tp_padding; |
| 120 | }; |
| 121 | |
| 122 | struct tpacket_hdr_variant1 { |
| 123 | __u32 tp_rxhash; |
| 124 | __u32 tp_vlan_tci; |
| 125 | }; |
| 126 | |
| 127 | struct tpacket3_hdr { |
| 128 | __u32 tp_next_offset; |
| 129 | __u32 tp_sec; |
| 130 | __u32 tp_nsec; |
| 131 | __u32 tp_snaplen; |
| 132 | __u32 tp_len; |
| 133 | __u32 tp_status; |
| 134 | __u16 tp_mac; |
| 135 | __u16 tp_net; |
| 136 | |
| 137 | union { |
| 138 | struct tpacket_hdr_variant1 hv1; |
| 139 | }; |
| 140 | }; |
| 141 | |
| 142 | struct tpacket_bd_ts { |
| 143 | unsigned int ts_sec; |
| 144 | union { |
| 145 | unsigned int ts_usec; |
| 146 | unsigned int ts_nsec; |
| 147 | }; |
| 148 | }; |
| 149 | |
| 150 | struct tpacket_hdr_v1 { |
| 151 | __u32 block_status; |
| 152 | __u32 num_pkts; |
| 153 | __u32 offset_to_first_pkt; |
| 154 | |
| 155 | __u32 blk_len; |
| 156 | |
| 157 | __aligned_u64 seq_num; |
| 158 | |
| 159 | struct tpacket_bd_ts ts_first_pkt, ts_last_pkt; |
| 160 | }; |
| 161 | |
| 162 | union tpacket_bd_header_u { |
| 163 | struct tpacket_hdr_v1 bh1; |
| 164 | }; |
| 165 | |
| 166 | struct tpacket_block_desc { |
| 167 | __u32 version; |
| 168 | __u32 offset_to_priv; |
| 169 | union tpacket_bd_header_u hdr; |
| 170 | }; |
| 171 | |
| 172 | #define TPACKET2_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket2_hdr)) + sizeof(struct sockaddr_ll)) |
| 173 | #define TPACKET3_HDRLEN (TPACKET_ALIGN(sizeof(struct tpacket3_hdr)) + sizeof(struct sockaddr_ll)) |
| 174 | |
| 175 | enum tpacket_versions { |
| 176 | TPACKET_V1, |
| 177 | TPACKET_V2, |
| 178 | TPACKET_V3 |
| 179 | }; |
| 180 | |
| 181 | |
| 182 | struct tpacket_req { |
| 183 | unsigned int tp_block_size; |
| 184 | unsigned int tp_block_nr; |
| 185 | unsigned int tp_frame_size; |
| 186 | unsigned int tp_frame_nr; |
| 187 | }; |
| 188 | |
| 189 | struct tpacket_req3 { |
| 190 | unsigned int tp_block_size; |
| 191 | unsigned int tp_block_nr; |
| 192 | unsigned int tp_frame_size; |
| 193 | unsigned int tp_frame_nr; |
| 194 | unsigned int tp_retire_blk_tov; |
| 195 | unsigned int tp_sizeof_priv; |
| 196 | unsigned int tp_feature_req_word; |
| 197 | }; |
| 198 | |
| 199 | union tpacket_req_u { |
| 200 | struct tpacket_req req; |
| 201 | struct tpacket_req3 req3; |
| 202 | }; |
| 203 | |
| 204 | struct packet_mreq { |
| 205 | int mr_ifindex; |
| 206 | unsigned short mr_type; |
| 207 | unsigned short mr_alen; |
| 208 | unsigned char mr_address[8]; |
| 209 | }; |
| 210 | |
| 211 | #define PACKET_MR_MULTICAST 0 |
| 212 | #define PACKET_MR_PROMISC 1 |
| 213 | #define PACKET_MR_ALLMULTI 2 |
| 214 | #define PACKET_MR_UNICAST 3 |
| 215 | |
| 216 | #endif |