Coverage Report

Created: 2026-11-20 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qemu/include/net/eth.h
Line
Count
Source
1
/*
2
 * QEMU network structures definitions and helper functions
3
 *
4
 * Copyright (c) 2012 Ravello Systems LTD (http://ravellosystems.com)
5
 *
6
 * Developed by Daynix Computing LTD (http://www.daynix.com)
7
 *
8
 * Portions developed by Free Software Foundation, Inc
9
 * Copyright (C) 1991-1997, 2001, 2003, 2006 Free Software Foundation, Inc.
10
 * See netinet/ip6.h and netinet/in.h (GNU C Library)
11
 *
12
 * Portions developed by Igor Kovalenko
13
 * Copyright (c) 2006 Igor Kovalenko
14
 * See hw/rtl8139.c (QEMU)
15
 *
16
 * Authors:
17
 * Dmitry Fleytman <dmitry@daynix.com>
18
 * Tamir Shomer <tamirs@daynix.com>
19
 * Yan Vugenfirer <yan@daynix.com>
20
 *
21
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
22
 * See the COPYING file in the top-level directory.
23
 *
24
 */
25
26
#ifndef QEMU_ETH_H
27
#define QEMU_ETH_H
28
29
#include "qemu/bswap.h"
30
#include "qemu/iov.h"
31
32
6.93M
#define ETH_ALEN 6
33
0
#define ETH_HLEN 14
34
1.31M
#define ETH_ZLEN 60     /* Min. octets in frame without FCS */
35
0
#define ETH_FCS_LEN 4
36
0
#define ETH_MTU 1500
37
38
struct eth_header {
39
    uint8_t  h_dest[ETH_ALEN];   /* destination eth addr */
40
    uint8_t  h_source[ETH_ALEN]; /* source ether addr    */
41
    uint16_t h_proto;            /* packet type ID field */
42
} QEMU_PACKED;
43
44
struct vlan_header {
45
    uint16_t  h_tci;     /* priority and VLAN ID  */
46
    uint16_t  h_proto;   /* encapsulated protocol */
47
};
48
49
struct ip_header {
50
    uint8_t  ip_ver_len;     /* version and header length */
51
    uint8_t  ip_tos;         /* type of service */
52
    uint16_t ip_len;         /* total length */
53
    uint16_t ip_id;          /* identification */
54
    uint16_t ip_off;         /* fragment offset field */
55
    uint8_t  ip_ttl;         /* time to live */
56
    uint8_t  ip_p;           /* protocol */
57
    uint16_t ip_sum;         /* checksum */
58
    uint32_t ip_src, ip_dst; /* source and destination address */
59
} QEMU_PACKED;
60
61
typedef struct tcp_header {
62
    uint16_t th_sport;          /* source port */
63
    uint16_t th_dport;          /* destination port */
64
    uint32_t th_seq;            /* sequence number */
65
    uint32_t th_ack;            /* acknowledgment number */
66
    uint16_t th_offset_flags;   /* data offset, reserved 6 bits, */
67
                                /* TCP protocol flags */
68
    uint16_t th_win;            /* window */
69
    uint16_t th_sum;            /* checksum */
70
    uint16_t th_urp;            /* urgent pointer */
71
} QEMU_PACKED tcp_header;
72
73
0
#define TCP_FLAGS_ONLY(flags) ((flags) & 0x3f)
74
75
#define TCP_HEADER_FLAGS(tcp) \
76
0
    TCP_FLAGS_ONLY(be16_to_cpu((tcp)->th_offset_flags))
77
78
0
#define TCP_FLAG_ACK  0x10
79
80
#define TCP_HEADER_DATA_OFFSET(tcp) \
81
0
    (((be16_to_cpu((tcp)->th_offset_flags) >> 12) & 0xf) << 2)
