From a08362ce46087f91e82c8dbadb33591c33e6c1e4 Mon Sep 17 00:00:00 2001 From: "Bjoern A. Zeeb" Date: Tue, 21 Jul 2009 21:58:55 +0000 Subject: [PATCH] sysctl_msec_to_ticks is used with both virtualized and non-vrtiualized sysctls so we cannot used one common function. Add a macro to convert the arg1 in the virtualized case to vnet.h to not expose the maths to all over the code. Add a wrapper for the single virtualized call, properly handling arg1 and call the default implementation from there. Convert the two over places to use the new macro. Reviewed by: rwatson Approved by: re (kib) --- sys/kern/kern_sysctl.c | 5 ----- sys/net/vnet.h | 6 ++++++ sys/netinet/tcp_subr.c | 10 +++++++++- sys/netinet6/in6_proto.c | 12 ++---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 94e45f13caf4..535ea810aead 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -948,11 +948,6 @@ sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS) { int error, s, tt; -#ifdef VIMAGE - if (arg1 != NULL) - arg1 = (void *)(TD_TO_VNET(req->td)->vnet_data_base + - (uintptr_t)arg1); -#endif tt = *(int *)arg1; s = (int)((int64_t)tt * 1000 / hz); diff --git a/sys/net/vnet.h b/sys/net/vnet.h index 23f0a331d5f1..aec448a11334 100644 --- a/sys/net/vnet.h +++ b/sys/net/vnet.h @@ -101,6 +101,11 @@ int vnet_sysctl_handle_uint(SYSCTL_HANDLER_ARGS); #define SYSCTL_VNET_UINT(parent, nbr, name, access, ptr, val, descr) \ SYSCTL_OID(parent, nbr, name, CTLTYPE_UINT|CTLFLAG_MPSAFE|(access), \ ptr, val, vnet_sysctl_handle_uint, "IU", descr) +#define VNET_SYSCTL_ARG(req, arg1) do { \ + if (arg1 != NULL) \ + arg1 = (void *)(TD_TO_VNET((req)->td)->vnet_data_base + \ + (uintptr_t)(arg1)); \ +} while (0) #endif /* SYSCTL_OID */ /* @@ -141,6 +146,7 @@ void vnet_data_destroy(struct vnet *vnet); SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr) #define SYSCTL_VNET_UINT(parent, nbr, name, access, ptr, val, descr) \ SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr) +#define VNET_SYSCTL_ARG(req, arg1) #endif /* SYSCTL_OID */ /* diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 8ebc889b74f3..e29283bad3cf 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -178,6 +178,14 @@ SYSCTL_VNET_PROC(_net_inet_tcp, TCPCTL_V6MSSDFLT, v6mssdflt, "Default TCP Maximum Segment Size for IPv6"); #endif +static int +vnet_sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS) +{ + + VNET_SYSCTL_ARG(req, arg1); + return (sysctl_msec_to_ticks(oidp, arg1, arg2, req)); +} + /* * Minimum MSS we accept and use. This prevents DoS attacks where * we are forced to a ridiculous low MSS like 20 and send hundreds @@ -236,7 +244,7 @@ SYSCTL_INT(_net_inet_tcp_inflight, OID_AUTO, debug, CTLFLAG_RW, SYSCTL_VNET_PROC(_net_inet_tcp_inflight, OID_AUTO, rttthresh, CTLTYPE_INT|CTLFLAG_RW, &VNET_NAME(tcp_inflight_rttthresh), 0, - sysctl_msec_to_ticks, "I", + vnet_sysctl_msec_to_ticks, "I", "RTT threshold below which inflight will deactivate itself"); SYSCTL_VNET_INT(_net_inet_tcp_inflight, OID_AUTO, min, CTLFLAG_RW, diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c index 1a536dc23fa2..57253f735460 100644 --- a/sys/netinet6/in6_proto.c +++ b/sys/netinet6/in6_proto.c @@ -452,11 +452,7 @@ sysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS) int error = 0; int old; -#ifdef VIMAGE - if (arg1 != NULL) - arg1 = (void *)(TD_TO_VNET(req->td)->vnet_data_base + - (uintptr_t)arg1); -#endif + VNET_SYSCTL_ARG(req, arg1); error = SYSCTL_OUT(req, arg1, sizeof(int)); if (error || !req->newptr) @@ -477,11 +473,7 @@ sysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS) int error = 0; int old; -#ifdef VIMAGE - if (arg1 != NULL) - arg1 = (void *)(TD_TO_VNET(req->td)->vnet_data_base + - (uintptr_t)arg1); -#endif + VNET_SYSCTL_ARG(req, arg1); error = SYSCTL_OUT(req, arg1, sizeof(int)); if (error || !req->newptr)