Lines Matching +full:touch +full:- +full:hold +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-or-later
72 [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
73 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
74 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
75 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
76 [IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL - 1] = 10000 /*ms*/,
77 [IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL - 1] = 1000 /*ms*/,
78 [IPV4_DEVCONF_ARP_EVICT_NOCARRIER - 1] = 1,
84 [IPV4_DEVCONF_ACCEPT_REDIRECTS - 1] = 1,
85 [IPV4_DEVCONF_SEND_REDIRECTS - 1] = 1,
86 [IPV4_DEVCONF_SECURE_REDIRECTS - 1] = 1,
87 [IPV4_DEVCONF_SHARED_MEDIA - 1] = 1,
88 [IPV4_DEVCONF_ACCEPT_SOURCE_ROUTE - 1] = 1,
89 [IPV4_DEVCONF_IGMPV2_UNSOLICITED_REPORT_INTERVAL - 1] = 10000 /*ms*/,
90 [IPV4_DEVCONF_IGMPV3_UNSOLICITED_REPORT_INTERVAL - 1] = 1000 /*ms*/,
91 [IPV4_DEVCONF_ARP_EVICT_NOCARRIER - 1] = 1,
96 IPV4_DEVCONF((*net->ipv4.devconf_dflt), attr)
102 [IFA_LABEL] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
131 u32 hash = inet_addr_hash(net, ifa->ifa_local); in inet_hash_insert()
134 hlist_add_head_rcu(&ifa->addr_lst, &net->ipv4.inet_addr_lst[hash]); in inet_hash_insert()
140 hlist_del_init_rcu(&ifa->addr_lst); in inet_hash_remove()
144 * __ip_dev_find - find the first device with a given source address.
172 result = ifa->ifa_dev->dev; in __ip_dev_find()
187 hlist_for_each_entry_rcu(ifa, &net->ipv4.inet_addr_lst[hash], addr_lst) in inet_lookup_ifaddr_rcu()
188 if (ifa->ifa_local == addr) in inet_lookup_ifaddr_rcu()
225 ifa->ifa_dev = in_dev; in inet_alloc_ifa()
227 INIT_HLIST_NODE(&ifa->addr_lst); in inet_alloc_ifa()
236 in_dev_put(ifa->ifa_dev); in inet_rcu_free_ifa()
242 /* Our reference to ifa->ifa_dev must be freed ASAP in inet_free_ifa()
244 * in_dev_put() -> in_dev_finish_destroy() -> netdev_put() in inet_free_ifa()
246 call_rcu_hurry(&ifa->rcu_head, inet_rcu_free_ifa); in inet_free_ifa()
253 kfree(rcu_dereference_protected(idev->mc_hash, 1)); in in_dev_free_rcu()
259 struct net_device *dev = idev->dev; in in_dev_finish_destroy()
261 WARN_ON(idev->ifa_list); in in_dev_finish_destroy()
262 WARN_ON(idev->mc_list); in in_dev_finish_destroy()
264 pr_debug("%s: %p=%s\n", __func__, idev, dev ? dev->name : "NIL"); in in_dev_finish_destroy()
266 netdev_put(dev, &idev->dev_tracker); in in_dev_finish_destroy()
267 if (!idev->dead) in in_dev_finish_destroy()
270 call_rcu(&idev->rcu_head, in_dev_free_rcu); in in_dev_finish_destroy()
277 int err = -ENOMEM; in inetdev_init()
284 memcpy(&in_dev->cnf, dev_net(dev)->ipv4.devconf_dflt, in inetdev_init()
285 sizeof(in_dev->cnf)); in inetdev_init()
286 in_dev->cnf.sysctl = NULL; in inetdev_init()
287 in_dev->dev = dev; in inetdev_init()
288 in_dev->arp_parms = neigh_parms_alloc(dev, &arp_tbl); in inetdev_init()
289 if (!in_dev->arp_parms) in inetdev_init()
291 if (IPV4_DEVCONF(in_dev->cnf, FORWARDING)) in inetdev_init()
293 /* Reference in_dev->dev */ in inetdev_init()
294 netdev_hold(dev, &in_dev->dev_tracker, GFP_KERNEL); in inetdev_init()
295 /* Account for reference dev->ip_ptr (below) */ in inetdev_init()
296 refcount_set(&in_dev->refcnt, 1); in inetdev_init()
301 in_dev->dead = 1; in inetdev_init()
302 neigh_parms_release(&arp_tbl, in_dev->arp_parms); in inetdev_init()
308 if (dev->flags & IFF_UP) in inetdev_init()
312 /* we can receive as soon as ip_ptr is set -- do this last */ in inetdev_init()
313 rcu_assign_pointer(dev->ip_ptr, in_dev); in inetdev_init()
329 dev = in_dev->dev; in inetdev_destroy()
331 in_dev->dead = 1; in inetdev_destroy()
335 while ((ifa = rtnl_dereference(in_dev->ifa_list)) != NULL) { in inetdev_destroy()
336 inet_del_ifa(in_dev, &in_dev->ifa_list, 0); in inetdev_destroy()
340 RCU_INIT_POINTER(dev->ip_ptr, NULL); in inetdev_destroy()
343 neigh_parms_release(&arp_tbl, in_dev->arp_parms); in inetdev_destroy()
355 err = -ENOMEM; in inet_blackhole_dev_init()
393 if (in_dev->dead) in __inet_del_ifa()
400 if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) { in __inet_del_ifa()
401 struct in_ifaddr __rcu **ifap1 = &ifa1->ifa_next; in __inet_del_ifa()
404 if (!(ifa->ifa_flags & IFA_F_SECONDARY) && in __inet_del_ifa()
405 ifa1->ifa_scope <= ifa->ifa_scope) in __inet_del_ifa()
406 last_prim = &ifa->ifa_next; in __inet_del_ifa()
408 if (!(ifa->ifa_flags & IFA_F_SECONDARY) || in __inet_del_ifa()
409 ifa1->ifa_mask != ifa->ifa_mask || in __inet_del_ifa()
410 !inet_ifa_match(ifa1->ifa_address, ifa)) { in __inet_del_ifa()
411 ifap1 = &ifa->ifa_next; in __inet_del_ifa()
418 *ifap1 = ifa->ifa_next; in __inet_del_ifa()
436 for (ifa = promote; ifa; ifa = rtnl_dereference(ifa->ifa_next)) { in __inet_del_ifa()
437 if (ifa1->ifa_mask == ifa->ifa_mask && in __inet_del_ifa()
438 inet_ifa_match(ifa1->ifa_address, ifa)) in __inet_del_ifa()
445 *ifap = ifa1->ifa_next; in __inet_del_ifa()
464 next_sec = rtnl_dereference(promote->ifa_next); in __inet_del_ifa()
468 rcu_assign_pointer(prev_prom->ifa_next, next_sec); in __inet_del_ifa()
471 rcu_assign_pointer(promote->ifa_next, last_sec); in __inet_del_ifa()
475 promote->ifa_flags &= ~IFA_F_SECONDARY; in __inet_del_ifa()
480 ifa = rtnl_dereference(ifa->ifa_next)) { in __inet_del_ifa()
481 if (ifa1->ifa_mask != ifa->ifa_mask || in __inet_del_ifa()
482 !inet_ifa_match(ifa1->ifa_address, ifa)) in __inet_del_ifa()
503 struct in_device *in_dev = ifa->ifa_dev; in __inet_insert_ifa()
504 struct net *net = dev_net(in_dev->dev); in __inet_insert_ifa()
511 ifa->ifa_flags &= ~IFA_F_SECONDARY; in __inet_insert_ifa()
512 last_primary = &in_dev->ifa_list; in __inet_insert_ifa()
515 ifa->ifa_flags &= ~IPV6ONLY_FLAGS; in __inet_insert_ifa()
517 ifap = &in_dev->ifa_list; in __inet_insert_ifa()
521 if (!(ifa1->ifa_flags & IFA_F_SECONDARY) && in __inet_insert_ifa()
522 ifa->ifa_scope <= ifa1->ifa_scope) in __inet_insert_ifa()
523 last_primary = &ifa1->ifa_next; in __inet_insert_ifa()
524 if (ifa1->ifa_mask == ifa->ifa_mask && in __inet_insert_ifa()
525 inet_ifa_match(ifa1->ifa_address, ifa)) { in __inet_insert_ifa()
526 if (ifa1->ifa_local == ifa->ifa_local) { in __inet_insert_ifa()
528 return -EEXIST; in __inet_insert_ifa()
530 if (ifa1->ifa_scope != ifa->ifa_scope) { in __inet_insert_ifa()
533 return -EINVAL; in __inet_insert_ifa()
535 ifa->ifa_flags |= IFA_F_SECONDARY; in __inet_insert_ifa()
538 ifap = &ifa1->ifa_next; in __inet_insert_ifa()
549 ivi.ivi_addr = ifa->ifa_address; in __inet_insert_ifa()
550 ivi.ivi_dev = ifa->ifa_dev; in __inet_insert_ifa()
560 if (!(ifa->ifa_flags & IFA_F_SECONDARY)) in __inet_insert_ifa()
563 rcu_assign_pointer(ifa->ifa_next, *ifap); in __inet_insert_ifa()
566 inet_hash_insert(dev_net(in_dev->dev), ifa); in __inet_insert_ifa()
568 cancel_delayed_work(&net->ipv4.addr_chk_work); in __inet_insert_ifa()
569 queue_delayed_work(system_power_efficient_wq, &net->ipv4.addr_chk_work, 0); in __inet_insert_ifa()
582 if (!ifa->ifa_local) { in inet_insert_ifa()
595 neigh_parms_data_state_setall(in_dev->arp_parms); in inet_set_ifa()
597 if (ipv4_is_loopback(ifa->ifa_local)) in inet_set_ifa()
598 ifa->ifa_scope = RT_SCOPE_HOST; in inet_set_ifa()
602 /* Caller must hold RCU or RTNL :
613 in_dev = rcu_dereference_rtnl(dev->ip_ptr); in inetdev_by_index()
629 if (ifa->ifa_mask == mask && inet_ifa_match(prefix, ifa)) in inet_ifa_byprefix()
640 .imr_multiaddr.s_addr = ifa->ifa_address, in ip_mc_autojoin_config()
641 .imr_ifindex = ifa->ifa_dev->dev->ifindex, in ip_mc_autojoin_config()
643 struct sock *sk = net->ipv4.mc_autojoin_sk; in ip_mc_autojoin_config()
657 return -EOPNOTSUPP; in ip_mc_autojoin_config()
664 struct net *net = sock_net(skb->sk); in inet_rtm_deladdr()
681 in_dev = inetdev_by_index(net, ifm->ifa_index); in inet_rtm_deladdr()
684 err = -ENODEV; in inet_rtm_deladdr()
688 for (ifap = &in_dev->ifa_list; in inet_rtm_deladdr()
690 ifap = &ifa->ifa_next) { in inet_rtm_deladdr()
692 ifa->ifa_local != nla_get_in_addr(tb[IFA_LOCAL])) in inet_rtm_deladdr()
695 if (tb[IFA_LABEL] && nla_strcmp(tb[IFA_LABEL], ifa->ifa_label)) in inet_rtm_deladdr()
699 (ifm->ifa_prefixlen != ifa->ifa_prefixlen || in inet_rtm_deladdr()
703 if (ipv4_is_multicast(ifa->ifa_address)) in inet_rtm_deladdr()
711 err = -EADDRNOTAVAIL; in inet_rtm_deladdr()
731 struct hlist_head *head = &net->ipv4.inet_addr_lst[i]; in check_lifetime()
741 flags = READ_ONCE(ifa->ifa_flags); in check_lifetime()
745 preferred_lft = READ_ONCE(ifa->ifa_preferred_lft); in check_lifetime()
746 valid_lft = READ_ONCE(ifa->ifa_valid_lft); in check_lifetime()
747 tstamp = READ_ONCE(ifa->ifa_tstamp); in check_lifetime()
749 age = (now - tstamp + in check_lifetime()
777 if (ifa->ifa_flags & IFA_F_PERMANENT) in check_lifetime()
781 age = (now - ifa->ifa_tstamp + in check_lifetime()
784 if (ifa->ifa_valid_lft != INFINITY_LIFE_TIME && in check_lifetime()
785 age >= ifa->ifa_valid_lft) { in check_lifetime()
789 ifap = &ifa->ifa_dev->ifa_list; in check_lifetime()
793 inet_del_ifa(ifa->ifa_dev, in check_lifetime()
797 ifap = &tmp->ifa_next; in check_lifetime()
800 } else if (ifa->ifa_preferred_lft != in check_lifetime()
802 age >= ifa->ifa_preferred_lft && in check_lifetime()
803 !(ifa->ifa_flags & IFA_F_DEPRECATED)) { in check_lifetime()
804 ifa->ifa_flags |= IFA_F_DEPRECATED; in check_lifetime()
823 queue_delayed_work(system_power_efficient_wq, &net->ipv4.addr_chk_work, in check_lifetime()
824 next_sched - now); in check_lifetime()
833 flags = ifa->ifa_flags & ~(IFA_F_PERMANENT | IFA_F_DEPRECATED); in set_ifa_lifetime()
837 WRITE_ONCE(ifa->ifa_valid_lft, timeout); in set_ifa_lifetime()
845 WRITE_ONCE(ifa->ifa_preferred_lft, timeout); in set_ifa_lifetime()
847 WRITE_ONCE(ifa->ifa_flags, flags); in set_ifa_lifetime()
848 WRITE_ONCE(ifa->ifa_tstamp, jiffies); in set_ifa_lifetime()
849 if (!ifa->ifa_cstamp) in set_ifa_lifetime()
850 WRITE_ONCE(ifa->ifa_cstamp, ifa->ifa_tstamp); in set_ifa_lifetime()
865 if (ifm->ifa_prefixlen > 32) { in inet_validate_rtm()
867 return -EINVAL; in inet_validate_rtm()
872 return -EINVAL; in inet_validate_rtm()
879 if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) { in inet_validate_rtm()
881 return -EINVAL; in inet_validate_rtm()
884 *valid_lft = ci->ifa_valid; in inet_validate_rtm()
885 *prefered_lft = ci->ifa_prefered; in inet_validate_rtm()
901 dev = __dev_get_by_index(net, ifm->ifa_index); in inet_rtm_to_ifa()
902 err = -ENODEV; in inet_rtm_to_ifa()
909 err = -ENOBUFS; in inet_rtm_to_ifa()
922 neigh_parms_data_state_setall(in_dev->arp_parms); in inet_rtm_to_ifa()
927 ifa->ifa_prefixlen = ifm->ifa_prefixlen; in inet_rtm_to_ifa()
928 ifa->ifa_mask = inet_make_mask(ifm->ifa_prefixlen); in inet_rtm_to_ifa()
929 ifa->ifa_flags = nla_get_u32_default(tb[IFA_FLAGS], ifm->ifa_flags); in inet_rtm_to_ifa()
930 ifa->ifa_scope = ifm->ifa_scope; in inet_rtm_to_ifa()
931 ifa->ifa_local = nla_get_in_addr(tb[IFA_LOCAL]); in inet_rtm_to_ifa()
932 ifa->ifa_address = nla_get_in_addr(tb[IFA_ADDRESS]); in inet_rtm_to_ifa()
935 ifa->ifa_broadcast = nla_get_in_addr(tb[IFA_BROADCAST]); in inet_rtm_to_ifa()
938 nla_strscpy(ifa->ifa_label, tb[IFA_LABEL], IFNAMSIZ); in inet_rtm_to_ifa()
940 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); in inet_rtm_to_ifa()
943 ifa->ifa_rt_priority = nla_get_u32(tb[IFA_RT_PRIORITY]); in inet_rtm_to_ifa()
946 ifa->ifa_proto = nla_get_u8(tb[IFA_PROTO]); in inet_rtm_to_ifa()
956 struct in_device *in_dev = ifa->ifa_dev; in find_matching_ifa()
960 if (ifa1->ifa_mask == ifa->ifa_mask && in find_matching_ifa()
961 inet_ifa_match(ifa1->ifa_address, ifa) && in find_matching_ifa()
962 ifa1->ifa_local == ifa->ifa_local) in find_matching_ifa()
974 struct net *net = sock_net(skb->sk); in inet_rtm_newaddr()
1001 if (ifa->ifa_flags & IFA_F_MCAUTOJOIN) { in inet_rtm_newaddr()
1012 u32 new_metric = ifa->ifa_rt_priority; in inet_rtm_newaddr()
1013 u8 new_proto = ifa->ifa_proto; in inet_rtm_newaddr()
1017 if (nlh->nlmsg_flags & NLM_F_EXCL || in inet_rtm_newaddr()
1018 !(nlh->nlmsg_flags & NLM_F_REPLACE)) { in inet_rtm_newaddr()
1020 ret = -EEXIST; in inet_rtm_newaddr()
1025 if (ifa->ifa_rt_priority != new_metric) { in inet_rtm_newaddr()
1027 ifa->ifa_rt_priority = new_metric; in inet_rtm_newaddr()
1030 ifa->ifa_proto = new_proto; in inet_rtm_newaddr()
1033 cancel_delayed_work(&net->ipv4.addr_chk_work); in inet_rtm_newaddr()
1035 &net->ipv4.addr_chk_work, 0); in inet_rtm_newaddr()
1051 int rc = -1; /* Something else, probably a multicast. */ in inet_abc_len()
1074 struct sockaddr_in *sin = (struct sockaddr_in *)&ifr->ifr_addr; in devinet_ioctl()
1080 int ret = -EFAULT; in devinet_ioctl()
1083 ifr->ifr_name[IFNAMSIZ - 1] = 0; in devinet_ioctl()
1088 colon = strchr(ifr->ifr_name, ':'); in devinet_ioctl()
1092 dev_load(net, ifr->ifr_name); in devinet_ioctl()
1105 sin->sin_family = AF_INET; in devinet_ioctl()
1109 ret = -EPERM; in devinet_ioctl()
1110 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in devinet_ioctl()
1117 ret = -EPERM; in devinet_ioctl()
1118 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in devinet_ioctl()
1120 ret = -EINVAL; in devinet_ioctl()
1121 if (sin->sin_family != AF_INET) in devinet_ioctl()
1125 ret = -EINVAL; in devinet_ioctl()
1131 ret = -ENODEV; in devinet_ioctl()
1132 dev = __dev_get_by_name(net, ifr->ifr_name); in devinet_ioctl()
1148 for (ifap = &in_dev->ifa_list; in devinet_ioctl()
1150 ifap = &ifa->ifa_next) { in devinet_ioctl()
1151 if (!strcmp(ifr->ifr_name, ifa->ifa_label) && in devinet_ioctl()
1153 ifa->ifa_local) { in devinet_ioctl()
1159 4.3BSD-style and passed in junk so we fall back to in devinet_ioctl()
1162 for (ifap = &in_dev->ifa_list; in devinet_ioctl()
1164 ifap = &ifa->ifa_next) in devinet_ioctl()
1165 if (!strcmp(ifr->ifr_name, ifa->ifa_label)) in devinet_ioctl()
1170 ret = -EADDRNOTAVAIL; in devinet_ioctl()
1177 sin->sin_addr.s_addr = ifa->ifa_local; in devinet_ioctl()
1182 sin->sin_addr.s_addr = ifa->ifa_broadcast; in devinet_ioctl()
1187 sin->sin_addr.s_addr = ifa->ifa_address; in devinet_ioctl()
1192 sin->sin_addr.s_addr = ifa->ifa_mask; in devinet_ioctl()
1197 ret = -EADDRNOTAVAIL; in devinet_ioctl()
1201 if (!(ifr->ifr_flags & IFF_UP)) in devinet_ioctl()
1206 /* NETDEV_UP/DOWN/CHANGE could touch a peer dev */ in devinet_ioctl()
1208 ret = dev_change_flags(dev, ifr->ifr_flags, NULL); in devinet_ioctl()
1212 ret = -EINVAL; in devinet_ioctl()
1213 if (inet_abc_len(sin->sin_addr.s_addr) < 0) in devinet_ioctl()
1217 ret = -ENOBUFS; in devinet_ioctl()
1225 memcpy(ifa->ifa_label, ifr->ifr_name, IFNAMSIZ); in devinet_ioctl()
1227 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); in devinet_ioctl()
1230 if (ifa->ifa_local == sin->sin_addr.s_addr) in devinet_ioctl()
1233 ifa->ifa_broadcast = 0; in devinet_ioctl()
1234 ifa->ifa_scope = 0; in devinet_ioctl()
1237 ifa->ifa_address = ifa->ifa_local = sin->sin_addr.s_addr; in devinet_ioctl()
1239 if (!(dev->flags & IFF_POINTOPOINT)) { in devinet_ioctl()
1240 ifa->ifa_prefixlen = inet_abc_len(ifa->ifa_address); in devinet_ioctl()
1241 ifa->ifa_mask = inet_make_mask(ifa->ifa_prefixlen); in devinet_ioctl()
1242 if ((dev->flags & IFF_BROADCAST) && in devinet_ioctl()
1243 ifa->ifa_prefixlen < 31) in devinet_ioctl()
1244 ifa->ifa_broadcast = ifa->ifa_address | in devinet_ioctl()
1245 ~ifa->ifa_mask; in devinet_ioctl()
1247 ifa->ifa_prefixlen = 32; in devinet_ioctl()
1248 ifa->ifa_mask = inet_make_mask(32); in devinet_ioctl()
1256 if (ifa->ifa_broadcast != sin->sin_addr.s_addr) { in devinet_ioctl()
1258 ifa->ifa_broadcast = sin->sin_addr.s_addr; in devinet_ioctl()
1265 if (ifa->ifa_address == sin->sin_addr.s_addr) in devinet_ioctl()
1267 ret = -EINVAL; in devinet_ioctl()
1268 if (inet_abc_len(sin->sin_addr.s_addr) < 0) in devinet_ioctl()
1272 ifa->ifa_address = sin->sin_addr.s_addr; in devinet_ioctl()
1281 ret = -EINVAL; in devinet_ioctl()
1282 if (bad_mask(sin->sin_addr.s_addr, 0)) in devinet_ioctl()
1285 if (ifa->ifa_mask != sin->sin_addr.s_addr) { in devinet_ioctl()
1286 __be32 old_mask = ifa->ifa_mask; in devinet_ioctl()
1288 ifa->ifa_mask = sin->sin_addr.s_addr; in devinet_ioctl()
1289 ifa->ifa_prefixlen = inet_mask_len(ifa->ifa_mask); in devinet_ioctl()
1294 * funny address, so don't touch it since in devinet_ioctl()
1297 if ((dev->flags & IFF_BROADCAST) && in devinet_ioctl()
1298 (ifa->ifa_prefixlen < 31) && in devinet_ioctl()
1299 (ifa->ifa_broadcast == in devinet_ioctl()
1300 (ifa->ifa_local|~old_mask))) { in devinet_ioctl()
1301 ifa->ifa_broadcast = (ifa->ifa_local | in devinet_ioctl()
1302 ~sin->sin_addr.s_addr); in devinet_ioctl()
1335 strcpy(ifr.ifr_name, ifa->ifa_label); in inet_gifconf()
1339 ifa->ifa_local; in inet_gifconf()
1342 done = -EFAULT; in inet_gifconf()
1345 len -= size; in inet_gifconf()
1358 if (READ_ONCE(ifa->ifa_flags) & IFA_F_SECONDARY) in in_dev_select_addr()
1360 if (ifa->ifa_scope != RT_SCOPE_LINK && in in_dev_select_addr()
1361 ifa->ifa_scope <= scope) in in_dev_select_addr()
1362 return ifa->ifa_local; in in_dev_select_addr()
1386 if (READ_ONCE(ifa->ifa_flags) & IFA_F_SECONDARY) in inet_select_addr()
1388 if (min(ifa->ifa_scope, localnet_scope) > scope) in inet_select_addr()
1391 addr = ifa->ifa_local; in inet_select_addr()
1395 addr = ifa->ifa_local; in inet_select_addr()
1450 unsigned char min_scope = min(ifa->ifa_scope, localnet_scope); in confirm_addr_indev()
1453 (local == ifa->ifa_local || !local) && in confirm_addr_indev()
1455 addr = ifa->ifa_local; in confirm_addr_indev()
1470 addr = ifa->ifa_local; in confirm_addr_indev()
1484 * - net: netns to check, cannot be NULL
1485 * - in_dev: only on this interface, NULL=any interface
1486 * - dst: only in the same subnet as dst, 0=any dst
1487 * - local: address, 0=autoselect the local address
1488 * - scope: maximum allowed scope value for the local address
1554 memcpy(old, ifa->ifa_label, IFNAMSIZ); in inetdev_changename()
1555 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); in inetdev_changename()
1563 if (strlen(dot) + strlen(dev->name) < IFNAMSIZ) in inetdev_changename()
1564 strcat(ifa->ifa_label, dot); in inetdev_changename()
1566 strcpy(ifa->ifa_label + (IFNAMSIZ - strlen(dot) - 1), dot); in inetdev_changename()
1580 ifa->ifa_local, dev, in inetdev_send_gratuitous_arp()
1581 ifa->ifa_local, NULL, in inetdev_send_gratuitous_arp()
1582 dev->dev_addr, NULL); in inetdev_send_gratuitous_arp()
1601 if (dev->flags & IFF_LOOPBACK) { in inetdev_event()
1606 /* Re-enabling IP */ in inetdev_event()
1607 if (inetdev_valid_mtu(dev->mtu)) in inetdev_event()
1616 RCU_INIT_POINTER(dev->ip_ptr, NULL); in inetdev_event()
1619 if (!inetdev_valid_mtu(dev->mtu)) in inetdev_event()
1621 if (dev->flags & IFF_LOOPBACK) { in inetdev_event()
1625 ifa->ifa_local = in inetdev_event()
1626 ifa->ifa_address = htonl(INADDR_LOOPBACK); in inetdev_event()
1627 ifa->ifa_prefixlen = 8; in inetdev_event()
1628 ifa->ifa_mask = inet_make_mask(8); in inetdev_event()
1629 ifa->ifa_scope = RT_SCOPE_HOST; in inetdev_event()
1630 memcpy(ifa->ifa_label, dev->name, IFNAMSIZ); in inetdev_event()
1634 neigh_parms_data_state_setall(in_dev->arp_parms); in inetdev_event()
1658 if (inetdev_valid_mtu(dev->mtu)) in inetdev_event()
1698 return (cstamp - INITIAL_JIFFIES) * 100UL / HZ; in cstamp_delta()
1723 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, sizeof(*ifm), in inet_fill_ifaddr()
1724 args->flags); in inet_fill_ifaddr()
1726 return -EMSGSIZE; in inet_fill_ifaddr()
1729 ifm->ifa_family = AF_INET; in inet_fill_ifaddr()
1730 ifm->ifa_prefixlen = ifa->ifa_prefixlen; in inet_fill_ifaddr()
1732 flags = READ_ONCE(ifa->ifa_flags); in inet_fill_ifaddr()
1733 /* Warning : ifm->ifa_flags is an __u8, it holds only 8 bits. in inet_fill_ifaddr()
1736 ifm->ifa_flags = (__u8)flags; in inet_fill_ifaddr()
1738 ifm->ifa_scope = ifa->ifa_scope; in inet_fill_ifaddr()
1739 ifm->ifa_index = ifa->ifa_dev->dev->ifindex; in inet_fill_ifaddr()
1741 if (args->netnsid >= 0 && in inet_fill_ifaddr()
1742 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) in inet_fill_ifaddr()
1745 tstamp = READ_ONCE(ifa->ifa_tstamp); in inet_fill_ifaddr()
1747 preferred = READ_ONCE(ifa->ifa_preferred_lft); in inet_fill_ifaddr()
1748 valid = READ_ONCE(ifa->ifa_valid_lft); in inet_fill_ifaddr()
1750 long tval = (jiffies - tstamp) / HZ; in inet_fill_ifaddr()
1753 preferred -= tval; in inet_fill_ifaddr()
1758 valid -= tval; in inet_fill_ifaddr()
1767 if ((ifa->ifa_address && in inet_fill_ifaddr()
1768 nla_put_in_addr(skb, IFA_ADDRESS, ifa->ifa_address)) || in inet_fill_ifaddr()
1769 (ifa->ifa_local && in inet_fill_ifaddr()
1770 nla_put_in_addr(skb, IFA_LOCAL, ifa->ifa_local)) || in inet_fill_ifaddr()
1771 (ifa->ifa_broadcast && in inet_fill_ifaddr()
1772 nla_put_in_addr(skb, IFA_BROADCAST, ifa->ifa_broadcast)) || in inet_fill_ifaddr()
1773 (ifa->ifa_label[0] && in inet_fill_ifaddr()
1774 nla_put_string(skb, IFA_LABEL, ifa->ifa_label)) || in inet_fill_ifaddr()
1775 (ifa->ifa_proto && in inet_fill_ifaddr()
1776 nla_put_u8(skb, IFA_PROTO, ifa->ifa_proto)) || in inet_fill_ifaddr()
1778 (ifa->ifa_rt_priority && in inet_fill_ifaddr()
1779 nla_put_u32(skb, IFA_RT_PRIORITY, ifa->ifa_rt_priority)) || in inet_fill_ifaddr()
1780 put_cacheinfo(skb, READ_ONCE(ifa->ifa_cstamp), tstamp, in inet_fill_ifaddr()
1789 return -EMSGSIZE; in inet_fill_ifaddr()
1797 struct netlink_ext_ack *extack = cb->extack; in inet_valid_dump_ifaddr_req()
1802 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet_valid_dump_ifaddr_req()
1804 return -EINVAL; in inet_valid_dump_ifaddr_req()
1808 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet_valid_dump_ifaddr_req()
1810 return -EINVAL; in inet_valid_dump_ifaddr_req()
1813 fillargs->ifindex = ifm->ifa_index; in inet_valid_dump_ifaddr_req()
1814 if (fillargs->ifindex) { in inet_valid_dump_ifaddr_req()
1815 cb->answer_flags |= NLM_F_DUMP_FILTERED; in inet_valid_dump_ifaddr_req()
1816 fillargs->flags |= NLM_F_DUMP_FILTERED; in inet_valid_dump_ifaddr_req()
1831 fillargs->netnsid = nla_get_s32(tb[i]); in inet_valid_dump_ifaddr_req()
1833 net = rtnl_get_net_ns_capable(sk, fillargs->netnsid); in inet_valid_dump_ifaddr_req()
1835 fillargs->netnsid = -1; in inet_valid_dump_ifaddr_req()
1842 return -EINVAL; in inet_valid_dump_ifaddr_req()
1881 u32 res = atomic_read(&net->ipv4.dev_addr_genid) + in inet_base_seq()
1882 READ_ONCE(net->dev_base_seq); in inet_base_seq()
1894 const struct nlmsghdr *nlh = cb->nlh; in inet_dump_ifaddr()
1896 .portid = NETLINK_CB(cb->skb).portid, in inet_dump_ifaddr()
1897 .seq = nlh->nlmsg_seq, in inet_dump_ifaddr()
1900 .netnsid = -1, in inet_dump_ifaddr()
1902 struct net *net = sock_net(skb->sk); in inet_dump_ifaddr()
1907 } *ctx = (void *)cb->ctx; in inet_dump_ifaddr()
1913 if (cb->strict_check) { in inet_dump_ifaddr()
1915 skb->sk, cb); in inet_dump_ifaddr()
1922 err = -ENODEV; in inet_dump_ifaddr()
1928 err = in_dev_dump_addr(in_dev, skb, cb, &ctx->ip_idx, in inet_dump_ifaddr()
1934 cb->seq = inet_base_seq(tgt_net); in inet_dump_ifaddr()
1936 for_each_netdev_dump(tgt_net, dev, ctx->ifindex) { in inet_dump_ifaddr()
1940 err = in_dev_dump_addr(in_dev, skb, cb, &ctx->ip_idx, in inet_dump_ifaddr()
1957 .seq = nlh ? nlh->nlmsg_seq : 0, in rtmsg_ifa()
1960 .netnsid = -1, in rtmsg_ifa()
1963 int err = -ENOBUFS; in rtmsg_ifa()
1966 net = dev_net(ifa->ifa_dev->dev); in rtmsg_ifa()
1973 /* -EMSGSIZE implies BUG in inet_nlmsg_size() */ in rtmsg_ifa()
1974 WARN_ON(err == -EMSGSIZE); in rtmsg_ifa()
1987 struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr); in inet_get_link_af_size()
1998 struct in_device *in_dev = rcu_dereference_rtnl(dev->ip_ptr); in inet_fill_link_af()
2003 return -ENODATA; in inet_fill_link_af()
2007 return -EMSGSIZE; in inet_fill_link_af()
2010 ((u32 *) nla_data(nla))[i] = READ_ONCE(in_dev->cnf.data[i]); in inet_fill_link_af()
2027 return -EAFNOSUPPORT; in inet_validate_link_af()
2039 return -EINVAL; in inet_validate_link_af()
2042 return -EINVAL; in inet_validate_link_af()
2057 return -EAFNOSUPPORT; in inet_set_link_af()
2060 return -EINVAL; in inet_set_link_af()
2107 return -EMSGSIZE; in inet_netconf_fill_devconf()
2113 ncm->ncm_family = AF_INET; in inet_netconf_fill_devconf()
2153 return -EMSGSIZE; in inet_netconf_fill_devconf()
2160 int err = -ENOBUFS; in inet_netconf_notify_devconf()
2169 /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ in inet_netconf_notify_devconf()
2170 WARN_ON(err == -EMSGSIZE); in inet_netconf_notify_devconf()
2195 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(struct netconfmsg))) { in inet_netconf_valid_get_req()
2197 return -EINVAL; in inet_netconf_valid_get_req()
2220 return -EINVAL; in inet_netconf_valid_get_req()
2231 struct net *net = sock_net(in_skb->sk); in inet_netconf_get_devconf()
2245 return -EINVAL; in inet_netconf_get_devconf()
2250 devconf = net->ipv4.devconf_all; in inet_netconf_get_devconf()
2253 devconf = net->ipv4.devconf_dflt; in inet_netconf_get_devconf()
2256 err = -ENODEV; in inet_netconf_get_devconf()
2262 devconf = &in_dev->cnf; in inet_netconf_get_devconf()
2266 err = -ENOBUFS; in inet_netconf_get_devconf()
2273 nlh->nlmsg_seq, RTM_NEWNETCONF, 0, in inet_netconf_get_devconf()
2276 /* -EMSGSIZE implies BUG in inet_netconf_msgsize_devconf() */ in inet_netconf_get_devconf()
2277 WARN_ON(err == -EMSGSIZE); in inet_netconf_get_devconf()
2292 const struct nlmsghdr *nlh = cb->nlh; in inet_netconf_dump_devconf()
2293 struct net *net = sock_net(skb->sk); in inet_netconf_dump_devconf()
2297 } *ctx = (void *)cb->ctx; in inet_netconf_dump_devconf()
2302 if (cb->strict_check) { in inet_netconf_dump_devconf()
2303 struct netlink_ext_ack *extack = cb->extack; in inet_netconf_dump_devconf()
2306 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ncm))) { in inet_netconf_dump_devconf()
2308 return -EINVAL; in inet_netconf_dump_devconf()
2313 return -EINVAL; in inet_netconf_dump_devconf()
2318 for_each_netdev_dump(net, dev, ctx->ifindex) { in inet_netconf_dump_devconf()
2322 err = inet_netconf_fill_devconf(skb, dev->ifindex, in inet_netconf_dump_devconf()
2323 &in_dev->cnf, in inet_netconf_dump_devconf()
2324 NETLINK_CB(cb->skb).portid, in inet_netconf_dump_devconf()
2325 nlh->nlmsg_seq, in inet_netconf_dump_devconf()
2331 if (ctx->all_default == 0) { in inet_netconf_dump_devconf()
2333 net->ipv4.devconf_all, in inet_netconf_dump_devconf()
2334 NETLINK_CB(cb->skb).portid, in inet_netconf_dump_devconf()
2335 nlh->nlmsg_seq, in inet_netconf_dump_devconf()
2340 ctx->all_default++; in inet_netconf_dump_devconf()
2342 if (ctx->all_default == 1) { in inet_netconf_dump_devconf()
2344 net->ipv4.devconf_dflt, in inet_netconf_dump_devconf()
2345 NETLINK_CB(cb->skb).portid, in inet_netconf_dump_devconf()
2346 nlh->nlmsg_seq, in inet_netconf_dump_devconf()
2351 ctx->all_default++; in inet_netconf_dump_devconf()
2369 if (in_dev && !test_bit(i, in_dev->cnf.state)) in devinet_copy_dflt_conf()
2370 in_dev->cnf.data[i] = net->ipv4.devconf_dflt->data[i]; in devinet_copy_dflt_conf()
2386 net->ipv4.devconf_all); in inet_forward_change()
2390 net->ipv4.devconf_dflt); in inet_forward_change()
2403 dev->ifindex, &in_dev->cnf); in inet_forward_change()
2410 if (cnf == net->ipv4.devconf_dflt) in devinet_conf_ifindex()
2412 else if (cnf == net->ipv4.devconf_all) in devinet_conf_ifindex()
2417 return idev->dev->ifindex; in devinet_conf_ifindex()
2424 int old_value = *(int *)ctl->data; in devinet_conf_proc()
2426 int new_value = *(int *)ctl->data; in devinet_conf_proc()
2429 struct ipv4_devconf *cnf = ctl->extra1; in devinet_conf_proc()
2430 struct net *net = ctl->extra2; in devinet_conf_proc()
2431 int i = (int *)ctl->data - cnf->data; in devinet_conf_proc()
2434 set_bit(i, cnf->state); in devinet_conf_proc()
2436 if (cnf == net->ipv4.devconf_dflt) in devinet_conf_proc()
2438 if (i == IPV4_DEVCONF_ACCEPT_LOCAL - 1 || in devinet_conf_proc()
2439 i == IPV4_DEVCONF_ROUTE_LOCALNET - 1) in devinet_conf_proc()
2443 if (i == IPV4_DEVCONF_BC_FORWARDING - 1 && in devinet_conf_proc()
2447 if (i == IPV4_DEVCONF_RP_FILTER - 1 && in devinet_conf_proc()
2454 if (i == IPV4_DEVCONF_PROXY_ARP - 1 && in devinet_conf_proc()
2461 if (i == IPV4_DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN - 1 && in devinet_conf_proc()
2476 int *valp = ctl->data; in devinet_sysctl_forward()
2479 struct net *net = ctl->extra2; in devinet_sysctl_forward()
2482 if (write && !ns_capable(net->user_ns, CAP_NET_ADMIN)) in devinet_sysctl_forward()
2483 return -EPERM; in devinet_sysctl_forward()
2498 struct ipv4_devconf *cnf = ctl->extra1; in devinet_sysctl_forward()
2502 dev_disable_lro(idev->dev); in devinet_sysctl_forward()
2505 idev->dev->ifindex, in devinet_sysctl_forward()
2514 net->ipv4.devconf_dflt); in devinet_sysctl_forward()
2523 int *valp = ctl->data; in ipv4_doint_and_flush()
2526 struct net *net = ctl->extra2; in ipv4_doint_and_flush()
2538 IPV4_DEVCONF_ ## attr - 1, \
2622 for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) { in __devinet_sysctl_register()
2623 t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf; in __devinet_sysctl_register()
2624 t->devinet_vars[i].extra1 = p; in __devinet_sysctl_register()
2625 t->devinet_vars[i].extra2 = net; in __devinet_sysctl_register()
2630 t->sysctl_header = register_net_sysctl(net, path, t->devinet_vars); in __devinet_sysctl_register()
2631 if (!t->sysctl_header) in __devinet_sysctl_register()
2634 p->sysctl = t; in __devinet_sysctl_register()
2643 return -ENOMEM; in __devinet_sysctl_register()
2649 struct devinet_sysctl_table *t = cnf->sysctl; in __devinet_sysctl_unregister()
2652 cnf->sysctl = NULL; in __devinet_sysctl_unregister()
2653 unregister_net_sysctl_table(t->sysctl_header); in __devinet_sysctl_unregister()
2664 if (!sysctl_dev_name_is_allowed(idev->dev->name)) in devinet_sysctl_register()
2665 return -EINVAL; in devinet_sysctl_register()
2667 err = neigh_sysctl_register(idev->dev, idev->arp_parms, NULL); in devinet_sysctl_register()
2670 err = __devinet_sysctl_register(dev_net(idev->dev), idev->dev->name, in devinet_sysctl_register()
2671 idev->dev->ifindex, &idev->cnf); in devinet_sysctl_register()
2673 neigh_sysctl_unregister(idev->arp_parms); in devinet_sysctl_register()
2679 struct net *net = dev_net(idev->dev); in devinet_sysctl_unregister()
2681 __devinet_sysctl_unregister(net, &idev->cnf, idev->dev->ifindex); in devinet_sysctl_unregister()
2682 neigh_sysctl_unregister(idev->arp_parms); in devinet_sysctl_unregister()
2689 IPV4_DEVCONF_FORWARDING - 1],
2709 err = -ENOMEM; in devinet_init_net()
2710 net->ipv4.inet_addr_lst = kmalloc_array(IN4_ADDR_HSIZE, in devinet_init_net()
2713 if (!net->ipv4.inet_addr_lst) in devinet_init_net()
2729 tbl[0].data = &all->data[IPV4_DEVCONF_FORWARDING - 1]; in devinet_init_net()
2738 memcpy(all, current->nsproxy->net_ns->ipv4.devconf_all, in devinet_init_net()
2741 current->nsproxy->net_ns->ipv4.devconf_dflt, in devinet_init_net()
2768 err = -ENOMEM; in devinet_init_net()
2773 net->ipv4.forw_hdr = forw_hdr; in devinet_init_net()
2777 INIT_HLIST_HEAD(&net->ipv4.inet_addr_lst[i]); in devinet_init_net()
2779 INIT_DEFERRABLE_WORK(&net->ipv4.addr_chk_work, check_lifetime); in devinet_init_net()
2781 net->ipv4.devconf_all = all; in devinet_init_net()
2782 net->ipv4.devconf_dflt = dflt; in devinet_init_net()
2798 kfree(net->ipv4.inet_addr_lst); in devinet_init_net()
2809 cancel_delayed_work_sync(&net->ipv4.addr_chk_work); in devinet_exit_net()
2812 tbl = net->ipv4.forw_hdr->ctl_table_arg; in devinet_exit_net()
2813 unregister_net_sysctl_table(net->ipv4.forw_hdr); in devinet_exit_net()
2814 __devinet_sysctl_unregister(net, net->ipv4.devconf_dflt, in devinet_exit_net()
2816 __devinet_sysctl_unregister(net, net->ipv4.devconf_all, in devinet_exit_net()
2820 kfree(net->ipv4.devconf_dflt); in devinet_exit_net()
2821 kfree(net->ipv4.devconf_all); in devinet_exit_net()
2822 kfree(net->ipv4.inet_addr_lst); in devinet_exit_net()