projects
/
project
/
odhcpd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ubus: use safe iterator
[project/odhcpd.git]
/
src
/
ndp.c
diff --git
a/src/ndp.c
b/src/ndp.c
index
6d18bb5
..
17ec8b4
100644
(file)
--- a/
src/ndp.c
+++ b/
src/ndp.c
@@
-111,6
+111,10
@@
int init_ndp(void)
// Open ICMPv6 socket
ping_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
// Open ICMPv6 socket
ping_socket = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_ICMPV6);
+ if (ping_socket < 0) {
+ syslog(LOG_ERR, "Unable to open raw socket: %s", strerror(errno));
+ return -1;
+ }
int val = 2;
setsockopt(ping_socket, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val));
int val = 2;
setsockopt(ping_socket, IPPROTO_RAW, IPV6_CHECKSUM, &val, sizeof(val));
@@
-167,6
+171,7
@@
int setup_ndp_interface(struct interface *iface, bool enable)
memcpy(entry, iface->static_ndp, iface->static_ndp_len);
for (entry = strtok_r(entry, " ", &saveptr); entry; entry = strtok_r(NULL, " ", &saveptr)) {
memcpy(entry, iface->static_ndp, iface->static_ndp_len);
for (entry = strtok_r(entry, " ", &saveptr); entry; entry = strtok_r(NULL, " ", &saveptr)) {
+ char *sep;
struct ndp_neighbor *n = malloc(sizeof(*n));
if (!n) {
syslog(LOG_ERR, "Malloc failed for static NDP-prefix %s", entry);
struct ndp_neighbor *n = malloc(sizeof(*n));
if (!n) {
syslog(LOG_ERR, "Malloc failed for static NDP-prefix %s", entry);
@@
-176,12
+181,20
@@
int setup_ndp_interface(struct interface *iface, bool enable)
n->iface = iface;
n->timeout = 0;
n->iface = iface;
n->timeout = 0;
-
char ipbuf[INET6_ADDRSTRLEN]
;
- if (
sscanf(entry, "%45s/%hhu", ipbuf, &n->len) < 2
- || n->len > 128 || inet_pton(AF_INET6, ipbuf, &n->addr) != 1) {
+
sep = strchr(entry, '/')
;
+ if (
!sep) {
+ free(n);
syslog(LOG_ERR, "Invalid static NDP-prefix %s", entry);
return -1;
}
syslog(LOG_ERR, "Invalid static NDP-prefix %s", entry);
return -1;
}
+
+ *sep = 0;
+ n->len = atoi(sep + 1);
+ if (inet_pton(AF_INET6, entry, &n->addr) != 1 || n->len > 128) {
+ free(n);
+ syslog(LOG_ERR, "Invalid static NDP-prefix %s/%s", entry, sep + 1);
+ return -1;
+ }
list_add(&n->head, &neighbors);
}
list_add(&n->head, &neighbors);
}