]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
3b653205 LP |
2 | |
3 | #include <arpa/inet.h> | |
11c3a366 TA |
4 | #include <endian.h> |
5 | #include <errno.h> | |
2817157b | 6 | #include <net/if.h> |
11c3a366 TA |
7 | #include <stdint.h> |
8 | #include <stdlib.h> | |
3b653205 | 9 | |
b5efdb8a | 10 | #include "alloc-util.h" |
3b653205 | 11 | #include "in-addr-util.h" |
11c3a366 | 12 | #include "macro.h" |
2817157b | 13 | #include "parse-util.h" |
11c3a366 | 14 | #include "util.h" |
3b653205 | 15 | |
34380032 | 16 | bool in4_addr_is_null(const struct in_addr *a) { |
fdedbe26 | 17 | assert(a); |
34380032 | 18 | |
fdedbe26 | 19 | return a->s_addr == 0; |
34380032 LP |
20 | } |
21 | ||
af93291c | 22 | int in_addr_is_null(int family, const union in_addr_union *u) { |
3b653205 LP |
23 | assert(u); |
24 | ||
25 | if (family == AF_INET) | |
34380032 | 26 | return in4_addr_is_null(&u->in); |
3b653205 LP |
27 | |
28 | if (family == AF_INET6) | |
fdedbe26 | 29 | return IN6_IS_ADDR_UNSPECIFIED(&u->in6); |
3b653205 LP |
30 | |
31 | return -EAFNOSUPPORT; | |
32 | } | |
33 | ||
fdedbe26 LP |
34 | bool in4_addr_is_link_local(const struct in_addr *a) { |
35 | assert(a); | |
36 | ||
37 | return (be32toh(a->s_addr) & UINT32_C(0xFFFF0000)) == (UINT32_C(169) << 24 | UINT32_C(254) << 16); | |
38 | } | |
39 | ||
af93291c LP |
40 | int in_addr_is_link_local(int family, const union in_addr_union *u) { |
41 | assert(u); | |
42 | ||
43 | if (family == AF_INET) | |
fdedbe26 | 44 | return in4_addr_is_link_local(&u->in); |
af93291c LP |
45 | |
46 | if (family == AF_INET6) | |
47 | return IN6_IS_ADDR_LINKLOCAL(&u->in6); | |
48 | ||
49 | return -EAFNOSUPPORT; | |
50 | } | |
3b653205 | 51 | |
85257f48 SS |
52 | int in_addr_is_multicast(int family, const union in_addr_union *u) { |
53 | assert(u); | |
54 | ||
55 | if (family == AF_INET) | |
56 | return IN_MULTICAST(be32toh(u->in.s_addr)); | |
57 | ||
58 | if (family == AF_INET6) | |
59 | return IN6_IS_ADDR_MULTICAST(&u->in6); | |
60 | ||
61 | return -EAFNOSUPPORT; | |
62 | } | |
63 | ||
fdedbe26 LP |
64 | bool in4_addr_is_localhost(const struct in_addr *a) { |
65 | assert(a); | |
66 | ||
67 | /* All of 127.x.x.x is localhost. */ | |
68 | return (be32toh(a->s_addr) & UINT32_C(0xFF000000)) == UINT32_C(127) << 24; | |
69 | } | |
70 | ||
072320ea TH |
71 | bool in4_addr_is_non_local(const struct in_addr *a) { |
72 | /* Whether the address is not null and not localhost. | |
73 | * | |
74 | * As such, it is suitable to configure as DNS/NTP server from DHCP. */ | |
75 | return !in4_addr_is_null(a) && | |
76 | !in4_addr_is_localhost(a); | |
77 | } | |
78 | ||
d830ebbd LP |
79 | int in_addr_is_localhost(int family, const union in_addr_union *u) { |
80 | assert(u); | |
81 | ||
82 | if (family == AF_INET) | |
fdedbe26 | 83 | return in4_addr_is_localhost(&u->in); |
d830ebbd | 84 | |
db15affc | 85 | if (family == AF_INET6) |
d830ebbd LP |
86 | return IN6_IS_ADDR_LOOPBACK(&u->in6); |
87 | ||
88 | return -EAFNOSUPPORT; | |
89 | } | |
90 | ||
623a4c97 | 91 | int in_addr_equal(int family, const union in_addr_union *a, const union in_addr_union *b) { |
3b653205 LP |
92 | assert(a); |
93 | assert(b); | |
94 | ||
95 | if (family == AF_INET) | |
96 | return a->in.s_addr == b->in.s_addr; | |
97 | ||
98 | if (family == AF_INET6) | |
99 | return | |
100 | a->in6.s6_addr32[0] == b->in6.s6_addr32[0] && | |
101 | a->in6.s6_addr32[1] == b->in6.s6_addr32[1] && | |
102 | a->in6.s6_addr32[2] == b->in6.s6_addr32[2] && | |
103 | a->in6.s6_addr32[3] == b->in6.s6_addr32[3]; | |
104 | ||
105 | return -EAFNOSUPPORT; | |
106 | } | |
107 | ||
108 | int in_addr_prefix_intersect( | |
0dd25fb9 | 109 | int family, |
3b653205 LP |
110 | const union in_addr_union *a, |
111 | unsigned aprefixlen, | |
112 | const union in_addr_union *b, | |
113 | unsigned bprefixlen) { | |
114 | ||
115 | unsigned m; | |
116 | ||
117 | assert(a); | |
118 | assert(b); | |
119 | ||
120 | /* Checks whether there are any addresses that are in both | |
121 | * networks */ | |
122 | ||
123 | m = MIN(aprefixlen, bprefixlen); | |
124 | ||
125 | if (family == AF_INET) { | |
126 | uint32_t x, nm; | |
127 | ||
128 | x = be32toh(a->in.s_addr ^ b->in.s_addr); | |
129 | nm = (m == 0) ? 0 : 0xFFFFFFFFUL << (32 - m); | |
130 | ||
131 | return (x & nm) == 0; | |
132 | } | |
133 | ||
134 | if (family == AF_INET6) { | |
135 | unsigned i; | |
136 | ||
137 | if (m > 128) | |
138 | m = 128; | |
139 | ||
140 | for (i = 0; i < 16; i++) { | |
141 | uint8_t x, nm; | |
142 | ||
143 | x = a->in6.s6_addr[i] ^ b->in6.s6_addr[i]; | |
144 | ||
145 | if (m < 8) | |
146 | nm = 0xFF << (8 - m); | |
147 | else | |
148 | nm = 0xFF; | |
149 | ||
150 | if ((x & nm) != 0) | |
151 | return 0; | |
152 | ||
153 | if (m > 8) | |
154 | m -= 8; | |
155 | else | |
156 | m = 0; | |
157 | } | |
158 | ||
159 | return 1; | |
160 | } | |
161 | ||
162 | return -EAFNOSUPPORT; | |
163 | } | |
164 | ||
0dd25fb9 | 165 | int in_addr_prefix_next(int family, union in_addr_union *u, unsigned prefixlen) { |
3b653205 LP |
166 | assert(u); |
167 | ||
168 | /* Increases the network part of an address by one. Returns | |
169 | * positive it that succeeds, or 0 if this overflows. */ | |
170 | ||
171 | if (prefixlen <= 0) | |
172 | return 0; | |
173 | ||
174 | if (family == AF_INET) { | |
175 | uint32_t c, n; | |
176 | ||
177 | if (prefixlen > 32) | |
178 | prefixlen = 32; | |
179 | ||
180 | c = be32toh(u->in.s_addr); | |
181 | n = c + (1UL << (32 - prefixlen)); | |
182 | if (n < c) | |
183 | return 0; | |
184 | n &= 0xFFFFFFFFUL << (32 - prefixlen); | |
185 | ||
186 | u->in.s_addr = htobe32(n); | |
187 | return 1; | |
188 | } | |
189 | ||
190 | if (family == AF_INET6) { | |
191 | struct in6_addr add = {}, result; | |
192 | uint8_t overflow = 0; | |
193 | unsigned i; | |
194 | ||
195 | if (prefixlen > 128) | |
196 | prefixlen = 128; | |
197 | ||
198 | /* First calculate what we have to add */ | |
199 | add.s6_addr[(prefixlen-1) / 8] = 1 << (7 - (prefixlen-1) % 8); | |
200 | ||
201 | for (i = 16; i > 0; i--) { | |
202 | unsigned j = i - 1; | |
203 | ||
204 | result.s6_addr[j] = u->in6.s6_addr[j] + add.s6_addr[j] + overflow; | |
205 | overflow = (result.s6_addr[j] < u->in6.s6_addr[j]); | |
206 | } | |
207 | ||
208 | if (overflow) | |
209 | return 0; | |
210 | ||
211 | u->in6 = result; | |
212 | return 1; | |
213 | } | |
214 | ||
215 | return -EAFNOSUPPORT; | |
216 | } | |
217 | ||
0dd25fb9 | 218 | int in_addr_to_string(int family, const union in_addr_union *u, char **ret) { |
3b653205 LP |
219 | char *x; |
220 | size_t l; | |
221 | ||
222 | assert(u); | |
223 | assert(ret); | |
224 | ||
225 | if (family == AF_INET) | |
226 | l = INET_ADDRSTRLEN; | |
227 | else if (family == AF_INET6) | |
228 | l = INET6_ADDRSTRLEN; | |
229 | else | |
230 | return -EAFNOSUPPORT; | |
231 | ||
232 | x = new(char, l); | |
233 | if (!x) | |
234 | return -ENOMEM; | |
235 | ||
236 | errno = 0; | |
237 | if (!inet_ntop(family, u, x, l)) { | |
238 | free(x); | |
f5e5c28f | 239 | return errno > 0 ? -errno : -EINVAL; |
3b653205 LP |
240 | } |
241 | ||
242 | *ret = x; | |
243 | return 0; | |
244 | } | |
245 | ||
2817157b LP |
246 | int in_addr_ifindex_to_string(int family, const union in_addr_union *u, int ifindex, char **ret) { |
247 | size_t l; | |
248 | char *x; | |
249 | int r; | |
250 | ||
251 | assert(u); | |
252 | assert(ret); | |
253 | ||
254 | /* Much like in_addr_to_string(), but optionally appends the zone interface index to the address, to properly | |
255 | * handle IPv6 link-local addresses. */ | |
256 | ||
257 | if (family != AF_INET6) | |
258 | goto fallback; | |
259 | if (ifindex <= 0) | |
260 | goto fallback; | |
261 | ||
262 | r = in_addr_is_link_local(family, u); | |
263 | if (r < 0) | |
264 | return r; | |
265 | if (r == 0) | |
266 | goto fallback; | |
267 | ||
268 | l = INET6_ADDRSTRLEN + 1 + DECIMAL_STR_MAX(ifindex) + 1; | |
269 | x = new(char, l); | |
270 | if (!x) | |
271 | return -ENOMEM; | |
272 | ||
273 | errno = 0; | |
274 | if (!inet_ntop(family, u, x, l)) { | |
275 | free(x); | |
276 | return errno > 0 ? -errno : -EINVAL; | |
277 | } | |
278 | ||
279 | sprintf(strchr(x, 0), "%%%i", ifindex); | |
280 | *ret = x; | |
281 | ||
282 | return 0; | |
283 | ||
284 | fallback: | |
285 | return in_addr_to_string(family, u, ret); | |
286 | } | |
287 | ||
0dd25fb9 | 288 | int in_addr_from_string(int family, const char *s, union in_addr_union *ret) { |
fd18634d | 289 | union in_addr_union buffer; |
3b653205 | 290 | assert(s); |
3b653205 LP |
291 | |
292 | if (!IN_SET(family, AF_INET, AF_INET6)) | |
293 | return -EAFNOSUPPORT; | |
294 | ||
295 | errno = 0; | |
fd18634d | 296 | if (inet_pton(family, s, ret ?: &buffer) <= 0) |
f5e5c28f | 297 | return errno > 0 ? -errno : -EINVAL; |
3b653205 LP |
298 | |
299 | return 0; | |
300 | } | |
74b2466e | 301 | |
4e2d5273 | 302 | int in_addr_from_string_auto(const char *s, int *ret_family, union in_addr_union *ret) { |
74b2466e LP |
303 | int r; |
304 | ||
305 | assert(s); | |
74b2466e LP |
306 | |
307 | r = in_addr_from_string(AF_INET, s, ret); | |
308 | if (r >= 0) { | |
4e2d5273 LP |
309 | if (ret_family) |
310 | *ret_family = AF_INET; | |
74b2466e LP |
311 | return 0; |
312 | } | |
313 | ||
314 | r = in_addr_from_string(AF_INET6, s, ret); | |
315 | if (r >= 0) { | |
4e2d5273 LP |
316 | if (ret_family) |
317 | *ret_family = AF_INET6; | |
74b2466e LP |
318 | return 0; |
319 | } | |
320 | ||
321 | return -EINVAL; | |
322 | } | |
44e7b949 | 323 | |
2817157b | 324 | int in_addr_ifindex_from_string_auto(const char *s, int *family, union in_addr_union *ret, int *ifindex) { |
67944f5c | 325 | _cleanup_free_ char *buf = NULL; |
2817157b LP |
326 | const char *suffix; |
327 | int r, ifi = 0; | |
328 | ||
329 | assert(s); | |
330 | assert(family); | |
331 | assert(ret); | |
332 | ||
333 | /* Similar to in_addr_from_string_auto() but also parses an optionally appended IPv6 zone suffix ("scope id") | |
334 | * if one is found. */ | |
335 | ||
336 | suffix = strchr(s, '%'); | |
337 | if (suffix) { | |
338 | ||
339 | if (ifindex) { | |
340 | /* If we shall return the interface index, try to parse it */ | |
341 | r = parse_ifindex(suffix + 1, &ifi); | |
342 | if (r < 0) { | |
343 | unsigned u; | |
344 | ||
345 | u = if_nametoindex(suffix + 1); | |
346 | if (u <= 0) | |
347 | return -errno; | |
348 | ||
349 | ifi = (int) u; | |
350 | } | |
351 | } | |
352 | ||
67944f5c YW |
353 | buf = strndup(s, suffix - s); |
354 | if (!buf) | |
355 | return -ENOMEM; | |
356 | ||
357 | s = buf; | |
2817157b LP |
358 | } |
359 | ||
360 | r = in_addr_from_string_auto(s, family, ret); | |
361 | if (r < 0) | |
362 | return r; | |
363 | ||
364 | if (ifindex) | |
365 | *ifindex = ifi; | |
366 | ||
367 | return r; | |
368 | } | |
369 | ||
5a941f5f | 370 | unsigned char in4_addr_netmask_to_prefixlen(const struct in_addr *addr) { |
44e7b949 LP |
371 | assert(addr); |
372 | ||
1a359852 | 373 | return 32U - u32ctz(be32toh(addr->s_addr)); |
44e7b949 | 374 | } |
df40eee8 | 375 | |
5a941f5f | 376 | struct in_addr* in4_addr_prefixlen_to_netmask(struct in_addr *addr, unsigned char prefixlen) { |
76917807 LP |
377 | assert(addr); |
378 | assert(prefixlen <= 32); | |
379 | ||
380 | /* Shifting beyond 32 is not defined, handle this specially. */ | |
381 | if (prefixlen == 0) | |
382 | addr->s_addr = 0; | |
383 | else | |
384 | addr->s_addr = htobe32((0xffffffff << (32 - prefixlen)) & 0xffffffff); | |
385 | ||
386 | return addr; | |
387 | } | |
388 | ||
5a941f5f | 389 | int in4_addr_default_prefixlen(const struct in_addr *addr, unsigned char *prefixlen) { |
1caa12d0 TG |
390 | uint8_t msb_octet = *(uint8_t*) addr; |
391 | ||
392 | /* addr may not be aligned, so make sure we only access it byte-wise */ | |
df40eee8 TG |
393 | |
394 | assert(addr); | |
df40eee8 TG |
395 | assert(prefixlen); |
396 | ||
1caa12d0 | 397 | if (msb_octet < 128) |
df40eee8 TG |
398 | /* class A, leading bits: 0 */ |
399 | *prefixlen = 8; | |
1caa12d0 | 400 | else if (msb_octet < 192) |
df40eee8 TG |
401 | /* class B, leading bits 10 */ |
402 | *prefixlen = 16; | |
1caa12d0 | 403 | else if (msb_octet < 224) |
df40eee8 TG |
404 | /* class C, leading bits 110 */ |
405 | *prefixlen = 24; | |
406 | else | |
407 | /* class D or E, no default prefixlen */ | |
408 | return -ERANGE; | |
409 | ||
410 | return 0; | |
411 | } | |
412 | ||
5a941f5f | 413 | int in4_addr_default_subnet_mask(const struct in_addr *addr, struct in_addr *mask) { |
df40eee8 TG |
414 | unsigned char prefixlen; |
415 | int r; | |
416 | ||
417 | assert(addr); | |
418 | assert(mask); | |
419 | ||
5a941f5f | 420 | r = in4_addr_default_prefixlen(addr, &prefixlen); |
df40eee8 TG |
421 | if (r < 0) |
422 | return r; | |
423 | ||
5a941f5f | 424 | in4_addr_prefixlen_to_netmask(mask, prefixlen); |
df40eee8 TG |
425 | return 0; |
426 | } | |
5a8bcb67 LP |
427 | |
428 | int in_addr_mask(int family, union in_addr_union *addr, unsigned char prefixlen) { | |
429 | assert(addr); | |
430 | ||
431 | if (family == AF_INET) { | |
432 | struct in_addr mask; | |
433 | ||
5a941f5f | 434 | if (!in4_addr_prefixlen_to_netmask(&mask, prefixlen)) |
5a8bcb67 LP |
435 | return -EINVAL; |
436 | ||
437 | addr->in.s_addr &= mask.s_addr; | |
438 | return 0; | |
439 | } | |
440 | ||
441 | if (family == AF_INET6) { | |
442 | unsigned i; | |
443 | ||
444 | for (i = 0; i < 16; i++) { | |
445 | uint8_t mask; | |
446 | ||
447 | if (prefixlen >= 8) { | |
448 | mask = 0xFF; | |
449 | prefixlen -= 8; | |
450 | } else { | |
451 | mask = 0xFF << (8 - prefixlen); | |
452 | prefixlen = 0; | |
453 | } | |
454 | ||
455 | addr->in6.s6_addr[i] &= mask; | |
456 | } | |
457 | ||
458 | return 0; | |
459 | } | |
460 | ||
461 | return -EAFNOSUPPORT; | |
462 | } | |
f7bf1abe | 463 | |
1274b6c6 LP |
464 | int in_addr_prefix_covers(int family, |
465 | const union in_addr_union *prefix, | |
466 | unsigned char prefixlen, | |
467 | const union in_addr_union *address) { | |
468 | ||
469 | union in_addr_union masked_prefix, masked_address; | |
470 | int r; | |
471 | ||
472 | assert(prefix); | |
473 | assert(address); | |
474 | ||
475 | masked_prefix = *prefix; | |
476 | r = in_addr_mask(family, &masked_prefix, prefixlen); | |
477 | if (r < 0) | |
478 | return r; | |
479 | ||
480 | masked_address = *address; | |
481 | r = in_addr_mask(family, &masked_address, prefixlen); | |
482 | if (r < 0) | |
483 | return r; | |
484 | ||
485 | return in_addr_equal(family, &masked_prefix, &masked_address); | |
486 | } | |
487 | ||
f4912f3a LP |
488 | int in_addr_parse_prefixlen(int family, const char *p, unsigned char *ret) { |
489 | uint8_t u; | |
490 | int r; | |
491 | ||
492 | if (!IN_SET(family, AF_INET, AF_INET6)) | |
493 | return -EAFNOSUPPORT; | |
494 | ||
495 | r = safe_atou8(p, &u); | |
496 | if (r < 0) | |
497 | return r; | |
498 | ||
499 | if (u > FAMILY_ADDRESS_SIZE(family) * 8) | |
500 | return -ERANGE; | |
501 | ||
502 | *ret = u; | |
503 | return 0; | |
504 | } | |
505 | ||
9e0fdc21 | 506 | int in_addr_prefix_from_string( |
f4912f3a LP |
507 | const char *p, |
508 | int family, | |
509 | union in_addr_union *ret_prefix, | |
510 | unsigned char *ret_prefixlen) { | |
511 | ||
67944f5c | 512 | _cleanup_free_ char *str = NULL; |
f7bf1abe SS |
513 | union in_addr_union buffer; |
514 | const char *e, *l; | |
f4912f3a | 515 | unsigned char k; |
f7bf1abe SS |
516 | int r; |
517 | ||
518 | assert(p); | |
519 | ||
520 | if (!IN_SET(family, AF_INET, AF_INET6)) | |
521 | return -EAFNOSUPPORT; | |
522 | ||
523 | e = strchr(p, '/'); | |
67944f5c YW |
524 | if (e) { |
525 | str = strndup(p, e - p); | |
526 | if (!str) | |
527 | return -ENOMEM; | |
528 | ||
529 | l = str; | |
530 | } else | |
f7bf1abe SS |
531 | l = p; |
532 | ||
533 | r = in_addr_from_string(family, l, &buffer); | |
534 | if (r < 0) | |
535 | return r; | |
536 | ||
f7bf1abe | 537 | if (e) { |
f4912f3a | 538 | r = in_addr_parse_prefixlen(family, e+1, &k); |
f7bf1abe SS |
539 | if (r < 0) |
540 | return r; | |
f4912f3a LP |
541 | } else |
542 | k = FAMILY_ADDRESS_SIZE(family) * 8; | |
f7bf1abe | 543 | |
f4912f3a LP |
544 | if (ret_prefix) |
545 | *ret_prefix = buffer; | |
546 | if (ret_prefixlen) | |
547 | *ret_prefixlen = k; | |
f7bf1abe | 548 | |
f4912f3a LP |
549 | return 0; |
550 | } | |
f7bf1abe | 551 | |
a4798d4e | 552 | int in_addr_prefix_from_string_auto_internal( |
f4912f3a | 553 | const char *p, |
9e0fdc21 | 554 | InAddrPrefixLenMode mode, |
f4912f3a LP |
555 | int *ret_family, |
556 | union in_addr_union *ret_prefix, | |
557 | unsigned char *ret_prefixlen) { | |
558 | ||
67944f5c | 559 | _cleanup_free_ char *str = NULL; |
f4912f3a LP |
560 | union in_addr_union buffer; |
561 | const char *e, *l; | |
562 | unsigned char k; | |
563 | int family, r; | |
564 | ||
565 | assert(p); | |
566 | ||
567 | e = strchr(p, '/'); | |
67944f5c YW |
568 | if (e) { |
569 | str = strndup(p, e - p); | |
570 | if (!str) | |
571 | return -ENOMEM; | |
572 | ||
573 | l = str; | |
574 | } else | |
f4912f3a LP |
575 | l = p; |
576 | ||
577 | r = in_addr_from_string_auto(l, &family, &buffer); | |
578 | if (r < 0) | |
579 | return r; | |
580 | ||
581 | if (e) { | |
582 | r = in_addr_parse_prefixlen(family, e+1, &k); | |
583 | if (r < 0) | |
a4798d4e | 584 | return r; |
f4912f3a | 585 | } else |
9e0fdc21 YW |
586 | switch (mode) { |
587 | case PREFIXLEN_FULL: | |
588 | k = FAMILY_ADDRESS_SIZE(family) * 8; | |
589 | break; | |
590 | case PREFIXLEN_REFUSE: | |
591 | return -ENOANO; /* To distinguish this error from others. */ | |
592 | case PREFIXLEN_LEGACY: | |
593 | if (family == AF_INET) { | |
594 | r = in4_addr_default_prefixlen(&buffer.in, &k); | |
595 | if (r < 0) | |
596 | return r; | |
597 | } else | |
598 | k = 0; | |
599 | break; | |
600 | default: | |
601 | assert_not_reached("Invalid prefixlen mode"); | |
602 | } | |
f4912f3a LP |
603 | |
604 | if (ret_family) | |
605 | *ret_family = family; | |
606 | if (ret_prefix) | |
607 | *ret_prefix = buffer; | |
608 | if (ret_prefixlen) | |
609 | *ret_prefixlen = k; | |
f7bf1abe SS |
610 | |
611 | return 0; | |
f4912f3a | 612 | |
f7bf1abe | 613 | } |
6c39e026 | 614 | |
7a08d314 | 615 | static void in_addr_data_hash_func(const struct in_addr_data *a, struct siphash *state) { |
6c39e026 | 616 | siphash24_compress(&a->family, sizeof(a->family), state); |
23577246 | 617 | siphash24_compress(&a->address, FAMILY_ADDRESS_SIZE(a->family), state); |
6c39e026 YW |
618 | } |
619 | ||
7a08d314 | 620 | static int in_addr_data_compare_func(const struct in_addr_data *x, const struct in_addr_data *y) { |
a0edd02e | 621 | int r; |
6c39e026 | 622 | |
a0edd02e FB |
623 | r = CMP(x->family, y->family); |
624 | if (r != 0) | |
625 | return r; | |
6c39e026 | 626 | |
23577246 | 627 | return memcmp(&x->address, &y->address, FAMILY_ADDRESS_SIZE(x->family)); |
6c39e026 YW |
628 | } |
629 | ||
7a08d314 | 630 | DEFINE_HASH_OPS(in_addr_data_hash_ops, struct in_addr_data, in_addr_data_hash_func, in_addr_data_compare_func); |