前两个例子是比较简单的应用。本例对报文头部做扩展,加上一个扩展报头。
/*
* This programe is working as plugin of netfilter which will pin a timestamp to
* the destination header of ipv6 packet every x seconds when the packet is
* the object multicast packet.
*/
#include <linux/netfilter.h>
#include <linux/netfilter_ipv6.h>
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/inet.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <net/checksum.h>
#include <net/udp.h>
#include <net/ipv6.h>
#include <linux/time.h>
#include <asm/byteorder.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("newand");
MODULE_DESCRIPTION("Change the header of ipv6 packet");
#define PRINT(fmt,args...) printk("debug: " fmt, ##args)
/* IP6 Hooks */
/* After promisc drops
, checksum checks. */
#define NF_IP6_PRE_ROUTING 0
/* If the packet is destined for this box. */
#define NF_IP6_LOCAL_IN 1
/* If the packet is destined for another interface. */
#define NF_IP6_FORWARD 2
/* Packets coming from a local process. */
#define NF_IP6_LOCAL_OUT 3
/* Packets about to hit the wire. */
#define NF_IP6_POST_ROUTING 4
/*sequence of measeure
sample packet*/
static int sample_seq = 0;
/*Next header destination header*/
struct ip6_dst_hdr
{
uint8_t ip6d_nxt;
uint8_t ip6d_len;
uint8_t ip6d_opt_type;
uint8_t ip6d_opt_len;
uint32_t ip6d_ssn;
uint32_t ip6d_sec;
uint32_t ip6d_usec;
};
/*
* Debug print the addresss of ipv6 packets
*/
inline
void print_6addr(const struct in6_addr *addr)
{
PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x