diff mbox

[ovs-dev,ICMP,v2,5/7] packets: Add support for modifying ICMP type and code.

Message ID 1446594530-22162-6-git-send-email-jpettit@nicira.com
State Accepted
Headers show

Commit Message

Justin Pettit Nov. 3, 2015, 11:48 p.m. UTC
Signed-off-by: Justin Pettit <jpettit@nicira.com>
---
 lib/packets.c |   18 ++++++++++++++++++
 lib/packets.h |    1 +
 2 files changed, 19 insertions(+), 0 deletions(-)

Comments

Flavio Leitner Nov. 5, 2015, 5 p.m. UTC | #1
On Tue, Nov 03, 2015 at 03:48:48PM -0800, Justin Pettit wrote:
> Signed-off-by: Justin Pettit <jpettit@nicira.com>
> ---

LGTM
Acked-by: Flavio Leitner <fbl@sysclose.org>
diff mbox

Patch

diff --git a/lib/packets.c b/lib/packets.c
index 342d8b7..701a5ec 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -905,6 +905,24 @@  packet_set_sctp_port(struct dp_packet *packet, ovs_be16 src, ovs_be16 dst)
     put_16aligned_be32(&sh->sctp_csum, old_csum ^ old_correct_csum ^ new_csum);
 }
 
+/* Sets the ICMP type and code of the ICMP header contained in 'packet'.
+ * 'packet' must be a valid ICMP packet with its l4 offset properly
+ * populated. */
+void
+packet_set_icmp(struct dp_packet *packet, uint8_t type, uint8_t code)
+{
+    struct icmp_header *ih = dp_packet_l4(packet);
+    ovs_be16 orig_tc = htons(ih->icmp_type << 8 | ih->icmp_code);
+    ovs_be16 new_tc = htons(type << 8 | code);
+
+    if (orig_tc != new_tc) {
+        ih->icmp_type = type;
+        ih->icmp_code = code;
+
+        ih->icmp_csum = recalc_csum16(ih->icmp_csum, orig_tc, new_tc);
+    }
+}
+
 void
 packet_set_nd(struct dp_packet *packet, const ovs_be32 target[4],
               const struct eth_addr sll, const struct eth_addr tll) {
diff --git a/lib/packets.h b/lib/packets.h
index 67f635e..de8d4b6 100644
--- a/lib/packets.h
+++ b/lib/packets.h
@@ -975,6 +975,7 @@  void packet_set_ipv6(struct dp_packet *, uint8_t proto, const ovs_be32 src[4],
 void packet_set_tcp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
 void packet_set_udp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
 void packet_set_sctp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_icmp(struct dp_packet *, uint8_t type, uint8_t code);
 void packet_set_nd(struct dp_packet *, const ovs_be32 target[4],
                    const struct eth_addr sll, const struct eth_addr tll);