Lines Matching +full:use +full:- +full:rtm

1 // SPDX-License-Identifier: GPL-2.0-or-later
85 return rcu_dereference(vif->dev); in vif_dev_read()
119 list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list, \
121 list_empty(&net->ipv4.mr_tables))
129 ret = list_entry_rcu(net->ipv4.mr_tables.next, in ipmr_mr_table_iter()
132 ret = list_entry_rcu(mrt->list.next, in ipmr_mr_table_iter()
135 if (&ret->list == &net->ipv4.mr_tables) in ipmr_mr_table_iter()
145 if (mrt->id == id) in ipmr_get_table()
164 err = fib_rules_lookup(net->ipv4.mr_rules_ops, in ipmr_fib_lookup()
175 struct ipmr_result *res = arg->result; in ipmr_rule_action()
178 switch (rule->action) { in ipmr_rule_action()
182 return -ENETUNREACH; in ipmr_rule_action()
184 return -EACCES; in ipmr_rule_action()
187 return -EINVAL; in ipmr_rule_action()
190 arg->table = fib_rule_get_table(rule, arg); in ipmr_rule_action()
192 mrt = ipmr_get_table(rule->fr_net, arg->table); in ipmr_rule_action()
194 return -EAGAIN; in ipmr_rule_action()
195 res->mrt = mrt; in ipmr_rule_action()
220 frh->dst_len = 0; in ipmr_rule_fill()
221 frh->src_len = 0; in ipmr_rule_fill()
222 frh->tos = 0; in ipmr_rule_fill()
249 INIT_LIST_HEAD(&net->ipv4.mr_tables); in ipmr_rules_init()
261 net->ipv4.mr_rules_ops = ops; in ipmr_rules_init()
278 list_for_each_entry_safe(mrt, next, &net->ipv4.mr_tables, list) { in ipmr_rules_exit()
279 list_del(&mrt->list); in ipmr_rules_exit()
282 fib_rules_unregister(net->ipv4.mr_rules_ops); in ipmr_rules_exit()
298 return fib_rule_matchall(rule) && rule->table == RT_TABLE_DEFAULT; in ipmr_rule_default()
303 for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
309 return net->ipv4.mrt; in ipmr_mr_table_iter()
315 return net->ipv4.mrt; in ipmr_get_table()
321 *mrt = net->ipv4.mrt; in ipmr_fib_lookup()
332 net->ipv4.mrt = mrt; in ipmr_rules_init()
339 ipmr_free_table(net->ipv4.mrt); in ipmr_rules_exit()
340 net->ipv4.mrt = NULL; in ipmr_rules_exit()
364 const struct mfc_cache_cmp_arg *cmparg = arg->key; in ipmr_hash_cmp()
367 return cmparg->mfc_mcastgrp != c->mfc_mcastgrp || in ipmr_hash_cmp()
368 cmparg->mfc_origin != c->mfc_origin; in ipmr_hash_cmp()
384 list_add_tail_rcu(&mrt->list, &net->ipv4.mr_tables); in ipmr_new_table_set()
404 return ERR_PTR(-EINVAL); in ipmr_new_table()
416 timer_shutdown_sync(&mrt->ipmr_expire_timer); in ipmr_free_table()
419 rhltable_destroy(&mrt->mfc_hash); in ipmr_free_table()
436 neigh_parms_data_state_setall(in_dev->arp_parms); in ipmr_init_vif_indev()
437 IPV4_DEVCONF(in_dev->cnf, RP_FILTER) = 0; in ipmr_init_vif_indev()
452 p.iph.daddr = v->vifc_rmt_addr.s_addr; in ipmr_new_tunnel()
453 p.iph.saddr = v->vifc_lcl_addr.s_addr; in ipmr_new_tunnel()
457 sprintf(p.name, "dvmrp%d", v->vifc_vifi); in ipmr_new_tunnel()
459 if (!tunnel_dev->netdev_ops->ndo_tunnel_ctl) in ipmr_new_tunnel()
461 err = tunnel_dev->netdev_ops->ndo_tunnel_ctl(tunnel_dev, &p, in ipmr_new_tunnel()
470 new_dev->flags |= IFF_MULTICAST; in ipmr_new_tunnel()
479 tunnel_dev->netdev_ops->ndo_tunnel_ctl(tunnel_dev, &p, in ipmr_new_tunnel()
489 return ERR_PTR(-ENOBUFS); in ipmr_new_tunnel()
498 .flowi4_oif = dev->ifindex, in reg_vif_xmit()
499 .flowi4_iif = skb->skb_iif ? : LOOPBACK_IFINDEX, in reg_vif_xmit()
500 .flowi4_mark = skb->mark, in reg_vif_xmit()
510 DEV_STATS_ADD(dev, tx_bytes, skb->len); in reg_vif_xmit()
515 ipmr_cache_report(mrt, skb, READ_ONCE(mrt->mroute_reg_vif_num), in reg_vif_xmit()
535 dev->type = ARPHRD_PIMREG; in reg_vif_setup()
536 dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr) - 8; in reg_vif_setup()
537 dev->flags = IFF_NOARP; in reg_vif_setup()
538 dev->netdev_ops = &reg_vif_netdev_ops; in reg_vif_setup()
539 dev->needs_free_netdev = true; in reg_vif_setup()
540 dev->netns_local = true; in reg_vif_setup()
548 if (mrt->id == RT_TABLE_DEFAULT) in ipmr_reg_vif()
551 sprintf(name, "pimreg%u", mrt->id); in ipmr_reg_vif()
590 * b. packet is not a NULL-REGISTER in __pim_rcv()
593 if (!ipv4_is_multicast(encap->daddr) || in __pim_rcv()
594 encap->tot_len == 0 || in __pim_rcv()
595 ntohs(encap->tot_len) + pimlen > skb->len) in __pim_rcv()
599 vif_num = READ_ONCE(mrt->mroute_reg_vif_num); in __pim_rcv()
601 reg_dev = vif_dev_read(&mrt->vif_table[vif_num]); in __pim_rcv()
605 skb->mac_header = skb->network_header; in __pim_rcv()
606 skb_pull(skb, (u8 *)encap - skb->data); in __pim_rcv()
608 skb->protocol = htons(ETH_P_IP); in __pim_rcv()
609 skb->ip_summed = CHECKSUM_NONE; in __pim_rcv()
632 &net->ipv4.ipmr_seq); in call_ipmr_vif_entry_notifiers()
640 &mfc->_c, tb_id, &net->ipv4.ipmr_seq); in call_ipmr_mfc_entry_notifiers()
644 * vif_delete - Delete a VIF entry
653 struct net *net = read_pnet(&mrt->net); in vif_delete()
658 if (vifi < 0 || vifi >= mrt->maxvif) in vif_delete()
659 return -EADDRNOTAVAIL; in vif_delete()
661 v = &mrt->vif_table[vifi]; in vif_delete()
663 dev = rtnl_dereference(v->dev); in vif_delete()
665 return -EADDRNOTAVAIL; in vif_delete()
669 vifi, mrt->id); in vif_delete()
670 RCU_INIT_POINTER(v->dev, NULL); in vif_delete()
672 if (vifi == mrt->mroute_reg_vif_num) { in vif_delete()
674 WRITE_ONCE(mrt->mroute_reg_vif_num, -1); in vif_delete()
676 if (vifi + 1 == mrt->maxvif) { in vif_delete()
679 for (tmp = vifi - 1; tmp >= 0; tmp--) { in vif_delete()
683 WRITE_ONCE(mrt->maxvif, tmp + 1); in vif_delete()
688 dev_set_allmulti(dev, -1); in vif_delete()
692 IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)--; in vif_delete()
695 dev->ifindex, &in_dev->cnf); in vif_delete()
699 if (v->flags & (VIFF_TUNNEL | VIFF_REGISTER) && !notify) in vif_delete()
702 netdev_put(dev, &v->dev_tracker); in vif_delete()
715 call_rcu(&c->_c.rcu, ipmr_cache_free_rcu); in ipmr_cache_free()
723 struct net *net = read_pnet(&mrt->net); in ipmr_destroy_unres()
727 atomic_dec(&mrt->cache_resolve_queue_len); in ipmr_destroy_unres()
729 while ((skb = skb_dequeue(&c->_c.mfc_un.unres.unresolved))) { in ipmr_destroy_unres()
730 if (ip_hdr(skb)->version == 0) { in ipmr_destroy_unres()
733 nlh->nlmsg_type = NLMSG_ERROR; in ipmr_destroy_unres()
734 nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); in ipmr_destroy_unres()
735 skb_trim(skb, nlh->nlmsg_len); in ipmr_destroy_unres()
737 e->error = -ETIMEDOUT; in ipmr_destroy_unres()
738 memset(&e->msg, 0, sizeof(e->msg)); in ipmr_destroy_unres()
758 mod_timer(&mrt->ipmr_expire_timer, jiffies+HZ/10); in ipmr_expire_process()
762 if (list_empty(&mrt->mfc_unres_queue)) in ipmr_expire_process()
768 list_for_each_entry_safe(c, next, &mrt->mfc_unres_queue, list) { in ipmr_expire_process()
769 if (time_after(c->mfc_un.unres.expires, now)) { in ipmr_expire_process()
770 unsigned long interval = c->mfc_un.unres.expires - now; in ipmr_expire_process()
776 list_del(&c->list); in ipmr_expire_process()
781 if (!list_empty(&mrt->mfc_unres_queue)) in ipmr_expire_process()
782 mod_timer(&mrt->ipmr_expire_timer, jiffies + expires); in ipmr_expire_process()
794 cache->mfc_un.res.minvif = MAXVIFS; in ipmr_update_thresholds()
795 cache->mfc_un.res.maxvif = 0; in ipmr_update_thresholds()
796 memset(cache->mfc_un.res.ttls, 255, MAXVIFS); in ipmr_update_thresholds()
798 for (vifi = 0; vifi < mrt->maxvif; vifi++) { in ipmr_update_thresholds()
801 cache->mfc_un.res.ttls[vifi] = ttls[vifi]; in ipmr_update_thresholds()
802 if (cache->mfc_un.res.minvif > vifi) in ipmr_update_thresholds()
803 cache->mfc_un.res.minvif = vifi; in ipmr_update_thresholds()
804 if (cache->mfc_un.res.maxvif <= vifi) in ipmr_update_thresholds()
805 cache->mfc_un.res.maxvif = vifi + 1; in ipmr_update_thresholds()
808 cache->mfc_un.res.lastuse = jiffies; in ipmr_update_thresholds()
815 int vifi = vifc->vifc_vifi; in vif_add()
816 struct vif_device *v = &mrt->vif_table[vifi]; in vif_add()
823 return -EADDRINUSE; in vif_add()
825 switch (vifc->vifc_flags) { in vif_add()
828 return -EINVAL; in vif_add()
832 if (mrt->mroute_reg_vif_num >= 0) in vif_add()
833 return -EADDRINUSE; in vif_add()
836 return -ENOBUFS; in vif_add()
851 if (vifc->vifc_flags == VIFF_USE_IFINDEX) { in vif_add()
852 dev = dev_get_by_index(net, vifc->vifc_lcl_ifindex); in vif_add()
855 return -EADDRNOTAVAIL; in vif_add()
858 dev = ip_dev_find(net, vifc->vifc_lcl_addr.s_addr); in vif_add()
861 return -EADDRNOTAVAIL; in vif_add()
869 return -EINVAL; in vif_add()
875 return -EADDRNOTAVAIL; in vif_add()
877 IPV4_DEVCONF(in_dev->cnf, MC_FORWARDING)++; in vif_add()
879 dev->ifindex, &in_dev->cnf); in vif_add()
883 vif_device_init(v, dev, vifc->vifc_rate_limit, in vif_add()
884 vifc->vifc_threshold, in vif_add()
885 vifc->vifc_flags | (!mrtsock ? VIFF_STATIC : 0), in vif_add()
890 memcpy(v->dev_parent_id.id, ppid.id, ppid.id_len); in vif_add()
891 v->dev_parent_id.id_len = ppid.id_len; in vif_add()
893 v->dev_parent_id.id_len = 0; in vif_add()
896 v->local = vifc->vifc_lcl_addr.s_addr; in vif_add()
897 v->remote = vifc->vifc_rmt_addr.s_addr; in vif_add()
901 rcu_assign_pointer(v->dev, dev); in vif_add()
902 netdev_tracker_alloc(dev, &v->dev_tracker, GFP_ATOMIC); in vif_add()
903 if (v->flags & VIFF_REGISTER) { in vif_add()
905 WRITE_ONCE(mrt->mroute_reg_vif_num, vifi); in vif_add()
907 if (vifi+1 > mrt->maxvif) in vif_add()
908 WRITE_ONCE(mrt->maxvif, vifi + 1); in vif_add()
911 vifi, mrt->id); in vif_add()
942 /* Look for a (S,G,iif) entry if parent != -1 */
961 c->_c.mfc_un.res.last_assert = jiffies - MFC_ASSERT_THRESH - 1; in ipmr_cache_alloc()
962 c->_c.mfc_un.res.minvif = MAXVIFS; in ipmr_cache_alloc()
963 c->_c.free = ipmr_cache_free_rcu; in ipmr_cache_alloc()
964 refcount_set(&c->_c.mfc_un.res.refcount, 1); in ipmr_cache_alloc()
974 skb_queue_head_init(&c->_c.mfc_un.unres.unresolved); in ipmr_cache_alloc_unres()
975 c->_c.mfc_un.unres.expires = jiffies + 10 * HZ; in ipmr_cache_alloc_unres()
988 while ((skb = __skb_dequeue(&uc->_c.mfc_un.unres.unresolved))) { in ipmr_cache_resolve()
989 if (ip_hdr(skb)->version == 0) { in ipmr_cache_resolve()
993 if (mr_fill_mroute(mrt, skb, &c->_c, in ipmr_cache_resolve()
995 nlh->nlmsg_len = skb_tail_pointer(skb) - in ipmr_cache_resolve()
998 nlh->nlmsg_type = NLMSG_ERROR; in ipmr_cache_resolve()
999 nlh->nlmsg_len = nlmsg_msg_size(sizeof(struct nlmsgerr)); in ipmr_cache_resolve()
1000 skb_trim(skb, nlh->nlmsg_len); in ipmr_cache_resolve()
1002 e->error = -EMSGSIZE; in ipmr_cache_resolve()
1003 memset(&e->msg, 0, sizeof(e->msg)); in ipmr_cache_resolve()
1009 ip_mr_forward(net, mrt, skb->dev, skb, c, 0); in ipmr_cache_resolve()
1029 mroute_sk = rcu_dereference(mrt->mroute_sk); in ipmr_cache_report()
1031 return -EINVAL; in ipmr_cache_report()
1039 return -ENOBUFS; in ipmr_cache_report()
1044 * And all this only to mangle msg->im_msgtype and in ipmr_cache_report()
1045 * to set msg->im_mbz to "mbz" :-) in ipmr_cache_report()
1052 msg->im_msgtype = assert; in ipmr_cache_report()
1053 msg->im_mbz = 0; in ipmr_cache_report()
1055 msg->im_vif = vifi; in ipmr_cache_report()
1056 msg->im_vif_hi = vifi >> 8; in ipmr_cache_report()
1059 int vif_num = READ_ONCE(mrt->mroute_reg_vif_num); in ipmr_cache_report()
1061 msg->im_vif = vif_num; in ipmr_cache_report()
1062 msg->im_vif_hi = vif_num >> 8; in ipmr_cache_report()
1064 ip_hdr(skb)->ihl = sizeof(struct iphdr) >> 2; in ipmr_cache_report()
1065 ip_hdr(skb)->tot_len = htons(ntohs(ip_hdr(pkt)->tot_len) + in ipmr_cache_report()
1069 skb_set_network_header(skb, skb->len); in ipmr_cache_report()
1071 skb_copy_to_linear_data(skb, pkt->data, ihl); in ipmr_cache_report()
1073 ip_hdr(skb)->protocol = 0; in ipmr_cache_report()
1075 msg->im_vif = vifi; in ipmr_cache_report()
1076 msg->im_vif_hi = vifi >> 8; in ipmr_cache_report()
1078 memcpy(skb->cb, pkt->cb, sizeof(skb->cb)); in ipmr_cache_report()
1081 igmp->type = assert; in ipmr_cache_report()
1082 msg->im_msgtype = assert; in ipmr_cache_report()
1083 igmp->code = 0; in ipmr_cache_report()
1084 ip_hdr(skb)->tot_len = htons(skb->len); /* Fix the length */ in ipmr_cache_report()
1085 skb->transport_header = skb->network_header; in ipmr_cache_report()
1112 list_for_each_entry(c, &mrt->mfc_unres_queue, _c.list) { in ipmr_cache_unresolved()
1113 if (c->mfc_mcastgrp == iph->daddr && in ipmr_cache_unresolved()
1114 c->mfc_origin == iph->saddr) { in ipmr_cache_unresolved()
1127 return -ENOBUFS; in ipmr_cache_unresolved()
1131 c->_c.mfc_parent = -1; in ipmr_cache_unresolved()
1132 c->mfc_origin = iph->saddr; in ipmr_cache_unresolved()
1133 c->mfc_mcastgrp = iph->daddr; in ipmr_cache_unresolved()
1140 out - Brad Parker in ipmr_cache_unresolved()
1149 atomic_inc(&mrt->cache_resolve_queue_len); in ipmr_cache_unresolved()
1150 list_add(&c->_c.list, &mrt->mfc_unres_queue); in ipmr_cache_unresolved()
1153 if (atomic_read(&mrt->cache_resolve_queue_len) == 1) in ipmr_cache_unresolved()
1154 mod_timer(&mrt->ipmr_expire_timer, in ipmr_cache_unresolved()
1155 c->_c.mfc_un.unres.expires); in ipmr_cache_unresolved()
1159 if (c->_c.mfc_un.unres.unresolved.qlen > 3) { in ipmr_cache_unresolved()
1161 err = -ENOBUFS; in ipmr_cache_unresolved()
1164 skb->dev = dev; in ipmr_cache_unresolved()
1165 skb->skb_iif = dev->ifindex; in ipmr_cache_unresolved()
1167 skb_queue_tail(&c->_c.mfc_un.unres.unresolved, skb); in ipmr_cache_unresolved()
1179 struct net *net = read_pnet(&mrt->net); in ipmr_mfc_delete()
1184 c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, in ipmr_mfc_delete()
1185 mfc->mfcc_mcastgrp.s_addr, parent); in ipmr_mfc_delete()
1188 return -ENOENT; in ipmr_mfc_delete()
1189 rhltable_remove(&mrt->mfc_hash, &c->_c.mnode, ipmr_rht_params); in ipmr_mfc_delete()
1190 list_del_rcu(&c->_c.list); in ipmr_mfc_delete()
1191 call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_DEL, c, mrt->id); in ipmr_mfc_delete()
1193 mr_cache_put(&c->_c); in ipmr_mfc_delete()
1206 if (mfc->mfcc_parent >= MAXVIFS) in ipmr_mfc_add()
1207 return -ENFILE; in ipmr_mfc_add()
1211 c = ipmr_cache_find_parent(mrt, mfc->mfcc_origin.s_addr, in ipmr_mfc_add()
1212 mfc->mfcc_mcastgrp.s_addr, parent); in ipmr_mfc_add()
1216 c->_c.mfc_parent = mfc->mfcc_parent; in ipmr_mfc_add()
1217 ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls); in ipmr_mfc_add()
1219 c->_c.mfc_flags |= MFC_STATIC; in ipmr_mfc_add()
1222 mrt->id); in ipmr_mfc_add()
1227 if (mfc->mfcc_mcastgrp.s_addr != htonl(INADDR_ANY) && in ipmr_mfc_add()
1228 !ipv4_is_multicast(mfc->mfcc_mcastgrp.s_addr)) in ipmr_mfc_add()
1229 return -EINVAL; in ipmr_mfc_add()
1233 return -ENOMEM; in ipmr_mfc_add()
1235 c->mfc_origin = mfc->mfcc_origin.s_addr; in ipmr_mfc_add()
1236 c->mfc_mcastgrp = mfc->mfcc_mcastgrp.s_addr; in ipmr_mfc_add()
1237 c->_c.mfc_parent = mfc->mfcc_parent; in ipmr_mfc_add()
1238 ipmr_update_thresholds(mrt, &c->_c, mfc->mfcc_ttls); in ipmr_mfc_add()
1240 c->_c.mfc_flags |= MFC_STATIC; in ipmr_mfc_add()
1242 ret = rhltable_insert_key(&mrt->mfc_hash, &c->cmparg, &c->_c.mnode, in ipmr_mfc_add()
1249 list_add_tail_rcu(&c->_c.list, &mrt->mfc_cache_list); in ipmr_mfc_add()
1255 list_for_each_entry(_uc, &mrt->mfc_unres_queue, list) { in ipmr_mfc_add()
1257 if (uc->mfc_origin == c->mfc_origin && in ipmr_mfc_add()
1258 uc->mfc_mcastgrp == c->mfc_mcastgrp) { in ipmr_mfc_add()
1259 list_del(&_uc->list); in ipmr_mfc_add()
1260 atomic_dec(&mrt->cache_resolve_queue_len); in ipmr_mfc_add()
1265 if (list_empty(&mrt->mfc_unres_queue)) in ipmr_mfc_add()
1266 del_timer(&mrt->ipmr_expire_timer); in ipmr_mfc_add()
1273 call_ipmr_mfc_entry_notifiers(net, FIB_EVENT_ENTRY_ADD, c, mrt->id); in ipmr_mfc_add()
1281 struct net *net = read_pnet(&mrt->net); in mroute_clean_tables()
1289 for (i = 0; i < mrt->maxvif; i++) { in mroute_clean_tables()
1290 if (((mrt->vif_table[i].flags & VIFF_STATIC) && in mroute_clean_tables()
1292 (!(mrt->vif_table[i].flags & VIFF_STATIC) && !(flags & MRT_FLUSH_VIFS))) in mroute_clean_tables()
1301 list_for_each_entry_safe(c, tmp, &mrt->mfc_cache_list, list) { in mroute_clean_tables()
1302 if (((c->mfc_flags & MFC_STATIC) && !(flags & MRT_FLUSH_MFC_STATIC)) || in mroute_clean_tables()
1303 (!(c->mfc_flags & MFC_STATIC) && !(flags & MRT_FLUSH_MFC))) in mroute_clean_tables()
1305 rhltable_remove(&mrt->mfc_hash, &c->mnode, ipmr_rht_params); in mroute_clean_tables()
1306 list_del_rcu(&c->list); in mroute_clean_tables()
1309 mrt->id); in mroute_clean_tables()
1316 if (atomic_read(&mrt->cache_resolve_queue_len) != 0) { in mroute_clean_tables()
1318 list_for_each_entry_safe(c, tmp, &mrt->mfc_unres_queue, list) { in mroute_clean_tables()
1319 list_del(&c->list); in mroute_clean_tables()
1339 if (sk == rtnl_dereference(mrt->mroute_sk)) { in mrtsock_destruct()
1340 IPV4_DEVCONF_ALL(net, MC_FORWARDING)--; in mrtsock_destruct()
1344 net->ipv4.devconf_all); in mrtsock_destruct()
1345 RCU_INIT_POINTER(mrt->mroute_sk, NULL); in mrtsock_destruct()
1369 /* There's one exception to the lock - MRT_DONE which needs to unlock */ in ip_mroute_setsockopt()
1371 if (sk->sk_type != SOCK_RAW || in ip_mroute_setsockopt()
1372 inet_sk(sk)->inet_num != IPPROTO_IGMP) { in ip_mroute_setsockopt()
1373 ret = -EOPNOTSUPP; in ip_mroute_setsockopt()
1377 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); in ip_mroute_setsockopt()
1379 ret = -ENOENT; in ip_mroute_setsockopt()
1383 if (sk != rcu_access_pointer(mrt->mroute_sk) && in ip_mroute_setsockopt()
1384 !ns_capable(net->user_ns, CAP_NET_ADMIN)) { in ip_mroute_setsockopt()
1385 ret = -EACCES; in ip_mroute_setsockopt()
1393 ret = -EINVAL; in ip_mroute_setsockopt()
1396 if (rtnl_dereference(mrt->mroute_sk)) { in ip_mroute_setsockopt()
1397 ret = -EADDRINUSE; in ip_mroute_setsockopt()
1403 rcu_assign_pointer(mrt->mroute_sk, sk); in ip_mroute_setsockopt()
1408 net->ipv4.devconf_all); in ip_mroute_setsockopt()
1412 if (sk != rcu_access_pointer(mrt->mroute_sk)) { in ip_mroute_setsockopt()
1413 ret = -EACCES; in ip_mroute_setsockopt()
1427 ret = -EINVAL; in ip_mroute_setsockopt()
1431 ret = -EFAULT; in ip_mroute_setsockopt()
1435 ret = -ENFILE; in ip_mroute_setsockopt()
1440 sk == rtnl_dereference(mrt->mroute_sk)); in ip_mroute_setsockopt()
1450 parent = -1; in ip_mroute_setsockopt()
1455 ret = -EINVAL; in ip_mroute_setsockopt()
1459 ret = -EFAULT; in ip_mroute_setsockopt()
1468 sk == rtnl_dereference(mrt->mroute_sk), in ip_mroute_setsockopt()
1473 ret = -EINVAL; in ip_mroute_setsockopt()
1477 ret = -EFAULT; in ip_mroute_setsockopt()
1485 ret = -EINVAL; in ip_mroute_setsockopt()
1489 ret = -EFAULT; in ip_mroute_setsockopt()
1492 mrt->mroute_do_assert = val; in ip_mroute_setsockopt()
1496 ret = -ENOPROTOOPT; in ip_mroute_setsockopt()
1500 ret = -EINVAL; in ip_mroute_setsockopt()
1504 ret = -EFAULT; in ip_mroute_setsockopt()
1510 if (val != mrt->mroute_do_pim) { in ip_mroute_setsockopt()
1511 mrt->mroute_do_pim = val; in ip_mroute_setsockopt()
1512 mrt->mroute_do_assert = val; in ip_mroute_setsockopt()
1513 mrt->mroute_do_wrvifwhole = do_wrvifwhole; in ip_mroute_setsockopt()
1518 ret = -ENOPROTOOPT; in ip_mroute_setsockopt()
1522 ret = -EINVAL; in ip_mroute_setsockopt()
1526 ret = -EFAULT; in ip_mroute_setsockopt()
1530 if (sk == rtnl_dereference(mrt->mroute_sk)) { in ip_mroute_setsockopt()
1531 ret = -EBUSY; in ip_mroute_setsockopt()
1537 raw_sk(sk)->ipmr_table = uval; in ip_mroute_setsockopt()
1542 ret = -ENOPROTOOPT; in ip_mroute_setsockopt()
1581 if (sk->sk_type != SOCK_RAW || in ip_mroute_getsockopt()
1582 inet_sk(sk)->inet_num != IPPROTO_IGMP) in ip_mroute_getsockopt()
1583 return -EOPNOTSUPP; in ip_mroute_getsockopt()
1585 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); in ip_mroute_getsockopt()
1587 return -ENOENT; in ip_mroute_getsockopt()
1595 return -ENOPROTOOPT; in ip_mroute_getsockopt()
1596 val = mrt->mroute_do_pim; in ip_mroute_getsockopt()
1599 val = mrt->mroute_do_assert; in ip_mroute_getsockopt()
1602 return -ENOPROTOOPT; in ip_mroute_getsockopt()
1606 return -EFAULT; in ip_mroute_getsockopt()
1608 return -EINVAL; in ip_mroute_getsockopt()
1613 return -EFAULT; in ip_mroute_getsockopt()
1615 return -EFAULT; in ip_mroute_getsockopt()
1629 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); in ipmr_ioctl()
1631 return -ENOENT; in ipmr_ioctl()
1636 if (vr->vifi >= mrt->maxvif) in ipmr_ioctl()
1637 return -EINVAL; in ipmr_ioctl()
1638 vr->vifi = array_index_nospec(vr->vifi, mrt->maxvif); in ipmr_ioctl()
1640 vif = &mrt->vif_table[vr->vifi]; in ipmr_ioctl()
1641 if (VIF_EXISTS(mrt, vr->vifi)) { in ipmr_ioctl()
1642 vr->icount = READ_ONCE(vif->pkt_in); in ipmr_ioctl()
1643 vr->ocount = READ_ONCE(vif->pkt_out); in ipmr_ioctl()
1644 vr->ibytes = READ_ONCE(vif->bytes_in); in ipmr_ioctl()
1645 vr->obytes = READ_ONCE(vif->bytes_out); in ipmr_ioctl()
1651 return -EADDRNOTAVAIL; in ipmr_ioctl()
1656 c = ipmr_cache_find(mrt, sr->src.s_addr, sr->grp.s_addr); in ipmr_ioctl()
1658 sr->pktcnt = c->_c.mfc_un.res.pkt; in ipmr_ioctl()
1659 sr->bytecnt = c->_c.mfc_un.res.bytes; in ipmr_ioctl()
1660 sr->wrong_if = c->_c.mfc_un.res.wrong_if; in ipmr_ioctl()
1665 return -EADDRNOTAVAIL; in ipmr_ioctl()
1667 return -ENOIOCTLCMD; in ipmr_ioctl()
1697 mrt = ipmr_get_table(net, raw_sk(sk)->ipmr_table ? : RT_TABLE_DEFAULT); in ipmr_compat_ioctl()
1699 return -ENOENT; in ipmr_compat_ioctl()
1704 return -EFAULT; in ipmr_compat_ioctl()
1705 if (vr.vifi >= mrt->maxvif) in ipmr_compat_ioctl()
1706 return -EINVAL; in ipmr_compat_ioctl()
1707 vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif); in ipmr_compat_ioctl()
1709 vif = &mrt->vif_table[vr.vifi]; in ipmr_compat_ioctl()
1711 vr.icount = READ_ONCE(vif->pkt_in); in ipmr_compat_ioctl()
1712 vr.ocount = READ_ONCE(vif->pkt_out); in ipmr_compat_ioctl()
1713 vr.ibytes = READ_ONCE(vif->bytes_in); in ipmr_compat_ioctl()
1714 vr.obytes = READ_ONCE(vif->bytes_out); in ipmr_compat_ioctl()
1718 return -EFAULT; in ipmr_compat_ioctl()
1722 return -EADDRNOTAVAIL; in ipmr_compat_ioctl()
1725 return -EFAULT; in ipmr_compat_ioctl()
1730 sr.pktcnt = c->_c.mfc_un.res.pkt; in ipmr_compat_ioctl()
1731 sr.bytecnt = c->_c.mfc_un.res.bytes; in ipmr_compat_ioctl()
1732 sr.wrong_if = c->_c.mfc_un.res.wrong_if; in ipmr_compat_ioctl()
1736 return -EFAULT; in ipmr_compat_ioctl()
1740 return -EADDRNOTAVAIL; in ipmr_compat_ioctl()
1742 return -ENOIOCTLCMD; in ipmr_compat_ioctl()
1759 v = &mrt->vif_table[0]; in ipmr_device_event()
1760 for (ct = 0; ct < mrt->maxvif; ct++, v++) { in ipmr_device_event()
1761 if (rcu_access_pointer(v->dev) == dev) in ipmr_device_event()
1783 skb->transport_header = skb->network_header; in ip_encap()
1787 iph->version = 4; in ip_encap()
1788 iph->tos = old_iph->tos; in ip_encap()
1789 iph->ttl = old_iph->ttl; in ip_encap()
1790 iph->frag_off = 0; in ip_encap()
1791 iph->daddr = daddr; in ip_encap()
1792 iph->saddr = saddr; in ip_encap()
1793 iph->protocol = IPPROTO_IPIP; in ip_encap()
1794 iph->ihl = 5; in ip_encap()
1795 iph->tot_len = htons(skb->len); in ip_encap()
1799 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); in ip_encap()
1806 struct ip_options *opt = &(IPCB(skb)->opt); in ipmr_forward_finish()
1810 if (unlikely(opt->optlen)) in ipmr_forward_finish()
1820 struct vif_device *out_vif = &mrt->vif_table[out_vifi]; in ipmr_forward_offloaded()
1821 struct vif_device *in_vif = &mrt->vif_table[in_vifi]; in ipmr_forward_offloaded()
1823 if (!skb->offload_l3_fwd_mark) in ipmr_forward_offloaded()
1825 if (!out_vif->dev_parent_id.id_len || !in_vif->dev_parent_id.id_len) in ipmr_forward_offloaded()
1827 return netdev_phys_item_id_same(&out_vif->dev_parent_id, in ipmr_forward_offloaded()
1828 &in_vif->dev_parent_id); in ipmr_forward_offloaded()
1844 struct vif_device *vif = &mrt->vif_table[vifi]; in ipmr_queue_xmit()
1855 if (vif->flags & VIFF_REGISTER) { in ipmr_queue_xmit()
1856 WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); in ipmr_queue_xmit()
1857 WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); in ipmr_queue_xmit()
1858 DEV_STATS_ADD(vif_dev, tx_bytes, skb->len); in ipmr_queue_xmit()
1867 if (vif->flags & VIFF_TUNNEL) { in ipmr_queue_xmit()
1869 vif->remote, vif->local, in ipmr_queue_xmit()
1872 iph->tos & INET_DSCP_MASK, vif->link); in ipmr_queue_xmit()
1877 rt = ip_route_output_ports(net, &fl4, NULL, iph->daddr, 0, in ipmr_queue_xmit()
1880 iph->tos & INET_DSCP_MASK, vif->link); in ipmr_queue_xmit()
1885 dev = rt->dst.dev; in ipmr_queue_xmit()
1887 if (skb->len+encap > dst_mtu(&rt->dst) && (ntohs(iph->frag_off) & IP_DF)) { in ipmr_queue_xmit()
1897 encap += LL_RESERVED_SPACE(dev) + rt->dst.header_len; in ipmr_queue_xmit()
1904 WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1); in ipmr_queue_xmit()
1905 WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len); in ipmr_queue_xmit()
1908 skb_dst_set(skb, &rt->dst); in ipmr_queue_xmit()
1912 * What do we do with netfilter? -- RR in ipmr_queue_xmit()
1914 if (vif->flags & VIFF_TUNNEL) { in ipmr_queue_xmit()
1915 ip_encap(net, skb, vif->local, vif->remote); in ipmr_queue_xmit()
1916 /* FIXME: extra output firewall step used to be here. --RR */ in ipmr_queue_xmit()
1918 DEV_STATS_ADD(vif_dev, tx_bytes, skb->len); in ipmr_queue_xmit()
1921 IPCB(skb)->flags |= IPSKB_FORWARDED; in ipmr_queue_xmit()
1930 * not mrouter) cannot join to more than one interface - it will in ipmr_queue_xmit()
1934 net, NULL, skb, skb->dev, dev, in ipmr_queue_xmit()
1947 for (ct = READ_ONCE(mrt->maxvif) - 1; ct >= 0; ct--) { in ipmr_find_vif()
1948 if (rcu_access_pointer(mrt->vif_table[ct].dev) == dev) in ipmr_find_vif()
1961 int psend = -1; in ip_mr_forward()
1964 vif = c->_c.mfc_parent; in ip_mr_forward()
1965 c->_c.mfc_un.res.pkt++; in ip_mr_forward()
1966 c->_c.mfc_un.res.bytes += skb->len; in ip_mr_forward()
1967 c->_c.mfc_un.res.lastuse = jiffies; in ip_mr_forward()
1969 if (c->mfc_origin == htonl(INADDR_ANY) && true_vifi >= 0) { in ip_mr_forward()
1977 cache_proxy->_c.mfc_un.res.ttls[true_vifi] < 255) in ip_mr_forward()
1982 if (rcu_access_pointer(mrt->vif_table[vif].dev) != dev) { in ip_mr_forward()
1993 * idea to use multicasting applications on router. in ip_mr_forward()
1998 c->_c.mfc_un.res.wrong_if++; in ip_mr_forward()
2000 if (true_vifi >= 0 && mrt->mroute_do_assert && in ip_mr_forward()
2004 * large chunk of pimd to kernel. Ough... --ANK in ip_mr_forward()
2006 (mrt->mroute_do_pim || in ip_mr_forward()
2007 c->_c.mfc_un.res.ttls[true_vifi] < 255) && in ip_mr_forward()
2009 c->_c.mfc_un.res.last_assert + in ip_mr_forward()
2011 c->_c.mfc_un.res.last_assert = jiffies; in ip_mr_forward()
2013 if (mrt->mroute_do_wrvifwhole) in ip_mr_forward()
2021 WRITE_ONCE(mrt->vif_table[vif].pkt_in, in ip_mr_forward()
2022 mrt->vif_table[vif].pkt_in + 1); in ip_mr_forward()
2023 WRITE_ONCE(mrt->vif_table[vif].bytes_in, in ip_mr_forward()
2024 mrt->vif_table[vif].bytes_in + skb->len); in ip_mr_forward()
2027 if (c->mfc_origin == htonl(INADDR_ANY) && in ip_mr_forward()
2028 c->mfc_mcastgrp == htonl(INADDR_ANY)) { in ip_mr_forward()
2030 true_vifi != c->_c.mfc_parent && in ip_mr_forward()
2031 ip_hdr(skb)->ttl > in ip_mr_forward()
2032 c->_c.mfc_un.res.ttls[c->_c.mfc_parent]) { in ip_mr_forward()
2037 psend = c->_c.mfc_parent; in ip_mr_forward()
2042 for (ct = c->_c.mfc_un.res.maxvif - 1; in ip_mr_forward()
2043 ct >= c->_c.mfc_un.res.minvif; ct--) { in ip_mr_forward()
2045 if ((c->mfc_origin != htonl(INADDR_ANY) || in ip_mr_forward()
2047 ip_hdr(skb)->ttl > c->_c.mfc_un.res.ttls[ct]) { in ip_mr_forward()
2048 if (psend != -1) { in ip_mr_forward()
2059 if (psend != -1) { in ip_mr_forward()
2082 .daddr = iph->daddr, in ipmr_rt_fib_lookup()
2083 .saddr = iph->saddr, in ipmr_rt_fib_lookup()
2084 .flowi4_tos = iph->tos & INET_DSCP_MASK, in ipmr_rt_fib_lookup()
2086 skb->dev->ifindex : 0), in ipmr_rt_fib_lookup()
2089 skb->dev->ifindex), in ipmr_rt_fib_lookup()
2090 .flowi4_mark = skb->mark, in ipmr_rt_fib_lookup()
2107 struct net *net = dev_net(skb->dev); in ip_mr_input()
2108 int local = skb_rtable(skb)->rt_flags & RTCF_LOCAL; in ip_mr_input()
2112 /* skb->dev passed in is the loX master dev for vrfs. in ip_mr_input()
2116 dev = skb->dev; in ip_mr_input()
2117 if (netif_is_l3_master(skb->dev)) { in ip_mr_input()
2118 dev = dev_get_by_index_rcu(net, IPCB(skb)->iif); in ip_mr_input()
2121 return -ENODEV; in ip_mr_input()
2128 if (IPCB(skb)->flags & IPSKB_FORWARDED) in ip_mr_input()
2137 if (IPCB(skb)->opt.router_alert) { in ip_mr_input()
2140 } else if (ip_hdr(skb)->protocol == IPPROTO_IGMP) { in ip_mr_input()
2149 mroute_sk = rcu_dereference(mrt->mroute_sk); in ip_mr_input()
2159 cache = ipmr_cache_find(mrt, ip_hdr(skb)->saddr, ip_hdr(skb)->daddr); in ip_mr_input()
2164 cache = ipmr_cache_find_any(mrt, ip_hdr(skb)->daddr, in ip_mr_input()
2176 return -ENOBUFS; in ip_mr_input()
2184 return -ENODEV; in ip_mr_input()
2206 struct net *net = dev_net(skb->dev); in pim_rcv_v1()
2217 if (!mrt->mroute_do_pim || in pim_rcv_v1()
2218 pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER) in pim_rcv_v1()
2233 struct net *net = dev_net(skb->dev); in pim_rcv()
2240 if (pim->type != ((PIM_VERSION << 4) | (PIM_TYPE_REGISTER)) || in pim_rcv()
2241 (pim->flags & PIM_NULL_REGISTER) || in pim_rcv()
2243 csum_fold(skb_checksum(skb, 0, skb->len, 0)))) in pim_rcv()
2259 struct rtmsg *rtm, u32 portid) in ipmr_get_route() argument
2267 return -ENOENT; in ipmr_get_route()
2271 if (!cache && skb->dev) { in ipmr_get_route()
2272 int vif = ipmr_find_vif(mrt, skb->dev); in ipmr_get_route()
2281 int vif = -1; in ipmr_get_route()
2283 dev = skb->dev; in ipmr_get_route()
2288 return -ENODEV; in ipmr_get_route()
2294 return -ENOMEM; in ipmr_get_route()
2301 iph->ihl = sizeof(struct iphdr) >> 2; in ipmr_get_route()
2302 iph->saddr = saddr; in ipmr_get_route()
2303 iph->daddr = daddr; in ipmr_get_route()
2304 iph->version = 0; in ipmr_get_route()
2310 err = mr_fill_mroute(mrt, skb, &cache->_c, rtm); in ipmr_get_route()
2320 struct rtmsg *rtm; in ipmr_fill_mroute() local
2323 nlh = nlmsg_put(skb, portid, seq, cmd, sizeof(*rtm), flags); in ipmr_fill_mroute()
2325 return -EMSGSIZE; in ipmr_fill_mroute()
2327 rtm = nlmsg_data(nlh); in ipmr_fill_mroute()
2328 rtm->rtm_family = RTNL_FAMILY_IPMR; in ipmr_fill_mroute()
2329 rtm->rtm_dst_len = 32; in ipmr_fill_mroute()
2330 rtm->rtm_src_len = 32; in ipmr_fill_mroute()
2331 rtm->rtm_tos = 0; in ipmr_fill_mroute()
2332 rtm->rtm_table = mrt->id; in ipmr_fill_mroute()
2333 if (nla_put_u32(skb, RTA_TABLE, mrt->id)) in ipmr_fill_mroute()
2335 rtm->rtm_type = RTN_MULTICAST; in ipmr_fill_mroute()
2336 rtm->rtm_scope = RT_SCOPE_UNIVERSE; in ipmr_fill_mroute()
2337 if (c->_c.mfc_flags & MFC_STATIC) in ipmr_fill_mroute()
2338 rtm->rtm_protocol = RTPROT_STATIC; in ipmr_fill_mroute()
2340 rtm->rtm_protocol = RTPROT_MROUTED; in ipmr_fill_mroute()
2341 rtm->rtm_flags = 0; in ipmr_fill_mroute()
2343 if (nla_put_in_addr(skb, RTA_SRC, c->mfc_origin) || in ipmr_fill_mroute()
2344 nla_put_in_addr(skb, RTA_DST, c->mfc_mcastgrp)) in ipmr_fill_mroute()
2346 err = mr_fill_mroute(mrt, skb, &c->_c, rtm); in ipmr_fill_mroute()
2348 if (err < 0 && err != -ENOENT) in ipmr_fill_mroute()
2356 return -EMSGSIZE; in ipmr_fill_mroute()
2391 struct net *net = read_pnet(&mrt->net); in mroute_netlink_event()
2393 int err = -ENOBUFS; in mroute_netlink_event()
2395 skb = nlmsg_new(mroute_msgsize(mfc->_c.mfc_parent >= MAXVIFS, in mroute_netlink_event()
2396 mrt->maxvif), in mroute_netlink_event()
2431 struct net *net = read_pnet(&mrt->net); in igmpmsg_netlink_event()
2439 payloadlen = pkt->len - sizeof(struct igmpmsg); in igmpmsg_netlink_event()
2451 rtgenm->rtgen_family = RTNL_FAMILY_IPMR; in igmpmsg_netlink_event()
2452 if (nla_put_u8(skb, IPMRA_CREPORT_MSGTYPE, msg->im_msgtype) || in igmpmsg_netlink_event()
2453 nla_put_u32(skb, IPMRA_CREPORT_VIF_ID, msg->im_vif | (msg->im_vif_hi << 8)) || in igmpmsg_netlink_event()
2455 msg->im_src.s_addr) || in igmpmsg_netlink_event()
2457 msg->im_dst.s_addr) || in igmpmsg_netlink_event()
2458 nla_put_u32(skb, IPMRA_CREPORT_TABLE, mrt->id)) in igmpmsg_netlink_event()
2475 rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE_R, -ENOBUFS); in igmpmsg_netlink_event()
2483 struct rtmsg *rtm; in ipmr_rtm_valid_getroute_req() local
2486 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in ipmr_rtm_valid_getroute_req()
2488 return -EINVAL; in ipmr_rtm_valid_getroute_req()
2492 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX, in ipmr_rtm_valid_getroute_req()
2495 rtm = nlmsg_data(nlh); in ipmr_rtm_valid_getroute_req()
2496 if ((rtm->rtm_src_len && rtm->rtm_src_len != 32) || in ipmr_rtm_valid_getroute_req()
2497 (rtm->rtm_dst_len && rtm->rtm_dst_len != 32) || in ipmr_rtm_valid_getroute_req()
2498 rtm->rtm_tos || rtm->rtm_table || rtm->rtm_protocol || in ipmr_rtm_valid_getroute_req()
2499 rtm->rtm_scope || rtm->rtm_type || rtm->rtm_flags) { in ipmr_rtm_valid_getroute_req()
2501 return -EINVAL; in ipmr_rtm_valid_getroute_req()
2504 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX, in ipmr_rtm_valid_getroute_req()
2509 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in ipmr_rtm_valid_getroute_req()
2510 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in ipmr_rtm_valid_getroute_req()
2512 return -EINVAL; in ipmr_rtm_valid_getroute_req()
2526 return -EINVAL; in ipmr_rtm_valid_getroute_req()
2536 struct net *net = sock_net(in_skb->sk); in ipmr_rtm_getroute()
2555 err = -ENOENT; in ipmr_rtm_getroute()
2564 err = -ENOENT; in ipmr_rtm_getroute()
2568 skb = nlmsg_new(mroute_msgsize(false, mrt->maxvif), GFP_KERNEL); in ipmr_rtm_getroute()
2570 err = -ENOBUFS; in ipmr_rtm_getroute()
2575 nlh->nlmsg_seq, cache, in ipmr_rtm_getroute()
2597 if (cb->strict_check) { in ipmr_rtm_dumproute()
2598 err = ip_valid_fib_dump_req(sock_net(skb->sk), cb->nlh, in ipmr_rtm_dumproute()
2607 mrt = ipmr_get_table(sock_net(skb->sk), filter.table_id); in ipmr_rtm_dumproute()
2609 if (rtnl_msg_family(cb->nlh) != RTNL_FAMILY_IPMR) in ipmr_rtm_dumproute()
2610 return skb->len; in ipmr_rtm_dumproute()
2612 NL_SET_ERR_MSG(cb->extack, "ipv4: MR table does not exist"); in ipmr_rtm_dumproute()
2613 return -ENOENT; in ipmr_rtm_dumproute()
2617 return skb->len ? : err; in ipmr_rtm_dumproute()
2648 mfcc->mfcc_ttls[vifi] = rtnh->rtnh_hops; in ipmr_nla_get_ttls()
2654 return remaining > 0 ? -EINVAL : vifi; in ipmr_nla_get_ttls()
2667 struct rtmsg *rtm; in rtm_to_ipmr_mfcc() local
2670 ret = nlmsg_validate_deprecated(nlh, sizeof(*rtm), RTA_MAX, in rtm_to_ipmr_mfcc()
2674 rtm = nlmsg_data(nlh); in rtm_to_ipmr_mfcc()
2676 ret = -EINVAL; in rtm_to_ipmr_mfcc()
2677 if (rtm->rtm_family != RTNL_FAMILY_IPMR || rtm->rtm_dst_len != 32 || in rtm_to_ipmr_mfcc()
2678 rtm->rtm_type != RTN_MULTICAST || in rtm_to_ipmr_mfcc()
2679 rtm->rtm_scope != RT_SCOPE_UNIVERSE || in rtm_to_ipmr_mfcc()
2680 !ipmr_rtm_validate_proto(rtm->rtm_protocol)) in rtm_to_ipmr_mfcc()
2684 mfcc->mfcc_parent = -1; in rtm_to_ipmr_mfcc()
2689 mfcc->mfcc_origin.s_addr = nla_get_be32(attr); in rtm_to_ipmr_mfcc()
2692 mfcc->mfcc_mcastgrp.s_addr = nla_get_be32(attr); in rtm_to_ipmr_mfcc()
2697 ret = -ENODEV; in rtm_to_ipmr_mfcc()
2703 ret = -EINVAL; in rtm_to_ipmr_mfcc()
2717 ret = -ENOENT; in rtm_to_ipmr_mfcc()
2721 *mrtsock = rtm->rtm_protocol == RTPROT_MROUTED ? 1 : 0; in rtm_to_ipmr_mfcc()
2723 mfcc->mfcc_parent = ipmr_find_vif(mrt, dev); in rtm_to_ipmr_mfcc()
2733 struct net *net = sock_net(skb->sk); in ipmr_rtm_route()
2744 parent = ret ? mfcc.mfcc_parent : -1; in ipmr_rtm_route()
2745 if (nlh->nlmsg_type == RTM_NEWROUTE) in ipmr_rtm_route()
2753 u32 queue_len = atomic_read(&mrt->cache_resolve_queue_len); in ipmr_fill_table()
2755 if (nla_put_u32(skb, IPMRA_TABLE_ID, mrt->id) || in ipmr_fill_table()
2758 mrt->mroute_reg_vif_num) || in ipmr_fill_table()
2760 mrt->mroute_do_assert) || in ipmr_fill_table()
2761 nla_put_u8(skb, IPMRA_TABLE_MROUTE_DO_PIM, mrt->mroute_do_pim) || in ipmr_fill_table()
2763 mrt->mroute_do_wrvifwhole)) in ipmr_fill_table()
2775 vif = &mrt->vif_table[vifid]; in ipmr_fill_vif()
2776 vif_dev = rtnl_dereference(vif->dev); in ipmr_fill_vif()
2785 if (nla_put_u32(skb, IPMRA_VIFA_IFINDEX, vif_dev->ifindex) || in ipmr_fill_vif()
2787 nla_put_u16(skb, IPMRA_VIFA_FLAGS, vif->flags) || in ipmr_fill_vif()
2788 nla_put_u64_64bit(skb, IPMRA_VIFA_BYTES_IN, vif->bytes_in, in ipmr_fill_vif()
2790 nla_put_u64_64bit(skb, IPMRA_VIFA_BYTES_OUT, vif->bytes_out, in ipmr_fill_vif()
2792 nla_put_u64_64bit(skb, IPMRA_VIFA_PACKETS_IN, vif->pkt_in, in ipmr_fill_vif()
2794 nla_put_u64_64bit(skb, IPMRA_VIFA_PACKETS_OUT, vif->pkt_out, in ipmr_fill_vif()
2796 nla_put_be32(skb, IPMRA_VIFA_LOCAL_ADDR, vif->local) || in ipmr_fill_vif()
2797 nla_put_be32(skb, IPMRA_VIFA_REMOTE_ADDR, vif->remote)) { in ipmr_fill_vif()
2811 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in ipmr_valid_dumplink()
2813 return -EINVAL; in ipmr_valid_dumplink()
2818 return -EINVAL; in ipmr_valid_dumplink()
2822 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || in ipmr_valid_dumplink()
2823 ifm->ifi_change || ifm->ifi_index) { in ipmr_valid_dumplink()
2825 return -EINVAL; in ipmr_valid_dumplink()
2833 struct net *net = sock_net(skb->sk); in ipmr_rtm_dumplink()
2839 if (cb->strict_check) { in ipmr_rtm_dumplink()
2840 int err = ipmr_valid_dumplink(cb->nlh, cb->extack); in ipmr_rtm_dumplink()
2846 s_t = cb->args[0]; in ipmr_rtm_dumplink()
2847 s_e = cb->args[1]; in ipmr_rtm_dumplink()
2856 nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, in ipmr_rtm_dumplink()
2857 cb->nlh->nlmsg_seq, RTM_NEWLINK, in ipmr_rtm_dumplink()
2864 hdr->ifi_family = RTNL_FAMILY_IPMR; in ipmr_rtm_dumplink()
2883 for (i = 0; i < mrt->maxvif; i++) { in ipmr_rtm_dumplink()
2905 cb->args[1] = e; in ipmr_rtm_dumplink()
2906 cb->args[0] = t; in ipmr_rtm_dumplink()
2908 return skb->len; in ipmr_rtm_dumplink()
2919 struct mr_vif_iter *iter = seq->private; in ipmr_vif_seq_start()
2925 return ERR_PTR(-ENOENT); in ipmr_vif_seq_start()
2927 iter->mrt = mrt; in ipmr_vif_seq_start()
2941 struct mr_vif_iter *iter = seq->private; in ipmr_vif_seq_show()
2942 struct mr_table *mrt = iter->mrt; in ipmr_vif_seq_show()
2953 name = vif_dev ? vif_dev->name : "none"; in ipmr_vif_seq_show()
2955 "%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n", in ipmr_vif_seq_show()
2956 vif - mrt->vif_table, in ipmr_vif_seq_show()
2957 name, vif->bytes_in, vif->pkt_in, in ipmr_vif_seq_show()
2958 vif->bytes_out, vif->pkt_out, in ipmr_vif_seq_show()
2959 vif->flags, vif->local, vif->remote); in ipmr_vif_seq_show()
2978 return ERR_PTR(-ENOENT); in ipmr_mfc_seq_start()
2992 const struct mr_mfc_iter *it = seq->private; in ipmr_mfc_seq_show()
2993 const struct mr_table *mrt = it->mrt; in ipmr_mfc_seq_show()
2995 seq_printf(seq, "%08X %08X %-3hd", in ipmr_mfc_seq_show()
2996 (__force u32) mfc->mfc_mcastgrp, in ipmr_mfc_seq_show()
2997 (__force u32) mfc->mfc_origin, in ipmr_mfc_seq_show()
2998 mfc->_c.mfc_parent); in ipmr_mfc_seq_show()
3000 if (it->cache != &mrt->mfc_unres_queue) { in ipmr_mfc_seq_show()
3002 mfc->_c.mfc_un.res.pkt, in ipmr_mfc_seq_show()
3003 mfc->_c.mfc_un.res.bytes, in ipmr_mfc_seq_show()
3004 mfc->_c.mfc_un.res.wrong_if); in ipmr_mfc_seq_show()
3005 for (n = mfc->_c.mfc_un.res.minvif; in ipmr_mfc_seq_show()
3006 n < mfc->_c.mfc_un.res.maxvif; n++) { in ipmr_mfc_seq_show()
3008 mfc->_c.mfc_un.res.ttls[n] < 255) in ipmr_mfc_seq_show()
3010 " %2d:%-3d", in ipmr_mfc_seq_show()
3011 n, mfc->_c.mfc_un.res.ttls[n]); in ipmr_mfc_seq_show()
3042 return net->ipv4.ipmr_seq + ipmr_rules_seq_read(net); in ipmr_seq_read()
3063 net->ipv4.ipmr_seq = 0; in ipmr_notifier_init()
3068 net->ipv4.ipmr_notifier_ops = ops; in ipmr_notifier_init()
3075 fib_notifier_ops_unregister(net->ipv4.ipmr_notifier_ops); in ipmr_notifier_exit()
3076 net->ipv4.ipmr_notifier_ops = NULL; in ipmr_notifier_exit()
3093 err = -ENOMEM; in ipmr_net_init()
3094 if (!proc_create_net("ip_mr_vif", 0, net->proc_net, &ipmr_vif_seq_ops, in ipmr_net_init()
3097 if (!proc_create_net("ip_mr_cache", 0, net->proc_net, &ipmr_mfc_seq_ops, in ipmr_net_init()
3105 remove_proc_entry("ip_mr_vif", net->proc_net); in ipmr_net_init()
3120 remove_proc_entry("ip_mr_cache", net->proc_net); in ipmr_net_exit()
3121 remove_proc_entry("ip_mr_vif", net->proc_net); in ipmr_net_exit()
3158 err = -EAGAIN; in ip_mr_init()