82
83
typedef struct udp_header {
84
    uint16_t uh_sport; /* source port */
85
    uint16_t uh_dport; /* destination port */
86
    uint16_t uh_ulen;  /* udp length */
87
    uint16_t uh_sum;   /* udp checksum */
88
} QEMU_PACKED udp_header;
89
90
typedef struct ip_pseudo_header {
91
    uint32_t ip_src;
92
    uint32_t ip_dst;
93
    uint8_t  zeros;
94
    uint8_t  ip_proto;
95
    uint16_t ip_payload;
96
} ip_pseudo_header;
97
98
/* IPv6 address */
99
struct in6_address {
100
    union {
101
        uint8_t __u6_addr8[16];
102
    } __in6_u;
103
};
104
105
struct ip6_header {
106
    union {
107
        struct ip6_hdrctl {
108
            uint32_t ip6_un1_flow; /* 4 bits version, 8 bits TC,
109
                                      20 bits flow-ID */
110
            uint16_t ip6_un1_plen; /* payload length */
111
            uint8_t  ip6_un1_nxt;  /* next header */
112
            uint8_t  ip6_un1_hlim; /* hop limit */
113
        } ip6_un1;
114
        uint8_t ip6_un2_vfc;       /* 4 bits version, top 4 bits tclass */
115
        struct ip6_ecn_access {
116
            uint8_t  ip6_un3_vfc;  /* 4 bits version, top 4 bits tclass */
117
            uint8_t  ip6_un3_ecn;  /* 2 bits ECN, top 6 bits payload length */
118
        } ip6_un3;
119
    } ip6_ctlun;
120
    struct in6_address ip6_src;    /* source address */
121
    struct in6_address ip6_dst;    /* destination address */
122
} QEMU_PACKED;
123
124
typedef struct ip6_pseudo_header {
125
    struct in6_address ip6_src;
126
    struct in6_address ip6_dst;
127
    uint32_t           len;
128
    uint8_t            zero[3];
129
    uint8_t            next_hdr;
130
} ip6_pseudo_header;
131
132
struct ip6_ext_hdr {
133
    uint8_t        ip6r_nxt;   /* next header */
134
    uint8_t        ip6r_len;   /* length in units of 8 octets */
135
};
136
137
struct ip6_ext_hdr_routing {
138
    uint8_t     nxt;
139
    uint8_t     len;
140
    uint8_t     rtype;
141
    uint8_t     segleft;
142
    uint8_t     rsvd[4];
143
};
144
145
struct ip6_option_hdr {
146
0
#define IP6_OPT_PAD1   (0x00)
147
0
#define IP6_OPT_HOME   (0xC9)
148
    uint8_t type;
149
    uint8_t len;
150
};
151
152
struct udp_hdr {
153
  uint16_t uh_sport;           /* source port */
154
  uint16_t uh_dport;           /* destination port */
155
  uint16_t uh_ulen;            /* udp length */
156
  uint16_t uh_sum;             /* udp checksum */
157
};
158
159
struct tcp_hdr {
160
    u_short     th_sport;   /* source port */
161
    u_short     th_dport;   /* destination port */
162
    uint32_t    th_seq;     /* sequence number */
163
    uint32_t    th_ack;     /* acknowledgment number */
164
#if HOST_BIG_ENDIAN
165
    u_char  th_off : 4,     /* data offset */
166
        th_x2:4;            /* (unused) */
167
#else
168
    u_char  th_x2 : 4,      /* (unused) */
169
        th_off:4;           /* data offset */
170
#endif
171
172
#define TH_ELN  0x1 /* explicit loss notification */
173
#define TH_ECN  0x2 /* explicit congestion notification */
174
#define TH_FS   0x4 /* fast start */
175
176
    u_char  th_flags;
177
0
#define TH_FIN  0x01
178
0
#define TH_SYN  0x02
179
0
#define TH_RST  0x04
180
0
#define TH_PUSH 0x08
181
0
#define TH_ACK  0x10
182
0
#define TH_URG  0x20
183
0
#define TH_ECE  0x40
184
0
#define TH_CWR  0x80
185
    u_short th_win;      /* window */
186
    u_short th_sum;      /* checksum */
187
    u_short th_urp;      /* urgent pointer */
188
};
189
190
0
#define ip6_nxt      ip6_ctlun.ip6_un1.ip6_un1_nxt
191
#define ip6_ecn_acc  ip6_ctlun.ip6_un3.ip6_un3_ecn
192
0
#define ip6_plen     ip6_ctlun.ip6_un1.ip6_un1_plen
193
194
#define PKT_GET_ETH_HDR(p)        \
195
0
    ((struct eth_header *)(p))
196
#define PKT_GET_VLAN_HDR(p)       \
197
0
    ((struct vlan_header *) (((uint8_t *)(p)) + sizeof(struct eth_header)))
198
#define PKT_GET_DVLAN_HDR(p)       \
199
    (PKT_GET_VLAN_HDR(p) + 1)
200
#define PKT_GET_IP_HDR(p)         \
201
0
    ((struct ip_header *)(((uint8_t *)(p)) + eth_get_l2_hdr_length(p)))
