Lines 445-450
Link Here
|
445 |
struct ifmibdata oldmib = ifp->mib; |
445 |
struct ifmibdata oldmib = ifp->mib; |
446 |
struct ifreq irr; |
446 |
struct ifreq irr; |
447 |
|
447 |
|
|
|
448 |
static int kmib[2] = { -1, 0 }; /* for sysctl net.ifdescr_maxlen */ |
449 |
size_t kmiblen = sizeof(kmib) / sizeof(kmib[0]); |
450 |
unsigned int alias_maxlen = MIBIF_ALIAS_SIZE; |
451 |
|
448 |
if (fetch_generic_mib(ifp, &oldmib) == -1) |
452 |
if (fetch_generic_mib(ifp, &oldmib) == -1) |
449 |
return (-1); |
453 |
return (-1); |
450 |
|
454 |
|
Lines 515-532
Link Here
|
515 |
} |
519 |
} |
516 |
|
520 |
|
517 |
out: |
521 |
out: |
|
|
522 |
|
523 |
/* |
524 |
* Find sysctl mib for net.ifdescr_maxlen (one time). |
525 |
* kmib[0] == -1 at first call to mib_fetch_ifmib(). |
526 |
* Then kmib[0] > 0 if we found sysctl mib for net.ifdescr_maxlen. |
527 |
* Else, kmib[0] == 0 (unexpected error from a kernel). |
528 |
*/ |
529 |
if (kmib[0] < 0 && |
530 |
sysctlnametomib("net.ifdescr_maxlen", kmib, &kmiblen) < 0) { |
531 |
kmib[0] = 0; |
532 |
syslog(LOG_WARNING, "sysctlnametomib net.ifdescr_maxlen: %m"); |
533 |
} |
534 |
|
535 |
/* |
536 |
* Fetch net.ifdescr_maxlen value every time to catch up with changes. |
537 |
*/ |
538 |
len = sizeof(alias_maxlen); |
539 |
if (kmib[0] && sysctl(kmib, 2, &alias_maxlen, &len, NULL, 0) < 0) { |
540 |
/* unexpected error from the kernel, use default value */ |
541 |
alias_maxlen = MIBIF_ALIAS_SIZE; |
542 |
syslog(LOG_WARNING, "sysctl net.ifdescr_maxlen: %m"); |
543 |
} |
544 |
|
545 |
/* |
546 |
* Kernel limit might be decreased after interfaces got |
547 |
* their descriptions assigned. Try to obtain them anyway. |
548 |
*/ |
549 |
if (alias_maxlen == 0) |
550 |
alias_maxlen = MIBIF_ALIAS_SIZE; |
551 |
|
552 |
/* |
553 |
* Allocate maximum memory for a buffer and later reallocate |
554 |
* to free extra memory. |
555 |
*/ |
556 |
if ((ifp->alias = malloc(alias_maxlen)) == NULL) { |
557 |
syslog(LOG_WARNING, "malloc(%d) failed: %m", (int)alias_maxlen); |
558 |
goto fin; |
559 |
} |
560 |
|
518 |
strlcpy(irr.ifr_name, ifp->name, sizeof(irr.ifr_name)); |
561 |
strlcpy(irr.ifr_name, ifp->name, sizeof(irr.ifr_name)); |
519 |
irr.ifr_buffer.buffer = MIBIF_PRIV(ifp)->alias; |
562 |
irr.ifr_buffer.buffer = ifp->alias; |
520 |
irr.ifr_buffer.length = sizeof(MIBIF_PRIV(ifp)->alias); |
563 |
irr.ifr_buffer.length = alias_maxlen; |
521 |
if (ioctl(mib_netsock, SIOCGIFDESCR, &irr) == -1) { |
564 |
if (ioctl(mib_netsock, SIOCGIFDESCR, &irr) == -1) { |
522 |
MIBIF_PRIV(ifp)->alias[0] = 0; |
565 |
free(ifp->alias); |
|
|
566 |
ifp->alias = NULL; |
523 |
if (errno != ENOMSG) |
567 |
if (errno != ENOMSG) |
524 |
syslog(LOG_WARNING, "SIOCGIFDESCR (%s): %m", ifp->name); |
568 |
syslog(LOG_WARNING, "SIOCGIFDESCR (%s): %m", ifp->name); |
525 |
} else if (irr.ifr_buffer.buffer == NULL) { |
569 |
} else if (irr.ifr_buffer.buffer == NULL) { |
526 |
MIBIF_PRIV(ifp)->alias[0] = 0; |
570 |
free(ifp->alias); |
|
|
571 |
ifp->alias = NULL; |
527 |
syslog(LOG_WARNING, "SIOCGIFDESCR (%s): too long (%zu)", |
572 |
syslog(LOG_WARNING, "SIOCGIFDESCR (%s): too long (%zu)", |
528 |
ifp->name, irr.ifr_buffer.length); |
573 |
ifp->name, irr.ifr_buffer.length); |
|
|
574 |
} else { |
575 |
ifp->alias_size = strnlen(ifp->alias, alias_maxlen) + 1; |
576 |
if (ifp->alias_size < alias_maxlen) |
577 |
ifp->alias = realloc(ifp->alias, ifp->alias_size); |
529 |
} |
578 |
} |
|
|
579 |
|
580 |
fin: |
530 |
ifp->mibtick = get_ticks(); |
581 |
ifp->mibtick = get_ticks(); |
531 |
return (0); |
582 |
return (0); |
532 |
} |
583 |
} |
Lines 706-711
Link Here
|
706 |
mibif_reset_hc_timer(); |
757 |
mibif_reset_hc_timer(); |
707 |
} |
758 |
} |
708 |
|
759 |
|
|
|
760 |
if(ifp->alias) { |
761 |
free(ifp->alias); |
762 |
ifp->alias = NULL; |
763 |
} |
709 |
free(ifp->private); |
764 |
free(ifp->private); |
710 |
ifp->private = NULL; |
765 |
ifp->private = NULL; |
711 |
free(ifp->physaddr); |
766 |
free(ifp->physaddr); |