sd-ndisc.c revision cbe91b3cba3298866f51abfa598c5751e90fd390
/***
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 <string.h>
#include <stdbool.h>
#include "async.h"
#include "list.h"
#include "socket-util.h"
#include "icmp6-util.h"
#include "sd-ndisc.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
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 (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 r;
}
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) {
int r, buflen = 0;
assert(s);
if (r < 0 || buflen <= 0)
if (!ra)
return -ENOMEM;
if (len < 0) {
return 0;
}
return 0;
if (ra->nd_ra_code != 0)
return 0;
if (event != SD_NDISC_EVENT_ROUTER_ADVERTISMENT_NONE) {
if (r < 0) {
strerror(-r));
return 0;
}
}
return 0;
}
struct ether_addr unset = { };
int r;
assert(s);
} else {
if (r < 0)
else {
}
next_timeout, 0,
if (r < 0) {
ndisc_notify(nd, r);
return 0;
}
if (r < 0)
return 0;
if (r < 0)
return 0;
}
return 0;
}
ndisc_init(nd);
return 0;
}
int r;
return -EINVAL;
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;
}