202
#define IP_HDR_GET_LEN(p)         \
203
0
    ((ldub_p(p + offsetof(struct ip_header, ip_ver_len)) & 0x0F) << 2)
204
#define IP_HDR_GET_P(p)                                           \
205
0
    (ldub_p(p + offsetof(struct ip_header, ip_p)))
206
#define PKT_GET_IP_HDR_LEN(p)     \
207
0
    (IP_HDR_GET_LEN(PKT_GET_IP_HDR(p)))
208
#define PKT_GET_IP6_HDR(p)        \
209
    ((struct ip6_header *) (((uint8_t *)(p)) + eth_get_l2_hdr_length(p)))
210
#define IP_HEADER_VERSION(ip)     \
211
0
    (((ip)->ip_ver_len >> 4) & 0xf)
212
#define IP4_IS_FRAGMENT(ip) \
213
0
    ((be16_to_cpu((ip)->ip_off) & (IP_OFFMASK | IP_MF)) != 0)
214
215
0
#define ETH_P_IP                  (0x0800)      /* Internet Protocol packet  */
216
#define ETH_P_ARP                 (0x0806)      /* Address Resolution packet */
217
0
#define ETH_P_IPV6                (0x86dd)
218
249
#define ETH_P_VLAN                (0x8100)
219
0
#define ETH_P_DVLAN               (0x88a8)
220
#define ETH_P_NCSI                (0x88f8)
221
0
#define ETH_P_UNKNOWN             (0xffff)
222
0
#define VLAN_VID_MASK             0x0fff
223
0
#define IP_HEADER_VERSION_4       (4)
224
0
#define IP_HEADER_VERSION_6       (6)
225
0
#define IP_PROTO_TCP              (6)
226
0
#define IP_PROTO_UDP              (17)
227
0
#define IP_PROTO_SCTP             (132)
228
0
#define IPTOS_ECN_MASK            0x03
229
0
#define IPTOS_ECN(x)              ((x) & IPTOS_ECN_MASK)
230
0
#define IPTOS_ECN_CE              0x03
231
0
#define IP6_ECN_MASK              0xC0
232
0
#define IP6_ECN(x)                ((x) & IP6_ECN_MASK)
233
0
#define IP6_ECN_CE                0xC0
234
#define IP4_DONT_FRAGMENT_FLAG    (1 << 14)
235
236
#define IS_SPECIAL_VLAN_ID(x)     \
237
0
    (((x) == 0) || ((x) == 0xFFF))
238
239
#define ETH_MAX_L2_HDR_LEN  \
240
0
    (sizeof(struct eth_header) + 2 * sizeof(struct vlan_header))
241
242
#define ETH_MAX_IP4_HDR_LEN   (60)
243
0
#define ETH_MAX_IP_DGRAM_LEN  (0xFFFF)
244
245
0
#define IP_FRAG_UNIT_SIZE     (8)
246
0
#define IP_FRAG_ALIGN_SIZE(x) ((x) & ~0x7)
247
#define IP_RF                 0x8000           /* reserved fragment flag */
248
0
#define IP_DF                 0x4000           /* don't fragment flag */
249
0
#define IP_MF                 0x2000           /* more fragments flag */
250
0
#define IP_OFFMASK            0x1fff           /* mask for fragmenting bits */
251
252
0
#define IP6_EXT_GRANULARITY   (8)  /* Size granularity for
253
                                      IPv6 extension headers */
