/build/buildd/libnl-1.0~pre6/lib/route/neightbl.c

00001 /*
00002  * lib/route/neightbl.c         neighbour tables
00003  *
00004  *      This library is free software; you can redistribute it and/or
00005  *      modify it under the terms of the GNU Lesser General Public
00006  *      License as published by the Free Software Foundation version 2.1
00007  *      of the License.
00008  *
00009  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
00010  */
00011 
00012 /**
00013  * @ingroup rtnl
00014  * @defgroup neightbl Neighbour Tables
00015  * @brief
00016  * @{
00017  */
00018 
00019 #include <netlink-local.h>
00020 #include <netlink/netlink.h>
00021 #include <netlink/utils.h>
00022 #include <netlink/route/rtnl.h>
00023 #include <netlink/route/neightbl.h>
00024 #include <netlink/route/link.h>
00025 
00026 /** @cond SKIP */
00027 #define NEIGHTBL_ATTR_FAMILY       0x001
00028 #define NEIGHTBL_ATTR_STATS        0x002
00029 #define NEIGHTBL_ATTR_NAME        0x004
00030 #define NEIGHTBL_ATTR_THRESH1     0x008
00031 #define NEIGHTBL_ATTR_THRESH2     0x010
00032 #define NEIGHTBL_ATTR_THRESH3     0x020
00033 #define NEIGHTBL_ATTR_CONFIG      0x040
00034 #define NEIGHTBL_ATTR_PARMS       0x080
00035 #define NEIGHTBL_ATTR_GC_INTERVAL  0x100
00036 
00037 #define NEIGHTBLPARM_ATTR_IFINDEX       0x0001
00038 #define NEIGHTBLPARM_ATTR_REFCNT                0x0002
00039 #define NEIGHTBLPARM_ATTR_QUEUE_LEN     0x0004
00040 #define NEIGHTBLPARM_ATTR_APP_PROBES    0x0008
00041 #define NEIGHTBLPARM_ATTR_UCAST_PROBES  0x0010
00042 #define NEIGHTBLPARM_ATTR_MCAST_PROBES  0x0020
00043 #define NEIGHTBLPARM_ATTR_PROXY_QLEN    0x0040
00044 #define NEIGHTBLPARM_ATTR_REACHABLE_TIME        0x0080
00045 #define NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME 0x0100
00046 #define NEIGHTBLPARM_ATTR_RETRANS_TIME  0x0200
00047 #define NEIGHTBLPARM_ATTR_GC_STALETIME  0x0400
00048 #define NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME 0x0800
00049 #define NEIGHTBLPARM_ATTR_ANYCAST_DELAY 0x1000
00050 #define NEIGHTBLPARM_ATTR_PROXY_DELAY   0x2000
00051 #define NEIGHTBLPARM_ATTR_LOCKTIME      0x4000
00052 
00053 static struct nl_cache_ops rtnl_neightbl_ops;
00054 /** @endcond */
00055 
00056 static int neightbl_filter(struct nl_object *obj, struct nl_object *filter)
00057 {
00058         struct rtnl_neightbl *o = (struct rtnl_neightbl *) obj;
00059         struct rtnl_neightbl *f = (struct rtnl_neightbl *) filter;
00060         struct rtnl_neightbl_parms *op = &o->nt_parms;
00061         struct rtnl_neightbl_parms *fp = &f->nt_parms;
00062 
00063 #define REQ(F) (f->nt_mask & NEIGHTBL_ATTR_##F)
00064 #define AVAIL(F) (o->nt_mask & NEIGHTBL_ATTR_##F)
00065 #define _O(F, EXPR) (REQ(F) && (!AVAIL(F) || (EXPR)))
00066 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (o->N != f->N)))
00067         
00068         if (_C(FAMILY,          nt_family)                              ||
00069             _O(NAME,            strcmp(o->nt_name, f->nt_name))         ||
00070             _C(THRESH1,         nt_gc_thresh1)                          ||
00071             _C(THRESH2,         nt_gc_thresh2)                          ||
00072             _C(THRESH3,         nt_gc_thresh3)                          ||
00073             _C(GC_INTERVAL,     nt_gc_interval))
00074                 return 0;
00075 #undef REQ
00076 #undef AVAIL
00077 #undef _O
00078 #undef _C
00079 
00080         if (!(f->nt_mask & NEIGHTBL_ATTR_PARMS) &&
00081             !(o->nt_mask & NEIGHTBL_ATTR_PARMS))
00082                 return 1;
00083 
00084 #define REQ(F) (fp->ntp_mask & NEIGHTBLPARM_ATTR_##F)
00085 #define AVAIL(F) (op->ntp_mask & NEIGHTBLPARM_ATTR_##F)
00086 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (op->N != fp->N)))
00087         if (_C(IFINDEX,                 ntp_ifindex)                    ||
00088             _C(QUEUE_LEN,               ntp_queue_len)                  ||
00089             _C(APP_PROBES,              ntp_app_probes)                 ||
00090             _C(UCAST_PROBES,            ntp_ucast_probes)               ||
00091             _C(MCAST_PROBES,            ntp_mcast_probes)               ||
00092             _C(PROXY_QLEN,              ntp_proxy_qlen)                 ||
00093             _C(LOCKTIME,                ntp_locktime)                   ||
00094             _C(RETRANS_TIME,            ntp_retrans_time)               ||
00095             _C(BASE_REACHABLE_TIME,     ntp_base_reachable_time)        ||
00096             _C(GC_STALETIME,            ntp_gc_stale_time)              ||
00097             _C(DELAY_PROBE_TIME,        ntp_probe_delay)                ||
00098             _C(ANYCAST_DELAY,           ntp_anycast_delay)              ||
00099             _C(PROXY_DELAY,             ntp_proxy_delay))
00100                 return 0;
00101 #undef REQ
00102 #undef AVAIL
00103 #undef _C
00104 
00105         return 1;
00106 }
00107 
00108 static struct nla_policy neightbl_policy[NDTA_MAX+1] = {
00109         [NDTA_NAME]             = { .type = NLA_STRING,
00110                                     .maxlen = NTBLNAMSIZ },
00111         [NDTA_THRESH1]          = { .type = NLA_U32 },
00112         [NDTA_THRESH2]          = { .type = NLA_U32 },
00113         [NDTA_THRESH3]          = { .type = NLA_U32 },
00114         [NDTA_GC_INTERVAL]      = { .type = NLA_U32 },
00115         [NDTA_CONFIG]           = { .minlen = sizeof(struct ndt_config) },
00116         [NDTA_STATS]            = { .minlen = sizeof(struct ndt_stats) },
00117         [NDTA_PARMS]            = { .type = NLA_NESTED },
00118 };
00119 
00120 static int neightbl_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *n,
00121                             void *arg)
00122 {
00123         struct rtnl_neightbl *ntbl;
00124         struct nlattr *tb[NDTA_MAX + 1];
00125         struct nl_parser_param *pp = arg;
00126         struct rtgenmsg *rtmsg;
00127         int err;
00128 
00129         ntbl = rtnl_neightbl_alloc();
00130         if (!ntbl) {
00131                 err = nl_errno(ENOMEM);
00132                 goto errout;
00133         }
00134 
00135         ntbl->ce_msgtype = n->nlmsg_type;
00136         rtmsg = nlmsg_data(n);
00137         
00138         err = nlmsg_parse(n, sizeof(*rtmsg), tb, NDTA_MAX, neightbl_policy);
00139         if (err < 0)
00140                 goto errout;
00141 
00142         ntbl->nt_family = rtmsg->rtgen_family;
00143 
00144         if (tb[NDTA_NAME] == NULL) {
00145                 err = nl_error(EINVAL, "NDTA_NAME is missing");
00146                 goto errout;
00147         }
00148 
00149         nla_strlcpy(ntbl->nt_name, tb[NDTA_NAME], NTBLNAMSIZ);
00150         ntbl->nt_mask |= NEIGHTBL_ATTR_NAME;
00151 
00152         if (tb[NDTA_THRESH1]) {
00153                 ntbl->nt_gc_thresh1 = nla_get_u32(tb[NDTA_THRESH1]);
00154                 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH1;
00155         }
00156 
00157         if (tb[NDTA_THRESH2]) {
00158                 ntbl->nt_gc_thresh2 = nla_get_u32(tb[NDTA_THRESH2]);
00159                 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH2;
00160         }
00161 
00162         if (tb[NDTA_THRESH3]) {
00163                 ntbl->nt_gc_thresh3 = nla_get_u32(tb[NDTA_THRESH3]);
00164                 ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH3;
00165         }
00166 
00167         if (tb[NDTA_GC_INTERVAL]) {
00168                 ntbl->nt_gc_interval = nla_get_u32(tb[NDTA_GC_INTERVAL]);
00169                 ntbl->nt_mask |= NEIGHTBL_ATTR_GC_INTERVAL;
00170         }
00171 
00172         if (tb[NDTA_CONFIG]) {
00173                 nla_memcpy(&ntbl->nt_config, tb[NDTA_CONFIG],
00174                            sizeof(ntbl->nt_config));
00175                 ntbl->nt_mask |= NEIGHTBL_ATTR_CONFIG;
00176         }
00177 
00178         if (tb[NDTA_STATS]) {
00179                 nla_memcpy(&ntbl->nt_stats, tb[NDTA_STATS],
00180                            sizeof(ntbl->nt_stats));
00181                 ntbl->nt_mask |= NEIGHTBL_ATTR_STATS;
00182         }
00183 
00184         if (tb[NDTA_PARMS]) {
00185                 struct nlattr *tbp[NDTPA_MAX + 1];
00186                 struct rtnl_neightbl_parms *p = &ntbl->nt_parms;
00187 
00188                 err = nla_parse_nested(tbp, NDTPA_MAX, tb[NDTA_PARMS], NULL);
00189                 if (err < 0)
00190                         goto errout;
00191 
00192 #define COPY_ENTRY(name, var) \
00193                 if (tbp[NDTPA_ ##name]) { \
00194                         p->ntp_ ##var = nla_get_u32(tbp[NDTPA_ ##name]); \
00195                         p->ntp_mask |= NEIGHTBLPARM_ATTR_ ##name; \
00196                 }
00197 
00198                 COPY_ENTRY(IFINDEX, ifindex);
00199                 COPY_ENTRY(REFCNT, refcnt);
00200                 COPY_ENTRY(QUEUE_LEN, queue_len);
00201                 COPY_ENTRY(APP_PROBES, app_probes);
00202                 COPY_ENTRY(UCAST_PROBES, ucast_probes);
00203                 COPY_ENTRY(MCAST_PROBES, mcast_probes);
00204                 COPY_ENTRY(PROXY_QLEN, proxy_qlen);
00205                 COPY_ENTRY(PROXY_DELAY, proxy_delay);
00206                 COPY_ENTRY(ANYCAST_DELAY, anycast_delay);
00207                 COPY_ENTRY(LOCKTIME, locktime);
00208                 COPY_ENTRY(REACHABLE_TIME, reachable_time);
00209                 COPY_ENTRY(BASE_REACHABLE_TIME, base_reachable_time);
00210                 COPY_ENTRY(RETRANS_TIME, retrans_time);
00211                 COPY_ENTRY(GC_STALETIME, gc_stale_time);
00212                 COPY_ENTRY(DELAY_PROBE_TIME, probe_delay);
00213 #undef COPY_ENTRY
00214 
00215                 ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00216         }
00217 
00218         err = pp->pp_cb((struct nl_object *) ntbl, pp);
00219         if (err < 0)
00220                 goto errout;
00221 
00222         return P_ACCEPT;
00223 errout:
00224         rtnl_neightbl_put(ntbl);
00225         return err;
00226 }
00227 
00228 static int neightbl_request_update(struct nl_cache *c, struct nl_handle *h)
00229 {
00230         return nl_rtgen_request(h, RTM_GETNEIGHTBL, AF_UNSPEC, NLM_F_DUMP);
00231 }
00232 
00233 
00234 static int neightbl_dump_brief(struct nl_object *arg, struct nl_dump_params *p)
00235 {
00236         int line = 1;
00237         struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
00238 
00239         dp_dump(p, "%s", ntbl->nt_name);
00240 
00241         if (ntbl->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX) {
00242                 struct nl_cache *link_cache;
00243                 
00244                 link_cache = nl_cache_mngt_require("route/link");
00245 
00246                 if (link_cache) {
00247                         char buf[32];
00248                         dp_dump(p, "<%s> ",
00249                                 rtnl_link_i2name(link_cache,
00250                                                  ntbl->nt_parms.ntp_ifindex,
00251                                                  buf, sizeof(buf)));
00252                 } else
00253                         dp_dump(p, "<%u> ", ntbl->nt_parms.ntp_ifindex);
00254         } else
00255                 dp_dump(p, " ");
00256 
00257         if (ntbl->nt_mask & NEIGHTBL_ATTR_CONFIG)
00258                 dp_dump(p, "entries %u ", ntbl->nt_config.ndtc_entries);
00259 
00260         if (ntbl->nt_mask & NEIGHTBL_ATTR_PARMS) {
00261                 char rt[32], rt2[32];
00262                 struct rtnl_neightbl_parms *pa = &ntbl->nt_parms;
00263 
00264                 dp_dump(p, "reachable-time %s retransmit-time %s",
00265                         nl_msec2str(pa->ntp_reachable_time, rt, sizeof(rt)),
00266                         nl_msec2str(pa->ntp_retrans_time, rt2, sizeof(rt2)));
00267         }
00268 
00269         dp_dump(p, "\n");
00270 
00271         return line;
00272 }
00273 
00274 static int neightbl_dump_full(struct nl_object *arg, struct nl_dump_params *p)
00275 {
00276         char x[32], y[32], z[32];
00277         struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
00278 
00279         int line = neightbl_dump_brief(arg, p);
00280 
00281         if (ntbl->nt_mask & NEIGHTBL_ATTR_CONFIG) {
00282                 dp_new_line(p, line++);
00283                 dp_dump(p, "    key-len %u entry-size %u last-flush %s\n",
00284                         ntbl->nt_config.ndtc_key_len,
00285                         ntbl->nt_config.ndtc_entry_size,
00286                         nl_msec2str(ntbl->nt_config.ndtc_last_flush,
00287                                       x, sizeof(x)));
00288 
00289                 dp_new_line(p, line++);
00290                 dp_dump(p, "    gc threshold %u/%u/%u interval %s " \
00291                             "chain-position %u\n",
00292                         ntbl->nt_gc_thresh1, ntbl->nt_gc_thresh2,
00293                         ntbl->nt_gc_thresh3,
00294                         nl_msec2str(ntbl->nt_gc_interval, x, sizeof(x)),
00295                         ntbl->nt_config.ndtc_hash_chain_gc);
00296 
00297                 dp_new_line(p, line++);
00298                 dp_dump(p, "    hash-rand 0x%08X/0x%08X last-rand %s\n",
00299                         ntbl->nt_config.ndtc_hash_rnd,
00300                         ntbl->nt_config.ndtc_hash_mask,
00301                         nl_msec2str(ntbl->nt_config.ndtc_last_rand,
00302                                       x, sizeof(x)));
00303         }
00304 
00305         if (ntbl->nt_mask & NEIGHTBL_ATTR_PARMS) {
00306                 struct rtnl_neightbl_parms *pa = &ntbl->nt_parms;
00307 
00308                 dp_new_line(p, line++);
00309                 dp_dump(p, "    refcnt %u pending-queue-limit %u " \
00310                             "proxy-delayed-queue-limit %u\n",
00311                         pa->ntp_refcnt,
00312                         pa->ntp_queue_len,
00313                         pa->ntp_proxy_qlen);
00314 
00315                 dp_new_line(p, line++);
00316                 dp_dump(p, "    num-userspace-probes %u num-unicast-probes " \
00317                             "%u num-multicast-probes %u\n",
00318                         pa->ntp_app_probes,
00319                         pa->ntp_ucast_probes,
00320                         pa->ntp_mcast_probes);
00321 
00322                 dp_new_line(p, line++);
00323                 dp_dump(p, "    min-age %s base-reachable-time %s " \
00324                             "stale-check-interval %s\n",
00325                         nl_msec2str(pa->ntp_locktime, x, sizeof(x)),
00326                         nl_msec2str(pa->ntp_base_reachable_time,
00327                                       y, sizeof(y)),
00328                         nl_msec2str(pa->ntp_gc_stale_time, z, sizeof(z)));
00329 
00330                 dp_new_line(p, line++);
00331                 dp_dump(p, "    initial-probe-delay %s answer-delay %s " \
00332                             "proxy-answer-delay %s\n",
00333                         nl_msec2str(pa->ntp_probe_delay, x, sizeof(x)),
00334                         nl_msec2str(pa->ntp_anycast_delay, y, sizeof(y)),
00335                         nl_msec2str(pa->ntp_proxy_delay, z, sizeof(z)));
00336         }
00337 
00338         return line;
00339 }
00340 
00341 static int neightbl_dump_stats(struct nl_object *arg, struct nl_dump_params *p)
00342 {
00343         struct rtnl_neightbl *ntbl = (struct rtnl_neightbl *) arg;
00344         int line = neightbl_dump_full(arg, p);
00345 
00346         if (!(ntbl->nt_mask & NEIGHTBL_ATTR_STATS))
00347                 return line;
00348 
00349         dp_new_line(p, line++);
00350         dp_dump(p, "    lookups %lld hits %lld failed %lld " \
00351                     "allocations %lld destroys %lld\n",
00352                 ntbl->nt_stats.ndts_lookups,
00353                 ntbl->nt_stats.ndts_hits,
00354                 ntbl->nt_stats.ndts_res_failed,
00355                 ntbl->nt_stats.ndts_allocs,
00356                 ntbl->nt_stats.ndts_destroys);
00357 
00358         dp_new_line(p, line++);
00359         dp_dump(p, "    hash-grows %lld forced-gc-runs %lld " \
00360                     "periodic-gc-runs %lld\n",
00361                 ntbl->nt_stats.ndts_hash_grows,
00362                 ntbl->nt_stats.ndts_forced_gc_runs,
00363                 ntbl->nt_stats.ndts_periodic_gc_runs);
00364 
00365         dp_dump(p, "    rcv-unicast-probes %lld rcv-multicast-probes %lld\n",
00366                 ntbl->nt_stats.ndts_rcv_probes_ucast,
00367                 ntbl->nt_stats.ndts_rcv_probes_mcast);
00368 
00369         return line;
00370 }
00371 
00372 /**
00373  * @name Neighbour Table Object Allocation/Freeage
00374  * @{
00375  */
00376 
00377 /**
00378  * Allocate a new neighbour table object
00379  * @return New neighbour table object
00380  */
00381 struct rtnl_neightbl *rtnl_neightbl_alloc(void)
00382 {
00383         return (struct rtnl_neightbl *)
00384                         nl_object_alloc_from_ops(&rtnl_neightbl_ops);
00385 }
00386 
00387 /**
00388  * Give back reference on neighbour table object.
00389  * @arg neightbl        Neighbour  table object to be given back.
00390  *
00391  * Decrements the reference counter and frees the object if the
00392  * last reference has been released.
00393  */
00394 void rtnl_neightbl_put(struct rtnl_neightbl *neightbl)
00395 {
00396         nl_object_put((struct nl_object *) neightbl);
00397 }
00398 /**
00399  * Free neighbour table object.
00400  * @arg neightbl        Neighbour table object to be freed.
00401  *
00402  * @note Always use rtnl_neightbl_put() unless you're absolutely sure
00403  *       that no other user may have a reference on this object.
00404  */
00405 void rtnl_neightbl_free(struct rtnl_neightbl *neightbl)
00406 {
00407         nl_object_free((struct nl_object *) neightbl);
00408 }
00409 
00410 /** @} */
00411 
00412 /**
00413  * @name Neighbour Table Cache Management
00414  * @{
00415  */
00416 
00417 /**
00418  * Build a neighbour table cache including all neighbour tables currently configured in the kernel.
00419  * @arg handle          netlink handle
00420  *
00421  * Allocates a new neighbour table cache, initializes it properly and
00422  * updates it to include all neighbour tables currently configured in
00423  * the kernel.
00424  *
00425  * @note The caller is responsible for destroying and freeing the
00426  *       cache after using it.
00427  * @return The new cache or NULL if an error occured.
00428  */
00429 struct nl_cache * rtnl_neightbl_alloc_cache(struct nl_handle *handle)
00430 {
00431         struct nl_cache * cache;
00432         
00433         cache = nl_cache_alloc_from_ops(&rtnl_neightbl_ops);
00434         if (cache == NULL)
00435                 return NULL;
00436         
00437         if (nl_cache_update(handle, cache) < 0) {
00438                 nl_cache_free(cache);
00439                 return NULL;
00440         }
00441 
00442         return cache;
00443 }
00444 
00445 /**
00446  * Lookup neighbour table by name and optional interface index
00447  * @arg cache           neighbour table cache
00448  * @arg name            name of table
00449  * @arg ifindex         optional interface index
00450  *
00451  * Looks up the neighbour table matching the specified name and
00452  * optionally the specified ifindex to retrieve device specific
00453  * parameter sets.
00454  *
00455  * @return ptr to neighbour table inside the cache or NULL if no
00456  *         match was found.
00457  */
00458 struct rtnl_neightbl *rtnl_neightbl_get(struct nl_cache *cache,
00459                                         const char *name, int ifindex)
00460 {
00461         struct rtnl_neightbl *nt;
00462 
00463         if (cache->c_ops != &rtnl_neightbl_ops)
00464                 return NULL;
00465 
00466         nl_list_for_each_entry(nt, &cache->c_items, ce_list) {
00467                 if (!strcasecmp(nt->nt_name, name) &&
00468                     ((!ifindex && !nt->nt_parms.ntp_ifindex) ||
00469                      (ifindex && ifindex == nt->nt_parms.ntp_ifindex))) {
00470                         nl_object_get((struct nl_object *) nt);
00471                         return nt;
00472                 }
00473         }
00474 
00475         return NULL;
00476 }
00477 
00478 /** @} */
00479 
00480 /**
00481  * @name Neighbour Table Modifications
00482  * @{
00483  */
00484 
00485 /**
00486  * Builds a netlink change request message to change neighbour table attributes
00487  * @arg old             neighbour table to change
00488  * @arg tmpl            template with requested changes
00489  *
00490  * Builds a new netlink message requesting a change of neighbour table
00491  * attributes. The netlink message header isn't fully equipped with all
00492  * relevant fields and must be sent out via nl_send_auto_complete() or
00493  * supplemented as needed.
00494  * \a old must point to a neighbour table currently configured in the
00495  * kernel and \a tmpl must contain the attributes to be changed set via
00496  * \c rtnl_neightbl_set_* functions.
00497  *
00498  * @return New netlink message
00499  */
00500 struct nl_msg * rtnl_neightbl_build_change_request(struct rtnl_neightbl *old,
00501                                                    struct rtnl_neightbl *tmpl)
00502 {
00503         struct nl_msg *m;
00504         struct ndtmsg ndt = {
00505                 .ndtm_family = old->nt_family,
00506         };
00507 
00508         m = nlmsg_build_simple(RTM_SETNEIGHTBL, 0);
00509         nlmsg_append(m, &ndt, sizeof(ndt), 1);
00510 
00511         nla_put_string(m, NDTA_NAME, old->nt_name);
00512 
00513         if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH1)
00514                 nla_put_u32(m, NDTA_THRESH1, tmpl->nt_gc_thresh1);
00515 
00516         if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH2)
00517                 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
00518 
00519         if (tmpl->nt_mask & NEIGHTBL_ATTR_THRESH2)
00520                 nla_put_u32(m, NDTA_THRESH2, tmpl->nt_gc_thresh2);
00521 
00522         if (tmpl->nt_mask & NEIGHTBL_ATTR_GC_INTERVAL)
00523                 nla_put_u64(m, NDTA_GC_INTERVAL,
00524                                       tmpl->nt_gc_interval);
00525 
00526         if (tmpl->nt_mask & NEIGHTBL_ATTR_PARMS) {
00527                 struct rtnl_neightbl_parms *p = &tmpl->nt_parms;
00528                 struct nl_msg *parms = nlmsg_build(NULL);
00529 
00530                 if (old->nt_parms.ntp_mask & NEIGHTBLPARM_ATTR_IFINDEX)
00531                         nla_put_u32(parms, NDTPA_IFINDEX,
00532                                               old->nt_parms.ntp_ifindex);
00533 
00534 
00535                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_QUEUE_LEN)
00536                         nla_put_u32(parms, NDTPA_QUEUE_LEN, p->ntp_queue_len);
00537 
00538                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_APP_PROBES)
00539                         nla_put_u32(parms, NDTPA_APP_PROBES, p->ntp_app_probes);
00540 
00541                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_UCAST_PROBES)
00542                         nla_put_u32(parms, NDTPA_UCAST_PROBES,
00543                                     p->ntp_ucast_probes);
00544 
00545                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_MCAST_PROBES)
00546                         nla_put_u32(parms, NDTPA_MCAST_PROBES,
00547                                     p->ntp_mcast_probes);
00548 
00549                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_QLEN)
00550                         nla_put_u32(parms, NDTPA_PROXY_QLEN,
00551                                     p->ntp_proxy_qlen);
00552 
00553                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME)
00554                         nla_put_u64(parms, NDTPA_BASE_REACHABLE_TIME,
00555                                     p->ntp_base_reachable_time);
00556 
00557                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_RETRANS_TIME)
00558                         nla_put_u64(parms, NDTPA_RETRANS_TIME,
00559                                     p->ntp_retrans_time);
00560 
00561                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_GC_STALETIME)
00562                         nla_put_u64(parms, NDTPA_GC_STALETIME,
00563                                     p->ntp_gc_stale_time);
00564 
00565                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME)
00566                         nla_put_u64(parms, NDTPA_DELAY_PROBE_TIME,
00567                                     p->ntp_proxy_delay);
00568 
00569                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_ANYCAST_DELAY)
00570                         nla_put_u64(parms, NDTPA_ANYCAST_DELAY,
00571                                     p->ntp_anycast_delay);
00572 
00573                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_PROXY_DELAY)
00574                         nla_put_u64(parms, NDTPA_PROXY_DELAY,
00575                                               p->ntp_proxy_delay);
00576 
00577                 if (p->ntp_mask & NEIGHTBLPARM_ATTR_LOCKTIME)
00578                         nla_put_u64(parms, NDTPA_LOCKTIME, p->ntp_locktime);
00579 
00580                 nla_put_nested(m, NDTA_PARMS, parms);
00581                 nlmsg_free(parms);
00582         }
00583         
00584         return m;
00585 }
00586 
00587 /**
00588  * Change neighbour table attributes
00589  * @arg handle          netlink handle
00590  * @arg old             neighbour table to be changed
00591  * @arg tmpl            template with requested changes
00592  *
00593  * Builds a new netlink message by calling
00594  * rtnl_neightbl_build_change_request(), sends the request to the
00595  * kernel and waits for the next ACK to be received, i.e. blocks
00596  * until the request has been processed.
00597  *
00598  * @return 0 on success or a negative error code
00599  */
00600 int rtnl_neightbl_change(struct nl_handle *handle, struct rtnl_neightbl *old,
00601                          struct rtnl_neightbl *tmpl)
00602 {
00603         int err;
00604         struct nl_msg *msg;
00605         
00606         msg = rtnl_neightbl_build_change_request(old, tmpl);
00607         err = nl_send_auto_complete(handle, msg);
00608         if (err < 0)
00609                 return err;
00610 
00611         nlmsg_free(msg);
00612         return nl_wait_for_ack(handle);
00613 }
00614 
00615 /** @} */
00616 
00617 /**
00618  * @name Attribute Modification
00619  * @{
00620  */
00621 
00622 /**
00623  * Set the address family of a neighbour table to the specified value
00624  * @arg ntbl            neighbour table to change
00625  * @arg family          new address family
00626  */
00627 void rtnl_neightbl_set_family(struct rtnl_neightbl *ntbl, int family)
00628 {
00629         ntbl->nt_family = family;
00630         ntbl->nt_mask |= NEIGHTBL_ATTR_FAMILY;
00631 }
00632 
00633 /**
00634  * Set the gc interval of a neighbour table to the specified value
00635  * @arg ntbl            neighbour table to change
00636  * @arg ms              new interval in milliseconds
00637  */
00638 void rtnl_neightbl_set_gc_interval(struct rtnl_neightbl *ntbl, uint64_t ms)
00639 {
00640         ntbl->nt_gc_interval = ms;
00641         ntbl->nt_mask |= NEIGHTBL_ATTR_GC_INTERVAL;
00642 }
00643 
00644 /**
00645  * Set the gc threshold 1 of a neighbour table to the specified value
00646  * @arg ntbl            neighbour table to change
00647  * @arg thresh          new gc threshold
00648  */
00649 void rtnl_neightbl_set_gc_tresh1(struct rtnl_neightbl *ntbl, int thresh)
00650 {
00651         ntbl->nt_gc_thresh1 = thresh;
00652         ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH1;
00653 }
00654 
00655 /**
00656  * Set the gc threshold 2 of a neighbour table to the specified value
00657  * @arg ntbl            neighbour table to change
00658  * @arg thresh          new gc threshold
00659  */
00660 void rtnl_neightbl_set_gc_tresh2(struct rtnl_neightbl *ntbl, int thresh)
00661 {
00662         ntbl->nt_gc_thresh2 = thresh;
00663         ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH2;
00664 }
00665 
00666 /**
00667  * Set the gc threshold 3 of a neighbour table to the specified value
00668  * @arg ntbl            neighbour table to change
00669  * @arg thresh          new gc threshold
00670  */
00671 void rtnl_neightbl_set_gc_tresh3(struct rtnl_neightbl *ntbl, int thresh)
00672 {
00673         ntbl->nt_gc_thresh3 = thresh;
00674         ntbl->nt_mask |= NEIGHTBL_ATTR_THRESH3;
00675 }
00676 
00677 /**
00678  * Set the table name of a neighbour table to the specified value
00679  * @arg ntbl            neighbour table to change
00680  * @arg name            new table name
00681  */
00682 void rtnl_neightbl_set_name(struct rtnl_neightbl *ntbl, const char *name)
00683 {
00684         strncpy(ntbl->nt_name, name, sizeof(ntbl->nt_name) - 1);
00685         ntbl->nt_mask |= NEIGHTBL_ATTR_NAME;
00686 }
00687 
00688 /**
00689  * Set the device of a neighbour table to the specified value
00690  * @arg ntbl            neighbour table to change
00691  * @arg ifindex         interface index of the device
00692  */
00693 void rtnl_neightbl_set_dev(struct rtnl_neightbl *ntbl, int ifindex)
00694 {
00695         ntbl->nt_parms.ntp_ifindex = ifindex;
00696         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_IFINDEX;
00697         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00698 }
00699 
00700 /**
00701  * Set the queue length for pending requests of a neighbour table to the specified value
00702  * @arg ntbl            neighbour table to change
00703  * @arg len             new queue len
00704  */
00705 void rtnl_neightbl_set_queue_len(struct rtnl_neightbl *ntbl, int len)
00706 {
00707         ntbl->nt_parms.ntp_queue_len = len;
00708         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_QUEUE_LEN;
00709         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00710 }
00711 
00712 /**
00713  * Set the queue length for delay proxy arp requests of a neighbour table to the specified value
00714  * @arg ntbl            neighbour table to change
00715  * @arg len             new queue len
00716  */
00717 void rtnl_neightbl_set_proxy_queue_len(struct rtnl_neightbl *ntbl, int len)
00718 {
00719         ntbl->nt_parms.ntp_proxy_qlen = len;
00720         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_QLEN;
00721         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00722 }
00723 
00724 /**
00725  * Set the number of application probes of a neighbour table to the specified value
00726  * @arg ntbl            neighbour table to change
00727  * @arg probes          new probes value
00728  */
00729 void rtnl_neightbl_set_app_probes(struct rtnl_neightbl *ntbl, int probes)
00730 {
00731         ntbl->nt_parms.ntp_app_probes = probes;
00732         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_APP_PROBES;
00733         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00734 }
00735 
00736 /**
00737  * Set the number of unicast probes of a neighbour table to the specified value
00738  * @arg ntbl            neighbour table to change
00739  * @arg probes          new probes value
00740  */
00741 void rtnl_neightbl_set_ucast_probes(struct rtnl_neightbl *ntbl, int probes)
00742 {
00743         ntbl->nt_parms.ntp_ucast_probes = probes;
00744         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_UCAST_PROBES;
00745         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00746 }
00747 
00748 /**
00749  * Set the number of multicast probes of a neighbour table to the specified value
00750  * @arg ntbl            neighbour table to change
00751  * @arg probes          new probes value
00752  */
00753 void rtnl_neightbl_set_mcast_probes(struct rtnl_neightbl *ntbl, int probes)
00754 {
00755         ntbl->nt_parms.ntp_mcast_probes = probes;
00756         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_MCAST_PROBES;
00757         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00758 }
00759 
00760 /**
00761  * Set the base reachable time of a neighbour table to the specified value
00762  * @arg ntbl            neighbour table to change
00763  * @arg ms              new base reachable time in milliseconds
00764  */
00765 void rtnl_neightbl_set_base_reachable_time(struct rtnl_neightbl *ntbl,
00766                                            uint64_t ms)
00767 {
00768         ntbl->nt_parms.ntp_base_reachable_time = ms;
00769         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_BASE_REACHABLE_TIME;
00770         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00771 }
00772 
00773 /**
00774  * Set the retransmit time of a neighbour table to the specified value
00775  * @arg ntbl            neighbour table to change
00776  * @arg ms              new retransmit time
00777  */
00778 void rtnl_neightbl_set_retrans_time(struct rtnl_neightbl *ntbl, uint64_t ms)
00779 {
00780         ntbl->nt_parms.ntp_retrans_time = ms;
00781         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_RETRANS_TIME;
00782         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00783 }
00784 
00785 /**
00786  * Set the gc stale time of a neighbour table to the specified value
00787  * @arg ntbl            neighbour table to change
00788  * @arg ms              new gc stale time in milliseconds
00789  */
00790 void rtnl_neightbl_set_gc_stale_time(struct rtnl_neightbl *ntbl, uint64_t ms)
00791 {
00792         ntbl->nt_parms.ntp_gc_stale_time = ms;
00793         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_GC_STALETIME;
00794         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00795 }
00796 
00797 /**
00798  * Set the first probe delay time of a neighbour table to the specified value
00799  * @arg ntbl            neighbour table to change
00800  * @arg ms              new first probe delay time in milliseconds
00801  */
00802 void rtnl_neightbl_set_delay_probe_time(struct rtnl_neightbl *ntbl, uint64_t ms)
00803 {
00804         ntbl->nt_parms.ntp_probe_delay = ms;
00805         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_DELAY_PROBE_TIME;
00806         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00807 }
00808 
00809 /**
00810  * Set the anycast delay of a neighbour table to the specified value
00811  * @arg ntbl            neighbour table to change
00812  * @arg ms              new anycast delay in milliseconds
00813  */
00814 void rtnl_neightbl_set_anycast_delay(struct rtnl_neightbl *ntbl, uint64_t ms)
00815 {
00816         ntbl->nt_parms.ntp_anycast_delay = ms;
00817         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_ANYCAST_DELAY;
00818         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00819 }
00820 
00821 /**
00822  * Set the proxy delay of a neighbour table to the specified value
00823  * @arg ntbl            neighbour table to change
00824  * @arg ms              new proxy delay in milliseconds
00825  */
00826 void rtnl_neightbl_set_proxy_delay(struct rtnl_neightbl *ntbl, uint64_t ms)
00827 {
00828         ntbl->nt_parms.ntp_proxy_delay = ms;
00829         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_PROXY_DELAY;
00830         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00831 }
00832 
00833 /**
00834  * Set the locktime of a neighbour table to the specified value
00835  * @arg ntbl            neighbour table to change
00836  * @arg ms              new locktime in milliseconds
00837  */
00838 void rtnl_neightbl_set_locktime(struct rtnl_neightbl *ntbl, uint64_t ms)
00839 {
00840         ntbl->nt_parms.ntp_locktime = ms;
00841         ntbl->nt_parms.ntp_mask |= NEIGHTBLPARM_ATTR_LOCKTIME;
00842         ntbl->nt_mask |= NEIGHTBL_ATTR_PARMS;
00843 }
00844 
00845 /** @} */
00846 
00847 static struct nl_cache_ops rtnl_neightbl_ops = {
00848         .co_name                = "route/neightbl",
00849         .co_size                = sizeof(struct rtnl_neightbl),
00850         .co_hdrsize             = sizeof(struct rtgenmsg),
00851         .co_msgtypes            = {
00852                                         { RTM_NEWNEIGHTBL, "new" },
00853                                         { RTM_SETNEIGHTBL, "set" },
00854                                         { RTM_GETNEIGHTBL, "get" },
00855                                         { -1, NULL },
00856                                   },
00857         .co_protocol            = NETLINK_ROUTE,
00858         .co_request_update      = &neightbl_request_update,
00859         .co_msg_parser          = &neightbl_msg_parser,
00860         .co_dump[NL_DUMP_BRIEF] = &neightbl_dump_brief,
00861         .co_dump[NL_DUMP_FULL]  = &neightbl_dump_full,
00862         .co_dump[NL_DUMP_STATS] = &neightbl_dump_stats,
00863         .co_filter              = &neightbl_filter,
00864 };
00865 
00866 static void __init neightbl_init(void)
00867 {
00868         nl_cache_mngt_register(&rtnl_neightbl_ops);
00869 }
00870 
00871 static void __exit neightbl_exit(void)
00872 {
00873         nl_cache_mngt_unregister(&rtnl_neightbl_ops);
00874 }
00875 
00876 /** @} */

Generated on Fri Apr 27 14:14:07 2007 for libnl by  doxygen 1.5.1