userspace can query the original ipv4 destination address of a REDIRECTed connection via getsockopt(m_sock, SOL_IP, SO_ORIGINAL_DST, &m_server_addr, &addrsize) but for ipv6 no such option existed. This adds getsockopt(..., IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, ...). Without this, userspace needs to parse /proc or use ctnetlink, which appears to be overkill. This uses option number 80 for IP6T_SO_ORIGINAL_DST, which is spare, to use the same number we use in the IPv4 socket option SO_ORIGINAL_DST.
Showing the changes to include/uapi/linux (2 of 3 files). Show all
Unified · Split
| @@ -240,6 +240,7 @@ struct in6_flowlabel_req { · 239 unmodified lines | ||
| 240 | 240 | * |
| 241 | 241 | * IP6T_SO_GET_REVISION_MATCH 68 |
| 242 | 242 | * IP6T_SO_GET_REVISION_TARGET 69 |
| 243 | + * IP6T_SO_ORIGINAL_DST 80 | |
| 243 | 244 | */ |
| 244 | 245 | |
| 245 | 246 | /* RFC5014: Source address selection */ |
| @@ -178,6 +178,9 @@ struct ip6t_error { · 177 unmodified lines | ||
| 178 | 178 | #define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 5) |
| 179 | 179 | #define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET |
| 180 | 180 | |
| 181 | +/* obtain original address if REDIRECT'd connection */ | |
| 182 | +#define IP6T_SO_ORIGINAL_DST 80 | |
| 183 | + | |
| 181 | 184 | /* ICMP matching stuff */ |
| 182 | 185 | struct ip6t_icmp { |
| 183 | 186 | __u8 type; /* type to match */ |