254
255
/* IP6 extension header types */
256
0
#define IP6_HOP_BY_HOP        (0)
257
0
#define IP6_ROUTING           (43)
258
0
#define IP6_FRAGMENT          (44)
259
#define IP6_ESP               (50)
260
0
#define IP6_AUTHENTICATION    (51)
261
#define IP6_NONE              (59)
262
0
#define IP6_DESTINATON        (60)
263
0
#define IP6_MOBILITY          (135)
264
265
static inline int is_multicast_ether_addr(const uint8_t *addr)
266
0
{
267
0
    return 0x01 & addr[0];
268
0
}
Unexecuted instantiation: colo.c:is_multicast_ether_addr
Unexecuted instantiation: checksum.c:is_multicast_ether_addr
Unexecuted instantiation: eth.c:is_multicast_ether_addr
Unexecuted instantiation: filter.c:is_multicast_ether_addr
Unexecuted instantiation: net.c:is_multicast_ether_addr
Unexecuted instantiation: colo-compare.c:is_multicast_ether_addr
Unexecuted instantiation: filter-rewriter.c:is_multicast_ether_addr
Unexecuted instantiation: slirp.c:is_multicast_ether_addr
Unexecuted instantiation: tap.c:is_multicast_ether_addr
Unexecuted instantiation: syndbg.c:is_multicast_ether_addr
Unexecuted instantiation: ne2000.c:is_multicast_ether_addr
Unexecuted instantiation: eepro100.c:is_multicast_ether_addr
Unexecuted instantiation: pcnet.c:is_multicast_ether_addr
Unexecuted instantiation: e1000.c:is_multicast_ether_addr
Unexecuted instantiation: e1000x_common.c:is_multicast_ether_addr
Unexecuted instantiation: net_tx_pkt.c:is_multicast_ether_addr
Unexecuted instantiation: net_rx_pkt.c:is_multicast_ether_addr
Unexecuted instantiation: e1000e.c:is_multicast_ether_addr
Unexecuted instantiation: e1000e_core.c:is_multicast_ether_addr
Unexecuted instantiation: igb.c:is_multicast_ether_addr
Unexecuted instantiation: igbvf.c:is_multicast_ether_addr
Unexecuted instantiation: igb_core.c:is_multicast_ether_addr
Unexecuted instantiation: rtl8139.c:is_multicast_ether_addr
Unexecuted instantiation: tulip.c:is_multicast_ether_addr
Unexecuted instantiation: vmxnet3.c:is_multicast_ether_addr
Unexecuted instantiation: virtio-net.c:is_multicast_ether_addr
Unexecuted instantiation: rocker.c:is_multicast_ether_addr
Unexecuted instantiation: rocker_of_dpa.c:is_multicast_ether_addr
Unexecuted instantiation: rocker-hmp-cmds.c:is_multicast_ether_addr
269
270
static inline int is_broadcast_ether_addr(const uint8_t *addr)
271
0
{
272
0
    return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff;
273
0
}
Unexecuted instantiation: colo.c:is_broadcast_ether_addr
Unexecuted instantiation: checksum.c:is_broadcast_ether_addr
Unexecuted instantiation: eth.c:is_broadcast_ether_addr
Unexecuted instantiation: filter.c:is_broadcast_ether_addr
Unexecuted instantiation: net.c:is_broadcast_ether_addr
Unexecuted instantiation: colo-compare.c:is_broadcast_ether_addr
Unexecuted instantiation: filter-rewriter.c:is_broadcast_ether_addr
Unexecuted instantiation: slirp.c:is_broadcast_ether_addr
Unexecuted instantiation: tap.c:is_broadcast_ether_addr
Unexecuted instantiation: syndbg.c:is_broadcast_ether_addr
Unexecuted instantiation: ne2000.c:is_broadcast_ether_addr
Unexecuted instantiation: eepro100.c:is_broadcast_ether_addr
Unexecuted instantiation: pcnet.c:is_broadcast_ether_addr
Unexecuted instantiation: e1000.c:is_broadcast_ether_addr
Unexecuted instantiation: e1000x_common.c:is_broadcast_ether_addr
Unexecuted instantiation: net_tx_pkt.c:is_broadcast_ether_addr
Unexecuted instantiation: net_rx_pkt.c:is_broadcast_ether_addr
Unexecuted instantiation: e1000e.c:is_broadcast_ether_addr
Unexecuted instantiation: e1000e_core.c:is_broadcast_ether_addr
Unexecuted instantiation: igb.c:is_broadcast_ether_addr
Unexecuted instantiation: igbvf.c:is_broadcast_ether_addr
Unexecuted instantiation: igb_core.c:is_broadcast_ether_addr
Unexecuted instantiation: rtl8139.c:is_broadcast_ether_addr
Unexecuted instantiation: tulip.c:is_broadcast_ether_addr
Unexecuted instantiation: vmxnet3.c:is_broadcast_ether_addr
Unexecuted instantiation: virtio-net.c:is_broadcast_ether_addr
Unexecuted instantiation: rocker.c:is_broadcast_ether_addr
Unexecuted instantiation: rocker_of_dpa.c:is_broadcast_ether_addr
Unexecuted instantiation: rocker-hmp-cmds.c:is_broadcast_ether_addr
274
275
static inline int is_unicast_ether_addr(const uint8_t *addr)
276
0
{
277
0
    return !is_multicast_ether_addr(addr);
278
0
}
Unexecuted instantiation: colo.c:is_unicast_ether_addr
Unexecuted instantiation: checksum.c:is_unicast_ether_addr
Unexecuted instantiation: eth.c:is_unicast_ether_addr
Unexecuted instantiation: filter.c:is_unicast_ether_addr
Unexecuted instantiation: net.c:is_unicast_ether_addr
Unexecuted instantiation: colo-compare.c:is_unicast_ether_addr
Unexecuted instantiation: filter-rewriter.c:is_unicast_ether_addr
Unexecuted instantiation: slirp.c:is_unicast_ether_addr
Unexecuted instantiation: tap.c:is_unicast_ether_addr
Unexecuted instantiation: syndbg.c:is_unicast_ether_addr
Unexecuted instantiation: ne2000.c:is_unicast_ether_addr
Unexecuted instantiation: eepro100.c:is_unicast_ether_addr
Unexecuted instantiation: pcnet.c:is_unicast_ether_addr
Unexecuted instantiation: e1000.c:is_unicast_ether_addr
Unexecuted instantiation: e1000x_common.c:is_unicast_ether_addr
Unexecuted instantiation: net_tx_pkt.c:is_unicast_ether_addr
Unexecuted instantiation: net_rx_pkt.c:is_unicast_ether_addr
Unexecuted instantiation: e1000e.c:is_unicast_ether_addr
Unexecuted instantiation: e1000e_core.c:is_unicast_ether_addr
Unexecuted instantiation: igb.c:is_unicast_ether_addr
Unexecuted instantiation: igbvf.c:is_unicast_ether_addr
Unexecuted instantiation: igb_core.c:is_unicast_ether_addr
Unexecuted instantiation: rtl8139.c:is_unicast_ether_addr
Unexecuted instantiation: tulip.c:is_unicast_ether_addr
Unexecuted instantiation: vmxnet3.c:is_unicast_ether_addr
Unexecuted instantiation: virtio-net.c:is_unicast_ether_addr
Unexecuted instantiation: rocker.c:is_unicast_ether_addr
Unexecuted instantiation: rocker_of_dpa.c:is_unicast_ether_addr
Unexecuted instantiation: rocker-hmp-cmds.c:is_unicast_ether_addr
279
280
typedef enum {
281
    ETH_PKT_UCAST = 0xAABBCC00,
282
    ETH_PKT_BCAST,
283
    ETH_PKT_MCAST
284
} eth_pkt_types_e;
285
286
static inline eth_pkt_types_e
287
get_eth_packet_type(const struct eth_header *ehdr)
288
0
{
289
0
    if (is_broadcast_ether_addr(ehdr->h_dest)) {
290
0
        return ETH_PKT_BCAST;
291
0
    } else if (is_multicast_ether_addr(ehdr->h_dest)) {
292
0
        return ETH_PKT_MCAST;
293
0
    } else { /* unicast */
294
0
        return ETH_PKT_UCAST;
295
0
    }
296
0
}
Unexecuted instantiation: colo.c:get_eth_packet_type
Unexecuted instantiation: checksum.c:get_eth_packet_type
Unexecuted instantiation: eth.c:get_eth_packet_type
Unexecuted instantiation: filter.c:get_eth_packet_type
Unexecuted instantiation: net.c:get_eth_packet_type
Unexecuted instantiation: colo-compare.c:get_eth_packet_type
Unexecuted instantiation: filter-rewriter.c:get_eth_packet_type
Unexecuted instantiation: slirp.c:get_eth_packet_type
Unexecuted instantiation: tap.c:get_eth_packet_type
Unexecuted instantiation: syndbg.c:get_eth_packet_type
Unexecuted instantiation: ne2000.c:get_eth_packet_type
Unexecuted instantiation: eepro100.c:get_eth_packet_type
Unexecuted instantiation: pcnet.c:get_eth_packet_type
Unexecuted instantiation: e1000.c:get_eth_packet_type
Unexecuted instantiation: e1000x_common.c:get_eth_packet_type
Unexecuted instantiation: net_tx_pkt.c:get_eth_packet_type
Unexecuted instantiation: net_rx_pkt.c:get_eth_packet_type
Unexecuted instantiation: e1000e.c:get_eth_packet_type
Unexecuted instantiation: e1000e_core.c:get_eth_packet_type
Unexecuted instantiation: igb.c:get_eth_packet_type
Unexecuted instantiation: igbvf.c:get_eth_packet_type
Unexecuted instantiation: igb_core.c:get_eth_packet_type
Unexecuted instantiation: rtl8139.c:get_eth_packet_type
Unexecuted instantiation: tulip.c:get_eth_packet_type
Unexecuted instantiation: vmxnet3.c:get_eth_packet_type
Unexecuted instantiation: virtio-net.c:get_eth_packet_type
Unexecuted instantiation: rocker.c:get_eth_packet_type
Unexecuted instantiation: rocker_of_dpa.c:get_eth_packet_type
Unexecuted instantiation: rocker-hmp-cmds.c:get_eth_packet_type
297
298
static inline uint32_t
299
eth_get_l2_hdr_length(const void *p)
300
0
{
301
0
    uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto);
