mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 00:47:10 +09:00
network-generator: add missing assertions
This commit is contained in:
@@ -110,6 +110,8 @@ static int address_new(Network *network, int family, unsigned char prefixlen,
|
||||
Address *address;
|
||||
|
||||
assert(network);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(addr);
|
||||
|
||||
address = new(Address, 1);
|
||||
if (!address)
|
||||
@@ -250,6 +252,7 @@ static int netdev_new(Context *context, const char *_kind, const char *_ifname,
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(_kind);
|
||||
|
||||
if (!ifname_valid(_ifname))
|
||||
return -EINVAL;
|
||||
@@ -364,6 +367,10 @@ static int network_set_dhcp_type(Context *context, const char *ifname, const cha
|
||||
DHCPType t;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(dhcp_type);
|
||||
|
||||
t = dracut_dhcp_type_from_string(dhcp_type);
|
||||
if (t < 0)
|
||||
return t;
|
||||
@@ -382,6 +389,9 @@ static int network_set_dhcp_type(Context *context, const char *ifname, const cha
|
||||
static int network_set_hostname(Context *context, const char *ifname, const char *hostname) {
|
||||
Network *network;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network)
|
||||
return -ENODEV;
|
||||
@@ -392,6 +402,9 @@ static int network_set_hostname(Context *context, const char *ifname, const char
|
||||
static int network_set_mtu(Context *context, const char *ifname, const char *mtu) {
|
||||
Network *network;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
if (isempty(mtu))
|
||||
return 0;
|
||||
|
||||
@@ -405,6 +418,10 @@ static int network_set_mtu(Context *context, const char *ifname, const char *mtu
|
||||
static int network_set_mac_address(Context *context, const char *ifname, const char *mac) {
|
||||
Network *network;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(mac);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network)
|
||||
return -ENODEV;
|
||||
@@ -416,6 +433,11 @@ static int network_set_address(Context *context, const char *ifname, int family,
|
||||
union in_addr_union *addr, union in_addr_union *peer) {
|
||||
Network *network;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(addr);
|
||||
|
||||
if (!in_addr_is_set(family, addr))
|
||||
return 0;
|
||||
|
||||
@@ -431,6 +453,10 @@ static int network_set_route(Context *context, const char *ifname, int family, u
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
|
||||
if (!(dest && in_addr_is_set(family, dest)) &&
|
||||
!(gateway && in_addr_is_set(family, gateway)))
|
||||
return 0;
|
||||
@@ -450,6 +476,10 @@ static int network_set_dns(Context *context, const char *ifname, const char *dns
|
||||
Network *network;
|
||||
int family, r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(dns);
|
||||
|
||||
r = in_addr_from_string_auto(dns, &family, &a);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -468,6 +498,9 @@ static int network_set_dhcp_use_dns(Context *context, const char *ifname, bool v
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network) {
|
||||
r = network_new(context, ifname, &network);
|
||||
@@ -484,6 +517,9 @@ static int network_set_vlan(Context *context, const char *ifname, const char *va
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network) {
|
||||
r = network_new(context, ifname, &network);
|
||||
@@ -498,6 +534,9 @@ static int network_set_bridge(Context *context, const char *ifname, const char *
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network) {
|
||||
r = network_new(context, ifname, &network);
|
||||
@@ -512,6 +551,9 @@ static int network_set_bond(Context *context, const char *ifname, const char *va
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
|
||||
network = network_get(context, ifname);
|
||||
if (!network) {
|
||||
r = network_new(context, ifname, &network);
|
||||
@@ -526,6 +568,10 @@ static int parse_cmdline_ip_mtu_mac(Context *context, const char *ifname, const
|
||||
const char *mtu, *p;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(value);
|
||||
|
||||
/* [<mtu>][:<macaddr>] */
|
||||
|
||||
p = strchr(value, ':');
|
||||
@@ -549,9 +595,15 @@ static int parse_cmdline_ip_mtu_mac(Context *context, const char *ifname, const
|
||||
}
|
||||
|
||||
static int parse_ip_address_one(int family, const char **value, union in_addr_union *ret) {
|
||||
const char *p = *value, *q, *buf;
|
||||
const char *p, *q, *buf;
|
||||
int r;
|
||||
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(value);
|
||||
assert(ret);
|
||||
|
||||
p = ASSERT_PTR(*value);
|
||||
|
||||
if (p[0] == ':') {
|
||||
*value = p + 1;
|
||||
return 0;
|
||||
@@ -592,6 +644,11 @@ static int parse_netmask_or_prefixlen(int family, const char **value, unsigned c
|
||||
const char *p, *q;
|
||||
int r;
|
||||
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(value);
|
||||
assert(*value);
|
||||
assert(ret);
|
||||
|
||||
r = parse_ip_address_one(family, value, &netmask);
|
||||
if (r > 0) {
|
||||
if (family == AF_INET6)
|
||||
@@ -618,9 +675,16 @@ static int parse_netmask_or_prefixlen(int family, const char **value, unsigned c
|
||||
}
|
||||
|
||||
static int parse_ip_dns_address_one(Context *context, const char *ifname, int family, const char **value) {
|
||||
const char *p = *value, *q, *buf;
|
||||
const char *p, *q, *buf;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(ifname);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(value);
|
||||
|
||||
p = ASSERT_PTR(*value);
|
||||
|
||||
if (isempty(p))
|
||||
return 0;
|
||||
|
||||
@@ -661,6 +725,10 @@ static int parse_cmdline_ip_address(Context *context, int family, const char *va
|
||||
unsigned char prefixlen;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(IN_SET(family, AF_INET, AF_INET6));
|
||||
assert(value);
|
||||
|
||||
/* ip=<client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<interface>:{none|off|dhcp|on|any|dhcp6|auto6|ibft|link6}[:[<mtu>][:<macaddr>]]
|
||||
* ip=<client-IP>:[<peer>]:<gateway-IP>:<netmask>:<client_hostname>:<interface>:{none|off|dhcp|on|any|dhcp6|auto6|ibft|link6}[:[<dns1>][:<dns2>]] */
|
||||
|
||||
@@ -747,6 +815,9 @@ static int parse_cmdline_ip_interface(Context *context, const char *value) {
|
||||
const char *ifname, *dhcp_type, *p;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(value);
|
||||
|
||||
/* ip=<interface>:{dhcp|on|any|dhcp6|auto6|link6}[:[<mtu>][:<macaddr>]] */
|
||||
|
||||
p = strchr(value, ':');
|
||||
@@ -776,6 +847,9 @@ static int parse_cmdline_ip(Context *context, const char *key, const char *value
|
||||
const char *p;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -800,6 +874,9 @@ static int parse_cmdline_rd_route(Context *context, const char *key, const char
|
||||
const char *buf, *p;
|
||||
int family, r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
/* rd.route=<net>/<netmask>:<gateway>[:<interface>] */
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
@@ -842,6 +919,9 @@ static int parse_cmdline_rd_route(Context *context, const char *key, const char
|
||||
}
|
||||
|
||||
static int parse_cmdline_nameserver(Context *context, const char *key, const char *value) {
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -851,6 +931,9 @@ static int parse_cmdline_nameserver(Context *context, const char *key, const cha
|
||||
static int parse_cmdline_rd_peerdns(Context *context, const char *key, const char *value) {
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return network_set_dhcp_use_dns(context, "", true);
|
||||
|
||||
@@ -866,6 +949,9 @@ static int parse_cmdline_vlan(Context *context, const char *key, const char *val
|
||||
NetDev *netdev;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -890,6 +976,9 @@ static int parse_cmdline_bridge(Context *context, const char *key, const char *v
|
||||
NetDev *netdev;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -928,6 +1017,9 @@ static int parse_cmdline_bond(Context *context, const char *key, const char *val
|
||||
NetDev *netdev;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
return -EINVAL;
|
||||
|
||||
@@ -985,6 +1077,9 @@ static int parse_cmdline_ifname(Context *context, const char *key, const char *v
|
||||
const char *name, *p;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
/* ifname=<interface>:<MAC> */
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
@@ -1009,6 +1104,9 @@ static int parse_cmdline_ifname_policy(Context *context, const char *key, const
|
||||
Link *link;
|
||||
int r;
|
||||
|
||||
assert(context);
|
||||
assert(key);
|
||||
|
||||
/* net.ifname-policy=policy1[,policy2,...][,<MAC>] */
|
||||
|
||||
if (proc_cmdline_value_missing(key, value))
|
||||
@@ -1139,6 +1237,9 @@ void context_clear(Context *context) {
|
||||
}
|
||||
|
||||
static int address_dump(Address *address, FILE *f) {
|
||||
assert(address);
|
||||
assert(f);
|
||||
|
||||
fprintf(f,
|
||||
"\n[Address]\n"
|
||||
"Address=%s\n",
|
||||
@@ -1150,6 +1251,9 @@ static int address_dump(Address *address, FILE *f) {
|
||||
}
|
||||
|
||||
static int route_dump(Route *route, FILE *f) {
|
||||
assert(route);
|
||||
assert(f);
|
||||
|
||||
fputs("\n[Route]\n", f);
|
||||
if (in_addr_is_set(route->family, &route->dest))
|
||||
fprintf(f, "Destination=%s\n",
|
||||
|
||||
Reference in New Issue
Block a user