summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorSusant Sahani <ssahani@vmware.com>2021-01-17 07:38:33 +0100
committerGitHub <noreply@github.com>2021-01-17 07:38:33 +0100
commitcda7fc8db36585c508bcfe4b22adaec82c686f1c (patch)
treeacf51795db5b25b8fa12259852a68ae7c70c495a /src/network
parentman: clarify what network scopes are (diff)
downloadsystemd-cda7fc8db36585c508bcfe4b22adaec82c686f1c.tar.xz
systemd-cda7fc8db36585c508bcfe4b22adaec82c686f1c.zip
network: tighten variable scope used in loop (#18277)
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkctl.c11
-rw-r--r--src/network/networkd-address-pool.c3
-rw-r--r--src/network/networkd-address.c3
-rw-r--r--src/network/networkd-brvlan.c13
-rw-r--r--src/network/networkd-dhcp-common.c3
-rw-r--r--src/network/networkd-dhcp4.c4
-rw-r--r--src/network/networkd-speed-meter.c3
-rw-r--r--src/network/test-networkd-conf.c3
-rw-r--r--src/network/wait-online/manager.c3
9 files changed, 20 insertions, 26 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index a4db632a76..512f9ba63b 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -580,8 +580,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
_cleanup_(link_info_array_freep) LinkInfo *links = NULL;
_cleanup_close_ int fd = -1;
- size_t allocated = 0, c = 0, j;
- sd_netlink_message *i;
+ size_t allocated = 0, c = 0;
int r;
assert(rtnl);
@@ -606,7 +605,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
return log_oom();
}
- for (i = reply; i; i = sd_netlink_message_next(i)) {
+ for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i)) {
if (!GREEDY_REALLOC0(links, allocated, c + 2)) /* We keep one trailing one as marker */
return -ENOMEM;
@@ -645,7 +644,7 @@ static int acquire_link_info(sd_bus *bus, sd_netlink *rtnl, char **patterns, Lin
typesafe_qsort(links, c, link_info_compare);
if (bus)
- for (j = 0; j < c; j++)
+ for (size_t j = 0; j < c; j++)
(void) acquire_link_bitrates(bus, links + j);
*ret = TAKE_PTR(links);
@@ -891,7 +890,7 @@ static int dump_gateways(
int ifindex) {
_cleanup_free_ struct local_address *local = NULL;
_cleanup_strv_free_ char **buf = NULL;
- int r, n, i;
+ int r, n;
assert(rtnl);
assert(table);
@@ -900,7 +899,7 @@ static int dump_gateways(
if (n <= 0)
return n;
- for (i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
_cleanup_free_ char *gateway = NULL, *description = NULL, *with_description = NULL;
char name[IF_NAMESIZE+1];
diff --git a/src/network/networkd-address-pool.c b/src/network/networkd-address-pool.c
index 7e27db6611..a9f8872760 100644
--- a/src/network/networkd-address-pool.c
+++ b/src/network/networkd-address-pool.c
@@ -135,7 +135,6 @@ static bool address_pool_prefix_is_taken(
static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixlen, union in_addr_union *found) {
union in_addr_union u;
- unsigned i;
int r;
assert(p);
@@ -150,7 +149,7 @@ static int address_pool_acquire_one(AddressPool *p, int family, unsigned prefixl
u = p->in_addr;
- for (i = 0; i < RANDOM_PREFIX_TRIAL_MAX; i++) {
+ for (unsigned i = 0; i < RANDOM_PREFIX_TRIAL_MAX; i++) {
r = in_addr_random_prefix(p->family, &u, p->prefixlen, prefixlen);
if (r <= 0)
return r;
diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c
index 551fa5928f..336dbb6486 100644
--- a/src/network/networkd-address.c
+++ b/src/network/networkd-address.c
@@ -599,7 +599,6 @@ bool link_address_is_dynamic(const Link *link, const Address *address) {
static int link_enumerate_ipv6_tentative_addresses(Link *link) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
- sd_netlink_message *addr;
int r;
assert(link);
@@ -614,7 +613,7 @@ static int link_enumerate_ipv6_tentative_addresses(Link *link) {
if (r < 0)
return r;
- for (addr = reply; addr; addr = sd_netlink_message_next(addr)) {
+ for (sd_netlink_message *addr = reply; addr; addr = sd_netlink_message_next(addr)) {
unsigned char flags;
int ifindex;
diff --git a/src/network/networkd-brvlan.c b/src/network/networkd-brvlan.c
index e53c73c30c..2847b336c9 100644
--- a/src/network/networkd-brvlan.c
+++ b/src/network/networkd-brvlan.c
@@ -44,9 +44,9 @@ static int find_next_bit(int i, uint32_t x) {
static int append_vlan_info_data(Link *const link, sd_netlink_message *req, uint16_t pvid, const uint32_t *br_vid_bitmap, const uint32_t *br_untagged_bitmap) {
struct bridge_vlan_info br_vlan;
- int i, j, k, r, cnt;
- uint16_t begin, end;
bool done, untagged = false;
+ uint16_t begin, end;
+ int r, cnt;
assert(link);
assert(req);
@@ -56,16 +56,17 @@ static int append_vlan_info_data(Link *const link, sd_netlink_message *req, uint
cnt = 0;
begin = end = UINT16_MAX;
- for (k = 0; k < BRIDGE_VLAN_BITMAP_LEN; k++) {
- unsigned base_bit;
- uint32_t vid_map = br_vid_bitmap[k];
+ for (int k = 0; k < BRIDGE_VLAN_BITMAP_LEN; k++) {
uint32_t untagged_map = br_untagged_bitmap[k];
+ uint32_t vid_map = br_vid_bitmap[k];
+ unsigned base_bit;
+ int i;
base_bit = k * 32;
i = -1;
done = false;
do {
- j = find_next_bit(i, vid_map);
+ int j = find_next_bit(i, vid_map);
if (j > 0) {
/* first hit of any bit */
if (begin == UINT16_MAX && end == UINT16_MAX) {
diff --git a/src/network/networkd-dhcp-common.c b/src/network/networkd-dhcp-common.c
index 0d1dc2e8ed..25c49d329f 100644
--- a/src/network/networkd-dhcp-common.c
+++ b/src/network/networkd-dhcp-common.c
@@ -809,7 +809,6 @@ int config_parse_dhcp_request_options(
void *userdata) {
Network *network = data;
- const char *p;
int r;
assert(filename);
@@ -826,7 +825,7 @@ int config_parse_dhcp_request_options(
return 0;
}
- for (p = rvalue;;) {
+ for (const char *p = rvalue;;) {
_cleanup_free_ char *n = NULL;
uint32_t i;
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index d5c1c507bf..5d3af46d4a 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -163,7 +163,7 @@ static int dhcp_route_configure(Route *route, Link *link) {
static int link_set_dns_routes(Link *link, const struct in_addr *address) {
const struct in_addr *dns;
uint32_t table;
- int i, n, r;
+ int n, r;
assert(link);
assert(link->dhcp_lease);
@@ -181,7 +181,7 @@ static int link_set_dns_routes(Link *link, const struct in_addr *address) {
table = link_get_dhcp_route_table(link);
- for (i = 0; i < n; i ++) {
+ for (int i = 0; i < n; i ++) {
_cleanup_(route_freep) Route *route = NULL;
r = route_new(&route);
diff --git a/src/network/networkd-speed-meter.c b/src/network/networkd-speed-meter.c
index e7f0682c3e..97204c89e9 100644
--- a/src/network/networkd-speed-meter.c
+++ b/src/network/networkd-speed-meter.c
@@ -44,7 +44,6 @@ static int process_message(Manager *manager, sd_netlink_message *message) {
static int speed_meter_handler(sd_event_source *s, uint64_t usec, void *userdata) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
Manager *manager = userdata;
- sd_netlink_message *i;
usec_t usec_now;
Link *link;
int r;
@@ -84,7 +83,7 @@ static int speed_meter_handler(sd_event_source *s, uint64_t usec, void *userdata
return 0;
}
- for (i = reply; i; i = sd_netlink_message_next(i))
+ for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i))
(void) process_message(manager, i);
return 0;
diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c
index 1142f10b10..5156fcc7d7 100644
--- a/src/network/test-networkd-conf.c
+++ b/src/network/test-networkd-conf.c
@@ -67,12 +67,11 @@ static void test_config_parse_hwaddr_one(const char *rvalue, int ret, const stru
static void test_config_parse_hwaddrs_one(const char *rvalue, const struct ether_addr* list, size_t n) {
_cleanup_set_free_free_ Set *s = NULL;
- size_t m;
assert_se(config_parse_hwaddrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL) == 0);
assert_se(set_size(s) == n);
- for (m = 0; m < n; m++) {
+ for (size_t m = 0; m < n; m++) {
_cleanup_free_ struct ether_addr *q = NULL;
assert_se(q = set_remove(s, &list[m]));
diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c
index e3b350f526..8321395550 100644
--- a/src/network/wait-online/manager.c
+++ b/src/network/wait-online/manager.c
@@ -207,7 +207,6 @@ static int on_rtnl_event(sd_netlink *rtnl, sd_netlink_message *mm, void *userdat
static int manager_rtnl_listen(Manager *m) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL, *reply = NULL;
- sd_netlink_message *i;
int r;
assert(m);
@@ -242,7 +241,7 @@ static int manager_rtnl_listen(Manager *m) {
if (r < 0)
return r;
- for (i = reply; i; i = sd_netlink_message_next(i)) {
+ for (sd_netlink_message *i = reply; i; i = sd_netlink_message_next(i)) {
r = manager_process_link(m->rtnl, i, m);
if (r < 0)
return r;