302
0
    struct vlan_header *hvlan = PKT_GET_VLAN_HDR(p);
303
0
    switch (proto) {
304
0
    case ETH_P_VLAN:
305
0
        return sizeof(struct eth_header) + sizeof(struct vlan_header);
306
0
    case ETH_P_DVLAN:
307
0
        if (be16_to_cpu(hvlan->h_proto) == ETH_P_VLAN) {
308
0
            return sizeof(struct eth_header) + 2 * sizeof(struct vlan_header);
309
0
        } else {
310
0
            return sizeof(struct eth_header) + sizeof(struct vlan_header);
311
0
        }
312
0
    default:
313
0
        return sizeof(struct eth_header);
314
0
    }
315
0
}
Unexecuted instantiation: colo.c:eth_get_l2_hdr_length
Unexecuted instantiation: checksum.c:eth_get_l2_hdr_length
Unexecuted instantiation: eth.c:eth_get_l2_hdr_length
Unexecuted instantiation: filter.c:eth_get_l2_hdr_length
Unexecuted instantiation: net.c:eth_get_l2_hdr_length
Unexecuted instantiation: colo-compare.c:eth_get_l2_hdr_length
Unexecuted instantiation: filter-rewriter.c:eth_get_l2_hdr_length
Unexecuted instantiation: slirp.c:eth_get_l2_hdr_length
Unexecuted instantiation: tap.c:eth_get_l2_hdr_length
Unexecuted instantiation: syndbg.c:eth_get_l2_hdr_length
Unexecuted instantiation: ne2000.c:eth_get_l2_hdr_length
Unexecuted instantiation: eepro100.c:eth_get_l2_hdr_length
Unexecuted instantiation: pcnet.c:eth_get_l2_hdr_length
Unexecuted instantiation: e1000.c:eth_get_l2_hdr_length
Unexecuted instantiation: e1000x_common.c:eth_get_l2_hdr_length
Unexecuted instantiation: net_tx_pkt.c:eth_get_l2_hdr_length
Unexecuted instantiation: net_rx_pkt.c:eth_get_l2_hdr_length
Unexecuted instantiation: e1000e.c:eth_get_l2_hdr_length
Unexecuted instantiation: e1000e_core.c:eth_get_l2_hdr_length
Unexecuted instantiation: igb.c:eth_get_l2_hdr_length
Unexecuted instantiation: igbvf.c:eth_get_l2_hdr_length
Unexecuted instantiation: igb_core.c:eth_get_l2_hdr_length
Unexecuted instantiation: rtl8139.c:eth_get_l2_hdr_length
Unexecuted instantiation: tulip.c:eth_get_l2_hdr_length
Unexecuted instantiation: vmxnet3.c:eth_get_l2_hdr_length
Unexecuted instantiation: virtio-net.c:eth_get_l2_hdr_length
Unexecuted instantiation: rocker.c:eth_get_l2_hdr_length
Unexecuted instantiation: rocker_of_dpa.c:eth_get_l2_hdr_length
Unexecuted instantiation: rocker-hmp-cmds.c:eth_get_l2_hdr_length
316
317
static inline uint32_t
318
eth_get_l2_hdr_length_iov(const struct iovec *iov, size_t iovcnt, size_t iovoff)
319
0
{
320
0
    uint8_t p[sizeof(struct eth_header) + sizeof(struct vlan_header)];
321
0
    size_t copied = iov_to_buf(iov, iovcnt, iovoff, p, ARRAY_SIZE(p));
322
323
0
    if (copied < ARRAY_SIZE(p)) {
324
0
        return MIN(copied, sizeof(struct eth_header));
325
0
    }
326
327
0
    return eth_get_l2_hdr_length(p);
328
0
}
Unexecuted instantiation: colo.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: checksum.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: eth.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: filter.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: net.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: colo-compare.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: filter-rewriter.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: slirp.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: tap.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: syndbg.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: ne2000.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: eepro100.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: pcnet.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: e1000.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: e1000x_common.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: net_tx_pkt.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: net_rx_pkt.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: e1000e.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: e1000e_core.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: igb.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: igbvf.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: igb_core.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: rtl8139.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: tulip.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: vmxnet3.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: virtio-net.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: rocker.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: rocker_of_dpa.c:eth_get_l2_hdr_length_iov
Unexecuted instantiation: rocker-hmp-cmds.c:eth_get_l2_hdr_length_iov
329
330
static inline uint16_t
331
eth_get_pkt_tci(const void *p)
332
0
{
333
0
    uint16_t proto = be16_to_cpu(PKT_GET_ETH_HDR(p)->h_proto);
334
0
    struct vlan_header *hvlan = PKT_GET_VLAN_HDR(p);
335
0
    switch (proto) {
336
0
    case ETH_P_VLAN:
337
0
    case ETH_P_DVLAN:
338
0
        return be16_to_cpu(hvlan->h_tci);
339
0
    default:
340
0
        return 0;
341
0
    }
342
0
}
Unexecuted instantiation: colo.c:eth_get_pkt_tci
Unexecuted instantiation: checksum.c:eth_get_pkt_tci
Unexecuted instantiation: eth.c:eth_get_pkt_tci
Unexecuted instantiation: filter.c:eth_get_pkt_tci
Unexecuted instantiation: net.c:eth_get_pkt_tci
Unexecuted instantiation: colo-compare.c:eth_get_pkt_tci
Unexecuted instantiation: filter-rewriter.c:eth_get_pkt_tci
Unexecuted instantiation: slirp.c:eth_get_pkt_tci
Unexecuted instantiation: tap.c:eth_get_pkt_tci
Unexecuted instantiation: syndbg.c:eth_get_pkt_tci
Unexecuted instantiation: ne2000.c:eth_get_pkt_tci
Unexecuted instantiation: eepro100.c:eth_get_pkt_tci
Unexecuted instantiation: pcnet.c:eth_get_pkt_tci
Unexecuted instantiation: e1000.c:eth_get_pkt_tci
Unexecuted instantiation: e1000x_common.c:eth_get_pkt_tci
Unexecuted instantiation: net_tx_pkt.c:eth_get_pkt_tci
Unexecuted instantiation: net_rx_pkt.c:eth_get_pkt_tci
Unexecuted instantiation: e1000e.c:eth_get_pkt_tci
Unexecuted instantiation: e1000e_core.c:eth_get_pkt_tci
Unexecuted instantiation: igb.c:eth_get_pkt_tci
Unexecuted instantiation: igbvf.c:eth_get_pkt_tci
Unexecuted instantiation: igb_core.c:eth_get_pkt_tci
Unexecuted instantiation: rtl8139.c:eth_get_pkt_tci
Unexecuted instantiation: tulip.c:eth_get_pkt_tci
Unexecuted instantiation: vmxnet3.c:eth_get_pkt_tci
Unexecuted instantiation: virtio-net.c:eth_get_pkt_tci
Unexecuted instantiation: rocker.c:eth_get_pkt_tci
Unexecuted instantiation: rocker_of_dpa.c:eth_get_pkt_tci
Unexecuted instantiation: rocker-hmp-cmds.c:eth_get_pkt_tci
343
344
size_t
345
eth_strip_vlan(const struct iovec *iov, int iovcnt, size_t iovoff,
346
               void *new_ehdr_buf,
347
               uint16_t *payload_offset, uint16_t *tci);
