-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per-customer translation algorithm
This commit implements recommendations from the rfc 7422 and the draft sunset4-nat64-port-allocation.
- Loading branch information
Showing
19 changed files
with
1,274 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef __NL_CUSTOMER_H__ | ||
#define __NL_CUSTOMER_H__ | ||
|
||
#include <net/genetlink.h> | ||
#include "nat64/mod/common/xlator.h" | ||
|
||
int handle_customer_config(struct xlator *jool, struct genl_info *info); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#ifndef __JOOL_MOD_POOL4_CUSTOMER_H_ | ||
#define __JOOL_MOD_POOL4_CUSTOMER_H_ | ||
|
||
#include <linux/net.h> | ||
#include "nat64/mod/common/types.h" | ||
#include "nat64/mod/common/config.h" | ||
|
||
struct customer_table { | ||
/** IPv6 addresses that use this customer table. */ | ||
struct ipv6_prefix prefix6; | ||
/** Number of bits of 'prefix6' which represent the subnetwork. */ | ||
__u8 groups6_size_len; | ||
|
||
/** Pool4 for this table. */ | ||
struct ipv4_prefix prefix4; | ||
/** Hop size that divide the ports range for every IPv6 subnetwork | ||
* in CIDR format. */ | ||
__u8 ports_division_len; | ||
|
||
struct port_range ports; | ||
|
||
/** Port range size "ports" in CIDR format, for bitwise operations. */ | ||
unsigned short ports_size_len; | ||
}; | ||
|
||
|
||
bool customer_table_contains(struct customer_table *table, struct in6_addr *src6); | ||
|
||
/** | ||
* Obtain the total count of ports from this customer. | ||
* (i.e. IPv4 prefix count * port range count ) | ||
*/ | ||
__u32 customer_table_get_total_ports_size(struct customer_table *table); | ||
|
||
/** | ||
* Indicates which IPv6 group the address belongs to. | ||
*/ | ||
__u16 customer_table_get_group_by_addr(struct customer_table *table, | ||
struct in6_addr *src6); | ||
|
||
/** | ||
* Indicates the available port size for each IPv6 group. | ||
*/ | ||
__u32 customer_table_get_group_ports_size(struct customer_table *table); | ||
|
||
/** | ||
* Number of contiguous ports to be used as requested by the user | ||
* for each IPv6 group. | ||
*/ | ||
__u16 customer_table_get_port_range_hop(struct customer_table *table); | ||
|
||
/** | ||
* Initial port number for the IPv6 group 'group', | ||
* you can add an offset so that the initial port is different for each | ||
* network request. | ||
*/ | ||
__u32 customer_get_group_first_port(struct customer_table *table, | ||
unsigned int offset, __u16 group, __u16 port_hop); | ||
|
||
/** | ||
* Ports hope size for the following range of available ports for an IPv6 group. | ||
*/ | ||
__u32 customer_table_get_group_ports_hop(struct customer_table *table); | ||
|
||
/** | ||
* Number of IPv6 addresses for each IPv6 group. | ||
*/ | ||
__u32 customer_table_get_group_size(struct customer_table *table); | ||
|
||
/** | ||
* Same as the port_range_count(ports) but | ||
* for bitwise operations (1 << port_mask). | ||
* | ||
* @return port_mask | ||
*/ | ||
unsigned short customer_table_get_ports_mask(struct customer_table *table); | ||
|
||
void customer_table_put(struct customer_table *customer); | ||
#endif /* __JOOL_MOD_POOL4_CUSTOMER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _JOOL_USR_CUSTOMER_H | ||
#define _JOOL_USR_CUSTOMER_H | ||
|
||
#include "nat64/common/config.h" | ||
#include "nat64/usr/types.h" | ||
|
||
int customer_display(display_flags flags); | ||
int customer_add(struct customer_entry_usr *entry); | ||
int customer_rm(bool quick); | ||
int customer_flush(bool quick); | ||
|
||
#endif /* _JOOL_USR_CUSTOMER_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#include "nat64/mod/common/nl/customer.h" | ||
|
||
#include "nat64/mod/common/nl/nl_common.h" | ||
#include "nat64/mod/common/nl/nl_core2.h" | ||
#include "nat64/mod/stateful/pool4/customer.h" | ||
#include "nat64/mod/stateful/pool4/db.h" | ||
#include "nat64/mod/stateful/bib/db.h" | ||
|
||
static int customer_table_to_usr(struct customer_table *table, void *arg) | ||
{ | ||
return nlbuffer_write(arg, table, sizeof(*table)); | ||
} | ||
|
||
static int handle_customer_display(struct pool4 *pool, struct genl_info *info, | ||
union request_customer *request) | ||
{ | ||
struct nlcore_buffer buffer; | ||
int error = 0; | ||
|
||
log_debug("Sending customer table to userspace."); | ||
|
||
error = nlbuffer_init_response(&buffer, info, nlbuffer_response_max_size()); | ||
if (error) | ||
return nlcore_respond(info, error); | ||
|
||
error = customerdb_foreach(pool, customer_table_to_usr, &buffer); | ||
nlbuffer_set_pending_data(&buffer, error > 0); | ||
error = (error >= 0) | ||
? nlbuffer_send(info, &buffer) | ||
: nlcore_respond(info, error); | ||
|
||
nlbuffer_free(&buffer); | ||
return error; | ||
} | ||
|
||
static int handle_customer_add(struct pool4 *pool, struct genl_info *info, | ||
union request_customer *request) | ||
{ | ||
if (verify_superpriv()) | ||
return nlcore_respond(info, -EPERM); | ||
|
||
log_debug("Adding elements to customer table."); | ||
return nlcore_respond(info, customerdb_add(pool, &request->add)); | ||
} | ||
|
||
static int handle_customer_rm(struct xlator *jool, struct genl_info *info, | ||
union request_customer *request) | ||
{ | ||
struct ipv4_range range; | ||
int error; | ||
|
||
if (verify_superpriv()) | ||
return nlcore_respond(info, -EPERM); | ||
|
||
log_debug("Removing elements from customer table."); | ||
|
||
error = customerdb_rm(jool->nat64.pool4, &range); | ||
|
||
if (!error && xlat_is_nat64() && !request->rm.quick) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
bib_rm_range(jool->nat64.bib, L4PROTO_TCP, &range); | ||
bib_rm_range(jool->nat64.bib, L4PROTO_ICMP, &range); | ||
bib_rm_range(jool->nat64.bib, L4PROTO_UDP, &range); | ||
} | ||
|
||
return nlcore_respond(info, error); | ||
} | ||
|
||
static int handle_customer_flush(struct xlator *jool, struct genl_info *info, | ||
union request_customer *request) | ||
{ | ||
struct ipv4_range range; | ||
int error; | ||
|
||
if (verify_superpriv()) | ||
return nlcore_respond(info, -EPERM); | ||
|
||
log_debug("Flushing customer table."); | ||
|
||
customerdb_flush(jool->nat64.pool4, &range, &error); | ||
if (!error && xlat_is_nat64() && !request->flush.quick) { | ||
bib_rm_range(jool->nat64.bib, L4PROTO_TCP, &range); | ||
bib_rm_range(jool->nat64.bib, L4PROTO_ICMP, &range); | ||
bib_rm_range(jool->nat64.bib, L4PROTO_UDP, &range); | ||
} | ||
|
||
return nlcore_respond(info, 0); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
int handle_customer_config(struct xlator *jool, struct genl_info *info) | ||
{ | ||
struct request_hdr *hdr = get_jool_hdr(info); | ||
union request_customer *request = (union request_customer *)(hdr + 1); | ||
int error; | ||
|
||
if (xlat_is_siit()) { | ||
log_err("SIIT doesn't have customer."); | ||
return nlcore_respond(info, -EINVAL); | ||
} | ||
|
||
error = validate_request_size(info, sizeof(*request)); | ||
if (error) | ||
return nlcore_respond(info, error); | ||
|
||
switch (be16_to_cpu(hdr->operation)) { | ||
case OP_DISPLAY: | ||
return handle_customer_display(jool->nat64.pool4, info, request); | ||
case OP_ADD: | ||
return handle_customer_add(jool->nat64.pool4, info, request); | ||
case OP_REMOVE: | ||
return handle_customer_rm(jool, info, request); | ||
case OP_FLUSH: | ||
return handle_customer_flush(jool, info, request); | ||
} | ||
|
||
log_err("Unknown operation: %u", be16_to_cpu(hdr->operation)); | ||
return nlcore_respond(info, -EINVAL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
1 comment
on commit 7313c3b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stateness was already validated in
handle_customer_config()
; no need to do it again