/* * clock_set_calendar_microtime: * * Sets the current calendar value by * recalculating the epoch and offset * from the system clock. * * Also adjusts the boottime to keep the * value consistent, writes the new * calendar value to the platform clock, * and sends calendar change notifications. */ void clock_set_calendar_microtime( clock_sec_t secs, clock_usec_t microsecs) { clock_sec_t sys; clock_usec_t microsys; clock_sec_t newsecs; spl_t s; newsecs = (microsecs < 500*USEC_PER_SEC)? secs: secs + 1; s = splclock(); clock_lock(); commpage_disable_timestamp(); /* * Calculate the new calendar epoch based on * the new value and the system clock. */ clock_get_system_microtime(&sys, µsys); TIME_SUB(secs, sys, microsecs, microsys, USEC_PER_SEC); /* * Adjust the boottime based on the delta. */ clock_boottime += secs - clock_calend.epoch; /* * Set the new calendar epoch. */ clock_calend.epoch = secs; nanoseconds_to_absolutetime((uint64_t)microsecs * NSEC_PER_USEC, &clock_calend.offset); /* * Cancel any adjustment in progress. */ calend_adjtotal = clock_calend.adjdelta = 0; clock_unlock(); /* * Set the new value for the platform clock. */ PESetGMTTimeOfDay(newsecs); splx(s); /* * Send host notifications. */ host_notify_calendar_change(); #if CONFIG_DTRACE clock_track_calend_nowait(); #endif }
/* * clock_initialize_calendar: * * Set the calendar and related clocks * from the platform clock at boot or * wake event. * * Also sends host notifications. */ void clock_initialize_calendar(void) { clock_sec_t sys, secs = PEGetGMTTimeOfDay(); clock_usec_t microsys, microsecs = 0; spl_t s; s = splclock(); clock_lock(); commpage_disable_timestamp(); if ((long)secs >= (long)clock_boottime) { /* * Initialize the boot time based on the platform clock. */ if (clock_boottime == 0) clock_boottime = secs; /* * Calculate the new calendar epoch based on * the platform clock and the system clock. */ clock_get_system_microtime(&sys, µsys); TIME_SUB(secs, sys, microsecs, microsys, USEC_PER_SEC); /* * Set the new calendar epoch. */ clock_calend.epoch = secs; nanoseconds_to_absolutetime((uint64_t)microsecs * NSEC_PER_USEC, &clock_calend.offset); /* * Cancel any adjustment in progress. */ calend_adjtotal = clock_calend.adjdelta = 0; } clock_unlock(); splx(s); /* * Send host notifications. */ host_notify_calendar_change(); #if CONFIG_DTRACE clock_track_calend_nowait(); #endif }
/* FUNCTION: netmain_iface() * * Display interface status * * PARAM1: CLI_CTX CLI context * * RETURN: int 0 if successful, otherwise error code * * iface -i <iface> */ STATIC int netmain_iface(CLI_CTX ctx) { GIO *gio = ctx->gio; struct net *ifp; int iface; if (CLI_HELP(ctx)) { return (0); } if (CLI_DEFINED(ctx, 'i')) { iface = (int)CLI_VALUE(ctx, 'i'); if ((iface < 1) || (iface > (int)ifNumber)) return (CLI_ERR_PARAM); ifp = nets[iface - 1]; if (CLI_DEFINED(ctx, 'm')) { uint32_t mtu = (uint32_t)CLI_VALUE(ctx, 'm'); if ((mtu >= 128) && (mtu < 65536)) { ifp->n_mtu = mtu; /* new interface MTU value */ } else return (CLI_ERR_PARAM); } gio_printf(gio, "Interface %s - %s, MTU %d\n", ifp->name, ifp->n_mib->ifDescr, ifp->n_mtu); #ifdef IP_V4 gio_printf(gio, "IPv4 address: %u.%u.%u.%u, ", PUSH_IPADDR(ifp->n_ipaddr)); gio_printf(gio, "subnet mask: %u.%u.%u.%u, ", PUSH_IPADDR(ifp->snmask)); gio_printf(gio, "gateway: %u.%u.%u.%u\n", PUSH_IPADDR(ifp->n_defgw)); #endif /* IP_V4 */ { char buf[80]; gio_printf(gio, "Flags: %s\n", in_bit2str(&ifp_flags[0], ifp->n_flags, &buf[0], 80, ',')); } #if defined(IP_V6) && defined(IP6_MENUS) if (ifp->n_flags & NF_IPV6) { int i; char ip6buf[46]; /* tmp buffer for ipv6 address text */ for (i = 0; i < MAX_V6_ADDRS; i++) { if (ifp->v6addrs[i]) { gio_printf(gio, "IPv6 %6s addr: %s", v6types[i], print_ip6(&(ifp->v6addrs[i]->addr), ip6buf)); gio_printf(gio, " - %s\n", ip6addrstates[ifp->v6addrs[i]->flags & IA_STATEMASK]); } } } else gio_printf(gio, "No IPv6 addresses\n"); #endif /* IP_V6 && IP6_MENUS */ gio_printf(gio, "Status: Admin:%s Oper:%s for: %s\n", (ifp->n_mib->ifAdminStatus == 1) ? "up" : "down", (ifp->n_mib->ifOperStatus == 1) ? "up" : "down", print_uptime(TIME_SUB(sysuptime(), (ifp->n_mib->ifLastChange)))); gio_printf(gio, "rcvd: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n", ifp->n_mib->ifInErrors, ifp->n_mib->ifInDiscards, ifp->n_mib->ifInUcastPkts, ifp->n_mib->ifInNUcastPkts, ifp->n_mib->ifInOctets); gio_printf(gio, "sent: errors:%lu dropped:%lu station:%lu bcast:%lu bytes:%lu\n", ifp->n_mib->ifOutErrors, ifp->n_mib->ifOutDiscards, ifp->n_mib->ifOutUcastPkts, ifp->n_mib->ifOutNUcastPkts, ifp->n_mib->ifOutOctets); gio_printf(gio, "MAC address: "); gio_hexdump(gio, ifp->n_mib->ifPhysAddress, 6, TRUE, FALSE); gio_printf(gio, " \n"); #ifdef IP_MULTICAST /* Print any multicast addresses assigned to this iface */ #ifndef USE_IGMPV3 if (ifp->mc_list) { struct in_multi *imp; gio_printf(gio, " Multicast addresses: \n"); for (imp = ifp->mc_list; imp; imp = imp->inm_next) { #ifdef IP_V6 if (*(u_long *)&imp->ip6addr != 0x0) { char ip6buf[40]; /* tmp buffer for ipv6 address text */ gio_printf(gio, " %s\n", print_ip6(&(imp->ip6addr), ip6buf)); } else #endif /* IP_V6 */ { gio_printf(gio, " %u.%u.%u.%u\n", PUSH_IPADDR(imp->inm_addr)); } } } #else /* if USE_IGMPV3 defined*/ igmp_print_membership(ifp, gio); #endif /* USE_IGMPV3 */ #endif /* IP_MULTICAST */ } else /* list all interfaces */ { for (iface = 1; iface <= (int)ifNumber; iface++) { gio_printf(gio, "%2d: %s - %s\n", iface, nets[iface-1]->name, nets[iface-1]->n_mib->ifDescr); } } return (0); }