Merge lp:~henrik-ziegeldorf/hipl/locator-type1-fix into lp:hipl
- locator-type1-fix
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | René Hummen | ||||
Approved revision: | 6135 | ||||
Merged at revision: | 6158 | ||||
Proposed branch: | lp:~henrik-ziegeldorf/hipl/locator-type1-fix | ||||
Merge into: | lp:hipl | ||||
Diff against target: |
294 lines (+59/-125) 6 files modified
modules/update/hipd/update.c (+7/-14) modules/update/hipd/update.h (+6/-0) modules/update/hipd/update_builder.c (+45/-11) modules/update/hipd/update_builder.h (+1/-3) modules/update/hipd/update_locator.c (+0/-92) modules/update/hipd/update_locator.h (+0/-5) |
||||
To merge this branch: | bzr merge lp:~henrik-ziegeldorf/hipl/locator-type1-fix | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Miika Komu | Needs Information | ||
Diego Biurrun | Approve | ||
Review via email: mp+83292@code.launchpad.net |
Commit message
Description of the change
This branch fixes BUG#790487 by including the ESP SPI in type 1 locators.
Additionally, the code for building the locator parameter is refactored and improved.
- 6128. By Henrik Ziegeldorf
-
Fixed misleading comment.
Christof Mroz (christof-mroz) wrote : | # |
One more minor thing:
On 24.11.2011 14:36, Henrik Ziegeldorf wrote:
> + int err = 0, i = 0, count = 0, addrs_len;
i and count are unsigned, and addrs_len is size_t.
Diego Biurrun (diego-biurrun) wrote : | # |
On Thu, Nov 24, 2011 at 01:36:51PM +0000, Henrik Ziegeldorf wrote:
> Henrik Ziegeldorf has proposed merging lp:~henrik-ziegeldorf/hipl/locator-type1-fix into lp:hipl.
>
> --- modules/
> +++ modules/
> @@ -80,22 +86,25 @@
>
> - HIP_IFE(
> + addrs_len = address_count * sizeof(struct hip_locator_
> + HIP_IFEL(
> + -1, "Could not allocate space for locator parameter\n");
You could return -ENOMEM here instead. Yes, that already applies to
many many parts of HIPL.
Diego
Henrik Ziegeldorf (henrik-ziegeldorf) wrote : | # |
> One more minor thing:
>
> On 24.11.2011 14:36, Henrik Ziegeldorf wrote:
> > + int err = 0, i = 0, count = 0,
> addrs_len;
>
> i and count are unsigned, and addrs_len is size_t.
Please include the corresponding hunk of the change, so I'm able to quickly locate the place in the code.
Henrik Ziegeldorf (henrik-ziegeldorf) wrote : | # |
> + HIP_IFEL(
> + -1, "Could not allocate space for locator parameter\n");
>
>
> Is locator_info only an intermediate struct, which is copied into the packet and then forgotten? If > so, then it could probably be allocated on the stack, thus saving you the free() afterwards.
>
> Unless the structs are prohibitively large, of course. I'll trust your judgement here.
You're right. However, there'll be a subsequent branch for refactoring the locator code. I'll probably address it there.
I've fixed all other issues.
If there are no further comments by tomorrow, I'll effect the merge.
- 6129. By Henrik Ziegeldorf
-
Use enum instead of defines.
- 6130. By Henrik Ziegeldorf
-
cosmetics: spelling
- 6131. By Henrik Ziegeldorf
-
Return -ENOMEM instead of -1.
- 6132. By Henrik Ziegeldorf
-
Format fix.
- 6133. By Henrik Ziegeldorf
-
addrs_len is of type size_t
- 6134. By Henrik Ziegeldorf
-
count is unsigned
- 6135. By Henrik Ziegeldorf
-
cosmetics: fix format
Christof Mroz (christof-mroz) wrote : | # |
On 24.11.2011 15:53, Henrik Ziegeldorf wrote:
>> One more minor thing:
>>
>> On 24.11.2011 14:36, Henrik Ziegeldorf wrote:
>>> + int err = 0, i = 0, count = 0,
>> addrs_len;
>>
>> i and count are unsigned, and addrs_len is size_t.
>
> Please include the corresponding hunk of the change, so I'm able to quickly locate the place in the code.
Sorry for that. Here's the hunk i meant:
> === modified file 'modules/
> --- modules/
> +++ modules/
> @@ -80,22 +86,25 @@
> + int err = 0, i = 0, count = 0, addrs_len;
Miika Komu (miika-iki) wrote : | # |
I noticed one function with one free() was removed. Where's the memory deallocated now?
You talk about refactoring but did you *test* handovers?
Henrik Ziegeldorf (henrik-ziegeldorf) wrote : | # |
> I noticed one function with one free() was removed. Where's the memory
> deallocated now?
Nowhere. That part was obsolete and has been removed during refactoring. Before, a temporary, intermediate message was used to build the parameter into and copy it from there later. All in all it was pretty useless and misleading.
> You talk about refactoring but did you *test* handovers?
Yes, on my virtual machines.
Preview Diff
1 | === modified file 'modules/update/hipd/update.c' |
2 | --- modules/update/hipd/update.c 2011-10-25 21:14:16 +0000 |
3 | +++ modules/update/hipd/update.c 2011-11-24 15:19:25 +0000 |
4 | @@ -707,13 +707,12 @@ |
5 | */ |
6 | int hip_trigger_update(struct hip_hadb_state *const hadb_entry) |
7 | { |
8 | - struct hip_common *locator_update_packet = NULL; |
9 | - struct hip_common *locator_msg = NULL; |
10 | - struct hip_locator_info_addr_item *locators = NULL; |
11 | - struct update_state *localstate = NULL; |
12 | - struct in6_addr local_addr; |
13 | - int err = 0; |
14 | - const int retransmit = 1; |
15 | + struct hip_common *locator_update_packet = NULL; |
16 | + struct hip_common *locator_msg = NULL; |
17 | + struct update_state *localstate = NULL; |
18 | + struct in6_addr local_addr; |
19 | + int err = 0; |
20 | + const int retransmit = 1; |
21 | |
22 | localstate = lmod_get_state_item(hadb_entry->hip_modular_state, "update"); |
23 | |
24 | @@ -732,13 +731,7 @@ |
25 | hadb_entry->spi_inbound_current), |
26 | -1, "Building of ESP_INFO param failed\n"); |
27 | |
28 | - HIP_IFEL(!(locator_msg = hip_msg_alloc()), |
29 | - -ENOMEM, "Out of memory while allocation memory for the packet\n"); |
30 | - HIP_IFE(hip_create_locators(locator_msg, &locators), -1); |
31 | - |
32 | - HIP_IFEL(hip_build_param_locator(locator_update_packet, |
33 | - locators, |
34 | - address_count), |
35 | + HIP_IFEL(hip_build_param_locator(locator_update_packet), |
36 | -1, "failed to build locator parameter\n"); |
37 | |
38 | localstate->update_id_out++; |
39 | |
40 | === modified file 'modules/update/hipd/update.h' |
41 | --- modules/update/hipd/update.h 2011-08-18 10:11:46 +0000 |
42 | +++ modules/update/hipd/update.h 2011-11-24 15:19:25 +0000 |
43 | @@ -91,12 +91,18 @@ |
44 | /* fixed part ends */ |
45 | } __attribute__((packed)); |
46 | |
47 | +/** |
48 | + * type 1 locator item |
49 | + */ |
50 | struct hip_locator_info_addr_item { |
51 | uint8_t traffic_type; |
52 | uint8_t locator_type; |
53 | uint8_t locator_length; |
54 | uint8_t reserved; /**< last bit is P (preferred) */ |
55 | uint32_t lifetime; |
56 | + /* The locator field comprises the 32-bit ESP SPI and address (IPv6 or IPv4-in-IPv6) |
57 | + * (c.f. http://tools.ietf.org/html/rfc5206#section-4.2) */ |
58 | + uint32_t esp_spi; |
59 | struct in6_addr address; |
60 | } __attribute__((packed)); |
61 | |
62 | |
63 | === modified file 'modules/update/hipd/update_builder.c' |
64 | --- modules/update/hipd/update_builder.c 2011-08-15 14:11:56 +0000 |
65 | +++ modules/update/hipd/update_builder.c 2011-11-24 15:19:25 +0000 |
66 | @@ -32,11 +32,20 @@ |
67 | |
68 | #include <arpa/inet.h> |
69 | #include <string.h> |
70 | +#include <errno.h> |
71 | |
72 | +#include "hipd/hadb.h" |
73 | +#include "hipd/hipd.h" |
74 | #include "lib/core/builder.h" |
75 | #include "lib/core/ife.h" |
76 | +#include "lib/core/list.h" |
77 | +#include "lib/core/prefix.h" |
78 | #include "update_builder.h" |
79 | |
80 | +enum hip_locator_traffic_type { |
81 | + HIP_LOCATOR_TRAFFIC_TYPE_DUAL, |
82 | + HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL |
83 | +}; |
84 | |
85 | /** |
86 | * build and append a HIP SEQ parameter to a message |
87 | @@ -80,22 +89,27 @@ |
88 | } |
89 | |
90 | /** |
91 | - * build a HIP locator parameter |
92 | + * Build a HIP locator parameter. |
93 | * |
94 | * @param msg the message where the REA will be appended |
95 | - * @param addrs list of addresses |
96 | - * @param addr_count number of addresses |
97 | * @return 0 on success, otherwise < 0. |
98 | */ |
99 | -int hip_build_param_locator(struct hip_common *const msg, |
100 | - const struct hip_locator_info_addr_item *const addrs, |
101 | - const int addr_count) |
102 | +int hip_build_param_locator(struct hip_common *const msg) |
103 | { |
104 | - int err = 0; |
105 | - struct hip_locator *locator_info = NULL; |
106 | - int addrs_len = addr_count * sizeof(struct hip_locator_info_addr_item); |
107 | + int err = 0, i = 0; |
108 | + unsigned int count = 0; |
109 | + size_t addrs_len; |
110 | + struct hip_locator *locator_info = NULL; |
111 | + struct hip_locator_info_addr_item *loc_info_item = NULL; |
112 | + struct hip_hadb_state *ha = NULL; |
113 | + LHASH_NODE *item = NULL, *tmp = NULL; |
114 | + struct netdev_address *n; |
115 | |
116 | - HIP_IFE(!(locator_info = malloc(sizeof(struct hip_locator) + addrs_len)), -1); |
117 | + addrs_len = address_count * sizeof(struct hip_locator_info_addr_item); |
118 | + HIP_IFEL(!(locator_info = malloc(sizeof(struct hip_locator) + addrs_len)), |
119 | + -ENOMEM, "Could not allocate space for locator parameter\n"); |
120 | + HIP_IFEL(!(ha = hip_hadb_find_byhits(&msg->hits, &msg->hitr)), |
121 | + -1, "Could not retrieve HA\n"); |
122 | |
123 | hip_set_param_type((struct hip_tlv_common *) locator_info, HIP_PARAM_LOCATOR); |
124 | |
125 | @@ -103,7 +117,27 @@ |
126 | sizeof(struct hip_locator), |
127 | addrs_len); |
128 | |
129 | - memcpy(locator_info + 1, addrs, addrs_len); |
130 | + /* build all locator info items from cached addresses */ |
131 | + loc_info_item = (struct hip_locator_info_addr_item *) (locator_info + 1); |
132 | + list_for_each_safe(item, tmp, addresses, i) { |
133 | + n = list_entry(item); |
134 | + HIP_DEBUG_IN6ADDR("Add address:", hip_cast_sa_addr(((struct sockaddr *) &n->addr))); |
135 | + HIP_ASSERT(!ipv6_addr_is_hit(hip_cast_sa_addr((struct sockaddr *) &n->addr))); |
136 | + memcpy(&loc_info_item[count].address, |
137 | + hip_cast_sa_addr((struct sockaddr *) &n->addr), |
138 | + sizeof(struct in6_addr)); |
139 | + if (n->flags & HIP_FLAG_CONTROL_TRAFFIC_ONLY) { |
140 | + loc_info_item[count].traffic_type = HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL; |
141 | + } else { |
142 | + loc_info_item[count].traffic_type = HIP_LOCATOR_TRAFFIC_TYPE_DUAL; |
143 | + } |
144 | + loc_info_item[count].locator_type = HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI; |
145 | + loc_info_item[count].locator_length = sizeof(struct in6_addr) / 4; |
146 | + loc_info_item[count].reserved = 0; |
147 | + loc_info_item[count].esp_spi = htonl(ha->spi_inbound_current); |
148 | + count++; |
149 | + } |
150 | + |
151 | HIP_IFE(hip_build_param(msg, locator_info), -1); |
152 | |
153 | out_err: |
154 | |
155 | === modified file 'modules/update/hipd/update_builder.h' |
156 | --- modules/update/hipd/update_builder.h 2011-08-15 14:11:56 +0000 |
157 | +++ modules/update/hipd/update_builder.h 2011-11-24 15:19:25 +0000 |
158 | @@ -41,8 +41,6 @@ |
159 | int hip_build_param_seq(struct hip_common *const msg, const uint32_t update_id); |
160 | int hip_build_param_ack(struct hip_common *const msg, |
161 | const uint32_t peer_update_id); |
162 | -int hip_build_param_locator(struct hip_common *const msg, |
163 | - const struct hip_locator_info_addr_item *const addrs, |
164 | - const int addr_count); |
165 | +int hip_build_param_locator(struct hip_common *const msg); |
166 | |
167 | #endif /* HIP_MODULES_UPDATE_HIPD_UPDATE_BUILDER_H */ |
168 | |
169 | === modified file 'modules/update/hipd/update_locator.c' |
170 | --- modules/update/hipd/update_locator.c 2011-08-15 14:11:56 +0000 |
171 | +++ modules/update/hipd/update_locator.c 2011-11-24 15:19:25 +0000 |
172 | @@ -34,107 +34,15 @@ |
173 | #include <string.h> |
174 | #include <openssl/lhash.h> |
175 | |
176 | -#include "config.h" |
177 | -#include "hipd/hipd.h" |
178 | #include "hipd/maintenance.h" |
179 | #include "lib/core/builder.h" |
180 | #include "lib/core/debug.h" |
181 | #include "lib/core/ife.h" |
182 | -#include "lib/core/list.h" |
183 | -#include "lib/core/prefix.h" |
184 | #include "lib/core/protodefs.h" |
185 | #include "update_builder.h" |
186 | #include "update.h" |
187 | #include "update_locator.h" |
188 | |
189 | - |
190 | -#define HIP_LOCATOR_TRAFFIC_TYPE_DUAL 0 |
191 | -#define HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL 1 |
192 | - |
193 | -/** |
194 | - * build a LOCATOR parameter for an UPDATE packet |
195 | - * |
196 | - * @param msg the LOCATOR parameter will be appended to this UPDATE message |
197 | - * @return zero on success on negative on failure |
198 | - */ |
199 | -int hip_build_locators_old(struct hip_common *const msg) |
200 | -{ |
201 | - int err = 0, i = 0, count = 0; |
202 | - int addr_max; |
203 | - struct netdev_address *n; |
204 | - LHASH_NODE *item = NULL, *tmp = NULL; |
205 | - struct hip_locator_info_addr_item *locs = NULL; |
206 | - |
207 | - if (address_count == 0) { |
208 | - HIP_DEBUG("Host has only one or no addresses no point " |
209 | - "in building LOCATOR2 parameters\n"); |
210 | - goto out_err; |
211 | - } |
212 | - |
213 | - addr_max = address_count; |
214 | - |
215 | - HIP_IFEL(!(locs = calloc(addr_max, sizeof(struct hip_locator_info_addr_item))), |
216 | - -1, "Malloc for LOCATORS type1 failed\n"); |
217 | - |
218 | - HIP_DEBUG("there are %d type 1 locator item\n", addr_max); |
219 | - |
220 | - list_for_each_safe(item, tmp, addresses, i) { |
221 | - n = list_entry(item); |
222 | - HIP_DEBUG_IN6ADDR("Add address:", |
223 | - hip_cast_sa_addr(((struct sockaddr *) &n->addr))); |
224 | - HIP_ASSERT(!ipv6_addr_is_hit(hip_cast_sa_addr((struct sockaddr *) &n->addr))); |
225 | - memcpy(&locs[count].address, hip_cast_sa_addr((struct sockaddr *) &n->addr), |
226 | - sizeof(struct in6_addr)); |
227 | - if (n->flags & HIP_FLAG_CONTROL_TRAFFIC_ONLY) { |
228 | - locs[count].traffic_type = HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL; |
229 | - } else { |
230 | - locs[count].traffic_type = HIP_LOCATOR_TRAFFIC_TYPE_DUAL; |
231 | - } |
232 | - locs[count].locator_type = HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI; |
233 | - locs[count].locator_length = sizeof(struct in6_addr) / 4; |
234 | - locs[count].reserved = 0; |
235 | - count++; |
236 | - } |
237 | - |
238 | - HIP_DEBUG("locator count %d\n", count); |
239 | - |
240 | - HIP_IFEL(count == 0, -1, "No locators to build\n"); |
241 | - |
242 | - err = hip_build_param_locator(msg, locs, count); |
243 | - |
244 | -out_err: |
245 | - free(locs); |
246 | - return err; |
247 | -} |
248 | - |
249 | -/** |
250 | - * build locators in an UPDATE message |
251 | - * |
252 | - * @param locator_msg the message where the LOCATOR should be appended |
253 | - * @param locators an extra pointer that will point to the LOCATOR |
254 | - * @return zero on success or negative on failure |
255 | - */ |
256 | -int hip_create_locators(struct hip_common *const locator_msg, |
257 | - struct hip_locator_info_addr_item **locators) |
258 | -{ |
259 | - int err = 0; |
260 | - struct hip_locator *loc = NULL; |
261 | - |
262 | - hip_msg_init(locator_msg); |
263 | - HIP_IFEL(hip_build_user_hdr(locator_msg, |
264 | - HIP_MSG_SET_LOCATOR_ON, 0), -1, |
265 | - "Failed to add user header\n"); |
266 | - HIP_IFEL(hip_build_locators_old(locator_msg), |
267 | - -1, |
268 | - "Failed to build locators\n"); |
269 | - loc = hip_get_param_readwrite(locator_msg, HIP_PARAM_LOCATOR); |
270 | - hip_print_locator_addresses(locator_msg); |
271 | - *locators = (struct hip_locator_info_addr_item *) (loc + 1); |
272 | - |
273 | -out_err: |
274 | - return err; |
275 | -} |
276 | - |
277 | /** |
278 | * Retrieve a locator address item from a list. |
279 | * |
280 | |
281 | === modified file 'modules/update/hipd/update_locator.h' |
282 | --- modules/update/hipd/update_locator.h 2011-04-20 09:18:09 +0000 |
283 | +++ modules/update/hipd/update_locator.h 2011-11-24 15:19:25 +0000 |
284 | @@ -29,11 +29,6 @@ |
285 | #include "lib/core/protodefs.h" |
286 | #include "update.h" |
287 | |
288 | -int hip_build_locators_old(struct hip_common *const msg); |
289 | - |
290 | -int hip_create_locators(struct hip_common *const locator_msg, |
291 | - struct hip_locator_info_addr_item **locators); |
292 | - |
293 | union hip_locator_info_addr *hip_get_locator_item(void *item_list, |
294 | int idx); |
295 |
review approve
On Thu, Nov 24, 2011 at 01:36:51PM +0000, Henrik Ziegeldorf wrote:
> Henrik Ziegeldorf has proposed merging lp:~henrik-ziegeldorf/hipl/locator-type1-fix into lp:hipl.
LGTM
> --- modules/ update/ hipd/update. h 2011-08-18 10:11:46 +0000 update/ hipd/update. h 2011-11-24 13:35:59 +0000 info_addr_ item {
> +++ modules/
> @@ -91,12 +91,18 @@
>
> +/**
> + * type 1 locator item
> + */
> struct hip_locator_
> uint8_t traffic_type;
> uint8_t locator_type;
> uint8_t locator_length;
> uint8_t reserved; /**< last bit is P (preferred) */
> uint32_t lifetime;
> + /* The locator field comprises of the ESP SPI and address (32 bit, IPv6 or IPv4-in-IPv6)
comprises the
> --- modules/ update/ hipd/update_ builder. c 2011-08-15 14:11:56 +0000 update/ hipd/update_ builder. c 2011-11-24 13:35:59 +0000 builder. h" TRAFFIC_ TYPE_DUAL 0 TRAFFIC_ TYPE_SIGNAL 1
> +++ modules/
> @@ -33,10 +33,16 @@
>
> +#include "hipd/hadb.h"
> +#include "hipd/hipd.h"
> #include "lib/core/
> #include "lib/core/ife.h"
> +#include "lib/core/list.h"
> +#include "lib/core/prefix.h"
> #include "update_builder.h"
>
> +#define HIP_LOCATOR_
> +#define HIP_LOCATOR_
enum? just a suggestion, feel free to ignore ...
Diego