sd-ndisc.c revision cddf4d81eacfc81cf761619fcb67bc07a744a6d1
/***
This file is part of systemd.
Copyright (C) 2014 Intel Corporation. All rights reserved.
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#include <string.h>
#include "sd-ndisc.h"
#include "alloc-util.h"
#include "async.h"
#include "icmp6-util.h"
#include "in-addr-util.h"
#include "list.h"
#include "socket-util.h"
#include "string-util.h"
#define NDISC_MAX_ROUTER_SOLICITATIONS 3
enum NDiscState {
_NDISC_STATE_INVALID = -1,
};
#define IP6_MIN_MTU (unsigned)1280
#define NDISC_OPT_LEN_UNITS 8
#define ND_RA_FLAG_PREF 0x18
#define ND_RA_FLAG_PREF_LOW 0x03
#define ND_RA_FLAG_PREF_MEDIUM 0x0
#define ND_RA_FLAG_PREF_HIGH 0x1
#define ND_RA_FLAG_PREF_INVALID 0x2
typedef struct NDiscPrefix NDiscPrefix;
struct NDiscPrefix {
unsigned n_ref;
};
struct sd_ndisc {
unsigned n_ref;
enum NDiscState state;
int event_priority;
int index;
struct ether_addr mac_addr;
int fd;
int nd_sent;
void *userdata;
};
#define log_ndisc(p, fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "NDisc CLIENT: " fmt, ##__VA_ARGS__)
if (!prefix)
return NULL;
return NULL;
return NULL;
}
if (!prefix)
return -ENOMEM;
return 0;
}
void *userdata) {
return 0;
}
return 0;
}
if (mac_addr)
else
return 0;
}
int r;
if (event)
else {
if (r < 0)
return 0;
}
return 0;
}
return 0;
}
}
if (!nd)
return NULL;
return nd;
}
return 0;
}
NDiscPrefix *prefix, *p;
if (!nd)
return NULL;
return NULL;
ndisc_init(nd);
return NULL;
}
if (!nd)
return -ENOMEM;
return 0;
}
return -ENOMSG;
return 0;
}
return -EADDRNOTAVAIL;
return 0;
}
NDiscPrefix *prefix, *p;
int r;
if (r < 0)
return r;
continue;
}
return 0;
}
}
return -EADDRNOTAVAIL;
}
const struct nd_opt_prefix_info *prefix_opt) {
char time_string[FORMAT_TIMESPAN_MAX];
int r;
return -ENOMSG;
return 0;
if (in_addr_is_link_local(AF_INET6, (const union in_addr_union *) &prefix_opt->nd_opt_pi_prefix) > 0)
return 0;
if (lifetime_valid < lifetime_preferred)
return 0;
if (r < 0 && r != -EADDRNOTAVAIL)
return r;
/* if router advertisment prefix valid timeout is zero, the timeout
callback will be called immediately to clean up the prefix */
if (r == -EADDRNOTAVAIL) {
if (r < 0)
return r;
} else {
}
}
if (r < 0)
return r;
return 0;
}
void *opt;
struct nd_opt_hdr *opt_hdr;
if (len < NDISC_OPT_LEN_UNITS) {
return -ENOMSG;
}
struct nd_opt_mtu *opt_mtu;
struct nd_opt_prefix_info *opt_prefix;
if (opt_hdr->nd_opt_len == 0)
return -ENOMSG;
switch (opt_hdr->nd_opt_type) {
case ND_OPT_MTU:
}
break;
opt_prefix = opt;
break;
}
}
if (len > 0)
return 0;
}
static int ndisc_router_advertisment_recv(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
union {
} control = {};
union sockaddr_union sa = {};
.msg_namelen = sizeof(sa),
.msg_iovlen = 1,
.msg_control = &control,
.msg_controllen = sizeof(control),
};
unsigned lifetime;
assert(s);
if (r < 0)
return -errno;
else if (buflen < 0)
/* This really should not happen */
return -EIO;
if (!ra)
return -ENOMEM;
if (len < 0) {
return 0;
return -errno;
return 0;
} else if (msg.msg_namelen == 0)
log_ndisc(nd, "Received invalid source address size from ICMPv6 socket: %zu bytes", (size_t)msg.msg_namelen);
return 0;
} else
if (hops != 255) {
return 0;
}
break;
}
}
return 0;
}
return 0;
if (ra->nd_ra_code != 0)
return 0;
switch (pref) {
case ND_RA_FLAG_PREF_LOW:
case ND_RA_FLAG_PREF_HIGH:
break;
default:
break;
}
lifetime);
if (r < 0) {
return 0;
}
if (nd->router_callback)
return 0;
}
int r;
assert(s);
} else {
if (r < 0)
else {
}
next_timeout, 0,
if (r < 0) {
/* we cannot continue if we are unable to rearm the timer */
return 0;
}
if (r < 0)
return 0;
if (r < 0)
return 0;
}
return 0;
}
ndisc_init(nd);
return 0;
}
int r;
return -EBUSY;
return -EINVAL;
if (r < 0)
return r;
if (r < 0)
goto error;
if (r < 0)
goto error;
if (r < 0)
goto error;
0, 0, ndisc_router_solicitation_timeout, nd);
if (r < 0)
goto error;
if (r < 0)
goto error;
if (r < 0)
ndisc_init(nd);
else
return r;
}