diff options
Diffstat (limited to 'src/sp_network_utils.c')
| -rw-r--r-- | src/sp_network_utils.c | 31 |
1 files changed, 0 insertions, 31 deletions
diff --git a/src/sp_network_utils.c b/src/sp_network_utils.c index 28bc324..4b78ca5 100644 --- a/src/sp_network_utils.c +++ b/src/sp_network_utils.c | |||
| @@ -12,37 +12,6 @@ static inline bool cidr6_match(const struct in6_addr address, | |||
| 12 | const struct in6_addr network, uint8_t bits); | 12 | const struct in6_addr network, uint8_t bits); |
| 13 | static inline int get_ip_version(const char *ip); | 13 | static inline int get_ip_version(const char *ip); |
| 14 | 14 | ||
| 15 | void apply_mask_on_ip(char *out, const char *const remote_addr) { | ||
| 16 | uint8_t mask4 = SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv4; | ||
| 17 | uint8_t mask6 = SNUFFLEUPAGUS_G(config).config_cookie_encryption->mask_ipv6; | ||
| 18 | const int ip_version = get_ip_version(remote_addr); | ||
| 19 | |||
| 20 | memset(out, 0, 128); | ||
| 21 | |||
| 22 | if (ip_version == AF_INET) { | ||
| 23 | struct in_addr out4; | ||
| 24 | inet_pton(AF_INET, remote_addr, &out4); | ||
| 25 | const long n = out4.s_addr & htonl(0xFFFFFFFFu << (32 - mask4)); | ||
| 26 | out[0] = (n >> 24) & 0xFF; | ||
| 27 | out[1] = (n >> 16) & 0xFF; | ||
| 28 | out[2] = (n >> 8) & 0xFF; | ||
| 29 | out[3] = (n >> 0) & 0xFF; | ||
| 30 | } else if (ip_version == AF_INET6) { | ||
| 31 | inet_pton(AF_INET6, remote_addr, out); | ||
| 32 | uint32_t *p_ip = (uint32_t *)out; | ||
| 33 | while (32 < mask6) { | ||
| 34 | *p_ip = 0xFFFFFFFFu; | ||
| 35 | p_ip++; | ||
| 36 | mask6 -= 32; | ||
| 37 | } | ||
| 38 | if (0 != mask6) { | ||
| 39 | *p_ip = htonl(0xFFFFFFFFu << (32 - mask6)); | ||
| 40 | } | ||
| 41 | } else { | ||
| 42 | sp_log_err("ip_mask", "It seems that %s isn't a valid ip.", remote_addr); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | /* http://fxr.watson.org/fxr/source/include/net/xfrm.h?v=linux-2.6#L840 */ | 15 | /* http://fxr.watson.org/fxr/source/include/net/xfrm.h?v=linux-2.6#L840 */ |
| 47 | static inline bool cidr4_match(const struct in_addr addr, | 16 | static inline bool cidr4_match(const struct in_addr addr, |
| 48 | const struct in_addr net, uint8_t bits) { | 17 | const struct in_addr net, uint8_t bits) { |
