net-util.c revision 2cc412b59353576cece2d5b30c6a39c70552f0a0
/*-*- 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"
#include "condition.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 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;
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) {
/* 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;
}