348
349
size_t
350
eth_strip_vlan_ex(const struct iovec *iov, int iovcnt, size_t iovoff, int index,
351
                  uint16_t vet, uint16_t vet_ext, void *new_ehdr_buf,
352
                  uint16_t *payload_offset, uint16_t *tci);
353
354
uint16_t
355
eth_get_l3_proto(const struct iovec *l2hdr_iov, int iovcnt, size_t l2hdr_len);
356
357
void eth_setup_vlan_headers(struct eth_header *ehdr, size_t *ehdr_size,
358
                            uint16_t vlan_tag, uint16_t vlan_ethtype);
359
360
361
uint8_t eth_get_gso_type(uint16_t l3_proto, uint8_t *l3_hdr, uint8_t l4proto);
362
363
typedef struct eth_ip6_hdr_info_st {
364
    uint8_t l4proto;
365
    size_t  full_hdr_len;
366
    struct  ip6_header ip6_hdr;
367
    bool    has_ext_hdrs;
368
    bool    rss_ex_src_valid;
369
    struct  in6_address rss_ex_src;
370
    bool    rss_ex_dst_valid;
371
    struct  in6_address rss_ex_dst;
372
    bool    fragment;
373
} eth_ip6_hdr_info;
374
375
typedef struct eth_ip4_hdr_info_st {
376
    struct ip_header ip4_hdr;
377
    bool   fragment;
378
} eth_ip4_hdr_info;
379
380
typedef enum EthL4HdrProto {
381
    ETH_L4_HDR_PROTO_INVALID,
382
    ETH_L4_HDR_PROTO_TCP,
383
    ETH_L4_HDR_PROTO_UDP,
384
    ETH_L4_HDR_PROTO_SCTP
385
} EthL4HdrProto;
386
387
typedef struct eth_l4_hdr_info_st {
388
    union {
389
        struct tcp_header tcp;
390
        struct udp_header udp;
391
    } hdr;
392
393
    EthL4HdrProto proto;
394
    bool has_tcp_data;
395
} eth_l4_hdr_info;
396
397
0
#define SCTP_COMMON_HEADER_LEN 12
398
399
void eth_get_protocols(const struct iovec *iov, size_t iovcnt, size_t iovoff,
400
                       bool *hasip4, bool *hasip6,
401
                       size_t *l3hdr_off,
402
                       size_t *l4hdr_off,
403
                       size_t *l5hdr_off,
404
                       eth_ip6_hdr_info *ip6hdr_info,
405
                       eth_ip4_hdr_info *ip4hdr_info,
406
                       eth_l4_hdr_info  *l4hdr_info);
