00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 #include <netlink-local.h>
00151 #include <netlink/netlink.h>
00152 #include <netlink/utils.h>
00153 #include <netlink/route/rtnl.h>
00154 #include <netlink/route/neighbour.h>
00155 #include <netlink/route/link.h>
00156
00157
00158 #define NEIGH_ATTR_FLAGS 0x01
00159 #define NEIGH_ATTR_STATE 0x02
00160 #define NEIGH_ATTR_LLADDR 0x04
00161 #define NEIGH_ATTR_DST 0x08
00162 #define NEIGH_ATTR_CACHEINFO 0x10
00163 #define NEIGH_ATTR_IFINDEX 0x20
00164 #define NEIGH_ATTR_FAMILY 0x40
00165 #define NEIGH_ATTR_TYPE 0x80
00166 #define NEIGH_ATTR_PROBES 0x100
00167
00168 static struct nl_cache_ops rtnl_neigh_ops;
00169
00170
00171 static void neigh_free_data(struct nl_object *c)
00172 {
00173 struct rtnl_neigh *neigh = nl_object_priv(c);
00174
00175 if (!neigh)
00176 return;
00177
00178 nl_addr_put(neigh->n_lladdr);
00179 nl_addr_put(neigh->n_dst);
00180 }
00181
00182 static int neigh_filter(struct nl_object *obj, struct nl_object *filter)
00183 {
00184 struct rtnl_neigh *o = (struct rtnl_neigh *) obj;
00185 struct rtnl_neigh *f = (struct rtnl_neigh *) filter;
00186
00187 #define REQ(F) (f->n_mask & NEIGH_ATTR_##F)
00188 #define AVAIL(F) (o->n_mask & NEIGH_ATTR_##F)
00189 #define _O(F, EXPR) (REQ(F) && (!AVAIL(F) || (EXPR)))
00190 #define _C(F, N) (REQ(F) && (!AVAIL(F) || (o->N != f->N)))
00191 if (_C(IFINDEX, n_ifindex) ||
00192 _C(FAMILY, n_family) ||
00193 _C(TYPE, n_type) ||
00194 _O(LLADDR, nl_addr_cmp(o->n_lladdr, f->n_lladdr)) ||
00195 _O(DST, nl_addr_cmp(o->n_dst, f->n_dst)) ||
00196 _O(STATE, f->n_state ^ (o->n_state & f->n_state_mask)) ||
00197 _O(FLAGS, f->n_flags ^ (o->n_flags & f->n_flag_mask)))
00198 return 0;
00199 #undef REQ
00200 #undef AVAIL
00201 #undef _O
00202 #undef _C
00203
00204 return 1;
00205 }
00206
00207 static struct nla_policy neigh_policy[NDA_MAX+1] = {
00208 [NDA_CACHEINFO] = { .minlen = sizeof(struct nda_cacheinfo) },
00209 [NDA_PROBES] = { .type = NLA_U32 },
00210 };
00211
00212 static int neigh_msg_parser(struct sockaddr_nl *who, struct nlmsghdr *n,
00213 void *arg)
00214 {
00215 struct rtnl_neigh *neigh;
00216 struct nlattr *tb[NDA_MAX + 1];
00217 struct nl_parser_param *pp = arg;
00218 struct ndmsg *nm;
00219 int err;
00220
00221 neigh = rtnl_neigh_alloc();
00222 if (!neigh) {
00223 err = nl_errno(ENOMEM);
00224 goto errout;
00225 }
00226
00227 neigh->ce_msgtype = n->nlmsg_type;
00228 nm = nlmsg_data(n);
00229
00230 err = nlmsg_parse(n, sizeof(*nm), tb, NDA_MAX, neigh_policy);
00231 if (err < 0)
00232 goto errout;
00233
00234 neigh->n_family = nm->ndm_family;
00235 neigh->n_ifindex = nm->ndm_ifindex;
00236 neigh->n_state = nm->ndm_state;
00237 neigh->n_flags = nm->ndm_flags;
00238 neigh->n_type = nm->ndm_type;
00239
00240 neigh->n_mask |= (NEIGH_ATTR_FAMILY | NEIGH_ATTR_IFINDEX |
00241 NEIGH_ATTR_STATE | NEIGH_ATTR_FLAGS |
00242 NEIGH_ATTR_TYPE);
00243
00244 if (tb[NDA_LLADDR]) {
00245 neigh->n_lladdr = nla_get_addr(tb[NDA_LLADDR], AF_UNSPEC);
00246 if (!neigh->n_lladdr)
00247 goto errout;
00248 nl_addr_set_family(neigh->n_lladdr,
00249 nl_addr_guess_family(neigh->n_lladdr));
00250 neigh->n_mask |= NEIGH_ATTR_LLADDR;
00251 }
00252
00253 if (tb[NDA_DST]) {
00254 neigh->n_dst = nla_get_addr(tb[NDA_DST], neigh->n_family);
00255 if (!neigh->n_dst)
00256 goto errout;
00257 neigh->n_mask |= NEIGH_ATTR_DST;
00258 }
00259
00260 if (tb[NDA_CACHEINFO]) {
00261 struct nda_cacheinfo *ci = nla_data(tb[NDA_CACHEINFO]);
00262
00263 neigh->n_cacheinfo.nci_confirmed = ci->ndm_confirmed;
00264 neigh->n_cacheinfo.nci_used = ci->ndm_used;
00265 neigh->n_cacheinfo.nci_updated = ci->ndm_updated;
00266 neigh->n_cacheinfo.nci_refcnt = ci->ndm_refcnt;
00267
00268 neigh->n_mask |= NEIGH_ATTR_CACHEINFO;
00269 }
00270
00271 if (tb[NDA_PROBES]) {
00272 neigh->n_probes = nla_get_u32(tb[NDA_PROBES]);
00273 neigh->n_mask |= NEIGH_ATTR_PROBES;
00274 }
00275
00276 err = pp->pp_cb((struct nl_object *) neigh, pp);
00277 if (err < 0)
00278 goto errout;
00279
00280 return P_ACCEPT;
00281
00282 errout:
00283 rtnl_neigh_put(neigh);
00284 return err;
00285 }
00286
00287 static int neigh_request_update(struct nl_cache *c, struct nl_handle *h)
00288 {
00289 return nl_rtgen_request(h, RTM_GETNEIGH, AF_UNSPEC, NLM_F_DUMP);
00290 }
00291
00292
00293 static int neigh_dump_brief(struct nl_object *a, struct nl_dump_params *p)
00294 {
00295 char dst[INET6_ADDRSTRLEN+5], lladdr[INET6_ADDRSTRLEN+5];
00296 struct rtnl_neigh *n = (struct rtnl_neigh *) a;
00297 struct nl_cache *link_cache;
00298 char state[128], flags[64];
00299
00300 link_cache = nl_cache_mngt_require("route/link");
00301
00302 dp_dump(p, "%s ", nl_addr2str(n->n_dst, dst, sizeof(dst)));
00303
00304 if (link_cache)
00305 dp_dump(p, "dev %s ",
00306 rtnl_link_i2name(link_cache, n->n_ifindex,
00307 state, sizeof(state)));
00308 else
00309 dp_dump(p, "dev %d ", n->n_ifindex);
00310
00311 if (n->n_mask & NEIGH_ATTR_LLADDR)
00312 dp_dump(p, "lladdr %s ",
00313 nl_addr2str(n->n_lladdr, lladdr, sizeof(lladdr)));
00314
00315 rtnl_neigh_state2str(n->n_state, state, sizeof(state));
00316 rtnl_neigh_flags2str(n->n_flags, flags, sizeof(flags));
00317
00318 if (state[0])
00319 dp_dump(p, "<%s", state);
00320 if (flags[0])
00321 dp_dump(p, "%s%s", state[0] ? "," : "<", flags);
00322 if (state[0] || flags[0])
00323 dp_dump(p, ">");
00324 dp_dump(p, "\n");
00325
00326 return 1;
00327 }
00328
00329 static int neigh_dump_full(struct nl_object *a, struct nl_dump_params *p)
00330 {
00331 char rtn_type[32];
00332 struct rtnl_neigh *n = (struct rtnl_neigh *) a;
00333 int hz = nl_get_hz();
00334
00335 int line = neigh_dump_brief(a, p);
00336
00337 dp_dump_line(p, line++, " refcnt %u type %s confirmed %u used "
00338 "%u updated %u\n",
00339 n->n_cacheinfo.nci_refcnt,
00340 nl_rtntype2str(n->n_type, rtn_type, sizeof(rtn_type)),
00341 n->n_cacheinfo.nci_confirmed/hz,
00342 n->n_cacheinfo.nci_used/hz, n->n_cacheinfo.nci_updated/hz);
00343
00344 return line;
00345 }
00346
00347 static int neigh_dump_stats(struct nl_object *a, struct nl_dump_params *p)
00348 {
00349 return neigh_dump_full(a, p);
00350 }
00351
00352 static int neigh_dump_xml(struct nl_object *obj, struct nl_dump_params *p)
00353 {
00354 struct rtnl_neigh *neigh = (struct rtnl_neigh *) obj;
00355 char buf[128];
00356 int line = 0;
00357
00358 dp_dump_line(p, line++, "<neighbour>\n");
00359 dp_dump_line(p, line++, " <family>%s</family>\n",
00360 nl_af2str(neigh->n_family, buf, sizeof(buf)));
00361
00362 if (neigh->n_mask & NEIGH_ATTR_LLADDR)
00363 dp_dump_line(p, line++, " <lladdr>%s</lladdr>\n",
00364 nl_addr2str(neigh->n_lladdr, buf, sizeof(buf)));
00365
00366 if (neigh->n_mask & NEIGH_ATTR_DST)
00367 dp_dump_line(p, line++, " <dst>%s</dst>\n",
00368 nl_addr2str(neigh->n_dst, buf, sizeof(buf)));
00369
00370 if (neigh->n_mask & NEIGH_ATTR_IFINDEX) {
00371 struct nl_cache *link_cache;
00372
00373 link_cache = nl_cache_mngt_require("route/link");
00374
00375 if (link_cache)
00376 dp_dump_line(p, line++, " <device>%s</device>\n",
00377 rtnl_link_i2name(link_cache,
00378 neigh->n_ifindex,
00379 buf, sizeof(buf)));
00380 else
00381 dp_dump_line(p, line++, " <device>%u</device>\n",
00382 neigh->n_ifindex);
00383 }
00384
00385 if (neigh->n_mask & NEIGH_ATTR_PROBES)
00386 dp_dump_line(p, line++, " <probes>%u</probes>\n",
00387 neigh->n_probes);
00388
00389 if (neigh->n_mask & NEIGH_ATTR_TYPE)
00390 dp_dump_line(p, line++, " <type>%s</type>\n",
00391 nl_rtntype2str(neigh->n_type, buf, sizeof(buf)));
00392
00393 rtnl_neigh_flags2str(neigh->n_flags, buf, sizeof(buf));
00394 if (buf[0])
00395 dp_dump_line(p, line++, " <flags>%s</flags>\n", buf);
00396
00397 rtnl_neigh_state2str(neigh->n_state, buf, sizeof(buf));
00398 if (buf[0])
00399 dp_dump_line(p, line++, " <state>%s</state>\n", buf);
00400
00401 dp_dump_line(p, line++, "</neighbour>\n");
00402
00403 #if 0
00404 struct rtnl_ncacheinfo n_cacheinfo;
00405 #endif
00406
00407 return line;
00408 }
00409
00410 static int neigh_dump_env(struct nl_object *obj, struct nl_dump_params *p)
00411 {
00412 struct rtnl_neigh *neigh = (struct rtnl_neigh *) obj;
00413 char buf[128];
00414 int line = 0;
00415
00416 dp_dump_line(p, line++, "NEIGH_FAMILY=%s\n",
00417 nl_af2str(neigh->n_family, buf, sizeof(buf)));
00418
00419 if (neigh->n_mask & NEIGH_ATTR_LLADDR)
00420 dp_dump_line(p, line++, "NEIGHT_LLADDR=%s\n",
00421 nl_addr2str(neigh->n_lladdr, buf, sizeof(buf)));
00422
00423 if (neigh->n_mask & NEIGH_ATTR_DST)
00424 dp_dump_line(p, line++, "NEIGH_DST=%s\n",
00425 nl_addr2str(neigh->n_dst, buf, sizeof(buf)));
00426
00427 if (neigh->n_mask & NEIGH_ATTR_IFINDEX) {
00428 struct nl_cache *link_cache;
00429
00430 dp_dump_line(p, line++, "NEIGH_IFINDEX=%u\n",
00431 neigh->n_ifindex);
00432
00433 link_cache = nl_cache_mngt_require("route/link");
00434 if (link_cache)
00435 dp_dump_line(p, line++, "NEIGH_IFNAME=%s\n",
00436 rtnl_link_i2name(link_cache,
00437 neigh->n_ifindex,
00438 buf, sizeof(buf)));
00439 }
00440
00441 if (neigh->n_mask & NEIGH_ATTR_PROBES)
00442 dp_dump_line(p, line++, "NEIGH_PROBES=%u\n",
00443 neigh->n_probes);
00444
00445 if (neigh->n_mask & NEIGH_ATTR_TYPE)
00446 dp_dump_line(p, line++, "NEIGH_TYPE=%s\n",
00447 nl_rtntype2str(neigh->n_type, buf, sizeof(buf)));
00448
00449 rtnl_neigh_flags2str(neigh->n_flags, buf, sizeof(buf));
00450 if (buf[0])
00451 dp_dump_line(p, line++, "NEIGH_FLAGS=%s\n", buf);
00452
00453 rtnl_neigh_state2str(neigh->n_state, buf, sizeof(buf));
00454 if (buf[0])
00455 dp_dump_line(p, line++, "NEIGH_STATE=%s\n", buf);
00456
00457 return line;
00458 }
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 struct rtnl_neigh *rtnl_neigh_alloc(void)
00470 {
00471 return (struct rtnl_neigh *) nl_object_alloc_from_ops(&rtnl_neigh_ops);
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481 void rtnl_neigh_put(struct rtnl_neigh *neigh)
00482 {
00483 nl_object_put((struct nl_object *) neigh);
00484 }
00485
00486
00487
00488
00489
00490
00491
00492 void rtnl_neigh_free(struct rtnl_neigh *neigh)
00493 {
00494 nl_object_free((struct nl_object *) neigh);
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515 struct nl_cache *rtnl_neigh_alloc_cache(struct nl_handle *handle)
00516 {
00517 struct nl_cache *cache = nl_cache_alloc_from_ops(&rtnl_neigh_ops);
00518
00519 if (cache == NULL)
00520 return NULL;
00521
00522 if (nl_cache_update(handle, cache) < 0) {
00523 nl_cache_free(cache);
00524 return NULL;
00525 }
00526
00527 NL_DBG(2, "Returning new cache %p\n", cache);
00528
00529 return cache;
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539 struct rtnl_neigh * rtnl_neigh_get(struct nl_cache *cache, int ifindex,
00540 struct nl_addr *dst)
00541 {
00542 struct rtnl_neigh *neigh;
00543
00544 nl_list_for_each_entry(neigh, &cache->c_items, ce_list) {
00545 if (neigh->n_ifindex == ifindex &&
00546 !nl_addr_cmp(neigh->n_dst, dst)) {
00547 nl_object_get((struct nl_object *) neigh);
00548 return neigh;
00549 }
00550 }
00551
00552 return NULL;
00553 }
00554
00555
00556
00557
00558
00559
00560
00561
00562 static struct nl_msg * build_neigh_msg(struct rtnl_neigh *tmpl, int cmd,
00563 int flags)
00564 {
00565 struct nl_msg *msg;
00566 struct ndmsg nhdr = {
00567 .ndm_ifindex = tmpl->n_ifindex,
00568 .ndm_family = nl_addr_get_family(tmpl->n_dst),
00569 .ndm_state = NUD_PERMANENT,
00570 };
00571
00572 if (tmpl->n_mask & NEIGH_ATTR_STATE)
00573 nhdr.ndm_state = tmpl->n_state;
00574
00575 msg = nlmsg_build_simple(cmd, flags);
00576 if (!msg)
00577 return NULL;
00578
00579 if (nlmsg_append(msg, &nhdr, sizeof(nhdr), 1) < 0)
00580 goto nla_put_failure;
00581
00582 NLA_PUT_ADDR(msg, NDA_DST, tmpl->n_dst);
00583
00584 if (tmpl->n_mask & NEIGH_ATTR_LLADDR)
00585 NLA_PUT_ADDR(msg, NDA_LLADDR, tmpl->n_lladdr);
00586
00587 return msg;
00588
00589 nla_put_failure:
00590 nlmsg_free(msg);
00591 return NULL;
00592 }
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613 struct nl_msg * rtnl_neigh_build_add_request(struct rtnl_neigh *tmpl, int flags)
00614 {
00615 return build_neigh_msg(tmpl, RTM_NEWNEIGH, NLM_F_CREATE | flags);
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 int rtnl_neigh_add(struct nl_handle *handle, struct rtnl_neigh *tmpl, int flags)
00637 {
00638 int err;
00639 struct nl_msg *msg;
00640
00641 msg = rtnl_neigh_build_add_request(tmpl, flags);
00642 if (!msg)
00643 return nl_errno(ENOMEM);
00644
00645 err = nl_send_auto_complete(handle, msg);
00646 if (err < 0)
00647 return err;
00648
00649 nlmsg_free(msg);
00650 return nl_wait_for_ack(handle);
00651 }
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 struct nl_msg *rtnl_neigh_build_delete_request(struct rtnl_neigh *neigh,
00674 int flags)
00675 {
00676 return build_neigh_msg(neigh, RTM_DELNEIGH, flags);
00677 }
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 int rtnl_neigh_delete(struct nl_handle *handle, struct rtnl_neigh *neigh,
00692 int flags)
00693 {
00694 int err;
00695 struct nl_msg *msg;
00696
00697 msg = rtnl_neigh_build_delete_request(neigh, flags);
00698 if (!msg)
00699 return nl_errno(ENOMEM);
00700
00701 err = nl_send_auto_complete(handle, msg);
00702 if (err < 0)
00703 return err;
00704
00705 nlmsg_free(msg);
00706 return nl_wait_for_ack(handle);
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730 struct nl_msg *rtnl_neigh_build_change_request(struct rtnl_neigh *neigh,
00731 int flags)
00732 {
00733 return build_neigh_msg(neigh, RTM_NEWNEIGH, NLM_F_REPLACE | flags);
00734 }
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750 int rtnl_neigh_change(struct nl_handle *handle, struct rtnl_neigh *neigh,
00751 int flags)
00752 {
00753 int err;
00754 struct nl_msg *msg;
00755
00756 msg = rtnl_neigh_build_change_request(neigh, flags);
00757 if (!msg)
00758 return nl_errno(ENOMEM);
00759
00760 err = nl_send_auto_complete(handle, msg);
00761 if (err < 0)
00762 return err;
00763
00764 nlmsg_free(msg);
00765 return nl_wait_for_ack(handle);
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775 static struct trans_tbl neigh_states[] = {
00776 __ADD(NUD_INCOMPLETE, incomplete)
00777 __ADD(NUD_REACHABLE, reachable)
00778 __ADD(NUD_STALE, stale)
00779 __ADD(NUD_DELAY, delay)
00780 __ADD(NUD_PROBE, probe)
00781 __ADD(NUD_FAILED, failed)
00782 __ADD(NUD_NOARP, norarp)
00783 __ADD(NUD_PERMANENT, permanent)
00784 };
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 char * rtnl_neigh_state2str(int state, char *buf, size_t len)
00798 {
00799 return __flags2str(state, buf, len, neigh_states,
00800 ARRAY_SIZE(neigh_states));
00801 }
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 int rtnl_neigh_str2state(const char *name)
00813 {
00814 return __str2type(name, neigh_states, ARRAY_SIZE(neigh_states));
00815 }
00816
00817
00818
00819
00820
00821
00822
00823
00824 static struct trans_tbl neigh_flags[] = {
00825 __ADD(NTF_PROXY, proxy)
00826 __ADD(NTF_ROUTER, router)
00827 };
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840 char * rtnl_neigh_flags2str(int flags, char *buf, size_t len)
00841 {
00842 return __flags2str(flags, buf, len, neigh_flags,
00843 ARRAY_SIZE(neigh_flags));
00844 }
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 int rtnl_neigh_str2flag(const char *name)
00856 {
00857 return __str2type(name, neigh_flags, ARRAY_SIZE(neigh_flags));
00858 }
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872 void rtnl_neigh_set_state(struct rtnl_neigh *neigh, int state)
00873 {
00874 neigh->n_state_mask |= state;
00875 neigh->n_state |= state;
00876 neigh->n_mask |= NEIGH_ATTR_STATE;
00877 }
00878
00879
00880
00881
00882
00883
00884 int rtnl_neigh_get_state(struct rtnl_neigh *neigh)
00885 {
00886 if (neigh->n_mask & NEIGH_ATTR_STATE)
00887 return neigh->n_state;
00888 else
00889 return -1;
00890 }
00891
00892
00893
00894
00895
00896
00897 void rtnl_neigh_unset_state(struct rtnl_neigh *neigh, int state)
00898 {
00899 neigh->n_state_mask |= state;
00900 neigh->n_state &= ~state;
00901 neigh->n_mask |= NEIGH_ATTR_STATE;
00902 }
00903
00904
00905
00906
00907
00908
00909 void rtnl_neigh_set_flags(struct rtnl_neigh *neigh, unsigned int flags)
00910 {
00911 neigh->n_flag_mask |= flags;
00912 neigh->n_flags |= flags;
00913 neigh->n_mask |= NEIGH_ATTR_FLAGS;
00914 }
00915
00916
00917
00918
00919
00920
00921 unsigned int rtnl_neigh_get_flags(struct rtnl_neigh *neigh)
00922 {
00923 return neigh->n_flags;
00924 }
00925
00926
00927
00928
00929
00930
00931 void rtnl_neigh_unset_flags(struct rtnl_neigh *neigh, unsigned int flags)
00932 {
00933 neigh->n_flag_mask |= flags;
00934 neigh->n_flags &= ~flags;
00935 neigh->n_mask |= NEIGH_ATTR_FLAGS;
00936 }
00937
00938
00939
00940
00941
00942
00943 void rtnl_neigh_set_ifindex(struct rtnl_neigh *neigh, int ifindex)
00944 {
00945 neigh->n_ifindex = ifindex;
00946 neigh->n_mask |= NEIGH_ATTR_IFINDEX;
00947 }
00948
00949
00950
00951
00952
00953
00954 int rtnl_neigh_get_ifindex(struct rtnl_neigh *neigh)
00955 {
00956 if (neigh->n_mask & NEIGH_ATTR_IFINDEX)
00957 return neigh->n_ifindex;
00958 else
00959 return RTNL_LINK_NOT_FOUND;
00960 }
00961
00962 static inline int __assign_addr(struct rtnl_neigh *neigh, struct nl_addr **pos,
00963 struct nl_addr *new, int flag, int nocheck)
00964 {
00965 if (!nocheck) {
00966 if (neigh->n_mask & NEIGH_ATTR_FAMILY) {
00967 if (new->a_family != neigh->n_family)
00968 return nl_error(EINVAL,
00969 "Address family mismatch");
00970 } else {
00971 neigh->n_family = new->a_family;
00972 neigh->n_mask |= NEIGH_ATTR_FAMILY;
00973 }
00974 }
00975
00976 if (*pos)
00977 nl_addr_put(*pos);
00978
00979 nl_addr_get(new);
00980 *pos = new;
00981
00982 neigh->n_mask |= flag;
00983
00984 return 0;
00985 }
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996 void rtnl_neigh_set_lladdr(struct rtnl_neigh *neigh, struct nl_addr *addr)
00997 {
00998 __assign_addr(neigh, &neigh->n_lladdr, addr, NEIGH_ATTR_LLADDR, 1);
00999 }
01000
01001
01002
01003
01004
01005
01006 struct nl_addr *rtnl_neigh_get_lladdr(struct rtnl_neigh *neigh)
01007 {
01008 if (neigh->n_mask & NEIGH_ATTR_LLADDR)
01009 return neigh->n_lladdr;
01010 else
01011 return NULL;
01012 }
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027 int rtnl_neigh_set_dst(struct rtnl_neigh *neigh, struct nl_addr *addr)
01028 {
01029 return __assign_addr(neigh, &neigh->n_dst, addr,
01030 NEIGH_ATTR_DST, 0);
01031 }
01032
01033
01034
01035
01036
01037
01038 struct nl_addr *rtnl_neigh_get_dst(struct rtnl_neigh *neigh)
01039 {
01040 if (neigh->n_mask & NEIGH_ATTR_DST)
01041 return neigh->n_dst;
01042 else
01043 return NULL;
01044 }
01045
01046
01047
01048
01049
01050
01051 void rtnl_neigh_set_family(struct rtnl_neigh *neigh, int family)
01052 {
01053 neigh->n_family = family;
01054 neigh->n_mask |= NEIGH_ATTR_FAMILY;
01055 }
01056
01057
01058
01059
01060
01061
01062 void rtnl_neigh_set_type(struct rtnl_neigh *neigh, int type)
01063 {
01064 neigh->n_type = type;
01065 neigh->n_mask = NEIGH_ATTR_TYPE;
01066 }
01067
01068
01069
01070
01071
01072
01073 int rtnl_neigh_get_type(struct rtnl_neigh *neigh)
01074 {
01075 if (neigh->n_mask & NEIGH_ATTR_TYPE)
01076 return neigh->n_type;
01077 else
01078 return -1;
01079 }
01080
01081
01082
01083 static struct nl_cache_ops rtnl_neigh_ops = {
01084 .co_name = "route/neigh",
01085 .co_size = sizeof(struct rtnl_neigh),
01086 .co_hdrsize = sizeof(struct ndmsg),
01087 .co_msgtypes = {
01088 { RTM_NEWNEIGH, "new" },
01089 { RTM_DELNEIGH, "delete" },
01090 { RTM_GETNEIGH, "get" },
01091 { -1, NULL },
01092 },
01093 .co_protocol = NETLINK_ROUTE,
01094 .co_request_update = neigh_request_update,
01095 .co_msg_parser = neigh_msg_parser,
01096 .co_free_data = neigh_free_data,
01097 .co_dump[NL_DUMP_BRIEF] = neigh_dump_brief,
01098 .co_dump[NL_DUMP_FULL] = neigh_dump_full,
01099 .co_dump[NL_DUMP_STATS] = neigh_dump_stats,
01100 .co_dump[NL_DUMP_XML] = neigh_dump_xml,
01101 .co_dump[NL_DUMP_ENV] = neigh_dump_env,
01102 .co_filter = neigh_filter,
01103 };
01104
01105 static void __init neigh_init(void)
01106 {
01107 nl_cache_mngt_register(&rtnl_neigh_ops);
01108 }
01109
01110 static void __exit neigh_exit(void)
01111 {
01112 nl_cache_mngt_unregister(&rtnl_neigh_ops);
01113 }
01114
01115