KD-Project_3: IPv6 packet and linux kernel module

Today we consider the way to send IPv6 multicast packet in the linux kernel module (The source code is available HERE). There is some work done regarding sending the IPv4 packet. It is described in previous post on this site.

What we did is a simple modification of the “hello world” sample presented in previous post. The modifications includes multiple points: IPv6 Header, IPv6 adresses and ipv6hdr structure:

#include ipv6.h

and we need the ipv6hdr to be able to send UDP payload in the IPv6 packet.

struct in6_addr saddr = {{{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }}};
struct in6_addr daddr = {{{ 0xff,02,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}};

struct ipv6hdr *iph = (struct ipv6hdr*)skb_push(skb,sizeof(struct ipv6hdr));
  iph->version = 6;
  iph->nexthdr = IPPROTO_UDP;
  iph->payload_len = htons(udp_total_len);
  iph->saddr = saddr;
  iph->daddr = daddr;