407
408
void
409
eth_fix_ip4_checksum(void *l3hdr, size_t l3hdr_len);
410
411
uint32_t
412
eth_calc_ip4_pseudo_hdr_csum(struct ip_header *iphdr,
413
                             uint16_t csl,
414
                             uint32_t *cso);
415
416
uint32_t
417
eth_calc_ip6_pseudo_hdr_csum(struct ip6_header *iphdr,
418
                             uint16_t csl,
419
                             uint8_t l4_proto,
420
                             uint32_t *cso);
421
422
bool
423
eth_parse_ipv6_hdr(const struct iovec *pkt, int pkt_frags,
424
                   size_t ip6hdr_off, eth_ip6_hdr_info *info);
425
426
/**
427
 * eth_pad_short_frame - pad a short frame to the minimum Ethernet frame length
428
 *
429
 * If the Ethernet frame size is shorter than 60 bytes, it will be padded to
430
 * 60 bytes at the address @padded_pkt.
431
 *
432
 * @padded_pkt: buffer address to hold the padded frame
433
 * @padded_buflen: pointer holding length of @padded_pkt. If the frame is
434
 *                 padded, the length will be updated to the padded one.
435
 * @pkt: address to hold the original Ethernet frame
436
 * @pkt_size: size of the original Ethernet frame
437
 * @return true if the frame is padded, otherwise false
438
 */
