: new match 'secpath'
RFC PATCH 1/1 : new match 'secpath'
This patch adds a new match secpath which can be used to match if a packet came out of an ipsec tunnel and various other related stuff (please see the helptext for more info). Comments are welcome.
Bye
Patrick
patch-o-matic_2.5/extra/secpath.patch +188 -0
@@ -0,0 +1,188 @@ +diff -Nru a/include/linux/netfilter_ipv4/ipt_secpath.h b/include/linux/netfilter_ipv4/ipt_secpath.h +--- /dev/null Wed Dec 31 16:00:00 1969 ++++ b/include/linux/netfilter_ipv4/ipt_secpath.h Mon Aug 25 15:07:40 2003 +@@ -0,0 +1,41 @@ ++#ifndef _IPT_SECPATH_H ++#define _IPT_SECPATH_H ++ ++#define SECPATH_MAX_DEPTH 4 /* must match XFRM_MAX_DEPTH */ ++ ++#define MATCH_PATH 0x1 ++ ++#define SECPATH_MODE_TRANSPORT 0 ++#define SECPATH_MODE_TUNNEL 1 ++ ++struct ipt_secpath_flags ++{ ++ u_int8_t saddr:1, ++ daddr:1, ++ spi:1, ++ proto:1, ++ mode:1; ++}; ++ ++struct ipt_secpath_elem ++{ ++ u_int32_t saddr; ++ u_int32_t smask; ++ u_int32_t daddr; ++ u_int32_t dmask; ++ u_int32_t spi; ++ u_int8_t proto; ++ u_int8_t mode; ++ ++ struct ipt_secpath_flags match; ++ struct ipt_secpath_flags invert; ++}; ++ ++struct ipt_secpath_info ++{ ++ struct ipt_secpath_elem path[SECPATH_MAX_DEPTH]; ++ u_int16_t len; ++ u_int16_t flags; ++}; ++ ++#endif +diff -Nru a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig +--- a/net/ipv4/netfilter/Kconfig Mon Aug 25 15:07:40 2003 ++++ b/net/ipv4/netfilter/Kconfig Mon Aug 25 15:07:40 2003 +@@ -301,6 +301,17 @@ + If you want to compile it as a module, say M here and read + <file:Documentation/modules.txt>. If unsure, say `N'. + ++config IP_NF_MATCH_SECPATH ++ tristate "Secpath match support" ++ depends on EXPERIMENTAL && IP_NF_IPTABLES ++ help ++ Secpath packet matching allows you to match various attributes ++ of a packets secpath which describes the path a packet took through ++ the (ipsec) transformers during decapsulation. ++ ++ If you want to compile it as a module, say M here and read ++ <file:Documentation/modules.txt>. If unsure, say `N'. ++ + # The targets + config IP_NF_FILTER + tristate "Packet filtering" +diff -Nru a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile +--- a/net/ipv4/netfilter/Makefile Mon Aug 25 15:07:40 2003 ++++ b/net/ipv4/netfilter/Makefile Mon Aug 25 15:07:40 2003 +@@ -65,6 +65,7 @@ + obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o + + obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o ++obj-$(CONFIG_IP_NF_MATCH_SECPATH) += ipt_secpath.o + + # targets + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o +diff -Nru a/net/ipv4/netfilter/ipt_secpath.c b/net/ipv4/netfilter/ipt_secpath.c +--- /dev/null Wed Dec 31 16:00:00 1969 ++++ b/net/ipv4/netfilter/ipt_secpath.c Mon Aug 25 15:07:40 2003 +@@ -0,0 +1,107 @@ ++/* IP tables module for matching various secpath attributes ++ * ++ * (C) 2003 by Patrick McHardy <[email protected]> ++ * ++ * This software is distributed under the terms GNU GPL ++ */ ++ ++#include <linux/config.h> ++#include <linux/module.h> ++#include <linux/skbuff.h> ++#include <net/xfrm.h> ++ ++#include <linux/netfilter_ipv4/ipt_secpath.h> ++#include <linux/netfilter_ipv4/ip_tables.h> ++ ++MODULE_AUTHOR("Patrick McHardy <[email protected]>"); ++MODULE_DESCRIPTION("IP secpath atttribute matching module"); ++MODULE_LICENSE("GPL"); ++ ++static int secpath_match(struct xfrm_state *x, const struct ipt_secpath_elem *e) ++{ ++ if (e->match.saddr) { ++ if ((e->saddr != ((u32) x->props.saddr.a4 & e->smask)) ^ ++ e->invert.saddr) ++ return 0; ++ } ++ if (e->match.daddr) { ++ if ((e->daddr != ((u32) x->id.daddr.a4 & e->dmask)) ^ ++ e->invert.daddr) ++ return 0; ++ } ++ if (e->match.spi) { ++ if ((e->spi != x->id.spi) ^ e->invert.spi) ++ return 0; ++ } ++ if (e->match.proto) { ++ if ((e->proto != x->id.proto) ^ e->invert.proto) ++ return 0; ++ } ++ if (e->match.mode) { ++ if ((e->mode != x->props.mode) ^ e->invert.mode) ++ return 0; ++ } ++ return 1; ++} ++ ++static int match(const struct sk_buff *skb, ++ const struct net_device *in, ++ const struct net_device *out, ++ const void *matchinfo, ++ int offset, int *hotdrop) ++{ ++ const struct ipt_secpath_info *info = matchinfo; ++ struct sec_path *sp = skb->sp; ++ unsigned int i; ++ int strict = info->flags & MATCH_PATH; ++ ++ if (sp == NULL) ++ return 0; ++ ++ if (strict && info->len != sp->len) ++ return 0; ++ ++ for (i = 0; i < sp->len; i++) { ++ if (secpath_match(sp->x[i].xvec, &info->path[strict ? i : 0])) { ++ if (!strict) ++ return 1; ++ } else if (strict) ++ return 0; ++ } ++ ++ return strict ? 1 : 0; ++} ++ ++static int checkentry(const char *tablename, const struct ipt_ip *ip, ++ void *matchinfo, unsigned int matchsize, ++ unsigned int hook_mask) ++{ ++ if (matchsize != IPT_ALIGN(sizeof(struct ipt_secpath_info))) { ++ printk(KERN_ERR "ipt_secpath: matchsize %u != %u.\n", ++ matchsize, IPT_ALIGN(sizeof(struct ipt_secpath_info))); ++ return 0; ++ } ++ ++ return 1; ++} ++ ++static struct ipt_match secpath_match = { ++ .name = "secpath", ++ .match = &match, ++ .checkentry = &checkentry, ++ .me = THIS_MODULE, ++}; ++ ++static int __init init(void) ++{ ++ return ipt_register_match(&secpath_match); ++} ++ ++static void __exit fini(void) ++{ ++ ipt_unregister_match(&secpath_match); ++ ++} ++ ++module_init(init); ++module_exit(fini);
patch-o-matic_2.5/extra/secpath.patch.help +45 -0
45 lines not on this page · raw message
userspace/extensions/libipt_secpath.c +331 -0
331 lines not on this page · raw message
userspace/extensions/.secpath-test +3 -0
@@ -0,0 +1,3 @@ +#!/bin/sh +# True if secpath match patch is applied. +[ -f $KERNEL_DIR/include/linux/netfilter_ipv4/ipt_secpath.h ] && echo secpath