Rev 4558 | Rev 4707 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4558 | Rev 4589 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2009 Lukas Mejdrech |
2 | * Copyright (c) 2009 Lukas Mejdrech |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup ip |
29 | /** @addtogroup ip |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
33 | /** |
34 | * @file |
34 | * @file |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #ifndef __NET_IP_CLIENT_H__ |
37 | #ifndef __NET_IP_CLIENT_H__ |
38 | #define __NET_IP_CLIENT_H__ |
38 | #define __NET_IP_CLIENT_H__ |
39 | 39 | ||
40 | #include <sys/types.h> |
40 | #include <sys/types.h> |
41 | 41 | ||
42 | typedef uint8_t ip_ttl_t; |
42 | typedef uint8_t ip_ttl_t; |
43 | typedef uint8_t ip_tos_t; |
43 | typedef uint8_t ip_tos_t; |
44 | typedef uint8_t ip_protocol_t; |
44 | typedef uint8_t ip_protocol_t; |
45 | 45 | ||
46 | #include "../structures/packet/packet.h" |
46 | #include "../structures/packet/packet.h" |
47 | 47 | ||
48 | #define IPVERSION 4 |
48 | #define IPVERSION 4 |
49 | #define MAXTTL 255 |
49 | #define MAXTTL 255 |
50 | #define IPDEFTTL 64 |
50 | #define IPDEFTTL 64 |
51 | 51 | ||
52 | #define IPTOS_TOS_MASK 0x1E |
52 | #define IPTOS_TOS_MASK 0x1E |
53 | #define IPTOS_PRECEDENCE_SHIFT 5 |
53 | #define IPTOS_PRECEDENCE_SHIFT 5 |
54 | #define IPTOS_DELAY_SHIFT 4 |
54 | #define IPTOS_DELAY_SHIFT 4 |
55 | #define IPTOS_THROUGHPUT_SHIFT 3 |
55 | #define IPTOS_THROUGHPUT_SHIFT 3 |
56 | #define IPTOS_RELIABILITY_SHIFT 2 |
56 | #define IPTOS_RELIABILITY_SHIFT 2 |
57 | #define IPTOS_COST_SHIFT 1 |
57 | #define IPTOS_COST_SHIFT 1 |
58 | 58 | ||
59 | #define IPTOS_NORMALDELAY ( 0x0 << IPTOS_DELAY_SHIFT ) |
59 | #define IPTOS_NORMALDELAY ( 0x0 << IPTOS_DELAY_SHIFT ) |
60 | #define IPTOS_LOWDELAY ( 0x1 << IPTOS_DELAY_SHIFT ) |
60 | #define IPTOS_LOWDELAY ( 0x1 << IPTOS_DELAY_SHIFT ) |
61 | 61 | ||
62 | #define IPTOS_NORMALTHROUGHPUT ( 0x0 << IPTOS_THROUGHPUT_SHIFT ) |
62 | #define IPTOS_NORMALTHROUGHPUT ( 0x0 << IPTOS_THROUGHPUT_SHIFT ) |
63 | #define IPTOS_THROUGHPUT ( 0x1 << IPTOS_THROUGHPUT_SHIFT ) |
63 | #define IPTOS_THROUGHPUT ( 0x1 << IPTOS_THROUGHPUT_SHIFT ) |
64 | 64 | ||
65 | #define IPTOS_NORMALRELIABILITY ( 0x0 << IPTOS_RELIABILITY_SHIFT ) |
65 | #define IPTOS_NORMALRELIABILITY ( 0x0 << IPTOS_RELIABILITY_SHIFT ) |
66 | #define IPTOS_RELIABILITY ( 0x1 << IPTOS_RELIABILITY_SHIFT ) |
66 | #define IPTOS_RELIABILITY ( 0x1 << IPTOS_RELIABILITY_SHIFT ) |
67 | 67 | ||
68 | #define IPTOS_NORMALCOST ( 0x0 << IPTOS_COST_SHIFT ) |
68 | #define IPTOS_NORMALCOST ( 0x0 << IPTOS_COST_SHIFT ) |
69 | #define IPTOS_MICNCOST ( 0x1 << IPTOS_COST_SHIFT ) |
69 | #define IPTOS_MICNCOST ( 0x1 << IPTOS_COST_SHIFT ) |
70 | 70 | ||
71 | #define IPTOS_PREC_MASK 0xE0 |
71 | #define IPTOS_PREC_MASK 0xE0 |
72 | #define IPTOS_PREC_ROUTINE ( 0x0 << IPTOS_PRECEDENCE_SHIFT ) |
72 | #define IPTOS_PREC_ROUTINE ( 0x0 << IPTOS_PRECEDENCE_SHIFT ) |
73 | #define IPTOS_PREC_PRIORITY ( 0x1 << IPTOS_PRECEDENCE_SHIFT ) |
73 | #define IPTOS_PREC_PRIORITY ( 0x1 << IPTOS_PRECEDENCE_SHIFT ) |
74 | #define IPTOS_PREC_IMMEDIATE ( 0x2 << IPTOS_PRECEDENCE_SHIFT ) |
74 | #define IPTOS_PREC_IMMEDIATE ( 0x2 << IPTOS_PRECEDENCE_SHIFT ) |
75 | #define IPTOS_PREC_FLASH ( 0x3 << IPTOS_PRECEDENCE_SHIFT ) |
75 | #define IPTOS_PREC_FLASH ( 0x3 << IPTOS_PRECEDENCE_SHIFT ) |
76 | #define IPTOS_PREC_FLASHOVERRIDE ( 0x4 << IPTOS_PRECEDENCE_SHIFT ) |
76 | #define IPTOS_PREC_FLASHOVERRIDE ( 0x4 << IPTOS_PRECEDENCE_SHIFT ) |
77 | #define IPTOS_PREC_CRITIC_ECP ( 0x5 << IPTOS_PRECEDENCE_SHIFT ) |
77 | #define IPTOS_PREC_CRITIC_ECP ( 0x5 << IPTOS_PRECEDENCE_SHIFT ) |
78 | #define IPTOS_PREC_INTERNETCONTROL ( 0x6 << IPTOS_PRECEDENCE_SHIFT ) |
78 | #define IPTOS_PREC_INTERNETCONTROL ( 0x6 << IPTOS_PRECEDENCE_SHIFT ) |
79 | #define IPTOS_PREC_NETCONTROL ( 0x7 << IPTOS_PRECEDENCE_SHIFT ) |
79 | #define IPTOS_PREC_NETCONTROL ( 0x7 << IPTOS_PRECEDENCE_SHIFT ) |
80 | 80 | ||
81 | #define IPOPT_COPY_SHIFT 7 |
81 | #define IPOPT_COPY_SHIFT 7 |
82 | #define IPOPT_CLASS_SHIFT 5 |
82 | #define IPOPT_CLASS_SHIFT 5 |
83 | #define IPOPT_NUMBER_SHIFT 0 |
83 | #define IPOPT_NUMBER_SHIFT 0 |
84 | #define IPOPT_CLASS_MASK 0x60 |
84 | #define IPOPT_CLASS_MASK 0x60 |
85 | #define IPOPT_NUMBER_MASK 0x1F |
85 | #define IPOPT_NUMBER_MASK 0x1F |
86 | 86 | ||
87 | #define IPOPT_COPY ( 1 << IPOPT_COPY_SHIFT ) |
87 | #define IPOPT_COPY ( 1 << IPOPT_COPY_SHIFT ) |
88 | 88 | ||
89 | #define IPOPT_TYPE( copy, class, number ) ((( copy ) & IPOPT_COPY ) | (( class ) & IPOPT_CLASS_MASK ) | (( number << IPOPT_NUMBER_SHIFT ) & IPOPT_NUMBER_MASK )) |
89 | #define IPOPT_TYPE( copy, class, number ) ((( copy ) & IPOPT_COPY ) | (( class ) & IPOPT_CLASS_MASK ) | (( number << IPOPT_NUMBER_SHIFT ) & IPOPT_NUMBER_MASK )) |
90 | 90 | ||
91 | #define IPOPT_COPIED( o ) (( o ) & IPOPT_COPY ) |
91 | #define IPOPT_COPIED( o ) (( o ) & IPOPT_COPY ) |
92 | #define IPOPT_CLASS( o ) (( o ) & IPOPT_CLASS_MASK ) |
92 | #define IPOPT_CLASS( o ) (( o ) & IPOPT_CLASS_MASK ) |
93 | #define IPOPT_NUMBER( o ) (( o ) & IPOPT_NUMBER_MASK ) |
93 | #define IPOPT_NUMBER( o ) (( o ) & IPOPT_NUMBER_MASK ) |
94 | 94 | ||
95 | #define IPOPT_CONTROL ( 0 << IPOPT_CLASS_SHIFT ) |
95 | #define IPOPT_CONTROL ( 0 << IPOPT_CLASS_SHIFT ) |
96 | #define IPOPT_RESERVED1 ( 1 << IPOPT_CLASS_SHIFT ) |
96 | #define IPOPT_RESERVED1 ( 1 << IPOPT_CLASS_SHIFT ) |
97 | #define IPOPT_MEASUREMENT ( 2 << IPOPT_CLASS_SHIFT ) |
97 | #define IPOPT_MEASUREMENT ( 2 << IPOPT_CLASS_SHIFT ) |
98 | #define IPOPT_RESERVED2 ( 3 << IPOPT_CLASS_SHIFT ) |
98 | #define IPOPT_RESERVED2 ( 3 << IPOPT_CLASS_SHIFT ) |
99 | 99 | ||
100 | //#define IPOPT_END_OF_LIST 0x0 |
100 | //#define IPOPT_END_OF_LIST 0x0 |
101 | #define IPOPT_END IPOPT_TYPE( 0, IPOPT_CONTROL, 0 ) |
101 | #define IPOPT_END IPOPT_TYPE( 0, IPOPT_CONTROL, 0 ) |
102 | //#define IPOPT_NO_OPERATION 0x1 |
102 | //#define IPOPT_NO_OPERATION 0x1 |
103 | #define IPOPT_NOOP IPOPT_TYPE( 0, IPOPT_CONTROL, 1 ) |
103 | #define IPOPT_NOOP IPOPT_TYPE( 0, IPOPT_CONTROL, 1 ) |
104 | //#define IPOPT_SECURITY 0x82 |
104 | //#define IPOPT_SECURITY 0x82 |
105 | #define IPOPT_SEC IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 2 ) |
105 | #define IPOPT_SEC IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 2 ) |
106 | #define IPOPT_SEC_LENGTH 11 |
106 | #define IPOPT_SEC_LENGTH 11 |
107 | #define IPOPT_SEC_UNCLASIFIED 0x0 |
107 | #define IPOPT_SEC_UNCLASIFIED 0x0 |
108 | #define IPOPT_SEC_CONFIDENTIAL 0xF035 |
108 | #define IPOPT_SEC_CONFIDENTIAL 0xF035 |
109 | #define IPOPT_SEC_EFTO 0x789A |
109 | #define IPOPT_SEC_EFTO 0x789A |
110 | #define IPOPT_SEC_MMMM 0xBC4D |
110 | #define IPOPT_SEC_MMMM 0xBC4D |
111 | #define IPOPT_SEC_PROG 0x5E26 |
111 | #define IPOPT_SEC_PROG 0x5E26 |
112 | #define IPOPT_SEC_RESTRICTED 0xAF13 |
112 | #define IPOPT_SEC_RESTRICTED 0xAF13 |
113 | #define IPOPT_SEC_SECRET 0xD788 |
113 | #define IPOPT_SEC_SECRET 0xD788 |
114 | #define IPOPT_SEC_TOP_SECRET 0x6BC5 |
114 | #define IPOPT_SEC_TOP_SECRET 0x6BC5 |
115 | //#define IPOPT_LOOSE_SOURCE 0x83 |
115 | //#define IPOPT_LOOSE_SOURCE 0x83 |
116 | #define IPOPT_LSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 3 ) |
116 | #define IPOPT_LSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 3 ) |
117 | //#define IPOPT_STRICT_SOURCE 0x89 |
117 | //#define IPOPT_STRICT_SOURCE 0x89 |
118 | #define IPOPT_SSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 9 ) |
118 | #define IPOPT_SSRR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 9 ) |
119 | //#define IPOPT_RECORD_ROUTE 0x07 |
119 | //#define IPOPT_RECORD_ROUTE 0x07 |
120 | #define IPOPT_RR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 7 ) |
120 | #define IPOPT_RR IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 7 ) |
121 | //#define IPOPT_STREAM_IDENTIFIER 0x88 |
121 | //#define IPOPT_STREAM_IDENTIFIER 0x88 |
122 | #define IPOPT_SID IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 8 ) |
122 | #define IPOPT_SID IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 8 ) |
123 | #define IPOPT_SID_LENGTH 4 |
123 | #define IPOPT_SID_LENGTH 4 |
124 | //#define IPOPT_INTERNET_TIMESTAMP 0x44 |
124 | //#define IPOPT_INTERNET_TIMESTAMP 0x44 |
125 | #define IPOPT_TIMESTAMP IPOPT_TYPE( IPOPT_COPY, IPOPT_MEASUREMENT, 4 ) |
125 | #define IPOPT_TIMESTAMP IPOPT_TYPE( IPOPT_COPY, IPOPT_MEASUREMENT, 4 ) |
126 | #define IPOPT_CIPSO IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 5 ) |
126 | #define IPOPT_CIPSO IPOPT_TYPE( IPOPT_COPY, IPOPT_CONTROL, 5 ) |
127 | 127 | ||
128 | #define IPOPT_NOP IPOPT_NOOP |
128 | #define IPOPT_NOP IPOPT_NOOP |
129 | #define IPOPT_EOL IPOPT_END |
129 | #define IPOPT_EOL IPOPT_END |
130 | #define IPOPT_TS IPOPT_TIMESTAMP |
130 | #define IPOPT_TS IPOPT_TIMESTAMP |
131 | 131 | ||
132 | #define IPOPT_TS_TSONLY 0 /* timestamps only */ |
132 | #define IPOPT_TS_TSONLY 0 /* timestamps only */ |
133 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
133 | #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ |
134 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
134 | #define IPOPT_TS_PRESPEC 3 /* specified modules only */ |
135 | 135 | ||
136 | int ip_client_prepare_packet( packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length ); |
136 | int ip_client_prepare_packet( packet_t packet, ip_protocol_t protocol, ip_ttl_t ttl, ip_tos_t tos, int dont_fragment, size_t ipopt_length ); |
137 | 137 | ||
- | 138 | int ip_client_process_packet( packet_t packet, ip_protocol_t * protocol, ip_ttl_t * ttl, ip_tos_t * tos, int * dont_fragment, size_t * ipopt_length ); |
|
- | 139 | ||
138 | // TODO ipopt manipulation |
140 | // TODO ipopt manipulation |
139 | 141 | ||
140 | #endif |
142 | #endif |
141 | 143 | ||
142 | /** @} |
144 | /** @} |
143 | */ |
145 | */ |
144 | 146 |