aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/ip_icmp.c
diff options
context:
space:
mode:
authorAlexander V. Chernikov <melifaro@FreeBSD.org>2012-10-10 19:06:11 +0000
committerAlexander V. Chernikov <melifaro@FreeBSD.org>2012-10-10 19:06:11 +0000
commit3c2824b9efba0e6165662fdf48848a0352d31334 (patch)
treeeadfb79e4a7a03342694f5708e28ff1340981a5c /sys/netinet/ip_icmp.c
parent627995dcded68710c4a866916e9de85b0bc829ea (diff)
downloadsrc-3c2824b9efba0e6165662fdf48848a0352d31334.tar.gz
src-3c2824b9efba0e6165662fdf48848a0352d31334.zip
Do not check if found IPv4 rte is dynamic if net.inet.icmp.drop_redirect is
enabled. This eliminates one mtx_lock() per each routing lookup thus improving performance in several cases (routing to directly connected interface or routing to default gateway). Icmp redirects should not be used to provide routing direction nowadays, even for end hosts. Routers should not use them too (and this is explicitly restricted in IPv6, see RFC 4861, clause 8.2). Current commit changes rnh_machaddr function to 'stock' rn_match (and back) for every AF_INET routing table in given VNET instance on drop_redirect sysctl change. This change is part of bigger patch eliminating rte locking. Sponsored by: Yandex LLC MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=241406
Diffstat (limited to 'sys/netinet/ip_icmp.c')
-rw-r--r--sys/netinet/ip_icmp.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c
index 6451cb652a31..7bbb9986e4b1 100644
--- a/sys/netinet/ip_icmp.c
+++ b/sys/netinet/ip_icmp.c
@@ -108,11 +108,7 @@ SYSCTL_VNET_UINT(_net_inet_icmp, OID_AUTO, maskfake, CTLFLAG_RW,
&VNET_NAME(icmpmaskfake), 0,
"Fake reply to ICMP Address Mask Request packets.");
-static VNET_DEFINE(int, drop_redirect) = 0;
-#define V_drop_redirect VNET(drop_redirect)
-SYSCTL_VNET_INT(_net_inet_icmp, OID_AUTO, drop_redirect, CTLFLAG_RW,
- &VNET_NAME(drop_redirect), 0,
- "Ignore ICMP redirects");
+VNET_DEFINE(int, drop_redirect) = 0;
static VNET_DEFINE(int, log_redirect) = 0;
#define V_log_redirect VNET(log_redirect)
@@ -157,6 +153,39 @@ static void icmp_send(struct mbuf *, struct mbuf *);
extern struct protosw inetsw[];
+static int
+sysctl_net_icmp_drop_redir(SYSCTL_HANDLER_ARGS)
+{
+ int error, new;
+ int i;
+ struct radix_node_head *rnh;
+
+ new = V_drop_redirect;
+ error = sysctl_handle_int(oidp, &new, 0, req);
+ if (error == 0 && req->newptr) {
+ new = (new != 0) ? 1 : 0;
+
+ if (new == V_drop_redirect)
+ return (0);
+
+ for (i = 0; i < rt_numfibs; i++) {
+ if ((rnh = rt_tables_get_rnh(i, AF_INET)) == NULL)
+ continue;
+ RADIX_NODE_HEAD_LOCK(rnh);
+ in_setmatchfunc(rnh, new);
+ RADIX_NODE_HEAD_UNLOCK(rnh);
+ }
+
+ V_drop_redirect = new;
+ }
+
+ return (error);
+}
+
+SYSCTL_VNET_PROC(_net_inet_icmp, OID_AUTO, drop_redirect,
+ CTLTYPE_INT|CTLFLAG_RW, 0, 0,
+ sysctl_net_icmp_drop_redir, "I", "Ignore ICMP redirects");
+
/*
* Kernel module interface for updating icmpstat. The argument is an index
* into icmpstat treated as an array of u_long. While this encodes the