oops
[libnl.git] / lib / route / addr.c
1 /*
2  * lib/route/addr.c             Addresses
3  *
4  *      This library is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU Lesser General Public
6  *      License as published by the Free Software Foundation version 2.1
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  *                         Baruch Even <baruch@ev-en.org>,
11  *                         Mediatrix Telecom, inc. <ericb@mediatrix.com>
12  */
13
14 /**
15  * @ingroup rtnl
16  * @defgroup rtaddr Addresses
17  * @brief
18  *
19  * @par 1) Address Addition
20  * @code
21  * // Allocate an empty address object to be filled out with the attributes
22  * // of the new address.
23  * struct rtnl_addr *addr = rtnl_addr_alloc();
24  *
25  * // Fill out the mandatory attributes of the new address. Setting the
26  * // local address will automatically set the address family and the
27  * // prefix length to the correct values.
28  * rtnl_addr_set_ifindex(addr, ifindex);
29  * rtnl_addr_set_local(addr, local_addr);
30  *
31  * // The label of the address can be specified, currently only supported
32  * // by IPv4 and DECnet.
33  * rtnl_addr_set_label(addr, "mylabel");
34  *
35  * // The peer address can be specified if necessary, in either case a peer
36  * // address will be sent to the kernel in order to fullfil the interface
37  * // requirements. If none is set, it will equal the local address.
38  * // Note: Real peer addresses are only supported by IPv4 for now.
39  * rtnl_addr_set_peer(addr, peer_addr);
40  *
41  * // In case you want to have the address have a scope other than global
42  * // it may be overwritten using rtnl_addr_set_scope(). The scope currently
43  * // cannot be set for IPv6 addresses.
44  * rtnl_addr_set_scope(addr, rtnl_str2scope("site"));
45  *
46  * // Broadcast and anycast address may be specified using the relevant
47  * // functions, the address family will be verified if one of the other
48  * // addresses has been set already. Currently only works for IPv4.
49  * rtnl_addr_set_broadcast(addr, broadcast_addr);
50  * rtnl_addr_set_anycast(addr, anycast_addr);
51  *
52  * // Build the netlink message and send it to the kernel, the operation will
53  * // block until the operation has been completed. Alternatively the required
54  * // netlink message can be built using rtnl_addr_build_add_request() to be
55  * // sent out using nl_send_auto_complete().
56  * rtnl_addr_add(handle, addr, 0);
57  *
58  * // Free the memory
59  * rtnl_addr_put(addr);
60  * @endcode
61  *
62  * @par 2) Address Deletion
63  * @code
64  * // Allocate an empty address object to be filled out with the attributes
65  * // matching the address to be deleted. Alternatively a fully equipped
66  * // address object out of a cache can be used instead.
67  * struct rtnl_addr *addr = rtnl_addr_alloc();
68  *
69  * // The only mandatory parameter besides the address family is the interface
70  * // index the address is on, i.e. leaving out all other parameters will
71  * // result in all addresses of the specified address family interface tuple
72  * // to be deleted.
73  * rtnl_addr_set_ifindex(addr, ifindex);
74  *
75  * // Specyfing the address family manually is only required if neither the
76  * // local nor peer address have been specified.
77  * rtnl_addr_set_family(addr, AF_INET);
78  *
79  * // Specyfing the local address is optional but the best choice to delete
80  * // specific addresses.
81  * rtnl_addr_set_local(addr, local_addr);
82  *
83  * // The label of the address can be specified, currently only supported
84  * // by IPv4 and DECnet.
85  * rtnl_addr_set_label(addr, "mylabel");
86  *
87  * // The peer address can be specified if necessary, in either case a peer
88  * // address will be sent to the kernel in order to fullfil the interface
89  * // requirements. If none is set, it will equal the local address.
90  * // Note: Real peer addresses are only supported by IPv4 for now.
91  * rtnl_addr_set_peer(addr, peer_addr);
92  *
93  * // Build the netlink message and send it to the kernel, the operation will
94  * // block until the operation has been completed. Alternatively the required
95  * // netlink message can be built using rtnl_addr_build_delete_request()
96  * // to be sent out using nl_send_auto_complete().
97  * rtnl_addr_delete(handle, addr, 0);
98  *
99  * // Free the memory
100  * rtnl_addr_put(addr);
101  * @endcode
102  * @{
103  */
104
105 #include <netlink-local.h>
106 #include <netlink/netlink.h>
107 #include <netlink/route/rtnl.h>
108 #include <netlink/route/addr.h>
109 #include <netlink/route/route.h>
110 #include <netlink/route/link.h>
111 #include <netlink/utils.h>
112
113 /** @cond SKIP */
114 #define ADDR_ATTR_FAMILY        0x0001
115 #define ADDR_ATTR_PREFIXLEN     0x0002
116 #define ADDR_ATTR_FLAGS         0x0004
117 #define ADDR_ATTR_SCOPE         0x0008
118 #define ADDR_ATTR_IFINDEX       0x0010
119 #define ADDR_ATTR_LABEL         0x0020
120 #define ADDR_ATTR_CACHEINFO     0x0040
121 #define ADDR_ATTR_PEER          0x0080
122 #define ADDR_ATTR_LOCAL         0x0100
123 #define ADDR_ATTR_BROADCAST     0x0200
124 #define ADDR_ATTR_ANYCAST       0x0400
125 #define ADDR_ATTR_MULTICAST     0x0800
126
127 static struct nl_cache_ops rtnl_addr_ops;
128 /** @endcond */
129
130 static void addr_free_data(struct nl_object *obj)
131 {
132         struct rtnl_addr *addr = nl_object_priv(obj);
133
134         if (!addr)
135                 return;
136
137         nl_addr_put(addr->a_peer);
138         nl_addr_put(addr->a_local);
139         nl_addr_put(addr->a_bcast);
140         nl_addr_put(addr->a_anycast);
141         nl_addr_put(addr->a_multicast);
142 }
143
144 static struct nla_policy addr_policy[IFA_MAX+1] = {
145         [IFA_LABEL]     = { .type = NLA_STRING,
146                             .maxlen = IFNAMSIZ },
147         [IFA_CACHEINFO] = { .minlen = sizeof(struct ifa_cacheinfo) },
148 };
149
150 static int addr_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *nlh,
151                            void *arg)
152 {
153         struct rtnl_addr *addr;
154         struct nl_parser_param *pp = arg;
155         struct ifaddrmsg *ifa;
156         struct nlattr *tb[IFA_MAX+1];
157         int err = -ENOMEM, peer_prefix = 0;
158
159         addr = rtnl_addr_alloc();
160         if (!addr) {
161                 err = nl_errno(ENOMEM);
162                 goto errout;
163         }
164         addr->ce_msgtype = nlh->nlmsg_type;
165
166         err = nlmsg_parse(nlh, sizeof(*ifa), tb, IFA_MAX, addr_policy);
167         if (err < 0)
168                 goto errout_free;
169
170         ifa = nlmsg_data(nlh);
171         addr->a_family = ifa->ifa_family;
172         addr->a_prefixlen = ifa->ifa_prefixlen;
173         addr->a_flags = ifa->ifa_flags;
174         addr->a_scope = ifa->ifa_scope;
175         addr->a_ifindex = ifa->ifa_index;
176
177         addr->a_mask = (ADDR_ATTR_FAMILY | ADDR_ATTR_PREFIXLEN |
178                         ADDR_ATTR_FLAGS | ADDR_ATTR_SCOPE | ADDR_ATTR_IFINDEX);
179
180         if (tb[IFA_LABEL]) {
181                 nla_strlcpy(addr->a_label, tb[IFA_LABEL], IFNAMSIZ);
182                 addr->a_mask |= ADDR_ATTR_LABEL;
183         }
184
185         if (tb[IFA_CACHEINFO]) {
186                 struct ifa_cacheinfo *ca;
187                 
188                 ca = nla_data(tb[IFA_CACHEINFO]);
189                 addr->a_cacheinfo.aci_prefered = ca->ifa_prefered;
190                 addr->a_cacheinfo.aci_valid = ca->ifa_valid;
191                 addr->a_cacheinfo.aci_cstamp = ca->cstamp;
192                 addr->a_cacheinfo.aci_tstamp = ca->tstamp;
193                 addr->a_mask |= ADDR_ATTR_CACHEINFO;
194         }
195
196         if (tb[IFA_LOCAL]) {
197                 addr->a_local = nla_get_addr(tb[IFA_LOCAL], addr->a_family);
198                 if (!addr->a_local)
199                         goto errout_free;
200                 addr->a_mask |= ADDR_ATTR_LOCAL;
201         }
202
203         if (tb[IFA_ADDRESS]) {
204                 struct nl_addr *a;
205
206                 a = nla_get_addr(tb[IFA_ADDRESS], addr->a_family);
207                 if (!a)
208                         goto errout_free;
209
210                 /* IPv6 sends the local address as IFA_ADDRESS with
211                  * no IFA_LOCAL, IPv4 sends both IFA_LOCAL and IFA_ADDRESS
212                  * with IFA_ADDRESS being the peer address if they differ */
213                 if (!tb[IFA_LOCAL] || !nl_addr_cmp(a, addr->a_local)) {
214                         nl_addr_put(addr->a_local);
215                         addr->a_local = a;
216                         addr->a_mask |= ADDR_ATTR_LOCAL;
217                 } else {
218                         addr->a_peer = a;
219                         addr->a_mask |= ADDR_ATTR_PEER;
220                         peer_prefix = 1;
221                 }
222         }
223
224         nl_addr_set_prefixlen(peer_prefix ? addr->a_peer : addr->a_local,
225                               addr->a_prefixlen);
226
227         if (tb[IFA_BROADCAST]) {
228                 addr->a_bcast = nla_get_addr(tb[IFA_BROADCAST], addr->a_family);
229                 if (!addr->a_bcast)
230                         goto errout_free;
231
232                 addr->a_mask |= ADDR_ATTR_BROADCAST;
233         }
234
235         if (tb[IFA_ANYCAST]) {
236                 addr->a_anycast = nla_get_addr(tb[IFA_ANYCAST], addr->a_family);
237                 if (!addr->a_anycast)
238                         goto errout_free;
239
240                 addr->a_mask |= ADDR_ATTR_ANYCAST;
241         }
242
243         if (tb[IFA_MULTICAST]) {
244                 addr->a_multicast = nla_get_addr(tb[IFA_MULTICAST],
245                                                  addr->a_family);
246                 if (!addr->a_multicast)
247                         goto errout_free;
248
249                 addr->a_mask |= ADDR_ATTR_MULTICAST;
250         }
251
252         err = pp->pp_cb((struct nl_object *) addr, pp);
253         if (err < 0)
254                 goto errout_free;
255
256         return P_ACCEPT;
257
258 errout_free:
259         rtnl_addr_free(addr);
260 errout:
261         return err;
262 }
263
264 static int addr_request_update(struct nl_cache *cache, struct nl_handle *handle)
265 {
266         return nl_rtgen_request(handle, RTM_GETADDR, AF_UNSPEC, NLM_F_DUMP);
267 }
268
269 static int addr_dump_brief(struct nl_object *obj, struct nl_dump_params *p)
270 {
271         struct rtnl_addr *addr = (struct rtnl_addr *) obj;
272         struct nl_cache *link_cache;
273         char buf[128];
274
275         link_cache = nl_cache_mngt_require("route/link");
276
277         if (addr->a_mask & ADDR_ATTR_LOCAL)
278                 dp_dump(p, "%s",
279                         nl_addr2str(addr->a_local, buf, sizeof(buf)));
280         else
281                 dp_dump(p, "none");
282
283         if (addr->a_mask & ADDR_ATTR_PEER)
284                 dp_dump(p, " peer %s",
285                         nl_addr2str(addr->a_peer, buf, sizeof(buf)));
286
287         dp_dump(p, " %s ", nl_af2str(addr->a_family, buf, sizeof(buf)));
288
289         if (link_cache)
290                 dp_dump(p, "dev %s ",
291                         rtnl_link_i2name(link_cache, addr->a_ifindex,
292                                          buf, sizeof(buf)));
293         else
294                 dp_dump(p, "dev %d ", addr->a_ifindex);
295
296         dp_dump(p, "scope %s",
297                 rtnl_scope2str(addr->a_scope, buf, sizeof(buf)));
298
299         rtnl_addr_flags2str(addr->a_flags, buf, sizeof(buf));
300         if (buf[0])
301                 dp_dump(p, " <%s>", buf);
302
303         dp_dump(p, "\n");
304
305         return 1;
306 }
307
308 static int addr_dump_full(struct nl_object *obj, struct nl_dump_params *p)
309 {
310         struct rtnl_addr *addr = (struct rtnl_addr *) obj;
311         int line = addr_dump_brief(obj, p);
312         char buf[128];
313
314         if (addr->a_mask & (ADDR_ATTR_LABEL | ADDR_ATTR_BROADCAST |
315                             ADDR_ATTR_ANYCAST | ADDR_ATTR_MULTICAST)) {
316                 dp_dump_line(p, line++, "  ");
317
318                 if (addr->a_mask & ADDR_ATTR_LABEL)
319                         dp_dump(p, " label %s", addr->a_label);
320
321                 if (addr->a_mask & ADDR_ATTR_BROADCAST)
322                         dp_dump(p, " broadcast %s",
323                                 nl_addr2str(addr->a_bcast, buf, sizeof(buf)));
324
325                 if (addr->a_mask & ADDR_ATTR_ANYCAST)
326                         dp_dump(p, " anycast %s",
327                                 nl_addr2str(addr->a_anycast, buf,
328                                               sizeof(buf)));
329
330                 if (addr->a_mask & ADDR_ATTR_MULTICAST)
331                         dp_dump(p, " multicast %s",
332                                 nl_addr2str(addr->a_multicast, buf,
333                                               sizeof(buf)));
334
335                 dp_dump(p, "\n");
336         }
337
338         if (addr->a_mask & ADDR_ATTR_CACHEINFO) {
339                 struct rtnl_addr_cacheinfo *ci = &addr->a_cacheinfo;
340
341                 dp_dump_line(p, line++, "   valid-lifetime %s",
342                              ci->aci_valid == 0xFFFFFFFFU ? "forever" :
343                              nl_msec2str(ci->aci_valid * 1000,
344                                            buf, sizeof(buf)));
345
346                 dp_dump(p, " preferred-lifetime %s\n",
347                         ci->aci_prefered == 0xFFFFFFFFU ? "forever" :
348                         nl_msec2str(ci->aci_prefered * 1000,
349                                       buf, sizeof(buf)));
350
351                 dp_dump_line(p, line++, "   created boot-time+%s ",
352                              nl_msec2str(addr->a_cacheinfo.aci_cstamp * 10,
353                                            buf, sizeof(buf)));
354                     
355                 dp_dump(p, "last-updated boot-time+%s\n",
356                         nl_msec2str(addr->a_cacheinfo.aci_tstamp * 10,
357                                       buf, sizeof(buf)));
358         }
359
360         return line;
361 }
362
363 static int addr_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
364 {
365         return addr_dump_full(obj, p);
366 }
367
368 static int addr_dump_xml(struct nl_object *obj, struct nl_dump_params *p)
369 {
370         struct rtnl_addr *addr = (struct rtnl_addr *) obj;
371         struct nl_cache *link_cache;
372         char buf[128];
373         int line = 0;
374
375         dp_dump_line(p, line++, "<address>\n");
376         dp_dump_line(p, line++, "  <family>%s</family>\n",
377                      nl_af2str(addr->a_family, buf, sizeof(buf)));
378
379         if (addr->a_mask & ADDR_ATTR_LOCAL)
380                 dp_dump_line(p, line++, "  <local>%s</local>\n",
381                              nl_addr2str(addr->a_local, buf, sizeof(buf)));
382
383         if (addr->a_mask & ADDR_ATTR_PEER)
384                 dp_dump_line(p, line++, "  <peer>%s</peer>\n",
385                              nl_addr2str(addr->a_peer, buf, sizeof(buf)));
386
387         if (addr->a_mask & ADDR_ATTR_BROADCAST)
388                 dp_dump_line(p, line++, "  <broadcast>%s</broadcast>\n",
389                              nl_addr2str(addr->a_bcast, buf, sizeof(buf)));
390
391         if (addr->a_mask & ADDR_ATTR_ANYCAST)
392                 dp_dump_line(p, line++, "  <anycast>%s</anycast>\n",
393                              nl_addr2str(addr->a_anycast, buf, sizeof(buf)));
394
395         if (addr->a_mask & ADDR_ATTR_MULTICAST)
396                 dp_dump_line(p, line++, "  <multicast>%s</multicast>\n",
397                              nl_addr2str(addr->a_multicast, buf,
398                                            sizeof(buf)));
399
400         if (addr->a_mask & ADDR_ATTR_PREFIXLEN)
401                 dp_dump_line(p, line++, "  <prefixlen>%u</prefixlen>\n",
402                              addr->a_prefixlen);
403         link_cache = nl_cache_mngt_require("route/link");
404
405         if (link_cache)
406                 dp_dump_line(p, line++, "  <device>%s</device>\n",
407                              rtnl_link_i2name(link_cache, addr->a_ifindex,
408                                               buf, sizeof(buf)));
409         else
410                 dp_dump_line(p, line++, "  <device>%u</device>\n",
411                              addr->a_ifindex);
412
413         if (addr->a_mask & ADDR_ATTR_SCOPE)
414                 dp_dump_line(p, line++, "  <scope>%s</scope>\n",
415                              rtnl_scope2str(addr->a_scope, buf, sizeof(buf)));
416
417         if (addr->a_mask & ADDR_ATTR_LABEL)
418                 dp_dump_line(p, line++, "  <label>%s</label>\n", addr->a_label);
419
420         rtnl_addr_flags2str(addr->a_flags, buf, sizeof(buf));
421         if (buf[0])
422                 dp_dump_line(p, line++, "  <flags>%s</flags>\n", buf);
423
424         if (addr->a_mask & ADDR_ATTR_CACHEINFO) {
425                 struct rtnl_addr_cacheinfo *ci = &addr->a_cacheinfo;
426
427                 dp_dump_line(p, line++, "  <cacheinfo>\n");
428
429                 dp_dump_line(p, line++, "    <valid>%s</valid>\n",
430                              ci->aci_valid == 0xFFFFFFFFU ? "forever" :
431                              nl_msec2str(ci->aci_valid * 1000,
432                                            buf, sizeof(buf)));
433
434                 dp_dump_line(p, line++, "    <prefered>%s</prefered>\n",
435                              ci->aci_prefered == 0xFFFFFFFFU ? "forever" :
436                              nl_msec2str(ci->aci_prefered * 1000,
437                                          buf, sizeof(buf)));
438
439                 dp_dump_line(p, line++, "    <created>%s</created>\n",
440                              nl_msec2str(addr->a_cacheinfo.aci_cstamp * 10,
441                                          buf, sizeof(buf)));
442
443                 dp_dump_line(p, line++, "    <last-update>%s</last-update>\n",
444                              nl_msec2str(addr->a_cacheinfo.aci_tstamp * 10,
445                                          buf, sizeof(buf)));
446
447                 dp_dump_line(p, line++, "  </cacheinfo>\n");
448         }
449
450         dp_dump_line(p, line++, "</address>\n");
451
452         return line;
453 }
454
455 static int addr_dump_env(struct nl_object *obj, struct nl_dump_params *p)
456 {
457         struct rtnl_addr *addr = (struct rtnl_addr *) obj;
458         struct nl_cache *link_cache;
459         char buf[128];
460         int line = 0;
461
462         dp_dump_line(p, line++, "ADDR_FAMILY=%s\n",
463                      nl_af2str(addr->a_family, buf, sizeof(buf)));
464
465         if (addr->a_mask & ADDR_ATTR_LOCAL)
466                 dp_dump_line(p, line++, "ADDR_LOCAL=%s\n",
467                              nl_addr2str(addr->a_local, buf, sizeof(buf)));
468
469         if (addr->a_mask & ADDR_ATTR_PEER)
470                 dp_dump_line(p, line++, "ADDR_PEER=%s\n",
471                              nl_addr2str(addr->a_peer, buf, sizeof(buf)));
472
473         if (addr->a_mask & ADDR_ATTR_BROADCAST)
474                 dp_dump_line(p, line++, "ADDR_BROADCAST=%s\n",
475                              nl_addr2str(addr->a_bcast, buf, sizeof(buf)));
476
477         if (addr->a_mask & ADDR_ATTR_ANYCAST)
478                 dp_dump_line(p, line++, "ADDR_ANYCAST=%s\n",
479                              nl_addr2str(addr->a_anycast, buf, sizeof(buf)));
480
481         if (addr->a_mask & ADDR_ATTR_MULTICAST)
482                 dp_dump_line(p, line++, "ADDR_MULTICAST=%s\n",
483                              nl_addr2str(addr->a_multicast, buf,
484                                            sizeof(buf)));
485
486         if (addr->a_mask & ADDR_ATTR_PREFIXLEN)
487                 dp_dump_line(p, line++, "ADDR_PREFIXLEN=%u\n",
488                              addr->a_prefixlen);
489         link_cache = nl_cache_mngt_require("route/link");
490
491         dp_dump_line(p, line++, "ADDR_IFINDEX=%u\n", addr->a_ifindex);
492         if (link_cache)
493                 dp_dump_line(p, line++, "ADDR_IFNAME=%s\n",
494                              rtnl_link_i2name(link_cache, addr->a_ifindex,
495                                               buf, sizeof(buf)));
496
497         if (addr->a_mask & ADDR_ATTR_SCOPE)
498                 dp_dump_line(p, line++, "ADDR_SCOPE=%s\n",
499                              rtnl_scope2str(addr->a_scope, buf, sizeof(buf)));
500
501         if (addr->a_mask & ADDR_ATTR_LABEL)
502                 dp_dump_line(p, line++, "ADDR_LABEL=%s\n", addr->a_label);
503
504         rtnl_addr_flags2str(addr->a_flags, buf, sizeof(buf));
505         if (buf[0])
506                 dp_dump_line(p, line++, "ADDR_FLAGS=%s\n", buf);
507
508         if (addr->a_mask & ADDR_ATTR_CACHEINFO) {
509                 struct rtnl_addr_cacheinfo *ci = &addr->a_cacheinfo;
510
511                 dp_dump_line(p, line++, "ADDR_CACHEINFO_VALID=%s\n",
512                              ci->aci_valid == 0xFFFFFFFFU ? "forever" :
513                              nl_msec2str(ci->aci_valid * 1000,
514                                            buf, sizeof(buf)));
515
516                 dp_dump_line(p, line++, "ADDR_CACHEINFO_PREFERED=%s\n",
517                              ci->aci_prefered == 0xFFFFFFFFU ? "forever" :
518                              nl_msec2str(ci->aci_prefered * 1000,
519                                          buf, sizeof(buf)));
520
521                 dp_dump_line(p, line++, "ADDR_CACHEINFO_CREATED=%s\n",
522                              nl_msec2str(addr->a_cacheinfo.aci_cstamp * 10,
523                                          buf, sizeof(buf)));
524
525                 dp_dump_line(p, line++, "ADDR_CACHEINFO_LASTUPDATE=%s\n",
526                              nl_msec2str(addr->a_cacheinfo.aci_tstamp * 10,
527                                          buf, sizeof(buf)));
528         }
529
530         return line;
531 }
532
533 static int addr_filter(struct nl_object *obj, struct nl_object *filter)
534 {
535         struct rtnl_addr *o = (struct rtnl_addr *) obj;
536         struct rtnl_addr *f = (struct rtnl_addr *) filter;
537
538 #define REQ(F) (f->a_mask & ADDR_ATTR_##F)
539 #define AVAIL(F) (o->a_mask & ADDR_ATTR_##F)
540 #define _O(F, EXPR) (REQ(F) && (!AVAIL(F) || (EXPR)))
541 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (o->N != f->N)))
542         if (_C(IFINDEX,    a_ifindex)                                   ||
543             _C(FAMILY,     a_family)                                    ||
544             _C(SCOPE,      a_scope)                                     ||
545             _O(FLAGS,      f->a_flags ^ (o->a_flags & f->a_flag_mask))  ||
546             _O(LABEL,      strcmp(o->a_label, f->a_label))              ||
547             _O(PEER,       nl_addr_cmp(o->a_peer, f->a_peer))           ||
548             _O(LOCAL,      nl_addr_cmp(o->a_local, f->a_local))         ||
549             _O(ANYCAST,    nl_addr_cmp(o->a_anycast, f->a_anycast))     ||
550             _O(MULTICAST,  nl_addr_cmp(o->a_multicast, f->a_multicast)) ||
551             _O(BROADCAST,  nl_addr_cmp(o->a_bcast, f->a_bcast)))
552                 return 0;
553 #undef REQ
554 #undef AVAIL
555 #undef _O
556 #undef _C
557
558         return 1;
559 }
560
561 /**
562  * @name Address Object Creation/Deletion
563  * @{
564  */
565
566 /**
567  * Allocate and initialize a new address object
568  * @note Free the memory after usage using rtnl_addr_put() or rtnl_addr_free().
569  * @return Newly allocated address object or NULL if an error occured.
570  */
571 struct rtnl_addr *rtnl_addr_alloc(void)
572 {
573         return (struct rtnl_addr *) nl_object_alloc_from_ops(&rtnl_addr_ops);
574 }
575
576 /**
577  * Give back a reference on a address object.
578  * @arg addr            Address object to be given back.
579  *
580  * Decrements the reference counter and frees the object if the
581  * last reference has been released.
582  */
583 void rtnl_addr_put(struct rtnl_addr *addr)
584 {
585         nl_object_put((struct nl_object *) addr);
586 }
587
588 /**
589  * Free an address object
590  * @arg addr            Address object to be freed.
591  *
592  * @note Always use rtnl_addr_put() unless you're absolutely sure
593  *       that no other user may have a reference on this object.
594  */
595 void rtnl_addr_free(struct rtnl_addr *addr)
596 {
597         nl_object_free((struct nl_object *) addr);
598 }
599
600 /** @} */
601
602 /**
603  * @name Address Cache Management
604  * @{
605  */
606
607 /**
608  * Allocate address cache and fill in all configured addresses
609  * @arg handle          Netlink handle.
610  *
611  * Allocates a new address cache, initializes it properly and updates it
612  * to include all addresses currently configured in the kernel.
613  *
614  * @note Free the memory after usage.
615  * @return Newly allocated cache or NULL if an error occured.
616  */
617 struct nl_cache *rtnl_addr_alloc_cache(struct nl_handle *handle)
618 {
619         struct nl_cache *cache;
620         
621         cache = nl_cache_alloc_from_ops(&rtnl_addr_ops);
622         if (!cache)
623                 return NULL;
624
625         if (nl_cache_update(handle, cache) < 0) {
626                 nl_cache_free(cache);
627                 return NULL;
628         }
629
630         return cache;
631 }
632
633 /** @} */
634
635 static struct nl_msg *build_addr_msg(struct rtnl_addr *tmpl, int cmd, int flags)
636 {
637         struct nl_msg *msg;
638         struct ifaddrmsg am = {
639                 .ifa_family = tmpl->a_family,
640                 .ifa_index = tmpl->a_ifindex,
641                 .ifa_prefixlen = tmpl->a_prefixlen,
642         };
643
644         if (tmpl->a_mask & ADDR_ATTR_SCOPE)
645                 am.ifa_scope = tmpl->a_scope;
646         else {
647                 /* compatibility hack */
648                 if (tmpl->a_family == AF_INET &&
649                     tmpl->a_mask & ADDR_ATTR_LOCAL &&
650                     *((char *) nl_addr_get_binary_addr(tmpl->a_local)) == 127)
651                         am.ifa_scope = RT_SCOPE_HOST;
652                 else
653                         am.ifa_scope = RT_SCOPE_UNIVERSE;
654         }
655
656         msg = nlmsg_build_simple(cmd, flags);
657         if (!msg)
658                 goto nla_put_failure;
659
660         if (nlmsg_append(msg, &am, sizeof(am), 1) < 0)
661                 goto nla_put_failure;
662
663         if (tmpl->a_mask & ADDR_ATTR_LOCAL)
664                 NLA_PUT_ADDR(msg, IFA_LOCAL, tmpl->a_local);
665
666         if (tmpl->a_mask & ADDR_ATTR_PEER)
667                 NLA_PUT_ADDR(msg, IFA_ADDRESS, tmpl->a_peer);
668         else
669                 NLA_PUT_ADDR(msg, IFA_ADDRESS, tmpl->a_local);
670
671         if (tmpl->a_mask & ADDR_ATTR_LABEL)
672                 NLA_PUT_STRING(msg, IFA_LABEL, tmpl->a_label);
673
674         if (tmpl->a_mask & ADDR_ATTR_BROADCAST)
675                 NLA_PUT_ADDR(msg, IFA_BROADCAST, tmpl->a_bcast);
676
677         if (tmpl->a_mask & ADDR_ATTR_ANYCAST)
678                 NLA_PUT_ADDR(msg, IFA_ANYCAST, tmpl->a_anycast);
679
680         return msg;
681
682 nla_put_failure:
683         nlmsg_free(msg);
684         return NULL;
685 }
686
687 /**
688  * @name Address Addition
689  * @{
690  */
691
692 /**
693  * Build netlink request message to request addition of new address
694  * @arg addr            Address object representing the new address.
695  * @arg flags           Additional netlink message flags.
696  *
697  * Builds a new netlink message requesting the addition of a new
698  * address. The netlink message header isn't fully equipped with
699  * all relevant fields and must thus be sent out via nl_send_auto_complete()
700  * or supplemented as needed.
701  *
702  * Minimal required attributes:
703  *   - interface index (rtnl_addr_set_ifindex())
704  *   - local address (rtnl_addr_set_local())
705  *
706  * The scope will default to universe except for loopback addresses in
707  * which case a host scope is used if not specified otherwise.
708  *
709  * @note Free the memory after usage using nlmsg_free().
710  * @return Newly allocated netlink message or NULL if an error occured.
711  */
712 struct nl_msg *rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags)
713 {
714         int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
715                        ADDR_ATTR_PREFIXLEN | ADDR_ATTR_LOCAL;
716
717         if ((addr->a_mask & required) != required) {
718                 nl_error(EINVAL, "Missing mandatory attributes, required are: "
719                                  "ifindex, family, prefixlen, local address.");
720                 return NULL;
721         }
722         
723         return build_addr_msg(addr, RTM_NEWADDR, NLM_F_CREATE | flags);
724 }
725
726 /**
727  * Request addition of new address
728  * @arg handle          Netlink handle.
729  * @arg addr            Address object representing the new address.
730  * @arg flags           Additional netlink message flags.
731  *
732  * Builds a netlink message by calling rtnl_addr_build_add_request(),
733  * sends the request to the kernel and waits for the next ACK to be
734  * received and thus blocks until the request has been fullfilled.
735  *
736  * @see rtnl_addr_build_add_request()
737  *
738  * @return 0 on sucess or a negative error if an error occured.
739  */
740 int rtnl_addr_add(struct nl_handle *handle, struct rtnl_addr *addr, int flags)
741 {
742         struct nl_msg *msg;
743         int err;
744
745         msg = rtnl_addr_build_add_request(addr, flags);
746         if (!msg)
747                 return nl_get_errno();
748
749         err = nl_send_auto_complete(handle, msg);
750         nlmsg_free(msg);
751         if (err < 0)
752                 return err;
753
754         return nl_wait_for_ack(handle);
755 }
756
757 /** @} */
758
759 /**
760  * @name Address Deletion
761  * @{
762  */
763
764 /**
765  * Build a netlink request message to request deletion of an address
766  * @arg addr            Address object to be deleteted.
767  * @arg flags           Additional netlink message flags.
768  *
769  * Builds a new netlink message requesting a deletion of an address.
770  * The netlink message header isn't fully equipped with all relevant
771  * fields and must thus be sent out via nl_send_auto_complete()
772  * or supplemented as needed.
773  *
774  * Minimal required attributes:
775  *   - interface index (rtnl_addr_set_ifindex())
776  *   - address family (rtnl_addr_set_family())
777  *
778  * Optional attributes:
779  *   - local address (rtnl_addr_set_local())
780  *   - label (rtnl_addr_set_label(), IPv4/DECnet only)
781  *   - peer address (rtnl_addr_set_peer(), IPv4 only)
782  *
783  * @note Free the memory after usage using nlmsg_free().
784  * @return Newly allocated netlink message or NULL if an error occured.
785  */
786 struct nl_msg *rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags)
787 {
788         int required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
789
790         if ((addr->a_mask & required) != required) {
791                 nl_error(EINVAL, "Missing mandatory attributes, required are: "
792                                  "ifindex, family");
793                 return NULL;
794         }
795         
796         return build_addr_msg(addr, RTM_DELADDR, flags);
797 }
798
799 /**
800  * Request deletion of an address
801  * @arg handle          Netlink handle.
802  * @arg addr            Address object to be deleted.
803  * @arg flags           Additional netlink message flags.
804  *
805  * Builds a netlink message by calling rtnl_addr_build_delete_request(),
806  * sends the request to the kernel and waits for the next ACK to be
807  * received and thus blocks until the request has been fullfilled.
808  *
809  * @see rtnl_addr_build_delete_request();
810  *
811  * @return 0 on sucess or a negative error if an error occured.
812  */
813 int rtnl_addr_delete(struct nl_handle *handle, struct rtnl_addr *addr,
814                      int flags)
815 {
816         struct nl_msg *msg;
817         int err;
818
819         msg = rtnl_addr_build_delete_request(addr, flags);
820         if (!msg)
821                 return nl_get_errno();
822
823         err = nl_send_auto_complete(handle, msg);
824         nlmsg_free(msg);
825         if (err < 0)
826                 return err;
827
828         return nl_wait_for_ack(handle);
829 }
830
831 /** @} */
832
833 /**
834  * @name Attribute Access
835  * @{
836  */
837
838 /**
839  * Set label of address object
840  * @arg addr            Address object to be modified.
841  * @arg label           New address label.
842  * 
843  * @note The maximum size of an address label is IFNAMSIZ.
844  */
845 void rtnl_addr_set_label(struct rtnl_addr *addr, const char *label)
846 {
847         strncpy(addr->a_label, label, sizeof(addr->a_label) - 1);
848         addr->a_mask |= ADDR_ATTR_LABEL;
849 }
850
851 /**
852  * Get label of address object
853  * @arg addr            Address object.
854  * @return Address label or NULL if not set.
855  */
856 char *rtnl_addr_get_label(struct rtnl_addr *addr)
857 {
858         if (addr->a_mask & ADDR_ATTR_LABEL)
859                 return addr->a_label;
860         else
861                 return NULL;
862 }
863
864 /**
865  * Set interface index of address object
866  * @arg addr            Address object ot be modified.
867  * @arg ifindex         New interface index this address is on.
868  */
869 void rtnl_addr_set_ifindex(struct rtnl_addr *addr, int ifindex)
870 {
871         addr->a_ifindex = ifindex;
872         addr->a_mask |= ADDR_ATTR_IFINDEX;
873 }
874
875 /**
876  * Get interface index of address object
877  * @arg addr            Address object.
878  * @return Interface index address is on or RTNL_LINK_NOT_FOUND if not set.
879  */
880 int rtnl_addr_get_ifindex(struct rtnl_addr *addr)
881 {
882         if (addr->a_mask & ADDR_ATTR_IFINDEX)
883                 return addr->a_ifindex;
884         else
885                 return RTNL_LINK_NOT_FOUND;
886 }
887
888 /**
889  * Set address family of address object.
890  * @arg addr            Address object to be modified.
891  * @arg family          New address family
892  *
893  * @note The address family is set automatically if one of the addresses
894  *       is set and the family hasn't been specified yet. Setting it manually
895  *       can be used to enforce family validation while setting addresses.
896  */
897 void rtnl_addr_set_family(struct rtnl_addr *addr, int family)
898 {
899         addr->a_family = family;
900         addr->a_mask |= ADDR_ATTR_FAMILY;
901 }
902
903 /**
904  * Get address family of address object.
905  * @arg addr            Address object.
906  * @return Address family or AF_UNSPEC if not set.
907  */
908 int rtnl_addr_get_family(struct rtnl_addr *addr)
909 {
910         if (addr->a_mask & ADDR_ATTR_FAMILY)
911                 return addr->a_family;
912         else
913                 return AF_UNSPEC;
914 }
915
916 /**
917  * Set prefix length of address object.
918  * @arg addr            Address object to be modified.
919  * @arg prefix          New prefix length.
920  */
921 void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefix)
922 {
923         addr->a_prefixlen = prefix;
924         addr->a_mask |= ADDR_ATTR_PREFIXLEN;
925 }
926
927 /**
928  * Get prefix length of address object.
929  * @arg addr            Address object.
930  * @return Prefix length or a negative number if not set.
931  */
932 int rtnl_addr_get_prefixlen(struct rtnl_addr *addr)
933 {
934         if (addr->a_mask & ADDR_ATTR_PREFIXLEN)
935                 return addr->a_prefixlen;
936         else
937                 return -1;
938 }
939
940 /**
941  * Set scope of address object.
942  * @arg addr            Address object to be modified.
943  * @arg scope           New scope.
944  */
945 void rtnl_addr_set_scope(struct rtnl_addr *addr, int scope)
946 {
947         addr->a_scope = scope;
948         addr->a_mask |= ADDR_ATTR_SCOPE;
949 }
950
951 /**
952  * Get scope of address object.
953  * @arg addr            Address object.
954  * @return Scope or a negative number if not set.
955  */
956 int rtnl_addr_get_scope(struct rtnl_addr *addr)
957 {
958         if (addr->a_mask & ADDR_ATTR_SCOPE)
959                 return addr->a_scope;
960         else
961                 return -1;
962 }
963
964 /**
965  * Set flags of address object.
966  * @arg addr            Address object to be modified.
967  * @arg flags           Additional flags to set.
968  *
969  * @note Existing flags that have been set will not be overwritten.
970  */
971 void rtnl_addr_set_flags(struct rtnl_addr *addr, unsigned int flags)
972 {
973         addr->a_flag_mask |= flags;
974         addr->a_flags |= flags;
975         addr->a_mask |= ADDR_ATTR_FLAGS;
976 }
977
978 /**
979  * Unset flags of address object.
980  * @arg addr            Address object to be modified.
981  * @arg flags           Flags to unset.
982  */
983 void rtnl_addr_unset_flags(struct rtnl_addr *addr, unsigned int flags)
984 {
985         addr->a_flag_mask |= flags;
986         addr->a_flags &= ~flags;
987         addr->a_mask |= ADDR_ATTR_FLAGS;
988 }
989
990 /**
991  * Get flags of address object.
992  * @arg addr            Address object.
993  * @return Flags in form of a bitmask.
994  */
995 unsigned int rtnl_addr_get_flags(struct rtnl_addr *addr)
996 {
997         return addr->a_flags;
998 }
999
1000 static inline int __assign_addr(struct rtnl_addr *addr, struct nl_addr **pos,
1001                                 struct nl_addr *new, int flag)
1002 {
1003         if (addr->a_mask & ADDR_ATTR_FAMILY) {
1004                 if (new->a_family != addr->a_family)
1005                         return nl_error(EINVAL, "Address family mismatch");
1006         } else
1007                 addr->a_family = new->a_family;
1008
1009         if (*pos)
1010                 nl_addr_put(*pos);
1011
1012         *pos = nl_addr_get(new);
1013         addr->a_mask |= (flag | ADDR_ATTR_FAMILY);
1014
1015         return 0;
1016 }
1017
1018 /**
1019  * Set local address of address object.
1020  * @arg addr            Address object to be modified.
1021  * @arg local           New local address.
1022  *
1023  * Assigns the new local address to the specified address object. The
1024  * address is validated against the address family if set already via
1025  * either rtnl_addr_set_family() or by setting one of the other addresses.
1026  * The assignment fails if the address families mismatch. In case the
1027  * address family has not been specified yet, the address family of the
1028  * new address is elected to be the new requirement.
1029  *
1030  * @note The address may not contain a prefix length if the peer address
1031  *       has been specified already.
1032  * 
1033  * @return 0 on success or a negative error code.
1034  */
1035 int rtnl_addr_set_local(struct rtnl_addr *addr, struct nl_addr *local)
1036 {
1037         int err;
1038
1039         err = __assign_addr(addr, &addr->a_local, local, ADDR_ATTR_LOCAL);
1040         if (err < 0)
1041                 return err;
1042
1043         if (!(addr->a_mask & ADDR_ATTR_PEER)) {
1044                 addr->a_prefixlen = nl_addr_get_prefixlen(addr->a_local);
1045                 addr->a_mask |= ADDR_ATTR_PREFIXLEN;
1046         }
1047
1048         return 0;
1049 }
1050
1051 /**
1052  * Get local address of address object.
1053  * @arg addr            Address object.
1054  * @return Local address or NULL if not set.
1055  */
1056 struct nl_addr *rtnl_addr_get_local(struct rtnl_addr *addr)
1057 {
1058         if (addr->a_mask & ADDR_ATTR_LOCAL)
1059                 return addr->a_local;
1060         else
1061                 return NULL;
1062 }
1063
1064 /**
1065  * Set peer address of address object.
1066  * @arg addr            Address object to be modified.
1067  * @arg peer            New peer address.
1068  *
1069  * Assigns the new peer address to the specified address object. The
1070  * address is validated against the address family if set already via
1071  * either rtnl_addr_set_family() or by setting one of the other addresses.
1072  * The assignment fails if the address families mismatch. In case the
1073  * address family has not been specified yet, the address family of this
1074  * new address is elected to be the requirement.
1075  * 
1076  * @return 0 on success or a negative error code.
1077  */
1078 int rtnl_addr_set_peer(struct rtnl_addr *addr, struct nl_addr *peer)
1079 {
1080         return __assign_addr(addr, &addr->a_peer, peer, ADDR_ATTR_PEER);
1081
1082         addr->a_prefixlen = nl_addr_get_prefixlen(addr->a_peer);
1083         addr->a_mask |= ADDR_ATTR_PREFIXLEN;
1084
1085         return 0;
1086 }
1087
1088 /**
1089  * Get peer address of address object.
1090  * @arg addr            Adress object.
1091  * @return Peer address or NULL if not set.
1092  */
1093 struct nl_addr *rtnl_addr_get_peer(struct rtnl_addr *addr)
1094 {
1095         if (addr->a_mask & ADDR_ATTR_PEER)
1096                 return addr->a_peer;
1097         else
1098                 return NULL;
1099 }
1100
1101 /**
1102  * Set broadcast address of address object.
1103  * @arg addr            Address object to be modified.
1104  * @arg bcast           New broadcast address.
1105  *
1106  * Assigns the new broadcast address to the specified address object. The
1107  * address is validated against the address family if set already via
1108  * either rtnl_addr_set_family() or by setting one of the other addresses.
1109  * The assignment fails if the address families mismatch. In case the
1110  * address family has not been specified yet, the address family of this
1111  * new address is elected to be the requirement.
1112  * 
1113  * @return 0 on success or a negative error code.
1114  */
1115 int rtnl_addr_set_broadcast(struct rtnl_addr *addr, struct nl_addr *bcast)
1116 {
1117         return __assign_addr(addr, &addr->a_bcast, bcast, ADDR_ATTR_BROADCAST);
1118 }
1119
1120 /**
1121  * Get broadcast address of address object.
1122  * @arg addr            Address object.
1123  * @return Broadcast address or NULL if not set.
1124  */
1125 struct nl_addr *rtnl_addr_get_broadcast(struct rtnl_addr *addr)
1126 {
1127         if (addr->a_mask & ADDR_ATTR_BROADCAST)
1128                 return addr->a_bcast;
1129         else
1130                 return NULL;
1131 }
1132
1133 /**
1134  * Set anycast address of address object.
1135  * @arg addr            Address object to be modified.
1136  * @arg anycast         New anycast address.
1137  *
1138  * Assigns the new anycast address to the specified address object. The
1139  * address is validated against the address family if set already via
1140  * either rtnl_addr_set_family() or by setting one of the other addresses.
1141  * The assignment fails if the address families mismatch. In case the
1142  * address family has not been specified yet, the address family of this
1143  * new address is elected to be the requirement.
1144  * 
1145  * @return 0 on success or a negative error code.
1146  */
1147 int rtnl_addr_set_anycast(struct rtnl_addr *addr, struct nl_addr *anycast)
1148 {
1149         return __assign_addr(addr, &addr->a_anycast, anycast,
1150                              ADDR_ATTR_ANYCAST);
1151 }
1152
1153 /**
1154  * Get anycast address of address object.
1155  * @arg addr            Address object.
1156  * @return Anycast address or NULL if not set.
1157  */
1158 struct nl_addr *rtnl_addr_get_anycast(struct rtnl_addr *addr)
1159 {
1160         if (addr->a_mask & ADDR_ATTR_ANYCAST)
1161                 return addr->a_anycast;
1162         else
1163                 return NULL;
1164 }
1165
1166 /**
1167  * Set multicast address of address object.
1168  * @arg addr            Address object to be modified.
1169  * @arg multicast       New multicast address.
1170  *
1171  * Assigns the new multicast address to the specified address object. The
1172  * address is validated against the address family if set already via
1173  * either rtnl_addr_set_family() or by setting one of the other addresses.
1174  * The assignment fails if the address families mismatch. In case the
1175  * address family has not been specified yet, the address family of this
1176  * new address is elected to be the requirement.
1177  * 
1178  * @return 0 on success or a negative error code.
1179  */
1180 int rtnl_addr_set_multicast(struct rtnl_addr *addr, struct nl_addr *multicast)
1181 {
1182         return __assign_addr(addr, &addr->a_multicast, multicast,
1183                              ADDR_ATTR_MULTICAST);
1184 }
1185
1186 /**
1187  * Get multicast address of address object.
1188  * @arg addr            Address object.
1189  * @return Multicast address or NULL if not set.
1190  */
1191 struct nl_addr *rtnl_addr_get_multicast(struct rtnl_addr *addr)
1192 {
1193         if (addr->a_mask & ADDR_ATTR_MULTICAST)
1194                 return addr->a_multicast;
1195         else
1196                 return NULL;
1197 }
1198
1199 /** @} */
1200
1201 /**
1202  * @name Address Flags Translations
1203  * @{
1204  */
1205
1206 static struct trans_tbl addr_flags[] = {
1207         __ADD(IFA_F_SECONDARY, secondary)
1208         __ADD(IFA_F_DEPRECATED, deprecated)
1209         __ADD(IFA_F_TENTATIVE, tentative)
1210         __ADD(IFA_F_PERMANENT, permanent)
1211 };
1212
1213 /**
1214  * Convert address flags to character string.
1215  * @arg flags           Address flags.
1216  * @arg buf             Destination buffer.
1217  * @arg size            Size of destination buffer.
1218  *
1219  * Converts address flags to a character string separated by commas and
1220  * stores the resulting character string in the specified destination buffer.
1221  *
1222  * @return Formatted flags as character string.
1223  */
1224 char *rtnl_addr_flags2str(int flags, char *buf, size_t size)
1225 {
1226         return __flags2str(flags, buf, size, addr_flags,
1227                            ARRAY_SIZE(addr_flags));
1228 }
1229
1230 /**
1231  * Convert character string to address flags.
1232  * @arg name            Name of address flags.
1233  *
1234  * Converts the provided character string specifying any number of address
1235  * flags separated by commas to the corresponding numeric bitmask.
1236  *
1237  * @return Address flags in form of a bitmask.
1238  */
1239 int rtnl_addr_str2flags(const char *name)
1240 {
1241         return __str2flags(name, addr_flags, ARRAY_SIZE(addr_flags));
1242 }
1243
1244 /** @} */
1245
1246 static struct nl_cache_ops rtnl_addr_ops = {
1247         .co_name                = "route/addr",
1248         .co_size                = sizeof(struct rtnl_addr),
1249         .co_hdrsize             = sizeof(struct ifaddrmsg),
1250         .co_msgtypes            = {
1251                                         { RTM_NEWADDR, "new" },
1252                                         { RTM_DELADDR, "delete" },
1253                                         { RTM_GETADDR, "get" },
1254                                         { -1, NULL },
1255                                   },
1256         .co_protocol            = NETLINK_ROUTE,
1257         .co_request_update      = addr_request_update,
1258         .co_msg_parser          = addr_msg_parser,
1259         .co_free_data           = addr_free_data,
1260         .co_dump[NL_DUMP_BRIEF] = addr_dump_brief,
1261         .co_dump[NL_DUMP_FULL]  = addr_dump_full,
1262         .co_dump[NL_DUMP_STATS] = addr_dump_stats,
1263         .co_dump[NL_DUMP_XML]   = addr_dump_xml,
1264         .co_dump[NL_DUMP_ENV]   = addr_dump_env,
1265         .co_filter              = addr_filter,
1266 };
1267
1268 static void __init addr_init(void)
1269 {
1270         nl_cache_mngt_register(&rtnl_addr_ops);
1271 }
1272
1273 static void __exit neigh_exit(void)
1274 {
1275         nl_cache_mngt_unregister(&rtnl_addr_ops);
1276 }
1277
1278 /** @} */