Line | Count | Source |
1 | | /* |
2 | | * QEMU System Emulator |
3 | | * |
4 | | * Copyright (c) 2003-2008 Fabrice Bellard |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | | * of this software and associated documentation files (the "Software"), to deal |
8 | | * in the Software without restriction, including without limitation the rights |
9 | | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | | * copies of the Software, and to permit persons to whom the Software is |
11 | | * furnished to do so, subject to the following conditions: |
12 | | * |
13 | | * The above copyright notice and this permission notice shall be included in |
14 | | * all copies or substantial portions of the Software. |
15 | | * |
16 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
19 | | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | | * THE SOFTWARE. |
23 | | */ |
24 | | |
25 | | #ifndef QEMU_NET_UTIL_H |
26 | | #define QEMU_NET_UTIL_H |
27 | | |
28 | | |
29 | | /* |
30 | | * Structure of an internet header, naked of options. |
31 | | */ |
32 | | struct ip { |
33 | | #if HOST_BIG_ENDIAN |
34 | | uint8_t ip_v:4, /* version */ |
35 | | ip_hl:4; /* header length */ |
36 | | #else |
37 | | uint8_t ip_hl:4, /* header length */ |
38 | | ip_v:4; /* version */ |
39 | | #endif |
40 | | uint8_t ip_tos; /* type of service */ |
41 | | uint16_t ip_len; /* total length */ |
42 | | uint16_t ip_id; /* identification */ |
43 | | uint16_t ip_off; /* fragment offset field */ |
44 | | #define IP_DF 0x4000 /* don't fragment flag */ |
45 | | #define IP_MF 0x2000 /* more fragments flag */ |
46 | | #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ |
47 | | uint8_t ip_ttl; /* time to live */ |
48 | | uint8_t ip_p; /* protocol */ |
49 | | uint16_t ip_sum; /* checksum */ |
50 | | struct in_addr ip_src, ip_dst; /* source and dest address */ |
51 | | } QEMU_PACKED; |
52 | | |
53 | | static inline bool in6_equal_net(const struct in6_addr *a, |
54 | | const struct in6_addr *b, |
55 | | int prefix_len) |
56 | 0 | { |
57 | 0 | if (memcmp(a, b, prefix_len / 8) != 0) { |
58 | 0 | return 0; |
59 | 0 | } |
60 | | |
61 | 0 | if (prefix_len % 8 == 0) { |
62 | 0 | return 1; |
63 | 0 | } |
64 | | |
65 | 0 | return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) |
66 | 0 | == b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); |
67 | 0 | } Unexecuted instantiation: net.c:in6_equal_net Unexecuted instantiation: util.c:in6_equal_net Unexecuted instantiation: colo-compare.c:in6_equal_net Unexecuted instantiation: colo.c:in6_equal_net Unexecuted instantiation: filter-rewriter.c:in6_equal_net Unexecuted instantiation: slirp.c:in6_equal_net Unexecuted instantiation: tap.c:in6_equal_net Unexecuted instantiation: xen_nic.c:in6_equal_net |
68 | | |
69 | 0 | #define TCPS_CLOSED 0 /* closed */ |
70 | | #define TCPS_LISTEN 1 /* listening for connection */ |
71 | 0 | #define TCPS_SYN_SENT 2 /* active, have sent syn */ |
72 | 0 | #define TCPS_SYN_RECEIVED 3 /* have send and received syn */ |
73 | | /* states < TCPS_ESTABLISHED are those where connections not established */ |
74 | 0 | #define TCPS_ESTABLISHED 4 /* established */ |
75 | 0 | #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ |
76 | | /* states > TCPS_CLOSE_WAIT are those where user has closed */ |
77 | 0 | #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ |
78 | | #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ |
79 | 0 | #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ |
80 | | /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ |
81 | | #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ |
82 | | #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ |
83 | | |
84 | | int net_parse_macaddr(uint8_t *macaddr, const char *p); |
85 | | |
86 | | /* |
87 | | * Close all @fds and free @fds itself |
88 | | */ |
89 | | void net_free_fds(int *fds, int nfds); |
90 | | |
91 | | /* |
92 | | * Parse @fds_param, where monitor fds are separated by a colon. |
93 | | * @nfds must be non-NULL. If *@nfds is zero - set it accordingly. |
94 | | * If *@nfds is non-zero - check that we have exactly *@nfds fds |
95 | | * and fail otherwise. |
96 | | */ |
97 | | int net_parse_fds(const char *fds_param, int **fds, int expected_nfds, |
98 | | Error **errp); |
99 | | |
100 | | #endif /* QEMU_NET_UTIL_H */ |