Print this page
4788 mac shouldn't abuse ddi_get_time(9f)

*** 20,29 **** --- 20,32 ---- */ /* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ + /* + * Copyright 2014 Nexenta Systems, Inc. All rights reserved. + */ #include <sys/strsun.h> #include <sys/sdt.h> #include <sys/mac.h> #include <sys/mac_impl.h>
*** 139,157 **** * flooding the network with bogus transactions). They are not meant to be * user-modifiable so they are not exposed as linkprops. */ static ulong_t dhcp_max_pending_txn = 512; static ulong_t dhcp_max_completed_txn = 512; ! static time_t txn_cleanup_interval = 60; /* * DHCPv4 transaction. It may be added to three different tables * (keyed by different fields). */ typedef struct dhcpv4_txn { uint32_t dt_xid; ! time_t dt_timestamp; uint8_t dt_cid[DHCP_MAX_OPT_SIZE]; uint8_t dt_cid_len; ipaddr_t dt_ipaddr; avl_node_t dt_node; avl_node_t dt_ipnode; --- 142,160 ---- * flooding the network with bogus transactions). They are not meant to be * user-modifiable so they are not exposed as linkprops. */ static ulong_t dhcp_max_pending_txn = 512; static ulong_t dhcp_max_completed_txn = 512; ! static hrtime_t txn_cleanup_interval = 60 * NANOSEC; /* * DHCPv4 transaction. It may be added to three different tables * (keyed by different fields). */ typedef struct dhcpv4_txn { uint32_t dt_xid; ! hrtime_t dt_timestamp; uint8_t dt_cid[DHCP_MAX_OPT_SIZE]; uint8_t dt_cid_len; ipaddr_t dt_ipaddr; avl_node_t dt_node; avl_node_t dt_ipnode;
*** 184,194 **** * DHCPv6 transaction. Unlike its v4 counterpart, this object gets freed up * as soon as the transaction completes or expires. */ typedef struct dhcpv6_txn { uint32_t dt_xid; ! time_t dt_timestamp; dhcpv6_cid_t *dt_cid; avl_node_t dt_node; struct dhcpv6_txn *dt_next; } dhcpv6_txn_t; --- 187,197 ---- * DHCPv6 transaction. Unlike its v4 counterpart, this object gets freed up * as soon as the transaction completes or expires. */ typedef struct dhcpv6_txn { uint32_t dt_xid; ! hrtime_t dt_timestamp; dhcpv6_cid_t *dt_cid; avl_node_t dt_node; struct dhcpv6_txn *dt_next; } dhcpv6_txn_t;
*** 453,463 **** if ((txn = kmem_zalloc(sizeof (*txn), KM_NOSLEEP)) == NULL) return (NULL); txn->dt_xid = xid; ! txn->dt_timestamp = ddi_get_time(); if (cid_len > 0) bcopy(cid, &txn->dt_cid, cid_len); txn->dt_cid_len = cid_len; txn->dt_ipaddr = ipaddr; return (txn); --- 456,466 ---- if ((txn = kmem_zalloc(sizeof (*txn), KM_NOSLEEP)) == NULL) return (NULL); txn->dt_xid = xid; ! txn->dt_timestamp = gethrtime(); if (cid_len > 0) bcopy(cid, &txn->dt_cid, cid_len); txn->dt_cid_len = cid_len; txn->dt_ipaddr = ipaddr; return (txn);
*** 510,521 **** * Find stale pending transactions and place them on a list * to be removed. */ for (txn = avl_first(&mcip->mci_v4_pending_txn); txn != NULL; txn = avl_walk(&mcip->mci_v4_pending_txn, txn, AVL_AFTER)) { ! if (ddi_get_time() - txn->dt_timestamp > ! txn_cleanup_interval) { DTRACE_PROBE2(found__expired__txn, mac_client_impl_t *, mcip, dhcpv4_txn_t *, txn); txn->dt_next = txn_list; --- 513,523 ---- * Find stale pending transactions and place them on a list * to be removed. */ for (txn = avl_first(&mcip->mci_v4_pending_txn); txn != NULL; txn = avl_walk(&mcip->mci_v4_pending_txn, txn, AVL_AFTER)) { ! if (gethrtime() - txn->dt_timestamp > txn_cleanup_interval) { DTRACE_PROBE2(found__expired__txn, mac_client_impl_t *, mcip, dhcpv4_txn_t *, txn); txn->dt_next = txn_list;
*** 615,625 **** * txns for retransmissions. */ if ((txn = find_dhcpv4_pending_txn(mcip, dh4->xid)) != NULL) { DTRACE_PROBE2(update, mac_client_impl_t *, mcip, dhcpv4_txn_t *, txn); ! txn->dt_timestamp = ddi_get_time(); goto done; } if (get_dhcpv4_option(dh4, end, CD_REQUESTED_IP_ADDR, &opt, &opt_len) != 0 || opt_len != sizeof (ipaddr)) { --- 617,627 ---- * txns for retransmissions. */ if ((txn = find_dhcpv4_pending_txn(mcip, dh4->xid)) != NULL) { DTRACE_PROBE2(update, mac_client_impl_t *, mcip, dhcpv4_txn_t *, txn); ! txn->dt_timestamp = gethrtime(); goto done; } if (get_dhcpv4_option(dh4, end, CD_REQUESTED_IP_ADDR, &opt, &opt_len) != 0 || opt_len != sizeof (ipaddr)) {
*** 1114,1124 **** if ((txn = kmem_zalloc(sizeof (dhcpv6_txn_t), KM_NOSLEEP)) == NULL) return (NULL); txn->dt_xid = xid; txn->dt_cid = cid; ! txn->dt_timestamp = ddi_get_time(); return (txn); } static void free_dhcpv6_txn(dhcpv6_txn_t *txn) --- 1116,1126 ---- if ((txn = kmem_zalloc(sizeof (dhcpv6_txn_t), KM_NOSLEEP)) == NULL) return (NULL); txn->dt_xid = xid; txn->dt_cid = cid; ! txn->dt_timestamp = gethrtime(); return (txn); } static void free_dhcpv6_txn(dhcpv6_txn_t *txn)
*** 1181,1192 **** * Find stale pending transactions and place them on a list * to be removed. */ for (txn = avl_first(&mcip->mci_v6_pending_txn); txn != NULL; txn = avl_walk(&mcip->mci_v6_pending_txn, txn, AVL_AFTER)) { ! if (ddi_get_time() - txn->dt_timestamp > ! txn_cleanup_interval) { DTRACE_PROBE2(found__expired__txn, mac_client_impl_t *, mcip, dhcpv6_txn_t *, txn); txn->dt_next = txn_list; --- 1183,1193 ---- * Find stale pending transactions and place them on a list * to be removed. */ for (txn = avl_first(&mcip->mci_v6_pending_txn); txn != NULL; txn = avl_walk(&mcip->mci_v6_pending_txn, txn, AVL_AFTER)) { ! if (gethrtime() - txn->dt_timestamp > txn_cleanup_interval) { DTRACE_PROBE2(found__expired__txn, mac_client_impl_t *, mcip, dhcpv6_txn_t *, txn); txn->dt_next = txn_list;
*** 1246,1256 **** } xid = DHCPV6_GET_TRANSID(dh6); if ((txn = find_dhcpv6_pending_txn(mcip, xid)) != NULL) { DTRACE_PROBE2(update, mac_client_impl_t *, mcip, dhcpv6_txn_t *, txn); ! txn->dt_timestamp = ddi_get_time(); goto done; } if ((txn = create_dhcpv6_txn(xid, cid)) == NULL) goto done; --- 1247,1257 ---- } xid = DHCPV6_GET_TRANSID(dh6); if ((txn = find_dhcpv6_pending_txn(mcip, xid)) != NULL) { DTRACE_PROBE2(update, mac_client_impl_t *, mcip, dhcpv6_txn_t *, txn); ! txn->dt_timestamp = gethrtime(); goto done; } if ((txn = create_dhcpv6_txn(xid, cid)) == NULL) goto done;
*** 1355,1376 **** if (!avl_is_empty(&mcip->mci_v4_pending_txn) || !avl_is_empty(&mcip->mci_v6_pending_txn)) { DTRACE_PROBE1(restarting__timer, mac_client_impl_t *, mcip); mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip, ! drv_usectohz(txn_cleanup_interval * 1000000)); } mutex_exit(&mcip->mci_protect_lock); } static void start_txn_cleanup_timer(mac_client_impl_t *mcip) { ASSERT(MUTEX_HELD(&mcip->mci_protect_lock)); if (mcip->mci_txn_cleanup_tid == 0) { mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip, ! drv_usectohz(txn_cleanup_interval * 1000000)); } } static void cancel_txn_cleanup_timer(mac_client_impl_t *mcip) --- 1356,1377 ---- if (!avl_is_empty(&mcip->mci_v4_pending_txn) || !avl_is_empty(&mcip->mci_v6_pending_txn)) { DTRACE_PROBE1(restarting__timer, mac_client_impl_t *, mcip); mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip, ! drv_usectohz(txn_cleanup_interval / (NANOSEC / MICROSEC))); } mutex_exit(&mcip->mci_protect_lock); } static void start_txn_cleanup_timer(mac_client_impl_t *mcip) { ASSERT(MUTEX_HELD(&mcip->mci_protect_lock)); if (mcip->mci_txn_cleanup_tid == 0) { mcip->mci_txn_cleanup_tid = timeout(txn_cleanup_timer, mcip, ! drv_usectohz(txn_cleanup_interval / (NANOSEC / MICROSEC))); } } static void cancel_txn_cleanup_timer(mac_client_impl_t *mcip)