Deleted Added
full compact
107a108,119
> /* baud rate of fastest interface */
> uint64_t mibif_maxspeed;
>
> /* user-forced update interval */
> u_int mibif_force_hc_update_interval;
>
> /* current update interval */
> u_int mibif_hc_update_interval;
>
> /* HC update timer handle */
> static void *hc_update_timer;
>
283,284c295,296
< /*
< * Fetch new MIB data.
---
> /**
> * Fetch the GENERIC IFMIB and update the HC counters
286,287c298,299
< int
< mib_fetch_ifmib(struct mibif *ifp)
---
> static int
> fetch_generic_mib(struct mibif *ifp, const struct ifmibdata *old)
291,292c303
< void *newmib;
< struct ifmibdata oldmib = ifp->mib;
---
> struct mibif_private *p = ifp->private;
309a321,427
> * Assume that one of the two following compounds is optimized away
> */
> if (ULONG_MAX >= 0xffffffffffffffffULL) {
> p->hc_inoctets = ifp->mib.ifmd_data.ifi_ibytes;
> p->hc_outoctets = ifp->mib.ifmd_data.ifi_obytes;
> p->hc_omcasts = ifp->mib.ifmd_data.ifi_omcasts;
> p->hc_opackets = ifp->mib.ifmd_data.ifi_opackets;
> p->hc_imcasts = ifp->mib.ifmd_data.ifi_imcasts;
> p->hc_ipackets = ifp->mib.ifmd_data.ifi_ipackets;
>
> } else if (ULONG_MAX >= 0xffffffff) {
>
> #define UPDATE(HC, MIB) \
> if (old->ifmd_data.MIB > ifp->mib.ifmd_data.MIB) \
> p->HC += (0x100000000ULL + \
> ifp->mib.ifmd_data.MIB) - \
> old->ifmd_data.MIB; \
> else \
> p->HC += ifp->mib.ifmd_data.MIB - \
> old->ifmd_data.MIB;
>
> UPDATE(hc_inoctets, ifi_ibytes)
> UPDATE(hc_outoctets, ifi_obytes)
> UPDATE(hc_omcasts, ifi_omcasts)
> UPDATE(hc_opackets, ifi_opackets)
> UPDATE(hc_imcasts, ifi_imcasts)
> UPDATE(hc_ipackets, ifi_ipackets)
>
> #undef UPDATE
> } else
> abort();
> return (0);
> }
>
> /**
> * Update the 64-bit interface counters
> */
> static void
> update_hc_counters(void *arg __unused)
> {
> struct mibif *ifp;
> struct ifmibdata oldmib;
>
> TAILQ_FOREACH(ifp, &mibif_list, link) {
> oldmib = ifp->mib;
> (void)fetch_generic_mib(ifp, &oldmib);
> }
> }
>
> /**
> * Recompute the poll timer for the HC counters
> */
> void
> mibif_reset_hc_timer(void)
> {
> u_int ticks;
>
> if ((ticks = mibif_force_hc_update_interval) == 0) {
> if (mibif_maxspeed <= 10000000) {
> /* at 10Mbps overflow needs 3436 seconds */
> ticks = 3000 * 100; /* 50 minutes */
> } else if (mibif_maxspeed <= 100000000) {
> /* at 100Mbps overflow needs 343 seconds */
> ticks = 300 * 100; /* 5 minutes */
> } else if (mibif_maxspeed < 650000000) {
> /* at 622Mbps overflow needs 53 seconds */
> ticks = 40 * 100; /* 40 seconds */
> } else if (mibif_maxspeed <= 1000000000) {
> /* at 1Gbps overflow needs 34 seconds */
> ticks = 20 * 100; /* 20 seconds */
> } else {
> /* at 10Gbps overflow needs 3.4 seconds */
> ticks = 100; /* 1 seconds */
> }
> }
>
> if (ticks == mibif_hc_update_interval)
> return;
>
> if (hc_update_timer != NULL) {
> timer_stop(hc_update_timer);
> hc_update_timer = NULL;
> }
> update_hc_counters(NULL);
> if ((hc_update_timer = timer_start_repeat(ticks * 10, ticks * 10,
> update_hc_counters, NULL, module)) == NULL) {
> syslog(LOG_ERR, "timer_start(%u): %m", ticks);
> return;
> }
> mibif_hc_update_interval = ticks;
> }
>
> /*
> * Fetch new MIB data.
> */
> int
> mib_fetch_ifmib(struct mibif *ifp)
> {
> int name[6];
> size_t len;
> void *newmib;
> struct ifmibdata oldmib = ifp->mib;
>
> if (fetch_generic_mib(ifp, &oldmib) == -1)
> return (-1);
>
> /*
326a445,448
> if (ifp->mib.ifmd_data.ifi_baudrate > mibif_maxspeed) {
> mibif_maxspeed = ifp->mib.ifmd_data.ifi_baudrate;
> mibif_reset_hc_timer();
> }
330a453,457
> name[0] = CTL_NET;
> name[1] = PF_LINK;
> name[2] = NETLINK_GENERIC;
> name[3] = IFMIB_IFDATA;
> name[4] = ifp->sysindex;
521a649
> struct mibif *ifp1;
533a662,673
>
> /* if this was the fastest interface - recompute this */
> if (ifp->mib.ifmd_data.ifi_baudrate == mibif_maxspeed) {
> mibif_maxspeed = ifp->mib.ifmd_data.ifi_baudrate;
> TAILQ_FOREACH(ifp1, &mibif_list, link)
> if (ifp1->mib.ifmd_data.ifi_baudrate > mibif_maxspeed)
> mibif_maxspeed =
> ifp1->mib.ifmd_data.ifi_baudrate;
> mibif_reset_hc_timer();
> }
>
> free(ifp->private);
591a732,738
> if ((ifp->private = malloc(sizeof(struct mibif_private))) == NULL) {
> syslog(LOG_WARNING, "%s: %m", __func__);
> free(ifp);
> return (NULL);
> }
> memset(ifp->private, 0, sizeof(struct mibif_private));
>