network-internal.c revision a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8
/*-*- 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 <fnmatch.h>
#include "strv.h"
#include "siphash24.h"
#include "libudev-private.h"
#include "network-internal.h"
#include "dhcp-lease-internal.h"
#include "log.h"
#include "utf8.h"
#include "util.h"
#include "conf-parser.h"
#include "condition.h"
/* fetch some persistent data unique (on this machine) to this device */
"ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
if (name)
break;
}
return name;
}
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;
}
const char *match_path,
const char *match_driver,
const char *match_type,
const char *match_name,
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 0;
return 0;
return 0;
return 0;
return 0;
return 0;
if (match_driver) {
return 0;
return 0;
}
return 0;
return 0;
return 1;
}
}
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();
"Interface name is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
free(n);
return 0;
}
free(*s);
if (*n) {
*s = n;
n = NULL;
} else
*s = NULL;
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;
char *n;
if (!n)
return log_oom();
"Interface alias is not ASCII clean or is too long, ignoring assignment: %s", rvalue);
free(n);
return 0;
}
free(*s);
if (*n)
*s = n;
else {
free(n);
*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) {
"Not a valid MAC address, ignoring assignment: %s", rvalue);
free(n);
return 0;
}
*hwaddr = n;
return 0;
}
int r;
/* IPv4 */
if (r > 0) {
/* succsefully parsed IPv4 address */
return -EINVAL;
} else if (r < 0)
return -errno;
else {
/* not an IPv4 address, so let's try IPv6 */
if (r > 0) {
/* successfully parsed IPv6 address */
return -EINVAL;
} else if (r < 0)
return -errno;
else
return -EINVAL;
}
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;
}
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++)
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;
}