439
bool eth_pad_short_frame(uint8_t *padded_pkt, size_t *padded_buflen,
440
                         const void *pkt, size_t pkt_size);
441
442
/**
443
 * eth_pad_short_frame_iov - pad a short frame, iovec version
444
 *
445
 * This is equivalent to eth_pad_short_frame(), except that it works
446
 * on a packet stored in a struct iovec.
447
 *
448
 * If the Ethernet frame size is shorter than 60 bytes, it will be padded to
449
 * 60 bytes at the address @padded_pkt (and the caller will need to handle
450
 * it as a not-in-an-iovec packet).
451
 *
452
 * @padded_pkt: buffer address to hold the padded frame
453
 * @padded_buflen: pointer holding length of @padded_pkt. If the frame is
454
 *                 padded, the length will be updated to the padded one.
455
 * @iov: iovec holding the original Ethernet frame
456
 * @iovcnt: number of elements in @iov
457
 * @pkt_size: size of the original Ethernet frame (i.e. iov_size(iov, iovcnt))
458
 * @return true if the frame is padded, otherwise false
459
 */
460
bool eth_pad_short_frame_iov(uint8_t *padded_pkt, size_t *padded_buflen,
461
                             const struct iovec *iov, int iovcnt,
462
                             size_t pkt_size);
463
464
#endif