Lines Matching refs:mrt
97 struct mr_table *mrt;
100 /* Big lock, protecting vif table, mrt cache and mroute socket state.
126 static int ip_mr_forward(struct net *net, struct mr_table *mrt,
129 static int ipmr_cache_report(struct mr_table *mrt,
131 static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
136 #define ipmr_for_each_table(mrt, net) \
137 list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list)
141 struct mr_table *mrt;
143 ipmr_for_each_table(mrt, net) {
144 if (mrt->id == id)
145 return mrt;
151 struct mr_table **mrt)
160 *mrt = res.mrt;
168 struct mr_table *mrt;
182 mrt = ipmr_get_table(rule->fr_net, rule->table);
183 if (mrt == NULL)
185 res->mrt = mrt;
237 struct mr_table *mrt;
246 mrt = ipmr_new_table(net, RT_TABLE_DEFAULT);
247 if (mrt == NULL) {
260 kfree(mrt);
268 struct mr_table *mrt, *next;
270 list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) {
271 list_del(&mrt->list);
272 kfree(mrt);
277 #define ipmr_for_each_table(mrt, net) \
278 for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
282 return net->ipv4.mrt;
286 struct mr_table **mrt)
288 *mrt = net->ipv4.mrt;
294 net->ipv4.mrt = ipmr_new_table(net, RT_TABLE_DEFAULT);
295 return net->ipv4.mrt ? 0 : -ENOMEM;
300 kfree(net->ipv4.mrt);
306 struct mr_table *mrt;
309 mrt = ipmr_get_table(net, id);
310 if (mrt != NULL)
311 return mrt;
313 mrt = kzalloc(sizeof(*mrt), GFP_KERNEL);
314 if (mrt == NULL)
316 write_pnet(&mrt->net, net);
317 mrt->id = id;
321 INIT_LIST_HEAD(&mrt->mfc_cache_array[i]);
323 INIT_LIST_HEAD(&mrt->mfc_unres_queue);
325 setup_timer(&mrt->ipmr_expire_timer, ipmr_expire_process,
326 (unsigned long)mrt);
329 mrt->mroute_reg_vif_num = -1;
332 list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables);
334 return mrt;
436 struct mr_table *mrt;
444 err = ipmr_fib_lookup(net, &fl, &mrt);
453 ipmr_cache_report(mrt, skb, mrt->mroute_reg_vif_num, IGMPMSG_WHOLEPKT);
473 static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt)
479 if (mrt->id == RT_TABLE_DEFAULT)
482 sprintf(name, "pimreg%u", mrt->id);
529 static int vif_delete(struct mr_table *mrt, int vifi, int notify,
536 if (vifi < 0 || vifi >= mrt->maxvif)
539 v = &mrt->vif_table[vifi];
551 if (vifi == mrt->mroute_reg_vif_num)
552 mrt->mroute_reg_vif_num = -1;
555 if (vifi+1 == mrt->maxvif) {
558 if (VIF_EXISTS(mrt, tmp))
561 mrt->maxvif = tmp+1;
589 static void ipmr_destroy_unres(struct mr_table *mrt, struct mfc_cache *c)
591 struct net *net = read_pnet(&mrt->net);
595 atomic_dec(&mrt->cache_resolve_queue_len);
620 struct mr_table *mrt = (struct mr_table *)arg;
626 mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10);
630 if (list_empty(&mrt->mfc_unres_queue))
636 list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) {
645 ipmr_destroy_unres(mrt, c);
648 if (!list_empty(&mrt->mfc_unres_queue))
649 mod_timer(&mrt->ipmr_expire_timer, jiffies + expires);
657 static void ipmr_update_thresholds(struct mr_table *mrt, struct mfc_cache *cache,
666 for (vifi = 0; vifi < mrt->maxvif; vifi++) {
667 if (VIF_EXISTS(mrt, vifi) &&
678 static int vif_add(struct net *net, struct mr_table *mrt,
682 struct vif_device *v = &mrt->vif_table[vifi];
688 if (VIF_EXISTS(mrt, vifi))
698 if (mrt->mroute_reg_vif_num >= 0)
700 dev = ipmr_reg_vif(net, mrt);
776 mrt->mroute_reg_vif_num = vifi;
778 if (vifi+1 > mrt->maxvif)
779 mrt->maxvif = vifi+1;
784 static struct mfc_cache *ipmr_cache_find(struct mr_table *mrt,
798 list_for_each_entry(c, &mrt->mfc_cache_array[line], list) {
840 static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,
854 if (__ipmr_fill_mroute(mrt, skb, c, NLMSG_DATA(nlh)) > 0) {
868 ip_mr_forward(net, mrt, skb, c, 0);
879 static int ipmr_cache_report(struct mr_table *mrt,
912 msg->im_vif = mrt->mroute_reg_vif_num;
944 if (mrt->mroute_sk == NULL) {
952 ret = sock_queue_rcv_skb(mrt->mroute_sk, skb);
967 ipmr_cache_unresolved(struct mr_table *mrt, vifi_t vifi, struct sk_buff *skb)
975 list_for_each_entry(c, &mrt->mfc_unres_queue, list) {
996 if (atomic_read(&mrt->cache_resolve_queue_len) >= 10 ||
1014 err = ipmr_cache_report(mrt, skb, vifi, IGMPMSG_NOCACHE);
1026 atomic_inc(&mrt->cache_resolve_queue_len);
1027 list_add(&c->list, &mrt->mfc_unres_queue);
1029 if (atomic_read(&mrt->cache_resolve_queue_len) == 1)
1030 mod_timer(&mrt->ipmr_expire_timer, c->mfc_un.unres.expires);
1052 static int ipmr_mfc_delete(struct mr_table *mrt, struct mfcctl *mfc)
1065 list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[line], list) {
1086 static int ipmr_mfc_add(struct net *net, struct mr_table *mrt,
1104 list_for_each_entry(c, &mrt->mfc_cache_array[line], list) {
1122 ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls);
1139 ipmr_update_thresholds(mrt, c, mfc->mfcc_ttls);
1144 list_add(&c->list, &mrt->mfc_cache_array[line]);
1153 list_for_each_entry(uc, &mrt->mfc_unres_queue, list) {
1164 atomic_dec(&mrt->cache_resolve_queue_len);
1169 if (list_empty(&mrt->mfc_unres_queue))
1170 del_timer(&mrt->ipmr_expire_timer);
1174 ipmr_cache_resolve(net, mrt, uc, c);
1184 static void mroute_clean_tables(struct mr_table *mrt)
1193 for (i = 0; i < mrt->maxvif; i++) {
1194 if (!(mrt->vif_table[i].flags&VIFF_STATIC))
1195 vif_delete(mrt, i, 0, &list);
1203 list_for_each_entry_safe(c, next, &mrt->mfc_cache_array[i], list) {
1214 if (atomic_read(&mrt->cache_resolve_queue_len) != 0) {
1216 list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) {
1218 ipmr_destroy_unres(mrt, c);
1227 struct mr_table *mrt;
1230 ipmr_for_each_table(mrt, net) {
1231 if (sk == mrt->mroute_sk) {
1235 mrt->mroute_sk = NULL;
1238 mroute_clean_tables(mrt);
1257 struct mr_table *mrt;
1259 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1260 if (mrt == NULL)
1264 if (sk != mrt->mroute_sk && !capable(CAP_NET_ADMIN))
1277 if (mrt->mroute_sk) {
1285 mrt->mroute_sk = sk;
1293 if (sk != mrt->mroute_sk)
1306 ret = vif_add(net, mrt, &vif, sk == mrt->mroute_sk);
1308 ret = vif_delete(mrt, vif.vifc_vifi, 0, NULL);
1325 ret = ipmr_mfc_delete(mrt, &mfc);
1327 ret = ipmr_mfc_add(net, mrt, &mfc, sk == mrt->mroute_sk);
1338 mrt->mroute_do_assert = (v) ? 1 : 0;
1352 if (v != mrt->mroute_do_pim) {
1353 mrt->mroute_do_pim = v;
1354 mrt->mroute_do_assert = v;
1369 if (sk == mrt->mroute_sk)
1399 struct mr_table *mrt;
1401 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1402 if (mrt == NULL)
1425 val = mrt->mroute_do_pim;
1428 val = mrt->mroute_do_assert;
1445 struct mr_table *mrt;
1447 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT);
1448 if (mrt == NULL)
1455 if (vr.vifi >= mrt->maxvif)
1458 vif = &mrt->vif_table[vr.vifi];
1459 if (VIF_EXISTS(mrt, vr.vifi)) {
1477 c = ipmr_cache_find(mrt, sr.src.s_addr, sr.grp.s_addr);
1500 struct mr_table *mrt;
1508 ipmr_for_each_table(mrt, net) {
1509 v = &mrt->vif_table[0];
1510 for (ct = 0; ct < mrt->maxvif; ct++, v++) {
1512 vif_delete(mrt, ct, 1, &list);
1572 static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,
1576 struct vif_device *vif = &mrt->vif_table[vifi];
1599 ipmr_cache_report(mrt, skb, vifi, IGMPMSG_WHOLEPKT);
1682 static int ipmr_find_vif(struct mr_table *mrt, struct net_device *dev)
1686 for (ct = mrt->maxvif-1; ct >= 0; ct--) {
1687 if (mrt->vif_table[ct].dev == dev)
1695 static int ip_mr_forward(struct net *net, struct mr_table *mrt,
1709 if (mrt->vif_table[vif].dev != skb->dev) {
1717 true_vifi = ipmr_find_vif(mrt, skb->dev);
1719 if (true_vifi >= 0 && mrt->mroute_do_assert &&
1725 (mrt->mroute_do_pim ||
1730 ipmr_cache_report(mrt, skb, true_vifi, IGMPMSG_WRONGVIF);
1735 mrt->vif_table[vif].pkt_in++;
1736 mrt->vif_table[vif].bytes_in += skb->len;
1753 ipmr_queue_xmit(net, mrt, skb2, cache,
1763 ipmr_queue_xmit(net, mrt, skb2, cache, psend);
1765 ipmr_queue_xmit(net, mrt, skb, cache, psend);
1786 struct mr_table *mrt;
1795 err = ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt);
1813 if (mrt->mroute_sk) {
1815 raw_rcv(mrt->mroute_sk, skb);
1824 cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr);
1842 vif = ipmr_find_vif(mrt, skb->dev);
1844 int err2 = ipmr_cache_unresolved(mrt, vif, skb);
1854 ip_mr_forward(net, mrt, skb, cache, local);
1871 static int __pim_rcv(struct mr_table *mrt, struct sk_buff *skb,
1890 if (mrt->mroute_reg_vif_num >= 0)
1891 reg_dev = mrt->vif_table[mrt->mroute_reg_vif_num].dev;
1924 struct mr_table *mrt;
1931 if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1934 if (!mrt->mroute_do_pim ||
1938 if (__pim_rcv(mrt, skb, sizeof(*pim))) {
1951 struct mr_table *mrt;
1963 if (ipmr_fib_lookup(net, &skb_rtable(skb)->fl, &mrt) < 0)
1966 if (__pim_rcv(mrt, skb, sizeof(*pim))) {
1974 static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
1986 if (VIF_EXISTS(mrt, c->mfc_parent))
1987 RTA_PUT(skb, RTA_IIF, 4, &mrt->vif_table[c->mfc_parent].dev->ifindex);
1992 if (VIF_EXISTS(mrt, ct) && c->mfc_un.res.ttls[ct] < 255) {
1998 nhp->rtnh_ifindex = mrt->vif_table[ct].dev->ifindex;
2016 struct mr_table *mrt;
2020 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
2021 if (mrt == NULL)
2025 cache = ipmr_cache_find(mrt, rt->rt_src, rt->rt_dst);
2039 if (dev == NULL || (vif = ipmr_find_vif(mrt, dev)) < 0) {
2056 err = ipmr_cache_unresolved(mrt, vif, skb2);
2063 err = __ipmr_fill_mroute(mrt, skb, cache, rtm);
2068 static int ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
2083 rtm->rtm_table = mrt->id;
2084 NLA_PUT_U32(skb, RTA_TABLE, mrt->id);
2093 if (__ipmr_fill_mroute(mrt, skb, c, rtm) < 0)
2106 struct mr_table *mrt;
2117 ipmr_for_each_table(mrt, net) {
2123 list_for_each_entry(mfc, &mrt->mfc_cache_array[h], list) {
2126 if (ipmr_fill_mroute(mrt, skb,
2156 struct mr_table *mrt;
2164 struct mr_table *mrt = iter->mrt;
2166 for (iter->ct = 0; iter->ct < mrt->maxvif; ++iter->ct) {
2167 if (!VIF_EXISTS(mrt, iter->ct))
2170 return &mrt->vif_table[iter->ct];
2180 struct mr_table *mrt;
2182 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
2183 if (mrt == NULL)
2186 iter->mrt = mrt;
2197 struct mr_table *mrt = iter->mrt;
2203 while (++iter->ct < mrt->maxvif) {
2204 if (!VIF_EXISTS(mrt, iter->ct))
2206 return &mrt->vif_table[iter->ct];
2220 struct mr_table *mrt = iter->mrt;
2231 vif - mrt->vif_table,
2262 struct mr_table *mrt;
2271 struct mr_table *mrt = it->mrt;
2276 it->cache = &mrt->mfc_cache_array[it->ct];
2284 it->cache = &mrt->mfc_unres_queue;
2299 struct mr_table *mrt;
2301 mrt = ipmr_get_table(net, RT_TABLE_DEFAULT);
2302 if (mrt == NULL)
2305 it->mrt = mrt;
2317 struct mr_table *mrt = it->mrt;
2327 if (it->cache == &mrt->mfc_unres_queue)
2330 BUG_ON(it->cache != &mrt->mfc_cache_array[it->ct]);
2333 it->cache = &mrt->mfc_cache_array[it->ct];
2341 it->cache = &mrt->mfc_unres_queue;
2358 struct mr_table *mrt = it->mrt;
2360 if (it->cache == &mrt->mfc_unres_queue)
2362 else if (it->cache == &mrt->mfc_cache_array[it->ct])
2376 const struct mr_table *mrt = it->mrt;
2390 if (it->cache != &mrt->mfc_unres_queue) {
2397 if (VIF_EXISTS(mrt, n) &&