aboutsummaryrefslogtreecommitdiff
path: root/src/openvpn/proto.h
diff options
context:
space:
mode:
authorArne Schwabe2018-12-03 17:48:18 +0100
committerGert Doering2018-12-04 21:01:15 +0100
commite11d2d14a9ef5311f791a9a614ab367c6f50ff11 (patch)
tree3ef63825794c0bea435c79136f14527db67bd933 /src/openvpn/proto.h
parent584b1717e7eaa8e44c675efb1f2dcbbaed2c0db3 (diff)
downloadopenvpn-e11d2d14a9ef5311f791a9a614ab367c6f50ff11.zip
openvpn-e11d2d14a9ef5311f791a9a614ab367c6f50ff11.tar.gz
Implement block-ipv6
This can be used to redirect all IPv6 traffic to the tun interface, effectively black holing the IPv6 traffic. Without ICMPv6 error messages this will result in timeouts when the server does not send error codes. block-ipv6 allows client side only blocking on all platforms that OpenVPN supports IPv6. On Android it is only way to do sensible IPv6 blocking on Android < 5.0 and broken devices (Samsung). PATCH V6: - Rebase on master and run uncrustify on the patch PATCH V5: - Fix even more style issues by Antonio - Remove check for dev == tun as this also works for tap PATCH V4: - Fix more style issues reported by Antonio - Clarify parts of the patch in comments and manpage PATCH V3: - Fix style iusses reported by Antonio and accidentily commited parts - merge udp_checksum and ipv6_checkusm into common ip_checksum method - Use fake ff80::7 address when no other address is configured. - Make block-ipv6 also work for server by replying block-ipv6 to all ipv6 traffic send to the server Note for the server the process_ip happens before the ipv6 route lookup so every ipv6 packet, regardless of its source address is replyied to with a no route to host packet. Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20181203164818.15756-1-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17977.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/proto.h')
-rw-r--r--src/openvpn/proto.h42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/openvpn/proto.h b/src/openvpn/proto.h
index 985aa99..4ddffc7 100644
--- a/src/openvpn/proto.h
+++ b/src/openvpn/proto.h
@@ -95,9 +95,10 @@ struct openvpn_iphdr {
uint8_t ttl;
-#define OPENVPN_IPPROTO_IGMP 2 /* IGMP protocol */
-#define OPENVPN_IPPROTO_TCP 6 /* TCP protocol */
-#define OPENVPN_IPPROTO_UDP 17 /* UDP protocol */
+#define OPENVPN_IPPROTO_IGMP 2 /* IGMP protocol */
+#define OPENVPN_IPPROTO_TCP 6 /* TCP protocol */
+#define OPENVPN_IPPROTO_UDP 17 /* UDP protocol */
+#define OPENVPN_IPPROTO_ICMPV6 58 /* ICMPV6 protocol */
uint8_t protocol;
uint16_t check;
@@ -120,6 +121,24 @@ struct openvpn_ipv6hdr {
struct in6_addr daddr;
};
+/*
+ * ICMPv6 header
+ */
+struct openvpn_icmp6hdr {
+#define OPENVPN_ICMP6_DESTINATION_UNREACHABLE 1
+#define OPENVPN_ND_ROUTER_SOLICIT 133
+#define OPENVPN_ND_ROUTER_ADVERT 134
+#define OPENVPN_ND_NEIGHBOR_SOLICIT 135
+#define OPENVPN_ND_NEIGHBOR_ADVERT 136
+#define OPENVPN_ND_INVERSE_SOLICIT 141
+#define OPENVPN_ND_INVERSE_ADVERT 142
+ uint8_t icmp6_type;
+#define OPENVPN_ICMP6_DU_NOROUTE 0
+#define OPENVPN_ICMP6_DU_COMMUNICATION_PROHIBTED 1
+ uint8_t icmp6_code;
+ uint16_t icmp6_cksum;
+ uint8_t icmp6_dataun[4];
+};
/*
* UDP header
@@ -265,6 +284,23 @@ bool is_ipv4(int tunnel_type, struct buffer *buf);
bool is_ipv6(int tunnel_type, struct buffer *buf);
+/**
+ * Calculates an IP or IPv6 checksum with a pseudo header as required by
+ * TCP, UDP and ICMPv6
+ *
+ * @param af - Address family for which the checksum is calculated
+ * AF_INET or AF_INET6
+ * @param payload - the TCP, ICMPv6 or UDP packet
+ * @param len_payload - length of payload
+ * @param src_addr - Source address of the packet
+ * @param dest_addr - Destination address of the packet
+ * @param proto next - header or IP protocol of the packet
+ * @return The calculated checksum in host order
+ */
+uint16_t
+ip_checksum(const sa_family_t af, const uint8_t *payload, const int len_payload,
+ const uint8_t *src_addr, const uint8_t *dest_addr, const int proto);
+
#ifdef PACKET_TRUNCATION_CHECK
void ipv4_packet_size_verify(const uint8_t *data,
const int size,