diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/filter.h | 5 | ||||
| -rw-r--r-- | lib/log.c | 4 | ||||
| -rw-r--r-- | lib/sockopt.c | 19 | ||||
| -rw-r--r-- | lib/sockopt.h | 3 | ||||
| -rw-r--r-- | lib/str.c | 42 | ||||
| -rw-r--r-- | lib/zebra.h | 5 |
6 files changed, 49 insertions, 29 deletions
diff --git a/lib/filter.h b/lib/filter.h index 37535cb13b..e6ccd33b3a 100644 --- a/lib/filter.h +++ b/lib/filter.h @@ -25,6 +25,11 @@ #include "if.h" +/* Filter direction. */ +#define FILTER_IN 0 +#define FILTER_OUT 1 +#define FILTER_MAX 2 + /* Filter type is made by `permit', `deny' and `dynamic'. */ enum filter_type { @@ -179,6 +179,7 @@ static void vzlog (struct zlog *zl, int priority, const char *format, va_list args) { char proto_str[32]; + int original_errno = errno; struct timestamp_control tsctl; tsctl.already_rendered = 0; @@ -197,6 +198,7 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list args) fflush (stderr); /* In this case we return at here. */ + errno = original_errno; return; } tsctl.precision = zl->timestamp_precision; @@ -249,6 +251,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list args) if (priority <= zl->maxlvl[ZLOG_DEST_MONITOR]) vty_log ((zl->record_priority ? zlog_priority[priority] : NULL), proto_str, format, &tsctl, args); + + errno = original_errno; } static char * diff --git a/lib/sockopt.c b/lib/sockopt.c index 257271bc0b..d8204936f9 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -219,6 +219,7 @@ setsockopt_ipv6_tclass(int sock, int tclass) int setsockopt_ipv4_multicast(int sock, int optname, + struct in_addr if_addr, unsigned int mcast_addr, unsigned int ifindex) { @@ -279,18 +280,20 @@ setsockopt_ipv4_multicast(int sock, #elif defined(HAVE_BSD_STRUCT_IP_MREQ_HACK) /* #if OS_TYPE */ /* standard BSD API */ - struct in_addr m; struct ip_mreq mreq; int ret; assert(optname == IP_ADD_MEMBERSHIP || optname == IP_DROP_MEMBERSHIP); - m.s_addr = htonl(ifindex); memset (&mreq, 0, sizeof(mreq)); mreq.imr_multiaddr.s_addr = mcast_addr; - mreq.imr_interface = m; - +#if !defined __OpenBSD__ + mreq.imr_interface.s_addr = htonl (ifindex); +#else + mreq.imr_interface.s_addr = if_addr.s_addr; +#endif + ret = setsockopt (sock, IPPROTO_IP, optname, (void *)&mreq, sizeof(mreq)); if ((ret < 0) && (optname == IP_ADD_MEMBERSHIP) && (errno == EADDRINUSE)) { @@ -318,7 +321,7 @@ setsockopt_ipv4_multicast(int sock, * Set IP_MULTICAST_IF socket option in an OS-dependent manner. */ int -setsockopt_ipv4_multicast_if(int sock, +setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, unsigned int ifindex) { @@ -336,7 +339,11 @@ setsockopt_ipv4_multicast_if(int sock, #elif defined(HAVE_BSD_STRUCT_IP_MREQ_HACK) struct in_addr m; - m.s_addr = htonl(ifindex); +#if !defined __OpenBSD__ + m.s_addr = htonl (ifindex); +#else + m.s_addr = if_addr.s_addr; +#endif return setsockopt (sock, IPPROTO_IP, IP_MULTICAST_IF, (void *)&m, sizeof(m)); #else diff --git a/lib/sockopt.h b/lib/sockopt.h index cb14efc7ba..a597314c3d 100644 --- a/lib/sockopt.h +++ b/lib/sockopt.h @@ -83,9 +83,10 @@ extern int setsockopt_ipv6_tclass (int, int); (((af) == AF_INET) : SOPT_SIZE_CMSG_IFINDEX_IPV4() \ ? SOPT_SIZE_CMSG_PKTINFO_IPV6()) -extern int setsockopt_ipv4_multicast_if(int sock, +extern int setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr, unsigned int ifindex); extern int setsockopt_ipv4_multicast(int sock, int optname, + struct in_addr if_addr, unsigned int mcast_addr, unsigned int ifindex); extern int setsockopt_ipv4_tos(int sock, int tos); @@ -54,26 +54,34 @@ snprintf(char *str, size_t size, const char *format, ...) #endif #ifndef HAVE_STRLCPY -/** - * Like strncpy but does not 0 fill the buffer and always null - * terminates. - * - * @param bufsize is the size of the destination buffer. - * - * @return index of the terminating byte. - **/ +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ size_t -strlcpy(char *d, const char *s, size_t bufsize) +strlcpy(char *dst, const char *src, size_t dsize) { - size_t len = strlen(s); - size_t ret = len; - if (bufsize > 0) { - if (len >= bufsize) - len = bufsize-1; - memcpy(d, s, len); - d[len] = 0; + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } } - return ret; + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ } #endif diff --git a/lib/zebra.h b/lib/zebra.h index 59c154ba46..b3a814c0d2 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -522,11 +522,6 @@ typedef enum { #define SAFI_ENCAP 7 /* per IANA */ #define SAFI_MAX 8 -/* Filter direction. */ -#define FILTER_IN 0 -#define FILTER_OUT 1 -#define FILTER_MAX 2 - /* Default Administrative Distance of each protocol. */ #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 #define ZEBRA_CONNECT_DISTANCE_DEFAULT 0 |
