Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Init rule variable iif oif and to, from

While foreign rules are added the network part is not attached.
attach manager to rules and use it in routing_policy_rule_free.
  • Loading branch information
ssahani authored and yuwata committed Dec 21, 2017
1 parent 281bb5c commit 36e6e28
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/network/networkd-manager.c
Expand Up @@ -726,11 +726,11 @@ static int manager_rtnl_process_link(sd_netlink *rtnl, sd_netlink_message *messa

int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, void *userdata) {
uint8_t tos = 0, to_prefixlen = 0, from_prefixlen = 0;
union in_addr_union to = {}, from = {};
RoutingPolicyRule *rule = NULL;
union in_addr_union to, from;
uint32_t fwmark = 0, table = 0;
char *iif = NULL, *oif = NULL;
Manager *m = userdata;
char *iif, *oif;
uint16_t type;
int family;
int r;
Expand Down
1 change: 1 addition & 0 deletions src/network/networkd-route.h
Expand Up @@ -26,6 +26,7 @@ typedef struct NetworkConfigSection NetworkConfigSection;
#include "networkd-network.h"

struct Route {
Manager *m;
Network *network;
NetworkConfigSection *section;

Expand Down
17 changes: 10 additions & 7 deletions src/network/networkd-routing-policy-rule.c
Expand Up @@ -60,10 +60,11 @@ void routing_policy_rule_free(RoutingPolicyRule *rule) {
network_config_section_free(rule->section);
}

if (rule->network->manager) {
set_remove(rule->network->manager->rules, rule);
set_remove(rule->network->manager->rules_foreign, rule);
}
}

if (rule->m) {
set_remove(rule->m->rules, rule);
set_remove(rule->m->rules_foreign, rule);
}

free(rule->iif);
Expand Down Expand Up @@ -236,7 +237,8 @@ int routing_policy_rule_make_local(Manager *m, RoutingPolicyRule *rule) {
return -ENOENT;
}

static int routing_policy_rule_add_internal(Set **rules,
static int routing_policy_rule_add_internal(Manager *m,
Set **rules,
int family,
const union in_addr_union *from,
uint8_t from_prefixlen,
Expand All @@ -258,6 +260,7 @@ static int routing_policy_rule_add_internal(Set **rules,
if (r < 0)
return r;

rule->m = m;
rule->family = family;
rule->from = *from;
rule->from_prefixlen = from_prefixlen;
Expand Down Expand Up @@ -298,7 +301,7 @@ int routing_policy_rule_add(Manager *m,
char *oif,
RoutingPolicyRule **ret) {

return routing_policy_rule_add_internal(&m->rules, family, from, from_prefixlen, to, to_prefixlen, tos, fwmark, table, iif, oif, ret);
return routing_policy_rule_add_internal(m, &m->rules, family, from, from_prefixlen, to, to_prefixlen, tos, fwmark, table, iif, oif, ret);
}

int routing_policy_rule_add_foreign(Manager *m,
Expand All @@ -313,7 +316,7 @@ int routing_policy_rule_add_foreign(Manager *m,
char *iif,
char *oif,
RoutingPolicyRule **ret) {
return routing_policy_rule_add_internal(&m->rules_foreign, family, from, from_prefixlen, to, to_prefixlen, tos, fwmark, table, iif, oif, ret);
return routing_policy_rule_add_internal(m, &m->rules_foreign, family, from, from_prefixlen, to, to_prefixlen, tos, fwmark, table, iif, oif, ret);
}

static int routing_policy_rule_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) {
Expand Down
2 changes: 2 additions & 0 deletions src/network/networkd-routing-policy-rule.h
Expand Up @@ -33,8 +33,10 @@ typedef struct RoutingPolicyRule RoutingPolicyRule;
typedef struct Network Network;
typedef struct Link Link;
typedef struct NetworkConfigSection NetworkConfigSection;
typedef struct Manager Manager;

struct RoutingPolicyRule {
Manager *m;
Network *network;
Link *link;
NetworkConfigSection *section;
Expand Down

0 comments on commit 36e6e28

Please sign in to comment.