net-util.c revision d69b12ac8aed834e4a8220d19c6895ef04c73679
/*-*- 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 "net-util.h"
#include "log.h"
#include "utf8.h"
#include "util.h"
#include "conf-parser.h"
const char *match_path,
const char *match_driver,
const char *match_type,
const char *match_name,
const char *dev_mac,
const char *dev_path,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
return 0;
return 0;
return 0;
return 0;
return 0;
return 1;
}
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;
char *n;
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;
else {
free(n);
*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)
else if (r < 0)
return -errno;
else {
/* not an IPv4 address, so let's try IPv6 */
if (r > 0)
else if (r < 0)
return -errno;
else
return -EINVAL;
}
return 0;
}