Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/ipfw/ip_fw_nat.c
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | struct cfg_nat { | ||||
int id; /* nat id */ | int id; /* nat id */ | ||||
struct in_addr ip; /* nat ip address */ | struct in_addr ip; /* nat ip address */ | ||||
struct libalias *lib; /* libalias instance */ | struct libalias *lib; /* libalias instance */ | ||||
int mode; /* aliasing mode */ | int mode; /* aliasing mode */ | ||||
int redir_cnt; /* number of entry in spool chain */ | int redir_cnt; /* number of entry in spool chain */ | ||||
/* chain of redir instances */ | /* chain of redir instances */ | ||||
LIST_HEAD(redir_chain, cfg_redir) redir_chain; | LIST_HEAD(redir_chain, cfg_redir) redir_chain; | ||||
char if_name[IF_NAMESIZE]; /* interface name */ | char if_name[IF_NAMESIZE]; /* interface name */ | ||||
u_short alias_port_lo; /* low range for port aliasing */ | |||||
u_short alias_port_hi; /* high range for port aliasing */ | |||||
donner: Here the struct can be reused. | |||||
}; | }; | ||||
static eventhandler_tag ifaddr_event_tag; | static eventhandler_tag ifaddr_event_tag; | ||||
static void | static void | ||||
ifaddr_change(void *arg __unused, struct ifnet *ifp) | ifaddr_change(void *arg __unused, struct ifnet *ifp) | ||||
{ | { | ||||
struct cfg_nat *ptr; | struct cfg_nat *ptr; | ||||
▲ Show 20 Lines • Show All 419 Lines • ▼ Show 20 Lines | nat44_config(struct ip_fw_chain *chain, struct nat44_cfg_nat *ucfg) | ||||
/* | /* | ||||
* XXX - what if this rule doesn't nat any ip and just | * XXX - what if this rule doesn't nat any ip and just | ||||
* redirect? | * redirect? | ||||
* do we set aliasaddress to 0.0.0.0? | * do we set aliasaddress to 0.0.0.0? | ||||
*/ | */ | ||||
ptr->ip = ucfg->ip; | ptr->ip = ucfg->ip; | ||||
ptr->redir_cnt = ucfg->redir_cnt; | ptr->redir_cnt = ucfg->redir_cnt; | ||||
ptr->mode = ucfg->mode; | ptr->mode = ucfg->mode; | ||||
ptr->alias_port_lo = ucfg->alias_port_lo; | |||||
ptr->alias_port_hi = ucfg->alias_port_hi; | |||||
Done Inline ActionsUsing a stuct the lines become ptr->portRange = ucfg->portRange; donner: Using a stuct the lines become
```
ptr->portRange = ucfg->portRange;
``` | |||||
strlcpy(ptr->if_name, ucfg->if_name, sizeof(ptr->if_name)); | strlcpy(ptr->if_name, ucfg->if_name, sizeof(ptr->if_name)); | ||||
LibAliasSetMode(ptr->lib, ptr->mode, ~0); | LibAliasSetMode(ptr->lib, ptr->mode, ~0); | ||||
LibAliasSetAddress(ptr->lib, ptr->ip); | LibAliasSetAddress(ptr->lib, ptr->ip); | ||||
LibAliasSetAliasPortRange(ptr->lib, ptr->alias_port_lo, ptr->alias_port_hi); | |||||
Done Inline ActionsWhy not take the (pointer to the) struct as argument? donner: Why not take the (pointer to the) struct as argument? | |||||
/* | /* | ||||
* Redir and LSNAT configuration. | * Redir and LSNAT configuration. | ||||
*/ | */ | ||||
/* Delete old cfgs. */ | /* Delete old cfgs. */ | ||||
del_redir_spool_cfg(ptr, &ptr->redir_chain); | del_redir_spool_cfg(ptr, &ptr->redir_chain); | ||||
/* Add new entries. */ | /* Add new entries. */ | ||||
add_redir_spool_cfg((char *)(ucfg + 1), ptr); | add_redir_spool_cfg((char *)(ucfg + 1), ptr); | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
export_nat_cfg(struct cfg_nat *ptr, struct nat44_cfg_nat *ucfg) | export_nat_cfg(struct cfg_nat *ptr, struct nat44_cfg_nat *ucfg) | ||||
{ | { | ||||
snprintf(ucfg->name, sizeof(ucfg->name), "%d", ptr->id); | snprintf(ucfg->name, sizeof(ucfg->name), "%d", ptr->id); | ||||
ucfg->ip = ptr->ip; | ucfg->ip = ptr->ip; | ||||
ucfg->redir_cnt = ptr->redir_cnt; | ucfg->redir_cnt = ptr->redir_cnt; | ||||
ucfg->mode = ptr->mode; | ucfg->mode = ptr->mode; | ||||
ucfg->alias_port_lo = ptr->alias_port_lo; | |||||
ucfg->alias_port_hi = ptr->alias_port_hi; | |||||
strlcpy(ucfg->if_name, ptr->if_name, sizeof(ucfg->if_name)); | strlcpy(ucfg->if_name, ptr->if_name, sizeof(ucfg->if_name)); | ||||
} | } | ||||
/* | /* | ||||
* Gets config for given nat instance | * Gets config for given nat instance | ||||
* Data layout (v0)(current): | * Data layout (v0)(current): | ||||
* Request: [ ipfw_obj_header nat44_cfg_nat .. ] | * Request: [ ipfw_obj_header nat44_cfg_nat .. ] | ||||
* | * | ||||
▲ Show 20 Lines • Show All 572 Lines • Show Last 20 Lines |
Here the struct can be reused.