network-internal.c revision 3ad0c5d8a4e2e2fa7ffcccd7f3457f577908494e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
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 "strv.h"
#include "siphash24.h"
#include "dhcp-lease-internal.h"
#include "log.h"
#include "utf8.h"
#include "util.h"
#include "conf-parser.h"
#include "condition.h"
#include "network-internal.h"
#include "sd-ndisc.h"
/* fetch some persistent data unique (on this machine) to this device */
FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
if (name)
return name;
}
return NULL;
}
int r;
uint8_t *v;
if (!name)
return -ENOENT;
sz = sizeof(sd_id128_t) + l;
/* fetch some persistent data unique to this machine */
r = sd_id128_get_machine((sd_id128_t*) v);
if (r < 0)
return r;
/* Let's hash the machine ID plus the device name. We
* use a fixed, but originally randomly created hash
* key here. */
return 0;
}
char * const *match_paths,
char * const *match_drivers,
char * const *match_types,
char * const *match_names,
const struct ether_addr *dev_mac,
const char *dev_path,
const char *dev_parent_driver,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
return false;
return false;
return false;
return false;
return false;
if (!strv_isempty(match_paths) &&
return false;
if (!strv_isempty(match_drivers) &&
return false;
if (!strv_isempty(match_types) &&
return false;
if (!strv_isempty(match_names) &&
return false;
return true;
}
int config_parse_net_condition(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
bool negate;
Condition *c;
_cleanup_free_ char *s = NULL;
if (negate)
rvalue++;
if (!s)
return log_oom();
if (!c)
return log_oom();
if (*ret)
*ret = c;
return 0;
}
int config_parse_ifname(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char **s = data;
_cleanup_free_ char *n = NULL;
if (!n)
return log_oom();
log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
return 0;
}
free(*s);
if (*n) {
*s = n;
n = NULL;
} else
*s = NULL;
return 0;
}
int config_parse_ifnames(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
size_t l;
int r;
char *n;
if (!n)
return log_oom();
log_syntax(unit, LOG_ERR, filename, line, 0, "Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
free(n);
return 0;
}
r = strv_consume(sv, n);
if (r < 0)
return log_oom();
}
return 0;
}
int config_parse_ifalias(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char **s = data;
_cleanup_free_ char *n = NULL;
if (!n)
return log_oom();
log_syntax(unit, LOG_ERR, filename, line, 0, "Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
return 0;
}
free(*s);
if (*n) {
*s = n;
n = NULL;
} else
*s = NULL;
return 0;
}
int config_parse_hwaddr(const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
struct ether_addr *n;
int r;
if (!n)
return log_oom();
&n->ether_addr_octet[0],
&n->ether_addr_octet[1],
&n->ether_addr_octet[2],
&n->ether_addr_octet[3],
&n->ether_addr_octet[4],
&n->ether_addr_octet[5]);
if (r != 6) {
log_syntax(unit, LOG_ERR, filename, line, 0, "Not a valid MAC address, ignoring assignment: %s", rvalue);
free(n);
return 0;
}
*hwaddr = n;
return 0;
}
unsigned i;
assert(f);
for (i = 0; i < size; i++)
}
int size = 0;
struct in_addr *new_addresses;
int r;
if (!new_addresses)
return -ENOMEM;
else
if (!addr_str)
return -ENOMEM;
if (r <= 0)
continue;
size ++;
}
return size;
}
unsigned i;
assert(f);
for (i = 0; i < size; i++)
}
int size = 0;
struct in6_addr *new_addresses;
int r;
if (!new_addresses)
return -ENOMEM;
else
if (!addr_str)
return -ENOMEM;
if (r <= 0)
continue;
size++;
}
return size;
}
unsigned i;
assert(f);
for (i = 0; i < size; i++) {
routes[i].dst_prefixlen);
}
fputs("\n", f);
}
int deserialize_dhcp_routes(struct sd_dhcp_route **ret, size_t *ret_size, size_t *ret_allocated, const char *string) {
/* WORD FORMAT: dst_ip/dst_prefixlen,gw_ip */
unsigned n;
int r;
return -ENOMEM;
if(!entry)
return -ENOMEM;
/* get the subnet */
if (!tok_end)
continue;
*tok_end = '\0';
if (r == 0)
continue;
/* get the prefixlen */
if (!tok_end)
continue;
*tok_end = '\0';
if (r < 0 || n > 32)
continue;
/* get the gateway */
if (r == 0)
continue;
size++;
}
return 0;
}
assert(f);
return -ENOMEM;
return 0;
}
return -EINVAL;
}