libnl  3.2.27
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-2012 Thomas Graf <tgraf@suug.ch>
10  * Copyright (c) 2003-2006 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  * @note The maximum size of an address label is IFNAMSIZ.
20  *
21  * @note The address may not contain a prefix length if the peer address
22  * has been specified already.
23  *
24  * @par 1) Address Addition
25  * @code
26  * // Allocate an empty address object to be filled out with the attributes
27  * // of the new address.
28  * struct rtnl_addr *addr = rtnl_addr_alloc();
29  *
30  * // Fill out the mandatory attributes of the new address. Setting the
31  * // local address will automatically set the address family and the
32  * // prefix length to the correct values.
33  * rtnl_addr_set_ifindex(addr, ifindex);
34  * rtnl_addr_set_local(addr, local_addr);
35  *
36  * // The label of the address can be specified, currently only supported
37  * // by IPv4 and DECnet.
38  * rtnl_addr_set_label(addr, "mylabel");
39  *
40  * // The peer address can be specified if necessary, in either case a peer
41  * // address will be sent to the kernel in order to fullfil the interface
42  * // requirements. If none is set, it will equal the local address.
43  * // Note: Real peer addresses are only supported by IPv4 for now.
44  * rtnl_addr_set_peer(addr, peer_addr);
45  *
46  * // In case you want to have the address have a scope other than global
47  * // it may be overwritten using rtnl_addr_set_scope(). The scope currently
48  * // cannot be set for IPv6 addresses.
49  * rtnl_addr_set_scope(addr, rtnl_str2scope("site"));
50  *
51  * // Broadcast address may be specified using the relevant
52  * // functions, the address family will be verified if one of the other
53  * // addresses has been set already. Currently only works for IPv4.
54  * rtnl_addr_set_broadcast(addr, broadcast_addr);
55  *
56  * // Build the netlink message and send it to the kernel, the operation will
57  * // block until the operation has been completed. Alternatively the required
58  * // netlink message can be built using rtnl_addr_build_add_request() to be
59  * // sent out using nl_send_auto_complete().
60  * rtnl_addr_add(sk, addr, 0);
61  *
62  * // Free the memory
63  * rtnl_addr_put(addr);
64  * @endcode
65  *
66  * @par 2) Address Deletion
67  * @code
68  * // Allocate an empty address object to be filled out with the attributes
69  * // matching the address to be deleted. Alternatively a fully equipped
70  * // address object out of a cache can be used instead.
71  * struct rtnl_addr *addr = rtnl_addr_alloc();
72  *
73  * // The only mandatory parameter besides the address family is the interface
74  * // index the address is on, i.e. leaving out all other parameters will
75  * // result in all addresses of the specified address family interface tuple
76  * // to be deleted.
77  * rtnl_addr_set_ifindex(addr, ifindex);
78  *
79  * // Specyfing the address family manually is only required if neither the
80  * // local nor peer address have been specified.
81  * rtnl_addr_set_family(addr, AF_INET);
82  *
83  * // Specyfing the local address is optional but the best choice to delete
84  * // specific addresses.
85  * rtnl_addr_set_local(addr, local_addr);
86  *
87  * // The label of the address can be specified, currently only supported
88  * // by IPv4 and DECnet.
89  * rtnl_addr_set_label(addr, "mylabel");
90  *
91  * // The peer address can be specified if necessary, in either case a peer
92  * // address will be sent to the kernel in order to fullfil the interface
93  * // requirements. If none is set, it will equal the local address.
94  * // Note: Real peer addresses are only supported by IPv4 for now.
95  * rtnl_addr_set_peer(addr, peer_addr);
96  *
97  * // Build the netlink message and send it to the kernel, the operation will
98  * // block until the operation has been completed. Alternatively the required
99  * // netlink message can be built using rtnl_addr_build_delete_request()
100  * // to be sent out using nl_send_auto_complete().
101  * rtnl_addr_delete(sk, addr, 0);
102  *
103  * // Free the memory
104  * rtnl_addr_put(addr);
105  * @endcode
106  * @{
107  */
108 
109 #include <netlink-private/netlink.h>
110 #include <netlink/netlink.h>
111 #include <netlink/route/rtnl.h>
112 #include <netlink/route/addr.h>
113 #include <netlink/route/route.h>
114 #include <netlink/route/link.h>
115 #include <netlink/utils.h>
116 
117 /** @cond SKIP */
118 #define ADDR_ATTR_FAMILY 0x0001
119 #define ADDR_ATTR_PREFIXLEN 0x0002
120 #define ADDR_ATTR_FLAGS 0x0004
121 #define ADDR_ATTR_SCOPE 0x0008
122 #define ADDR_ATTR_IFINDEX 0x0010
123 #define ADDR_ATTR_LABEL 0x0020
124 #define ADDR_ATTR_CACHEINFO 0x0040
125 #define ADDR_ATTR_PEER 0x0080
126 #define ADDR_ATTR_LOCAL 0x0100
127 #define ADDR_ATTR_BROADCAST 0x0200
128 #define ADDR_ATTR_MULTICAST 0x0400
129 #define ADDR_ATTR_ANYCAST 0x0800
130 
131 static struct nl_cache_ops rtnl_addr_ops;
132 static struct nl_object_ops addr_obj_ops;
133 /** @endcond */
134 
135 static void addr_constructor(struct nl_object *obj)
136 {
137  struct rtnl_addr *addr = nl_object_priv(obj);
138 
139  addr->a_scope = RT_SCOPE_NOWHERE;
140 }
141 
142 static void addr_free_data(struct nl_object *obj)
143 {
144  struct rtnl_addr *addr = nl_object_priv(obj);
145 
146  if (!addr)
147  return;
148 
149  nl_addr_put(addr->a_peer);
150  nl_addr_put(addr->a_local);
151  nl_addr_put(addr->a_bcast);
152  nl_addr_put(addr->a_multicast);
153  nl_addr_put(addr->a_anycast);
154  rtnl_link_put(addr->a_link);
155 }
156 
157 static int addr_clone(struct nl_object *_dst, struct nl_object *_src)
158 {
159  struct rtnl_addr *dst = nl_object_priv(_dst);
160  struct rtnl_addr *src = nl_object_priv(_src);
161 
162  if (src->a_link) {
163  nl_object_get(OBJ_CAST(src->a_link));
164  dst->a_link = src->a_link;
165  }
166 
167  if (src->a_peer)
168  if (!(dst->a_peer = nl_addr_clone(src->a_peer)))
169  return -NLE_NOMEM;
170 
171  if (src->a_local)
172  if (!(dst->a_local = nl_addr_clone(src->a_local)))
173  return -NLE_NOMEM;
174 
175  if (src->a_bcast)
176  if (!(dst->a_bcast = nl_addr_clone(src->a_bcast)))
177  return -NLE_NOMEM;
178 
179  if (src->a_multicast)
180  if (!(dst->a_multicast = nl_addr_clone(src->a_multicast)))
181  return -NLE_NOMEM;
182 
183  if (src->a_anycast)
184  if (!(dst->a_anycast = nl_addr_clone(src->a_anycast)))
185  return -NLE_NOMEM;
186 
187  return 0;
188 }
189 
190 static struct nla_policy addr_policy[IFA_MAX+1] = {
191  [IFA_LABEL] = { .type = NLA_STRING,
192  .maxlen = IFNAMSIZ },
193  [IFA_CACHEINFO] = { .minlen = sizeof(struct ifa_cacheinfo) },
194 };
195 
196 static int addr_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
197  struct nlmsghdr *nlh, struct nl_parser_param *pp)
198 {
199  struct rtnl_addr *addr;
200  struct ifaddrmsg *ifa;
201  struct nlattr *tb[IFA_MAX+1];
202  int err, family;
203  struct nl_cache *link_cache;
204  struct nl_addr *plen_addr = NULL;
205 
206  addr = rtnl_addr_alloc();
207  if (!addr)
208  return -NLE_NOMEM;
209 
210  addr->ce_msgtype = nlh->nlmsg_type;
211 
212  err = nlmsg_parse(nlh, sizeof(*ifa), tb, IFA_MAX, addr_policy);
213  if (err < 0)
214  goto errout;
215 
216  ifa = nlmsg_data(nlh);
217  addr->a_family = family = ifa->ifa_family;
218  addr->a_prefixlen = ifa->ifa_prefixlen;
219  addr->a_scope = ifa->ifa_scope;
220  addr->a_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) :
221  ifa->ifa_flags;
222  addr->a_ifindex = ifa->ifa_index;
223 
224  addr->ce_mask = (ADDR_ATTR_FAMILY | ADDR_ATTR_PREFIXLEN |
225  ADDR_ATTR_FLAGS | ADDR_ATTR_SCOPE | ADDR_ATTR_IFINDEX);
226 
227  if (tb[IFA_LABEL]) {
228  nla_strlcpy(addr->a_label, tb[IFA_LABEL], IFNAMSIZ);
229  addr->ce_mask |= ADDR_ATTR_LABEL;
230  }
231 
232  /* IPv6 only */
233  if (tb[IFA_CACHEINFO]) {
234  struct ifa_cacheinfo *ca;
235 
236  ca = nla_data(tb[IFA_CACHEINFO]);
237  addr->a_cacheinfo.aci_prefered = ca->ifa_prefered;
238  addr->a_cacheinfo.aci_valid = ca->ifa_valid;
239  addr->a_cacheinfo.aci_cstamp = ca->cstamp;
240  addr->a_cacheinfo.aci_tstamp = ca->tstamp;
241  addr->ce_mask |= ADDR_ATTR_CACHEINFO;
242  }
243 
244  if (tb[IFA_LOCAL]) {
245  addr->a_local = nl_addr_alloc_attr(tb[IFA_LOCAL], family);
246  if (!addr->a_local)
247  goto errout_nomem;
248  addr->ce_mask |= ADDR_ATTR_LOCAL;
249  plen_addr = addr->a_local;
250  }
251 
252  if (tb[IFA_ADDRESS]) {
253  struct nl_addr *a;
254 
255  a = nl_addr_alloc_attr(tb[IFA_ADDRESS], family);
256  if (!a)
257  goto errout_nomem;
258 
259  /* IPv6 sends the local address as IFA_ADDRESS with
260  * no IFA_LOCAL, IPv4 sends both IFA_LOCAL and IFA_ADDRESS
261  * with IFA_ADDRESS being the peer address if they differ */
262  if (!tb[IFA_LOCAL] || !nl_addr_cmp(a, addr->a_local)) {
263  nl_addr_put(addr->a_local);
264  addr->a_local = a;
265  addr->ce_mask |= ADDR_ATTR_LOCAL;
266  } else {
267  addr->a_peer = a;
268  addr->ce_mask |= ADDR_ATTR_PEER;
269  }
270 
271  plen_addr = a;
272  }
273 
274  if (plen_addr)
275  nl_addr_set_prefixlen(plen_addr, addr->a_prefixlen);
276 
277  /* IPv4 only */
278  if (tb[IFA_BROADCAST]) {
279  addr->a_bcast = nl_addr_alloc_attr(tb[IFA_BROADCAST], family);
280  if (!addr->a_bcast)
281  goto errout_nomem;
282 
283  addr->ce_mask |= ADDR_ATTR_BROADCAST;
284  }
285 
286  /* IPv6 only */
287  if (tb[IFA_MULTICAST]) {
288  addr->a_multicast = nl_addr_alloc_attr(tb[IFA_MULTICAST],
289  family);
290  if (!addr->a_multicast)
291  goto errout_nomem;
292 
293  addr->ce_mask |= ADDR_ATTR_MULTICAST;
294  }
295 
296  /* IPv6 only */
297  if (tb[IFA_ANYCAST]) {
298  addr->a_anycast = nl_addr_alloc_attr(tb[IFA_ANYCAST],
299  family);
300  if (!addr->a_anycast)
301  goto errout_nomem;
302 
303  addr->ce_mask |= ADDR_ATTR_ANYCAST;
304  }
305 
306  if ((link_cache = __nl_cache_mngt_require("route/link"))) {
307  struct rtnl_link *link;
308 
309  if ((link = rtnl_link_get(link_cache, addr->a_ifindex))) {
310  rtnl_addr_set_link(addr, link);
311 
312  /* rtnl_addr_set_link incs refcnt */
313  rtnl_link_put(link);
314  }
315  }
316 
317  err = pp->pp_cb((struct nl_object *) addr, pp);
318 errout:
319  rtnl_addr_put(addr);
320 
321  return err;
322 
323 errout_nomem:
324  err = -NLE_NOMEM;
325  goto errout;
326 }
327 
328 static int addr_request_update(struct nl_cache *cache, struct nl_sock *sk)
329 {
330  return nl_rtgen_request(sk, RTM_GETADDR, AF_UNSPEC, NLM_F_DUMP);
331 }
332 
333 static void addr_dump_line(struct nl_object *obj, struct nl_dump_params *p)
334 {
335  struct rtnl_addr *addr = (struct rtnl_addr *) obj;
336  struct nl_cache *link_cache;
337  char buf[128];
338 
339  link_cache = nl_cache_mngt_require_safe("route/link");
340 
341  if (addr->ce_mask & ADDR_ATTR_LOCAL)
342  nl_dump_line(p, "%s",
343  nl_addr2str(addr->a_local, buf, sizeof(buf)));
344  else
345  nl_dump_line(p, "none");
346 
347  if (addr->ce_mask & ADDR_ATTR_PEER)
348  nl_dump(p, " peer %s",
349  nl_addr2str(addr->a_peer, buf, sizeof(buf)));
350 
351  nl_dump(p, " %s ", nl_af2str(addr->a_family, buf, sizeof(buf)));
352 
353  if (link_cache)
354  nl_dump(p, "dev %s ",
355  rtnl_link_i2name(link_cache, addr->a_ifindex,
356  buf, sizeof(buf)));
357  else
358  nl_dump(p, "dev %d ", addr->a_ifindex);
359 
360  nl_dump(p, "scope %s",
361  rtnl_scope2str(addr->a_scope, buf, sizeof(buf)));
362 
363  rtnl_addr_flags2str(addr->a_flags, buf, sizeof(buf));
364  if (buf[0])
365  nl_dump(p, " <%s>", buf);
366 
367  nl_dump(p, "\n");
368 
369  if (link_cache)
370  nl_cache_put(link_cache);
371 }
372 
373 static void addr_dump_details(struct nl_object *obj, struct nl_dump_params *p)
374 {
375  struct rtnl_addr *addr = (struct rtnl_addr *) obj;
376  char buf[128];
377 
378  addr_dump_line(obj, p);
379 
380  if (addr->ce_mask & (ADDR_ATTR_LABEL | ADDR_ATTR_BROADCAST |
381  ADDR_ATTR_MULTICAST)) {
382  nl_dump_line(p, " ");
383 
384  if (addr->ce_mask & ADDR_ATTR_LABEL)
385  nl_dump(p, " label %s", addr->a_label);
386 
387  if (addr->ce_mask & ADDR_ATTR_BROADCAST)
388  nl_dump(p, " broadcast %s",
389  nl_addr2str(addr->a_bcast, buf, sizeof(buf)));
390 
391  if (addr->ce_mask & ADDR_ATTR_MULTICAST)
392  nl_dump(p, " multicast %s",
393  nl_addr2str(addr->a_multicast, buf,
394  sizeof(buf)));
395 
396  if (addr->ce_mask & ADDR_ATTR_ANYCAST)
397  nl_dump(p, " anycast %s",
398  nl_addr2str(addr->a_anycast, buf,
399  sizeof(buf)));
400 
401  nl_dump(p, "\n");
402  }
403 
404  if (addr->ce_mask & ADDR_ATTR_CACHEINFO) {
405  struct rtnl_addr_cacheinfo *ci = &addr->a_cacheinfo;
406 
407  nl_dump_line(p, " valid-lifetime %s",
408  ci->aci_valid == 0xFFFFFFFFU ? "forever" :
409  nl_msec2str(ci->aci_valid * 1000,
410  buf, sizeof(buf)));
411 
412  nl_dump(p, " preferred-lifetime %s\n",
413  ci->aci_prefered == 0xFFFFFFFFU ? "forever" :
414  nl_msec2str(ci->aci_prefered * 1000,
415  buf, sizeof(buf)));
416 
417  nl_dump_line(p, " created boot-time+%s ",
418  nl_msec2str(addr->a_cacheinfo.aci_cstamp * 10,
419  buf, sizeof(buf)));
420 
421  nl_dump(p, "last-updated boot-time+%s\n",
422  nl_msec2str(addr->a_cacheinfo.aci_tstamp * 10,
423  buf, sizeof(buf)));
424  }
425 }
426 
427 static void addr_dump_stats(struct nl_object *obj, struct nl_dump_params *p)
428 {
429  addr_dump_details(obj, p);
430 }
431 
432 static int addr_compare(struct nl_object *_a, struct nl_object *_b,
433  uint32_t attrs, int flags)
434 {
435  struct rtnl_addr *a = (struct rtnl_addr *) _a;
436  struct rtnl_addr *b = (struct rtnl_addr *) _b;
437  int diff = 0;
438 
439 #define ADDR_DIFF(ATTR, EXPR) ATTR_DIFF(attrs, ADDR_ATTR_##ATTR, a, b, EXPR)
440 
441  diff |= ADDR_DIFF(IFINDEX, a->a_ifindex != b->a_ifindex);
442  diff |= ADDR_DIFF(FAMILY, a->a_family != b->a_family);
443  diff |= ADDR_DIFF(SCOPE, a->a_scope != b->a_scope);
444  diff |= ADDR_DIFF(LABEL, strcmp(a->a_label, b->a_label));
445  diff |= ADDR_DIFF(PEER, nl_addr_cmp(a->a_peer, b->a_peer));
446  diff |= ADDR_DIFF(LOCAL, nl_addr_cmp(a->a_local, b->a_local));
447  diff |= ADDR_DIFF(MULTICAST, nl_addr_cmp(a->a_multicast,
448  b->a_multicast));
449  diff |= ADDR_DIFF(BROADCAST, nl_addr_cmp(a->a_bcast, b->a_bcast));
450  diff |= ADDR_DIFF(ANYCAST, nl_addr_cmp(a->a_anycast, b->a_anycast));
451  diff |= ADDR_DIFF(CACHEINFO, memcmp(&a->a_cacheinfo, &b->a_cacheinfo,
452  sizeof (a->a_cacheinfo)));
453 
454  if (flags & LOOSE_COMPARISON)
455  diff |= ADDR_DIFF(FLAGS,
456  (a->a_flags ^ b->a_flags) & b->a_flag_mask);
457  else
458  diff |= ADDR_DIFF(FLAGS, a->a_flags != b->a_flags);
459 
460 #undef ADDR_DIFF
461 
462  return diff;
463 }
464 
465 static const struct trans_tbl addr_attrs[] = {
466  __ADD(ADDR_ATTR_FAMILY, family),
467  __ADD(ADDR_ATTR_PREFIXLEN, prefixlen),
468  __ADD(ADDR_ATTR_FLAGS, flags),
469  __ADD(ADDR_ATTR_SCOPE, scope),
470  __ADD(ADDR_ATTR_IFINDEX, ifindex),
471  __ADD(ADDR_ATTR_LABEL, label),
472  __ADD(ADDR_ATTR_CACHEINFO, cacheinfo),
473  __ADD(ADDR_ATTR_PEER, peer),
474  __ADD(ADDR_ATTR_LOCAL, local),
475  __ADD(ADDR_ATTR_BROADCAST, broadcast),
476  __ADD(ADDR_ATTR_MULTICAST, multicast),
477 };
478 
479 static char *addr_attrs2str(int attrs, char *buf, size_t len)
480 {
481  return __flags2str(attrs, buf, len, addr_attrs,
482  ARRAY_SIZE(addr_attrs));
483 }
484 
485 /**
486  * @name Allocation/Freeing
487  * @{
488  */
489 
490 struct rtnl_addr *rtnl_addr_alloc(void)
491 {
492  return (struct rtnl_addr *) nl_object_alloc(&addr_obj_ops);
493 }
494 
495 void rtnl_addr_put(struct rtnl_addr *addr)
496 {
497  nl_object_put((struct nl_object *) addr);
498 }
499 
500 /** @} */
501 
502 /**
503  * @name Cache Management
504  * @{
505  */
506 
507 int rtnl_addr_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
508 {
509  return nl_cache_alloc_and_fill(&rtnl_addr_ops, sk, result);
510 }
511 
512 /**
513  * Search address in cache
514  * @arg cache Address cache
515  * @arg ifindex Interface index of address
516  * @arg addr Local address part
517  *
518  * Searches address cache previously allocated with rtnl_addr_alloc_cache()
519  * for an address with a matching local address.
520  *
521  * The reference counter is incremented before returning the address, therefore
522  * the reference must be given back with rtnl_addr_put() after usage.
523  *
524  * @return Address object or NULL if no match was found.
525  */
526 struct rtnl_addr *rtnl_addr_get(struct nl_cache *cache, int ifindex,
527  struct nl_addr *addr)
528 {
529  struct rtnl_addr *a;
530 
531  if (cache->c_ops != &rtnl_addr_ops)
532  return NULL;
533 
534  nl_list_for_each_entry(a, &cache->c_items, ce_list) {
535  if (ifindex && a->a_ifindex != ifindex)
536  continue;
537 
538  if (a->ce_mask & ADDR_ATTR_LOCAL &&
539  !nl_addr_cmp(a->a_local, addr)) {
540  nl_object_get((struct nl_object *) a);
541  return a;
542  }
543  }
544 
545  return NULL;
546 }
547 
548 /** @} */
549 
550 static int build_addr_msg(struct rtnl_addr *tmpl, int cmd, int flags,
551  struct nl_msg **result)
552 {
553  struct nl_msg *msg;
554  struct ifaddrmsg am = {
555  .ifa_family = tmpl->a_family,
556  .ifa_index = tmpl->a_ifindex,
557  .ifa_prefixlen = tmpl->a_prefixlen,
558  .ifa_flags = tmpl->a_flags,
559  };
560 
561  if (tmpl->ce_mask & ADDR_ATTR_SCOPE)
562  am.ifa_scope = tmpl->a_scope;
563  else {
564  /* compatibility hack */
565  if (tmpl->a_family == AF_INET &&
566  tmpl->ce_mask & ADDR_ATTR_LOCAL &&
567  *((char *) nl_addr_get_binary_addr(tmpl->a_local)) == 127)
568  am.ifa_scope = RT_SCOPE_HOST;
569  else
570  am.ifa_scope = RT_SCOPE_UNIVERSE;
571  }
572 
573  msg = nlmsg_alloc_simple(cmd, flags);
574  if (!msg)
575  return -NLE_NOMEM;
576 
577  if (nlmsg_append(msg, &am, sizeof(am), NLMSG_ALIGNTO) < 0)
578  goto nla_put_failure;
579 
580  if (tmpl->ce_mask & ADDR_ATTR_LOCAL)
581  NLA_PUT_ADDR(msg, IFA_LOCAL, tmpl->a_local);
582 
583  if (tmpl->ce_mask & ADDR_ATTR_PEER)
584  NLA_PUT_ADDR(msg, IFA_ADDRESS, tmpl->a_peer);
585  else if (tmpl->ce_mask & ADDR_ATTR_LOCAL)
586  NLA_PUT_ADDR(msg, IFA_ADDRESS, tmpl->a_local);
587 
588  if (tmpl->ce_mask & ADDR_ATTR_LABEL)
589  NLA_PUT_STRING(msg, IFA_LABEL, tmpl->a_label);
590 
591  if (tmpl->ce_mask & ADDR_ATTR_BROADCAST)
592  NLA_PUT_ADDR(msg, IFA_BROADCAST, tmpl->a_bcast);
593 
594  if (tmpl->ce_mask & ADDR_ATTR_CACHEINFO) {
595  struct ifa_cacheinfo ca = {
596  .ifa_valid = tmpl->a_cacheinfo.aci_valid,
597  .ifa_prefered = tmpl->a_cacheinfo.aci_prefered,
598  };
599 
600  NLA_PUT(msg, IFA_CACHEINFO, sizeof(ca), &ca);
601  }
602 
603  if (tmpl->a_flags & ~0xFF) {
604  /* only set the IFA_FLAGS attribute, if they actually contain additional
605  * flags that are not already set to am.ifa_flags.
606  *
607  * Older kernels refuse RTM_NEWADDR and RTM_NEWROUTE messages with EINVAL
608  * if they contain unknown netlink attributes. See net/core/rtnetlink.c, which
609  * was fixed by kernel commit 661d2967b3f1b34eeaa7e212e7b9bbe8ee072b59.
610  *
611  * With this workaround, libnl will function correctly with older kernels,
612  * unless there is a new libnl user that wants to set these flags. In this
613  * case it's up to the user to workaround this issue. */
614  NLA_PUT_U32(msg, IFA_FLAGS, tmpl->a_flags);
615  }
616 
617  *result = msg;
618  return 0;
619 
620 nla_put_failure:
621  nlmsg_free(msg);
622  return -NLE_MSGSIZE;
623 }
624 
625 /**
626  * @name Addition
627  * @{
628  */
629 
630 /**
631  * Build netlink request message to request addition of new address
632  * @arg addr Address object representing the new address.
633  * @arg flags Additional netlink message flags.
634  * @arg result Pointer to store resulting message.
635  *
636  * Builds a new netlink message requesting the addition of a new
637  * address. The netlink message header isn't fully equipped with
638  * all relevant fields and must thus be sent out via nl_send_auto_complete()
639  * or supplemented as needed.
640  *
641  * Minimal required attributes:
642  * - interface index (rtnl_addr_set_ifindex())
643  * - local address (rtnl_addr_set_local())
644  *
645  * The scope will default to universe except for loopback addresses in
646  * which case a host scope is used if not specified otherwise.
647  *
648  * @note Free the memory after usage using nlmsg_free().
649  *
650  * @return 0 on success or a negative error code.
651  */
652 int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags,
653  struct nl_msg **result)
654 {
655  uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY |
656  ADDR_ATTR_PREFIXLEN | ADDR_ATTR_LOCAL;
657 
658  if ((addr->ce_mask & required) != required)
659  return -NLE_MISSING_ATTR;
660 
661  return build_addr_msg(addr, RTM_NEWADDR, NLM_F_CREATE | flags, result);
662 }
663 
664 /**
665  * Request addition of new address
666  * @arg sk Netlink socket.
667  * @arg addr Address object representing the new address.
668  * @arg flags Additional netlink message flags.
669  *
670  * Builds a netlink message by calling rtnl_addr_build_add_request(),
671  * sends the request to the kernel and waits for the next ACK to be
672  * received and thus blocks until the request has been fullfilled.
673  *
674  * @see rtnl_addr_build_add_request()
675  *
676  * @return 0 on sucess or a negative error if an error occured.
677  */
678 int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
679 {
680  struct nl_msg *msg;
681  int err;
682 
683  if ((err = rtnl_addr_build_add_request(addr, flags, &msg)) < 0)
684  return err;
685 
686  err = nl_send_auto_complete(sk, msg);
687  nlmsg_free(msg);
688  if (err < 0)
689  return err;
690 
691  return wait_for_ack(sk);
692 }
693 
694 /** @} */
695 
696 /**
697  * @name Deletion
698  * @{
699  */
700 
701 /**
702  * Build a netlink request message to request deletion of an address
703  * @arg addr Address object to be deleteted.
704  * @arg flags Additional netlink message flags.
705  * @arg result Pointer to store resulting message.
706  *
707  * Builds a new netlink message requesting a deletion of an address.
708  * The netlink message header isn't fully equipped with all relevant
709  * fields and must thus be sent out via nl_send_auto_complete()
710  * or supplemented as needed.
711  *
712  * Minimal required attributes:
713  * - interface index (rtnl_addr_set_ifindex())
714  * - address family (rtnl_addr_set_family())
715  *
716  * Optional attributes:
717  * - local address (rtnl_addr_set_local())
718  * - label (rtnl_addr_set_label(), IPv4/DECnet only)
719  * - peer address (rtnl_addr_set_peer(), IPv4 only)
720  *
721  * @note Free the memory after usage using nlmsg_free().
722  *
723  * @return 0 on success or a negative error code.
724  */
725 int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags,
726  struct nl_msg **result)
727 {
728  uint32_t required = ADDR_ATTR_IFINDEX | ADDR_ATTR_FAMILY;
729 
730  if ((addr->ce_mask & required) != required)
731  return -NLE_MISSING_ATTR;
732 
733  return build_addr_msg(addr, RTM_DELADDR, flags, result);
734 }
735 
736 /**
737  * Request deletion of an address
738  * @arg sk Netlink socket.
739  * @arg addr Address object to be deleted.
740  * @arg flags Additional netlink message flags.
741  *
742  * Builds a netlink message by calling rtnl_addr_build_delete_request(),
743  * sends the request to the kernel and waits for the next ACK to be
744  * received and thus blocks until the request has been fullfilled.
745  *
746  * @see rtnl_addr_build_delete_request();
747  *
748  * @return 0 on sucess or a negative error if an error occured.
749  */
750 int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
751 {
752  struct nl_msg *msg;
753  int err;
754 
755  if ((err = rtnl_addr_build_delete_request(addr, flags, &msg)) < 0)
756  return err;
757 
758  err = nl_send_auto_complete(sk, msg);
759  nlmsg_free(msg);
760  if (err < 0)
761  return err;
762 
763  return wait_for_ack(sk);
764 }
765 
766 /** @} */
767 
768 /**
769  * @name Attributes
770  * @{
771  */
772 
773 int rtnl_addr_set_label(struct rtnl_addr *addr, const char *label)
774 {
775  if (strlen(label) > sizeof(addr->a_label) - 1)
776  return -NLE_RANGE;
777 
778  strcpy(addr->a_label, label);
779  addr->ce_mask |= ADDR_ATTR_LABEL;
780 
781  return 0;
782 }
783 
784 char *rtnl_addr_get_label(struct rtnl_addr *addr)
785 {
786  if (addr->ce_mask & ADDR_ATTR_LABEL)
787  return addr->a_label;
788  else
789  return NULL;
790 }
791 
792 void rtnl_addr_set_ifindex(struct rtnl_addr *addr, int ifindex)
793 {
794  addr->a_ifindex = ifindex;
795  addr->ce_mask |= ADDR_ATTR_IFINDEX;
796 }
797 
798 int rtnl_addr_get_ifindex(struct rtnl_addr *addr)
799 {
800  return addr->a_ifindex;
801 }
802 
803 void rtnl_addr_set_link(struct rtnl_addr *addr, struct rtnl_link *link)
804 {
805  rtnl_link_put(addr->a_link);
806 
807  if (!link)
808  return;
809 
810  nl_object_get(OBJ_CAST(link));
811  addr->a_link = link;
812  addr->a_ifindex = link->l_index;
813  addr->ce_mask |= ADDR_ATTR_IFINDEX;
814 }
815 
816 struct rtnl_link *rtnl_addr_get_link(struct rtnl_addr *addr)
817 {
818  if (addr->a_link) {
819  nl_object_get(OBJ_CAST(addr->a_link));
820  return addr->a_link;
821  }
822 
823  return NULL;
824 }
825 
826 void rtnl_addr_set_family(struct rtnl_addr *addr, int family)
827 {
828  addr->a_family = family;
829  addr->ce_mask |= ADDR_ATTR_FAMILY;
830 }
831 
832 int rtnl_addr_get_family(struct rtnl_addr *addr)
833 {
834  return addr->a_family;
835 }
836 
837 /**
838  * Set the prefix length / netmask
839  * @arg addr Address
840  * @arg prefixlen Length of prefix (netmask)
841  *
842  * Modifies the length of the prefix. If the address object contains a peer
843  * address the prefix length will apply to it, otherwise the prefix length
844  * will apply to the local address of the address.
845  *
846  * If the address object contains a peer or local address the corresponding
847  * `struct nl_addr` will be updated with the new prefix length.
848  *
849  * @note Specifying a length of 0 will remove the prefix length alltogether.
850  *
851  * @see rtnl_addr_get_prefixlen()
852  */
853 void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefixlen)
854 {
855  addr->a_prefixlen = prefixlen;
856 
857  if (prefixlen)
858  addr->ce_mask |= ADDR_ATTR_PREFIXLEN;
859  else
860  addr->ce_mask &= ~ADDR_ATTR_PREFIXLEN;
861 
862  /*
863  * The prefix length always applies to the peer address if
864  * a peer address is present.
865  */
866  if (addr->a_peer)
867  nl_addr_set_prefixlen(addr->a_peer, prefixlen);
868  else if (addr->a_local)
869  nl_addr_set_prefixlen(addr->a_local, prefixlen);
870 }
871 
872 int rtnl_addr_get_prefixlen(struct rtnl_addr *addr)
873 {
874  return addr->a_prefixlen;
875 }
876 
877 void rtnl_addr_set_scope(struct rtnl_addr *addr, int scope)
878 {
879  addr->a_scope = scope;
880  addr->ce_mask |= ADDR_ATTR_SCOPE;
881 }
882 
883 int rtnl_addr_get_scope(struct rtnl_addr *addr)
884 {
885  return addr->a_scope;
886 }
887 
888 void rtnl_addr_set_flags(struct rtnl_addr *addr, unsigned int flags)
889 {
890  addr->a_flag_mask |= flags;
891  addr->a_flags |= flags;
892  addr->ce_mask |= ADDR_ATTR_FLAGS;
893 }
894 
895 void rtnl_addr_unset_flags(struct rtnl_addr *addr, unsigned int flags)
896 {
897  addr->a_flag_mask |= flags;
898  addr->a_flags &= ~flags;
899  addr->ce_mask |= ADDR_ATTR_FLAGS;
900 }
901 
902 unsigned int rtnl_addr_get_flags(struct rtnl_addr *addr)
903 {
904  return addr->a_flags;
905 }
906 
907 static inline int __assign_addr(struct rtnl_addr *addr, struct nl_addr **pos,
908  struct nl_addr *new, int flag)
909 {
910  if (new) {
911  if (addr->ce_mask & ADDR_ATTR_FAMILY) {
912  if (new->a_family != addr->a_family)
913  return -NLE_AF_MISMATCH;
914  } else
915  addr->a_family = new->a_family;
916 
917  if (*pos)
918  nl_addr_put(*pos);
919 
920  *pos = nl_addr_get(new);
921  addr->ce_mask |= (flag | ADDR_ATTR_FAMILY);
922  } else {
923  if (*pos)
924  nl_addr_put(*pos);
925 
926  *pos = NULL;
927  addr->ce_mask &= ~flag;
928  }
929 
930  return 0;
931 }
932 
933 int rtnl_addr_set_local(struct rtnl_addr *addr, struct nl_addr *local)
934 {
935  int err;
936 
937  /* Prohibit local address with prefix length if peer address is present */
938  if ((addr->ce_mask & ADDR_ATTR_PEER) && local &&
939  nl_addr_get_prefixlen(local))
940  return -NLE_INVAL;
941 
942  err = __assign_addr(addr, &addr->a_local, local, ADDR_ATTR_LOCAL);
943  if (err < 0)
944  return err;
945 
946  /* Never overwrite the prefix length if a peer address is present */
947  if (!(addr->ce_mask & ADDR_ATTR_PEER))
948  rtnl_addr_set_prefixlen(addr, local ? nl_addr_get_prefixlen(local) : 0);
949 
950  return 0;
951 }
952 
953 struct nl_addr *rtnl_addr_get_local(struct rtnl_addr *addr)
954 {
955  return addr->a_local;
956 }
957 
958 int rtnl_addr_set_peer(struct rtnl_addr *addr, struct nl_addr *peer)
959 {
960  int err;
961 
962  if (peer && peer->a_family != AF_INET)
963  return -NLE_AF_NOSUPPORT;
964 
965  err = __assign_addr(addr, &addr->a_peer, peer, ADDR_ATTR_PEER);
966  if (err < 0)
967  return err;
968 
969  rtnl_addr_set_prefixlen(addr, peer ? nl_addr_get_prefixlen(peer) : 0);
970 
971  return 0;
972 }
973 
974 struct nl_addr *rtnl_addr_get_peer(struct rtnl_addr *addr)
975 {
976  return addr->a_peer;
977 }
978 
979 int rtnl_addr_set_broadcast(struct rtnl_addr *addr, struct nl_addr *bcast)
980 {
981  if (bcast && bcast->a_family != AF_INET)
982  return -NLE_AF_NOSUPPORT;
983 
984  return __assign_addr(addr, &addr->a_bcast, bcast, ADDR_ATTR_BROADCAST);
985 }
986 
987 struct nl_addr *rtnl_addr_get_broadcast(struct rtnl_addr *addr)
988 {
989  return addr->a_bcast;
990 }
991 
992 int rtnl_addr_set_multicast(struct rtnl_addr *addr, struct nl_addr *multicast)
993 {
994  if (multicast && multicast->a_family != AF_INET6)
995  return -NLE_AF_NOSUPPORT;
996 
997  return __assign_addr(addr, &addr->a_multicast, multicast,
998  ADDR_ATTR_MULTICAST);
999 }
1000 
1001 struct nl_addr *rtnl_addr_get_multicast(struct rtnl_addr *addr)
1002 {
1003  return addr->a_multicast;
1004 }
1005 
1006 int rtnl_addr_set_anycast(struct rtnl_addr *addr, struct nl_addr *anycast)
1007 {
1008  if (anycast && anycast->a_family != AF_INET6)
1009  return -NLE_AF_NOSUPPORT;
1010 
1011  return __assign_addr(addr, &addr->a_anycast, anycast,
1012  ADDR_ATTR_ANYCAST);
1013 }
1014 
1015 struct nl_addr *rtnl_addr_get_anycast(struct rtnl_addr *addr)
1016 {
1017  return addr->a_anycast;
1018 }
1019 
1020 uint32_t rtnl_addr_get_valid_lifetime(struct rtnl_addr *addr)
1021 {
1022  if (addr->ce_mask & ADDR_ATTR_CACHEINFO)
1023  return addr->a_cacheinfo.aci_valid;
1024  else
1025  return 0xFFFFFFFFU;
1026 }
1027 
1028 void rtnl_addr_set_valid_lifetime(struct rtnl_addr *addr, uint32_t lifetime)
1029 {
1030  addr->a_cacheinfo.aci_valid = lifetime;
1031  addr->ce_mask |= ADDR_ATTR_CACHEINFO;
1032 }
1033 
1034 uint32_t rtnl_addr_get_preferred_lifetime(struct rtnl_addr *addr)
1035 {
1036  if (addr->ce_mask & ADDR_ATTR_CACHEINFO)
1037  return addr->a_cacheinfo.aci_prefered;
1038  else
1039  return 0xFFFFFFFFU;
1040 }
1041 
1042 void rtnl_addr_set_preferred_lifetime(struct rtnl_addr *addr, uint32_t lifetime)
1043 {
1044  addr->a_cacheinfo.aci_prefered = lifetime;
1045  addr->ce_mask |= ADDR_ATTR_CACHEINFO;
1046 }
1047 
1048 uint32_t rtnl_addr_get_create_time(struct rtnl_addr *addr)
1049 {
1050  return addr->a_cacheinfo.aci_cstamp;
1051 }
1052 
1053 uint32_t rtnl_addr_get_last_update_time(struct rtnl_addr *addr)
1054 {
1055  return addr->a_cacheinfo.aci_tstamp;
1056 }
1057 
1058 /** @} */
1059 
1060 /**
1061  * @name Flags Translations
1062  * @{
1063  */
1064 
1065 static const struct trans_tbl addr_flags[] = {
1066  __ADD(IFA_F_SECONDARY, secondary),
1067  __ADD(IFA_F_NODAD, nodad),
1068  __ADD(IFA_F_OPTIMISTIC, optimistic),
1069  __ADD(IFA_F_HOMEADDRESS, homeaddress),
1070  __ADD(IFA_F_DEPRECATED, deprecated),
1071  __ADD(IFA_F_TENTATIVE, tentative),
1072  __ADD(IFA_F_PERMANENT, permanent),
1073  __ADD(IFA_F_MANAGETEMPADDR, mngtmpaddr),
1074  __ADD(IFA_F_NOPREFIXROUTE, noprefixroute),
1075 };
1076 
1077 char *rtnl_addr_flags2str(int flags, char *buf, size_t size)
1078 {
1079  return __flags2str(flags, buf, size, addr_flags,
1080  ARRAY_SIZE(addr_flags));
1081 }
1082 
1083 int rtnl_addr_str2flags(const char *name)
1084 {
1085  return __str2flags(name, addr_flags, ARRAY_SIZE(addr_flags));
1086 }
1087 
1088 /** @} */
1089 
1090 static struct nl_object_ops addr_obj_ops = {
1091  .oo_name = "route/addr",
1092  .oo_size = sizeof(struct rtnl_addr),
1093  .oo_constructor = addr_constructor,
1094  .oo_free_data = addr_free_data,
1095  .oo_clone = addr_clone,
1096  .oo_dump = {
1097  [NL_DUMP_LINE] = addr_dump_line,
1098  [NL_DUMP_DETAILS] = addr_dump_details,
1099  [NL_DUMP_STATS] = addr_dump_stats,
1100  },
1101  .oo_compare = addr_compare,
1102  .oo_attrs2str = addr_attrs2str,
1103  .oo_id_attrs = (ADDR_ATTR_FAMILY | ADDR_ATTR_IFINDEX |
1104  ADDR_ATTR_LOCAL | ADDR_ATTR_PREFIXLEN),
1105 };
1106 
1107 static struct nl_af_group addr_groups[] = {
1108  { AF_INET, RTNLGRP_IPV4_IFADDR },
1109  { AF_INET6, RTNLGRP_IPV6_IFADDR },
1110  { END_OF_GROUP_LIST },
1111 };
1112 
1113 static struct nl_cache_ops rtnl_addr_ops = {
1114  .co_name = "route/addr",
1115  .co_hdrsize = sizeof(struct ifaddrmsg),
1116  .co_msgtypes = {
1117  { RTM_NEWADDR, NL_ACT_NEW, "new" },
1118  { RTM_DELADDR, NL_ACT_DEL, "del" },
1119  { RTM_GETADDR, NL_ACT_GET, "get" },
1120  END_OF_MSGTYPES_LIST,
1121  },
1122  .co_protocol = NETLINK_ROUTE,
1123  .co_groups = addr_groups,
1124  .co_request_update = addr_request_update,
1125  .co_msg_parser = addr_msg_parser,
1126  .co_obj_ops = &addr_obj_ops,
1127 };
1128 
1129 static void __init addr_init(void)
1130 {
1131  nl_cache_mngt_register(&rtnl_addr_ops);
1132 }
1133 
1134 static void __exit addr_exit(void)
1135 {
1136  nl_cache_mngt_unregister(&rtnl_addr_ops);
1137 }
1138 
1139 /** @} */
int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg)
Definition: nl.c:1252
struct nl_addr * nl_addr_clone(const struct nl_addr *addr)
Clone existing abstract address object.
Definition: addr.c:471
Dump object briefly on one line.
Definition: types.h:22
void nl_addr_set_prefixlen(struct nl_addr *addr, int prefixlen)
Set the prefix length of an abstract address.
Definition: addr.c:917
void nlmsg_free(struct nl_msg *msg)
Release a reference from an netlink message.
Definition: msg.c:558
int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
Compare abstract addresses.
Definition: addr.c:563
void * nlmsg_data(const struct nlmsghdr *nlh)
Return pointer to message payload.
Definition: msg.c:105
#define NLA_PUT_ADDR(msg, attrtype, addr)
Add address attribute to netlink message.
Definition: attr.h:286
unsigned int nl_addr_get_prefixlen(const struct nl_addr *addr)
Return prefix length of abstract address object.
Definition: addr.c:928
void rtnl_addr_set_prefixlen(struct rtnl_addr *addr, int prefixlen)
Set the prefix length / netmask.
Definition: addr.c:853
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition: object.c:54
int nl_cache_mngt_unregister(struct nl_cache_ops *ops)
Unregister a set of cache operations.
Definition: cache_mngt.c:287
Attribute validation policy.
Definition: attr.h:67
int rtnl_addr_build_add_request(struct rtnl_addr *addr, int flags, struct nl_msg **result)
Build netlink request message to request addition of new address.
Definition: addr.c:652
struct nl_cache * nl_cache_mngt_require_safe(const char *name)
Return cache previously provided via nl_cache_mngt_provide()
Definition: cache_mngt.c:430
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition: object.c:204
char * nl_msec2str(uint64_t msec, char *buf, size_t len)
Convert milliseconds to a character string.
Definition: utils.c:547
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
Definition: attr.c:699
int nlmsg_parse(struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[], int maxtype, struct nla_policy *policy)
parse attributes of a netlink message
Definition: msg.c:213
struct rtnl_addr * rtnl_addr_get(struct nl_cache *cache, int ifindex, struct nl_addr *addr)
Search address in cache.
Definition: addr.c:526
struct nl_addr * nl_addr_get(struct nl_addr *addr)
Increase the reference counter of an abstract address.
Definition: addr.c:501
struct nl_addr * nl_addr_alloc_attr(const struct nlattr *nla, int family)
Allocate abstract address based on Netlink attribute.
Definition: addr.c:255
NUL terminated character string.
Definition: attr.h:43
Dump all attributes but no statistics.
Definition: types.h:23
int rtnl_addr_delete(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request deletion of an address.
Definition: addr.c:750
int nl_cache_mngt_register(struct nl_cache_ops *ops)
Register a set of cache operations.
Definition: cache_mngt.c:252
int nl_rtgen_request(struct nl_sock *sk, int type, int family, int flags)
Send routing netlink request message.
Definition: rtnl.c:41
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
Definition: attr.h:162
void * nla_data(const struct nlattr *nla)
Return pointer to the payload section.
Definition: attr.c:120
int rtnl_addr_build_delete_request(struct rtnl_addr *addr, int flags, struct nl_msg **result)
Build a netlink request message to request deletion of an address.
Definition: addr.c:725
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
Definition: attr.h:233
int nlmsg_append(struct nl_msg *n, void *data, size_t len, int pad)
Append data to tail of a netlink message.
Definition: msg.c:442
int rtnl_addr_add(struct nl_sock *sk, struct rtnl_addr *addr, int flags)
Request addition of new address.
Definition: addr.c:678
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition: object.c:215
#define NLA_PUT_STRING(msg, attrtype, value)
Add string attribute to netlink message.
Definition: attr.h:260
void nl_addr_put(struct nl_addr *addr)
Decrease the reference counter of an abstract address.
Definition: addr.c:517
uint16_t type
Type of attribute or NLA_UNSPEC.
Definition: attr.h:69
struct nl_msg * nlmsg_alloc_simple(int nlmsgtype, int flags)
Allocate a new netlink message.
Definition: msg.c:346
Dumping parameters.
Definition: types.h:33
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition: utils.c:914
Dump all attributes including statistics.
Definition: types.h:24
void * nl_addr_get_binary_addr(const struct nl_addr *addr)
Get binary address of abstract address object.
Definition: addr.c:893
int nl_cache_alloc_and_fill(struct nl_cache_ops *ops, struct nl_sock *sock, struct nl_cache **result)
Allocate new cache and fill it.
Definition: cache.c:233
size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize)
Copy string attribute payload to a buffer.
Definition: attr.c:378
char * nl_addr2str(const struct nl_addr *addr, char *buf, size_t size)
Convert abstract address object to character string.
Definition: addr.c:951