View | Details | Raw Unified | Return to bug 217763
Collapse All | Expand All

(-)snmp_mibII/mibII.c (-4 / +59 lines)
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);
(-)snmp_mibII/mibII.h (-4 / +2 lines)
Lines 57-64 Link Here
57
#include "snmp_mibII.h"
57
#include "snmp_mibII.h"
58
#include "mibII_tree.h"
58
#include "mibII_tree.h"
59
59
60
/* maximum size of the interface alias */
60
/* maximum size of the interface alias unless overridden with net.ifdescr_maxlen */
61
#define	MIBIF_ALIAS_SIZE	(64 + 1)
61
#define	MIBIF_ALIAS_SIZE	1024
62
62
63
/*
63
/*
64
 * Interface list and flags.
64
 * Interface list and flags.
Lines 81-88 Link Here
81
	uint64_t	hc_imcasts;
81
	uint64_t	hc_imcasts;
82
	uint64_t	hc_ipackets;
82
	uint64_t	hc_ipackets;
83
83
84
	/* this should be made public */
85
	char		alias[MIBIF_ALIAS_SIZE];
86
};
84
};
87
#define	MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private))
85
#define	MIBIF_PRIV(IFP) ((struct mibif_private *)((IFP)->private))
88
86
(-)snmp_mibII/mibII_interfaces.c (-1 / +1 lines)
Lines 528-534 Link Here
528
		break;
528
		break;
529
529
530
	  case LEAF_ifAlias:
530
	  case LEAF_ifAlias:
531
		ret = string_get(value, MIBIF_PRIV(ifp)->alias, -1);
531
		ret = string_get(value, ifp->alias, ifp->alias_size - 1);
532
		break;
532
		break;
533
533
534
	  case LEAF_ifCounterDiscontinuityTime:
534
	  case LEAF_ifCounterDiscontinuityTime:
(-)snmp_mibII/snmp_mibII.h (+3 lines)
Lines 80-85 Link Here
80
	/* to be set by ifType specific modules. This is ifSpecific. */
80
	/* to be set by ifType specific modules. This is ifSpecific. */
81
	struct asn_oid	spec_oid;
81
	struct asn_oid	spec_oid;
82
82
83
	char		*alias;
84
	size_t		alias_size;
85
83
	/* private data - don't touch */
86
	/* private data - don't touch */
84
	void		*private;
87
	void		*private;
85
};
88
};

Return to bug 217763