Commit 73baeace authored by David S. Miller's avatar David S. Miller

Merge bk://kernel.bkbits.net/acme/net-2.5

into nuts.ninka.net:/home/davem/src/BK/net-2.5
parents 6c17d503 f989c276
...@@ -347,13 +347,14 @@ struct ipt_match ...@@ -347,13 +347,14 @@ struct ipt_match
/* Return true or false: return FALSE and set *hotdrop = 1 to /* Return true or false: return FALSE and set *hotdrop = 1 to
force immediate packet drop. */ force immediate packet drop. */
/* Arguments changed since 2.4, as this must now handle
non-linear skbs, using skb_copy_bits and
skb_ip_make_writable. */
int (*match)(const struct sk_buff *skb, int (*match)(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop); int *hotdrop);
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
...@@ -367,7 +368,7 @@ struct ipt_match ...@@ -367,7 +368,7 @@ struct ipt_match
/* Called when entry of this type deleted. */ /* Called when entry of this type deleted. */
void (*destroy)(void *matchinfo, unsigned int matchinfosize); void (*destroy)(void *matchinfo, unsigned int matchinfosize);
/* Set this to THIS_MODULE if you are a module, otherwise NULL */ /* Set this to THIS_MODULE. */
struct module *me; struct module *me;
}; };
...@@ -378,14 +379,6 @@ struct ipt_target ...@@ -378,14 +379,6 @@ struct ipt_target
const char name[IPT_FUNCTION_MAXNAMELEN]; const char name[IPT_FUNCTION_MAXNAMELEN];
/* Returns verdict. */
unsigned int (*target)(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in,
const struct net_device *out,
const void *targinfo,
void *userdata);
/* Called when user tries to insert an entry of this type: /* Called when user tries to insert an entry of this type:
hook_mask is a bitmask of hooks from which it can be hook_mask is a bitmask of hooks from which it can be
called. */ called. */
...@@ -399,7 +392,17 @@ struct ipt_target ...@@ -399,7 +392,17 @@ struct ipt_target
/* Called when entry of this type deleted. */ /* Called when entry of this type deleted. */
void (*destroy)(void *targinfo, unsigned int targinfosize); void (*destroy)(void *targinfo, unsigned int targinfosize);
/* Set this to THIS_MODULE if you are a module, otherwise NULL */ /* Returns verdict. Argument order changed since 2.4, as this
must now handle non-linear skbs, using skb_copy_bits and
skb_ip_make_writable. */
unsigned int (*target)(struct sk_buff **pskb,
const struct net_device *in,
const struct net_device *out,
unsigned int hooknum,
const void *targinfo,
void *userdata);
/* Set this to THIS_MODULE. */
struct module *me; struct module *me;
}; };
...@@ -429,7 +432,7 @@ struct ipt_table ...@@ -429,7 +432,7 @@ struct ipt_table
/* Man behind the curtain... */ /* Man behind the curtain... */
struct ipt_table_info *private; struct ipt_table_info *private;
/* Set this to THIS_MODULE if you are a module, otherwise NULL */ /* Set to THIS_MODULE. */
struct module *me; struct module *me;
}; };
......
...@@ -16,7 +16,6 @@ extern struct proto tcpv6_prot; ...@@ -16,7 +16,6 @@ extern struct proto tcpv6_prot;
struct flowi; struct flowi;
/* extention headers */ /* extention headers */
extern void ipv6_hopopts_init(void);
extern void ipv6_rthdr_init(void); extern void ipv6_rthdr_init(void);
extern void ipv6_frag_init(void); extern void ipv6_frag_init(void);
extern void ipv6_nodata_init(void); extern void ipv6_nodata_init(void);
......
...@@ -2863,9 +2863,6 @@ int unregister_netdevice(struct net_device *dev) ...@@ -2863,9 +2863,6 @@ int unregister_netdevice(struct net_device *dev)
extern void net_device_init(void); extern void net_device_init(void);
extern void ip_auto_config(void); extern void ip_auto_config(void);
#ifdef CONFIG_NET_DIVERT
extern void dv_init(void);
#endif /* CONFIG_NET_DIVERT */
/* /*
...@@ -2889,10 +2886,6 @@ static int __init net_dev_init(void) ...@@ -2889,10 +2886,6 @@ static int __init net_dev_init(void)
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
INIT_LIST_HEAD(&ptype_base[i]); INIT_LIST_HEAD(&ptype_base[i]);
#ifdef CONFIG_NET_DIVERT
dv_init();
#endif /* CONFIG_NET_DIVERT */
/* /*
* Initialise the packet receive queues. * Initialise the packet receive queues.
*/ */
......
...@@ -123,6 +123,7 @@ void * dst_alloc(struct dst_ops * ops) ...@@ -123,6 +123,7 @@ void * dst_alloc(struct dst_ops * ops)
if (!dst) if (!dst)
return NULL; return NULL;
memset(dst, 0, ops->entry_size); memset(dst, 0, ops->entry_size);
atomic_set(&dst->__refcnt, 0);
dst->ops = ops; dst->ops = ops;
dst->lastuse = jiffies; dst->lastuse = jiffies;
dst->path = dst; dst->path = dst;
......
...@@ -40,11 +40,12 @@ ...@@ -40,11 +40,12 @@
const char sysctl_divert_version[32]="0.46"; /* Current version */ const char sysctl_divert_version[32]="0.46"; /* Current version */
int __init dv_init(void) static int __init dv_init(void)
{ {
printk(KERN_INFO "NET4: Frame Diverter %s\n", sysctl_divert_version); printk(KERN_INFO "NET4: Frame Diverter %s\n", sysctl_divert_version);
return 0; return 0;
} }
module_init(dv_init);
/* /*
* Allocate a divert_blk for a device. This must be an ethernet nic. * Allocate a divert_blk for a device. This must be an ethernet nic.
......
...@@ -111,9 +111,9 @@ static struct ipt_table nat_table = { ...@@ -111,9 +111,9 @@ static struct ipt_table nat_table = {
/* Source NAT */ /* Source NAT */
static unsigned int ipt_snat_target(struct sk_buff **pskb, static unsigned int ipt_snat_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
...@@ -132,9 +132,9 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb, ...@@ -132,9 +132,9 @@ static unsigned int ipt_snat_target(struct sk_buff **pskb,
} }
static unsigned int ipt_dnat_target(struct sk_buff **pskb, static unsigned int ipt_dnat_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
......
...@@ -214,9 +214,9 @@ ip_checkentry(const struct ipt_ip *ip) ...@@ -214,9 +214,9 @@ ip_checkentry(const struct ipt_ip *ip)
static unsigned int static unsigned int
ipt_error(struct sk_buff **pskb, ipt_error(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
...@@ -232,13 +232,10 @@ int do_match(struct ipt_entry_match *m, ...@@ -232,13 +232,10 @@ int do_match(struct ipt_entry_match *m,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
/* Stop iteration if it doesn't match */ /* Stop iteration if it doesn't match */
if (!m->u.kernel.match->match(skb, in, out, m->data, if (!m->u.kernel.match->match(skb, in, out, m->data, offset, hotdrop))
offset, hdr, datalen, hotdrop))
return 1; return 1;
else else
return 0; return 0;
...@@ -262,7 +259,6 @@ ipt_do_table(struct sk_buff **pskb, ...@@ -262,7 +259,6 @@ ipt_do_table(struct sk_buff **pskb,
static const char nulldevname[IFNAMSIZ] = { 0 }; static const char nulldevname[IFNAMSIZ] = { 0 };
u_int16_t offset; u_int16_t offset;
struct iphdr *ip; struct iphdr *ip;
void *protohdr;
u_int16_t datalen; u_int16_t datalen;
int hotdrop = 0; int hotdrop = 0;
/* Initializing verdict to NF_DROP keeps gcc happy. */ /* Initializing verdict to NF_DROP keeps gcc happy. */
...@@ -271,13 +267,8 @@ ipt_do_table(struct sk_buff **pskb, ...@@ -271,13 +267,8 @@ ipt_do_table(struct sk_buff **pskb,
void *table_base; void *table_base;
struct ipt_entry *e, *back; struct ipt_entry *e, *back;
/* FIXME: Push down to extensions --RR */
if (skb_is_nonlinear(*pskb) && skb_linearize(*pskb, GFP_ATOMIC) != 0)
return NF_DROP;
/* Initialization */ /* Initialization */
ip = (*pskb)->nh.iph; ip = (*pskb)->nh.iph;
protohdr = (u_int32_t *)ip + ip->ihl;
datalen = (*pskb)->len - ip->ihl * 4; datalen = (*pskb)->len - ip->ihl * 4;
indev = in ? in->name : nulldevname; indev = in ? in->name : nulldevname;
outdev = out ? out->name : nulldevname; outdev = out ? out->name : nulldevname;
...@@ -320,8 +311,7 @@ ipt_do_table(struct sk_buff **pskb, ...@@ -320,8 +311,7 @@ ipt_do_table(struct sk_buff **pskb,
if (IPT_MATCH_ITERATE(e, do_match, if (IPT_MATCH_ITERATE(e, do_match,
*pskb, in, out, *pskb, in, out,
offset, protohdr, offset, &hotdrop) != 0)
datalen, &hotdrop) != 0)
goto no_match; goto no_match;
ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1); ADD_COUNTER(e->counters, ntohs(ip->tot_len), 1);
...@@ -364,8 +354,8 @@ ipt_do_table(struct sk_buff **pskb, ...@@ -364,8 +354,8 @@ ipt_do_table(struct sk_buff **pskb,
= 0xeeeeeeec; = 0xeeeeeeec;
#endif #endif
verdict = t->u.kernel.target->target(pskb, verdict = t->u.kernel.target->target(pskb,
hook,
in, out, in, out,
hook,
t->data, t->data,
userdata); userdata);
...@@ -382,7 +372,6 @@ ipt_do_table(struct sk_buff **pskb, ...@@ -382,7 +372,6 @@ ipt_do_table(struct sk_buff **pskb,
#endif #endif
/* Target might have changed stuff. */ /* Target might have changed stuff. */
ip = (*pskb)->nh.iph; ip = (*pskb)->nh.iph;
protohdr = (u_int32_t *)ip + ip->ihl;
datalen = (*pskb)->len - ip->ihl * 4; datalen = (*pskb)->len - ip->ihl * 4;
if (verdict == IPT_CONTINUE) if (verdict == IPT_CONTINUE)
...@@ -1458,22 +1447,24 @@ port_match(u_int16_t min, u_int16_t max, u_int16_t port, int invert) ...@@ -1458,22 +1447,24 @@ port_match(u_int16_t min, u_int16_t max, u_int16_t port, int invert)
static int static int
tcp_find_option(u_int8_t option, tcp_find_option(u_int8_t option,
const struct tcphdr *tcp, const struct sk_buff *skb,
u_int16_t datalen, unsigned int optlen,
int invert, int invert,
int *hotdrop) int *hotdrop)
{ {
unsigned int i = sizeof(struct tcphdr); /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
const u_int8_t *opt = (u_int8_t *)tcp; char opt[60 - sizeof(struct tcphdr)];
unsigned int i;
duprintf("tcp_match: finding option\n"); duprintf("tcp_match: finding option\n");
/* If we don't have the whole header, drop packet. */ /* If we don't have the whole header, drop packet. */
if (tcp->doff * 4 > datalen) { if (skb_copy_bits(skb, skb->nh.iph->ihl*4 + sizeof(struct tcphdr),
opt, optlen) < 0) {
*hotdrop = 1; *hotdrop = 1;
return 0; return 0;
} }
while (i < tcp->doff * 4) { for (i = 0; i < optlen; ) {
if (opt[i] == option) return !invert; if (opt[i] == option) return !invert;
if (opt[i] < 2) i++; if (opt[i] < 2) i++;
else i += opt[i+1]?:1; else i += opt[i+1]?:1;
...@@ -1488,25 +1479,29 @@ tcp_match(const struct sk_buff *skb, ...@@ -1488,25 +1479,29 @@ tcp_match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct tcphdr *tcp = hdr; struct tcphdr tcph;
const struct ipt_tcp *tcpinfo = matchinfo; const struct ipt_tcp *tcpinfo = matchinfo;
/* To quote Alan: if (offset) {
/* To quote Alan:
Don't allow a fragment of TCP 8 bytes in. Nobody normal
causes this. Its a cracker trying to break in by doing a
flag overwrite to pass the direction checks.
*/
if (offset == 1) { Don't allow a fragment of TCP 8 bytes in. Nobody normal
duprintf("Dropping evil TCP offset=1 frag.\n"); causes this. Its a cracker trying to break in by doing a
*hotdrop = 1; flag overwrite to pass the direction checks.
*/
if (offset == 1) {
duprintf("Dropping evil TCP offset=1 frag.\n");
*hotdrop = 1;
}
/* Must not be a fragment. */
return 0; return 0;
} else if (offset == 0 && datalen < sizeof(struct tcphdr)) { }
#define FWINVTCP(bool,invflg) ((bool) ^ !!(tcpinfo->invflags & invflg))
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0) {
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("Dropping evil TCP offset=0 tinygram.\n"); duprintf("Dropping evil TCP offset=0 tinygram.\n");
...@@ -1514,27 +1509,24 @@ tcp_match(const struct sk_buff *skb, ...@@ -1514,27 +1509,24 @@ tcp_match(const struct sk_buff *skb,
return 0; return 0;
} }
/* FIXME: Try tcp doff >> packet len against various stacks --RR */ if (!port_match(tcpinfo->spts[0], tcpinfo->spts[1],
ntohs(tcph.source),
#define FWINVTCP(bool,invflg) ((bool) ^ !!(tcpinfo->invflags & invflg)) !!(tcpinfo->invflags & IPT_TCP_INV_SRCPT)))
return 0;
/* Must not be a fragment. */ if (!port_match(tcpinfo->dpts[0], tcpinfo->dpts[1],
return !offset ntohs(tcph.dest),
&& port_match(tcpinfo->spts[0], tcpinfo->spts[1], !!(tcpinfo->invflags & IPT_TCP_INV_DSTPT)))
ntohs(tcp->source), return 0;
!!(tcpinfo->invflags & IPT_TCP_INV_SRCPT)) if (!FWINVTCP((((unsigned char *)&tcph)[13] & tcpinfo->flg_mask)
&& port_match(tcpinfo->dpts[0], tcpinfo->dpts[1], == tcpinfo->flg_cmp,
ntohs(tcp->dest), IPT_TCP_INV_FLAGS))
!!(tcpinfo->invflags & IPT_TCP_INV_DSTPT)) return 0;
&& FWINVTCP((((unsigned char *)tcp)[13] if (tcpinfo->option &&
& tcpinfo->flg_mask) !tcp_find_option(tcpinfo->option, skb, tcph.doff*4 - sizeof(tcph),
== tcpinfo->flg_cmp, tcpinfo->invflags & IPT_TCP_INV_OPTION,
IPT_TCP_INV_FLAGS) hotdrop))
&& (!tcpinfo->option return 0;
|| tcp_find_option(tcpinfo->option, tcp, datalen, return 1;
tcpinfo->invflags
& IPT_TCP_INV_OPTION,
hotdrop));
} }
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
...@@ -1560,14 +1552,16 @@ udp_match(const struct sk_buff *skb, ...@@ -1560,14 +1552,16 @@ udp_match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct udphdr *udp = hdr; struct udphdr udph;
const struct ipt_udp *udpinfo = matchinfo; const struct ipt_udp *udpinfo = matchinfo;
if (offset == 0 && datalen < sizeof(struct udphdr)) { /* Must not be a fragment. */
if (offset)
return 0;
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &udph, sizeof(udph)) < 0) {
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("Dropping evil UDP tinygram.\n"); duprintf("Dropping evil UDP tinygram.\n");
...@@ -1575,13 +1569,11 @@ udp_match(const struct sk_buff *skb, ...@@ -1575,13 +1569,11 @@ udp_match(const struct sk_buff *skb,
return 0; return 0;
} }
/* Must not be a fragment. */ return port_match(udpinfo->spts[0], udpinfo->spts[1],
return !offset ntohs(udph.source),
&& port_match(udpinfo->spts[0], udpinfo->spts[1], !!(udpinfo->invflags & IPT_UDP_INV_SRCPT))
ntohs(udp->source),
!!(udpinfo->invflags & IPT_UDP_INV_SRCPT))
&& port_match(udpinfo->dpts[0], udpinfo->dpts[1], && port_match(udpinfo->dpts[0], udpinfo->dpts[1],
ntohs(udp->dest), ntohs(udph.dest),
!!(udpinfo->invflags & IPT_UDP_INV_DSTPT)); !!(udpinfo->invflags & IPT_UDP_INV_DSTPT));
} }
...@@ -1631,14 +1623,16 @@ icmp_match(const struct sk_buff *skb, ...@@ -1631,14 +1623,16 @@ icmp_match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct icmphdr *icmp = hdr; struct icmphdr icmph;
const struct ipt_icmp *icmpinfo = matchinfo; const struct ipt_icmp *icmpinfo = matchinfo;
if (offset == 0 && datalen < 2) { /* Must not be a fragment. */
if (offset)
return 0;
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &icmph, sizeof(icmph)) < 0){
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("Dropping evil ICMP tinygram.\n"); duprintf("Dropping evil ICMP tinygram.\n");
...@@ -1646,13 +1640,11 @@ icmp_match(const struct sk_buff *skb, ...@@ -1646,13 +1640,11 @@ icmp_match(const struct sk_buff *skb,
return 0; return 0;
} }
/* Must not be a fragment. */ return icmp_type_code_match(icmpinfo->type,
return !offset icmpinfo->code[0],
&& icmp_type_code_match(icmpinfo->type, icmpinfo->code[1],
icmpinfo->code[0], icmph.type, icmph.code,
icmpinfo->code[1], !!(icmpinfo->invflags&IPT_ICMP_INV));
icmp->type, icmp->code,
!!(icmpinfo->invflags&IPT_ICMP_INV));
} }
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
......
...@@ -23,37 +23,31 @@ MODULE_LICENSE("GPL"); ...@@ -23,37 +23,31 @@ MODULE_LICENSE("GPL");
static unsigned int static unsigned int
target(struct sk_buff **pskb, target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
struct iphdr *iph = (*pskb)->nh.iph;
const struct ipt_DSCP_info *dinfo = targinfo; const struct ipt_DSCP_info *dinfo = targinfo;
u_int8_t sh_dscp = ((dinfo->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK); u_int8_t sh_dscp = ((dinfo->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK);
if ((iph->tos & IPT_DSCP_MASK) != sh_dscp) { if (((*pskb)->nh.iph->tos & IPT_DSCP_MASK) != sh_dscp) {
u_int16_t diffs[2]; u_int16_t diffs[2];
/* raw socket (tcpdump) may have clone of incoming if (!skb_ip_make_writable(pskb, sizeof(struct iphdr)))
* skb: don't disturb it --RR */ return NF_DROP;
if (skb_cloned(*pskb) && !(*pskb)->sk) {
struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC); diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF;
if (!nskb) (*pskb)->nh.iph->tos = ((*pskb)->nh.iph->tos & ~IPT_DSCP_MASK)
return NF_DROP; | sh_dscp;
kfree_skb(*pskb); diffs[1] = htons((*pskb)->nh.iph->tos);
*pskb = nskb; (*pskb)->nh.iph->check
iph = (*pskb)->nh.iph; = csum_fold(csum_partial((char *)diffs,
} sizeof(diffs),
(*pskb)->nh.iph->check
diffs[0] = htons(iph->tos) ^ 0xFFFF; ^ 0xFFFF));
iph->tos = (iph->tos & ~IPT_DSCP_MASK) | sh_dscp;
diffs[1] = htons(iph->tos);
iph->check = csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
iph->check^0xFFFF));
(*pskb)->nfcache |= NFC_ALTERED; (*pskb)->nfcache |= NFC_ALTERED;
} }
return IPT_CONTINUE; return IPT_CONTINUE;
......
...@@ -19,105 +19,85 @@ ...@@ -19,105 +19,85 @@
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* set ECT codepoint from IP header. /* set ECT codepoint from IP header.
* return 0 in case there was no ECT codepoint * return 0 if there was an error. */
* return 1 in case ECT codepoint has been overwritten
* return < 0 in case there was error */
static inline int static inline int
set_ect_ip(struct sk_buff **pskb, struct iphdr *iph, set_ect_ip(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
const struct ipt_ECN_info *einfo)
{ {
if ((iph->tos & IPT_ECN_IP_MASK) if (((*pskb)->nh.iph->tos & IPT_ECN_IP_MASK)
!= (einfo->ip_ect & IPT_ECN_IP_MASK)) { != (einfo->ip_ect & IPT_ECN_IP_MASK)) {
u_int16_t diffs[2]; u_int16_t diffs[2];
/* raw socket (tcpdump) may have clone of incoming if (!skb_ip_make_writable(pskb, sizeof(struct iphdr)))
* skb: don't disturb it --RR */ return 0;
if (skb_cloned(*pskb) && !(*pskb)->sk) {
struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC); diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF;
if (!nskb) (*pskb)->nh.iph->tos &= ~IPT_ECN_IP_MASK;
return NF_DROP; (*pskb)->nh.iph->tos |= (einfo->ip_ect & IPT_ECN_IP_MASK);
kfree_skb(*pskb); diffs[1] = htons((*pskb)->nh.iph->tos);
*pskb = nskb; (*pskb)->nh.iph->check
iph = (*pskb)->nh.iph; = csum_fold(csum_partial((char *)diffs,
} sizeof(diffs),
(*pskb)->nh.iph->check
diffs[0] = htons(iph->tos) ^ 0xFFFF; ^0xFFFF));
iph->tos = iph->tos & ~IPT_ECN_IP_MASK;
iph->tos = iph->tos | (einfo->ip_ect & IPT_ECN_IP_MASK);
diffs[1] = htons(iph->tos);
iph->check = csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
iph->check^0xFFFF));
(*pskb)->nfcache |= NFC_ALTERED; (*pskb)->nfcache |= NFC_ALTERED;
return 1;
} }
return 0; return 1;
} }
/* Return 0 if there was an error. */
static inline int static inline int
set_ect_tcp(struct sk_buff **pskb, struct iphdr *iph, set_ect_tcp(struct sk_buff **pskb, const struct ipt_ECN_info *einfo)
const struct ipt_ECN_info *einfo)
{ {
struct tcphdr tcph;
struct tcphdr *tcph = (void *) iph + iph->ihl * 4;
u_int16_t *tcpflags = (u_int16_t *)tcph + 6;
u_int16_t diffs[2]; u_int16_t diffs[2];
/* raw socket (tcpdump) may have clone of incoming /* Not enought header? */
* skb: don't disturb it --RR */ if (skb_copy_bits(*pskb, (*pskb)->nh.iph->ihl*4, &tcph, sizeof(tcph))
if (skb_cloned(*pskb) && !(*pskb)->sk) { < 0)
struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC); return 0;
if (!nskb)
return NF_DROP;
kfree_skb(*pskb);
*pskb = nskb;
iph = (*pskb)->nh.iph;
}
diffs[0] = *tcpflags; diffs[0] = ((u_int16_t *)&tcph)[6];
if (einfo->operation & IPT_ECN_OP_SET_ECE)
tcph.ece = einfo->proto.tcp.ece;
if (einfo->operation & IPT_ECN_OP_SET_ECE if (einfo->operation & IPT_ECN_OP_SET_CWR)
&& tcph->ece != einfo->proto.tcp.ece) { tcph.cwr = einfo->proto.tcp.cwr;
tcph->ece = einfo->proto.tcp.ece; diffs[1] = ((u_int16_t *)&tcph)[6];
}
if (einfo->operation & IPT_ECN_OP_SET_CWR /* Only mangle if it's changed. */
&& tcph->cwr != einfo->proto.tcp.cwr) { if (diffs[0] != diffs[1]) {
tcph->cwr = einfo->proto.tcp.cwr;
}
if (diffs[0] != *tcpflags) {
diffs[0] = diffs[0] ^ 0xFFFF; diffs[0] = diffs[0] ^ 0xFFFF;
diffs[1] = *tcpflags; if (!skb_ip_make_writable(pskb,
tcph->check = csum_fold(csum_partial((char *)diffs, (*pskb)->nh.iph->ihl*4+sizeof(tcph)))
return 0;
tcph.check = csum_fold(csum_partial((char *)diffs,
sizeof(diffs), sizeof(diffs),
tcph->check^0xFFFF)); tcph.check^0xFFFF));
memcpy((*pskb)->data + (*pskb)->nh.iph->ihl*4,
&tcph, sizeof(tcph));
(*pskb)->nfcache |= NFC_ALTERED; (*pskb)->nfcache |= NFC_ALTERED;
return 1;
} }
return 1;
return 0;
} }
static unsigned int static unsigned int
target(struct sk_buff **pskb, target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
struct iphdr *iph = (*pskb)->nh.iph;
const struct ipt_ECN_info *einfo = targinfo; const struct ipt_ECN_info *einfo = targinfo;
if (einfo->operation & IPT_ECN_OP_SET_IP) if (einfo->operation & IPT_ECN_OP_SET_IP)
set_ect_ip(pskb, iph, einfo); if (!set_ect_ip(pskb, einfo))
return NF_DROP;
if (einfo->operation & (IPT_ECN_OP_SET_ECE | IPT_ECN_OP_SET_CWR) if (einfo->operation & (IPT_ECN_OP_SET_ECE | IPT_ECN_OP_SET_CWR)
&& iph->protocol == IPPROTO_TCP) && (*pskb)->nh.iph->protocol == IPPROTO_TCP)
set_ect_tcp(pskb, iph, einfo); if (!set_ect_tcp(pskb, einfo))
return NF_DROP;
return IPT_CONTINUE; return IPT_CONTINUE;
} }
......
This diff is collapsed.
...@@ -9,9 +9,9 @@ ...@@ -9,9 +9,9 @@
static unsigned int static unsigned int
target(struct sk_buff **pskb, target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
......
...@@ -57,9 +57,9 @@ masquerade_check(const char *tablename, ...@@ -57,9 +57,9 @@ masquerade_check(const char *tablename,
static unsigned int static unsigned int
masquerade_target(struct sk_buff **pskb, masquerade_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
......
...@@ -65,18 +65,22 @@ static int route_mirror(struct sk_buff *skb) ...@@ -65,18 +65,22 @@ static int route_mirror(struct sk_buff *skb)
return 0; return 0;
} }
static void static int ip_rewrite(struct sk_buff **pskb)
ip_rewrite(struct sk_buff *skb)
{ {
struct iphdr *iph = skb->nh.iph; u32 odaddr, osaddr;
u32 odaddr = iph->saddr;
u32 osaddr = iph->daddr;
skb->nfcache |= NFC_ALTERED; if (!skb_ip_make_writable(pskb, sizeof(struct iphdr)))
return 0;
odaddr = (*pskb)->nh.iph->saddr;
osaddr = (*pskb)->nh.iph->daddr;
(*pskb)->nfcache |= NFC_ALTERED;
/* Rewrite IP header */ /* Rewrite IP header */
iph->daddr = odaddr; (*pskb)->nh.iph->daddr = odaddr;
iph->saddr = osaddr; (*pskb)->nh.iph->saddr = osaddr;
return 1;
} }
/* Stolen from ip_finish_output2 */ /* Stolen from ip_finish_output2 */
...@@ -100,29 +104,28 @@ static void ip_direct_send(struct sk_buff *skb) ...@@ -100,29 +104,28 @@ static void ip_direct_send(struct sk_buff *skb)
} }
static unsigned int ipt_mirror_target(struct sk_buff **pskb, static unsigned int ipt_mirror_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
if (((*pskb)->dst != NULL) && if (((*pskb)->dst != NULL) && route_mirror(*pskb)) {
route_mirror(*pskb)) { if (!ip_rewrite(pskb))
return NF_DROP;
ip_rewrite(*pskb);
/* If we are not at FORWARD hook (INPUT/PREROUTING), /* If we are not at FORWARD hook (INPUT/PREROUTING),
* the TTL isn't decreased by the IP stack */ * the TTL isn't decreased by the IP stack */
if (hooknum != NF_IP_FORWARD) { if (hooknum != NF_IP_FORWARD) {
struct iphdr *iph = (*pskb)->nh.iph; if ((*pskb)->nh.iph->ttl <= 1) {
if (iph->ttl <= 1) {
/* this will traverse normal stack, and /* this will traverse normal stack, and
* thus call conntrack on the icmp packet */ * thus call conntrack on the icmp packet */
icmp_send(*pskb, ICMP_TIME_EXCEEDED, icmp_send(*pskb, ICMP_TIME_EXCEEDED,
ICMP_EXC_TTL, 0); ICMP_EXC_TTL, 0);
return NF_DROP; return NF_DROP;
} }
ip_decrease_ttl(iph); /* Made writable by ip_rewrite */
ip_decrease_ttl((*pskb)->nh.iph);
} }
/* Don't let conntrack code see this packet: /* Don't let conntrack code see this packet:
......
...@@ -53,9 +53,9 @@ redirect_check(const char *tablename, ...@@ -53,9 +53,9 @@ redirect_check(const char *tablename,
static unsigned int static unsigned int
redirect_target(struct sk_buff **pskb, redirect_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
......
This diff is collapsed.
...@@ -36,9 +36,9 @@ optlen(const u_int8_t *opt, unsigned int offset) ...@@ -36,9 +36,9 @@ optlen(const u_int8_t *opt, unsigned int offset)
static unsigned int static unsigned int
ipt_tcpmss_target(struct sk_buff **pskb, ipt_tcpmss_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
...@@ -49,15 +49,8 @@ ipt_tcpmss_target(struct sk_buff **pskb, ...@@ -49,15 +49,8 @@ ipt_tcpmss_target(struct sk_buff **pskb,
unsigned int i; unsigned int i;
u_int8_t *opt; u_int8_t *opt;
/* raw socket (tcpdump) may have clone of incoming skb: don't if (!skb_ip_make_writable(pskb, (*pskb)->len))
disturb it --RR */ return NF_DROP;
if (skb_cloned(*pskb) && !(*pskb)->sk) {
struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
kfree_skb(*pskb);
*pskb = nskb;
}
iph = (*pskb)->nh.iph; iph = (*pskb)->nh.iph;
tcplen = (*pskb)->len - iph->ihl*4; tcplen = (*pskb)->len - iph->ihl*4;
......
...@@ -9,35 +9,30 @@ ...@@ -9,35 +9,30 @@
static unsigned int static unsigned int
target(struct sk_buff **pskb, target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, const void *targinfo,
void *userinfo) void *userinfo)
{ {
struct iphdr *iph = (*pskb)->nh.iph;
const struct ipt_tos_target_info *tosinfo = targinfo; const struct ipt_tos_target_info *tosinfo = targinfo;
if ((iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) { if (((*pskb)->nh.iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) {
u_int16_t diffs[2]; u_int16_t diffs[2];
/* raw socket (tcpdump) may have clone of incoming if (!skb_ip_make_writable(pskb, sizeof(struct iphdr)))
skb: don't disturb it --RR */ return NF_DROP;
if (skb_cloned(*pskb) && !(*pskb)->sk) {
struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC);
if (!nskb)
return NF_DROP;
kfree_skb(*pskb);
*pskb = nskb;
iph = (*pskb)->nh.iph;
}
diffs[0] = htons(iph->tos) ^ 0xFFFF; diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF;
iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos; (*pskb)->nh.iph->tos
diffs[1] = htons(iph->tos); = ((*pskb)->nh.iph->tos & IPTOS_PREC_MASK)
iph->check = csum_fold(csum_partial((char *)diffs, | tosinfo->tos;
sizeof(diffs), diffs[1] = htons((*pskb)->nh.iph->tos);
iph->check^0xFFFF)); (*pskb)->nh.iph->check
= csum_fold(csum_partial((char *)diffs,
sizeof(diffs),
(*pskb)->nh.iph->check
^0xFFFF));
(*pskb)->nfcache |= NFC_ALTERED; (*pskb)->nfcache |= NFC_ALTERED;
} }
return IPT_CONTINUE; return IPT_CONTINUE;
......
...@@ -155,9 +155,9 @@ struct sk_buff *ulog_alloc_skb(unsigned int size) ...@@ -155,9 +155,9 @@ struct sk_buff *ulog_alloc_skb(unsigned int size)
} }
static unsigned int ipt_ulog_target(struct sk_buff **pskb, static unsigned int ipt_ulog_target(struct sk_buff **pskb,
unsigned int hooknum,
const struct net_device *in, const struct net_device *in,
const struct net_device *out, const struct net_device *out,
unsigned int hooknum,
const void *targinfo, void *userinfo) const void *targinfo, void *userinfo)
{ {
ulog_buff_t *ub; ulog_buff_t *ub;
...@@ -238,8 +238,9 @@ static unsigned int ipt_ulog_target(struct sk_buff **pskb, ...@@ -238,8 +238,9 @@ static unsigned int ipt_ulog_target(struct sk_buff **pskb,
else else
pm->outdev_name[0] = '\0'; pm->outdev_name[0] = '\0';
if (copy_len) /* copy_len <= (*pskb)->len, so can't fail. */
memcpy(pm->payload, (*pskb)->data, copy_len); if (skb_copy_bits(*pskb, 0, pm->payload, copy_len) < 0)
BUG();
/* check if we are building multi-part messages */ /* check if we are building multi-part messages */
if (ub->qlen > 1) { if (ub->qlen > 1) {
......
...@@ -35,14 +35,16 @@ match(const struct sk_buff *skb, ...@@ -35,14 +35,16 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ahhdr *ah = hdr; struct ahhdr ah;
const struct ipt_ah *ahinfo = matchinfo; const struct ipt_ah *ahinfo = matchinfo;
if (offset == 0 && datalen < sizeof(struct ahhdr)) { /* Must not be a fragment. */
if (offset)
return 0;
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &ah, sizeof(ah)) < 0) {
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("Dropping evil AH tinygram.\n"); duprintf("Dropping evil AH tinygram.\n");
...@@ -50,11 +52,9 @@ match(const struct sk_buff *skb, ...@@ -50,11 +52,9 @@ match(const struct sk_buff *skb,
return 0; return 0;
} }
/* Must not be a fragment. */ return spi_match(ahinfo->spis[0], ahinfo->spis[1],
return !offset ntohl(ah.spi),
&& spi_match(ahinfo->spis[0], ahinfo->spis[1], !!(ahinfo->invflags & IPT_AH_INV_SPI));
ntohl(ah->spi),
!!(ahinfo->invflags & IPT_AH_INV_SPI));
} }
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
......
...@@ -14,8 +14,6 @@ match(const struct sk_buff *skb, ...@@ -14,8 +14,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_conntrack_info *sinfo = matchinfo; const struct ipt_conntrack_info *sinfo = matchinfo;
......
...@@ -19,8 +19,7 @@ MODULE_LICENSE("GPL"); ...@@ -19,8 +19,7 @@ MODULE_LICENSE("GPL");
static int match(const struct sk_buff *skb, const struct net_device *in, static int match(const struct sk_buff *skb, const struct net_device *in,
const struct net_device *out, const void *matchinfo, const struct net_device *out, const void *matchinfo,
int offset, const void *hdr, u_int16_t datalen, int offset, int *hotdrop)
int *hotdrop)
{ {
const struct ipt_dscp_info *info = matchinfo; const struct ipt_dscp_info *info = matchinfo;
const struct iphdr *iph = skb->nh.iph; const struct iphdr *iph = skb->nh.iph;
......
...@@ -19,34 +19,40 @@ MODULE_DESCRIPTION("IP tables ECN matching module"); ...@@ -19,34 +19,40 @@ MODULE_DESCRIPTION("IP tables ECN matching module");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
static inline int match_ip(const struct sk_buff *skb, static inline int match_ip(const struct sk_buff *skb,
const struct iphdr *iph,
const struct ipt_ecn_info *einfo) const struct ipt_ecn_info *einfo)
{ {
return ((iph->tos&IPT_ECN_IP_MASK) == einfo->ip_ect); return ((skb->nh.iph->tos&IPT_ECN_IP_MASK) == einfo->ip_ect);
} }
static inline int match_tcp(const struct sk_buff *skb, static inline int match_tcp(const struct sk_buff *skb,
const struct iphdr *iph, const struct ipt_ecn_info *einfo,
const struct ipt_ecn_info *einfo) int *hotdrop)
{ {
struct tcphdr *tcph = (void *)iph + iph->ihl*4; struct tcphdr tcph;
/* In practice, TCP match does this, so can't fail. But let's
be good citizens. */
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0) {
*hotdrop = 0;
return 0;
}
if (einfo->operation & IPT_ECN_OP_MATCH_ECE) { if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
if (einfo->invert & IPT_ECN_OP_MATCH_ECE) { if (einfo->invert & IPT_ECN_OP_MATCH_ECE) {
if (tcph->ece == 1) if (tcph.ece == 1)
return 0; return 0;
} else { } else {
if (tcph->ece == 0) if (tcph.ece == 0)
return 0; return 0;
} }
} }
if (einfo->operation & IPT_ECN_OP_MATCH_CWR) { if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
if (einfo->invert & IPT_ECN_OP_MATCH_CWR) { if (einfo->invert & IPT_ECN_OP_MATCH_CWR) {
if (tcph->cwr == 1) if (tcph.cwr == 1)
return 0; return 0;
} else { } else {
if (tcph->cwr == 0) if (tcph.cwr == 0)
return 0; return 0;
} }
} }
...@@ -56,20 +62,18 @@ static inline int match_tcp(const struct sk_buff *skb, ...@@ -56,20 +62,18 @@ static inline int match_tcp(const struct sk_buff *skb,
static int match(const struct sk_buff *skb, const struct net_device *in, static int match(const struct sk_buff *skb, const struct net_device *in,
const struct net_device *out, const void *matchinfo, const struct net_device *out, const void *matchinfo,
int offset, const void *hdr, u_int16_t datalen, int offset, int *hotdrop)
int *hotdrop)
{ {
const struct ipt_ecn_info *info = matchinfo; const struct ipt_ecn_info *info = matchinfo;
const struct iphdr *iph = skb->nh.iph;
if (info->operation & IPT_ECN_OP_MATCH_IP) if (info->operation & IPT_ECN_OP_MATCH_IP)
if (!match_ip(skb, iph, info)) if (!match_ip(skb, info))
return 0; return 0;
if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) { if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
if (iph->protocol != IPPROTO_TCP) if (skb->nh.iph->protocol != IPPROTO_TCP)
return 0; return 0;
if (!match_tcp(skb, iph, info)) if (!match_tcp(skb, info, hotdrop))
return 0; return 0;
} }
......
...@@ -35,14 +35,16 @@ match(const struct sk_buff *skb, ...@@ -35,14 +35,16 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct esphdr *esp = hdr; struct esphdr esp;
const struct ipt_esp *espinfo = matchinfo; const struct ipt_esp *espinfo = matchinfo;
if (offset == 0 && datalen < sizeof(struct esphdr)) { /* Must not be a fragment. */
if (offset)
return 0;
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &esp, sizeof(esp)) < 0) {
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("Dropping evil ESP tinygram.\n"); duprintf("Dropping evil ESP tinygram.\n");
...@@ -50,11 +52,9 @@ match(const struct sk_buff *skb, ...@@ -50,11 +52,9 @@ match(const struct sk_buff *skb,
return 0; return 0;
} }
/* Must not be a fragment. */ return spi_match(espinfo->spis[0], espinfo->spis[1],
return !offset ntohl(esp.spi),
&& spi_match(espinfo->spis[0], espinfo->spis[1], !!(espinfo->invflags & IPT_ESP_INV_SPI));
ntohl(esp->spi),
!!(espinfo->invflags & IPT_ESP_INV_SPI));
} }
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
......
...@@ -28,8 +28,6 @@ match(const struct sk_buff *skb, ...@@ -28,8 +28,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_helper_info *info = matchinfo; const struct ipt_helper_info *info = matchinfo;
......
...@@ -15,8 +15,6 @@ match(const struct sk_buff *skb, ...@@ -15,8 +15,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_length_info *info = matchinfo; const struct ipt_length_info *info = matchinfo;
......
...@@ -47,8 +47,6 @@ ipt_limit_match(const struct sk_buff *skb, ...@@ -47,8 +47,6 @@ ipt_limit_match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
struct ipt_rateinfo *r = ((struct ipt_rateinfo *)matchinfo)->master; struct ipt_rateinfo *r = ((struct ipt_rateinfo *)matchinfo)->master;
......
...@@ -12,8 +12,6 @@ match(const struct sk_buff *skb, ...@@ -12,8 +12,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_mac_info *info = matchinfo; const struct ipt_mac_info *info = matchinfo;
......
...@@ -11,8 +11,6 @@ match(const struct sk_buff *skb, ...@@ -11,8 +11,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_mark_info *info = matchinfo; const struct ipt_mark_info *info = matchinfo;
......
...@@ -39,15 +39,18 @@ match(const struct sk_buff *skb, ...@@ -39,15 +39,18 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct udphdr *udp = hdr; u16 ports[2];
const struct ipt_multiport *multiinfo = matchinfo; const struct ipt_multiport *multiinfo = matchinfo;
/* Must be big enough to read ports. */ /* Must not be a fragment. */
if (offset == 0 && datalen < sizeof(struct udphdr)) { if (offset)
return 0;
/* Must be big enough to read ports (both UDP and TCP have
them at the start). */
if (skb_copy_bits(skb, skb->nh.iph->ihl*4, ports, sizeof(ports)) < 0) {
/* We've been asked to examine this packet, and we /* We've been asked to examine this packet, and we
can't. Hence, no choice but to drop. */ can't. Hence, no choice but to drop. */
duprintf("ipt_multiport:" duprintf("ipt_multiport:"
...@@ -56,11 +59,9 @@ match(const struct sk_buff *skb, ...@@ -56,11 +59,9 @@ match(const struct sk_buff *skb,
return 0; return 0;
} }
/* Must not be a fragment. */ return ports_match(multiinfo->ports,
return !offset multiinfo->flags, multiinfo->count,
&& ports_match(multiinfo->ports, ntohs(ports[0]), ntohs(ports[1]));
multiinfo->flags, multiinfo->count,
ntohs(udp->source), ntohs(udp->dest));
} }
/* Called when user tries to insert an entry of this type. */ /* Called when user tries to insert an entry of this type. */
......
...@@ -115,8 +115,6 @@ match(const struct sk_buff *skb, ...@@ -115,8 +115,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_owner_info *info = matchinfo; const struct ipt_owner_info *info = matchinfo;
...@@ -170,8 +168,11 @@ checkentry(const char *tablename, ...@@ -170,8 +168,11 @@ checkentry(const char *tablename,
return 0; return 0;
} }
if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) if (matchsize != IPT_ALIGN(sizeof(struct ipt_owner_info))) {
printk("Matchsize %u != %Zu\n", matchsize,
IPT_ALIGN(sizeof(struct ipt_owner_info)));
return 0; return 0;
}
return 1; return 1;
} }
......
...@@ -14,8 +14,6 @@ match(const struct sk_buff *skb, ...@@ -14,8 +14,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
int i; int i;
......
...@@ -13,8 +13,6 @@ static int match(const struct sk_buff *skb, ...@@ -13,8 +13,6 @@ static int match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_pkttype_info *info = matchinfo; const struct ipt_pkttype_info *info = matchinfo;
......
...@@ -13,8 +13,6 @@ match(const struct sk_buff *skb, ...@@ -13,8 +13,6 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_state_info *sinfo = matchinfo; const struct ipt_state_info *sinfo = matchinfo;
......
...@@ -11,24 +11,32 @@ ...@@ -11,24 +11,32 @@
/* Returns 1 if the mss option is set and matched by the range, 0 otherwise */ /* Returns 1 if the mss option is set and matched by the range, 0 otherwise */
static inline int static inline int
mssoption_match(u_int16_t min, u_int16_t max, mssoption_match(u_int16_t min, u_int16_t max,
const struct tcphdr *tcp, const struct sk_buff *skb,
u_int16_t datalen,
int invert, int invert,
int *hotdrop) int *hotdrop)
{ {
unsigned int i; struct tcphdr tcph;
const u_int8_t *opt = (u_int8_t *)tcp; /* tcp.doff is only 4 bits, ie. max 15 * 4 bytes */
u8 opt[15 * 4 - sizeof(tcph)];
unsigned int i, optlen;
/* If we don't have the whole header, drop packet. */ /* If we don't have the whole header, drop packet. */
if (tcp->doff * 4 > datalen) { if (skb_copy_bits(skb, skb->nh.iph->ihl*4, &tcph, sizeof(tcph)) < 0)
*hotdrop = 1; goto dropit;
return 0;
} /* Malformed. */
if (tcph.doff*4 < sizeof(tcph))
for (i = sizeof(struct tcphdr); i < tcp->doff * 4; ) { goto dropit;
if ((opt[i] == TCPOPT_MSS)
&& ((tcp->doff * 4 - i) >= TCPOLEN_MSS) optlen = tcph.doff*4 - sizeof(tcph);
&& (opt[i+1] == TCPOLEN_MSS)) { /* Truncated options. */
if (skb_copy_bits(skb, skb->nh.iph->ihl*4+sizeof(tcph), opt, optlen)<0)
goto dropit;
for (i = 0; i < optlen; ) {
if (opt[i] == TCPOPT_MSS
&& (optlen - i) >= TCPOLEN_MSS
&& opt[i+1] == TCPOLEN_MSS) {
u_int16_t mssval; u_int16_t mssval;
mssval = (opt[i+2] << 8) | opt[i+3]; mssval = (opt[i+2] << 8) | opt[i+3];
...@@ -38,8 +46,11 @@ mssoption_match(u_int16_t min, u_int16_t max, ...@@ -38,8 +46,11 @@ mssoption_match(u_int16_t min, u_int16_t max,
if (opt[i] < 2) i++; if (opt[i] < 2) i++;
else i += opt[i+1]?:1; else i += opt[i+1]?:1;
} }
return invert; return invert;
dropit:
*hotdrop = 1;
return 0;
} }
static int static int
...@@ -48,15 +59,11 @@ match(const struct sk_buff *skb, ...@@ -48,15 +59,11 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_tcpmss_match_info *info = matchinfo; const struct ipt_tcpmss_match_info *info = matchinfo;
const struct tcphdr *tcph = (void *)skb->nh.iph + skb->nh.iph->ihl*4;
return mssoption_match(info->mss_min, info->mss_max, tcph, return mssoption_match(info->mss_min, info->mss_max, skb,
skb->len - skb->nh.iph->ihl*4,
info->invert, hotdrop); info->invert, hotdrop);
} }
......
...@@ -11,14 +11,11 @@ match(const struct sk_buff *skb, ...@@ -11,14 +11,11 @@ match(const struct sk_buff *skb,
const struct net_device *out, const struct net_device *out,
const void *matchinfo, const void *matchinfo,
int offset, int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop) int *hotdrop)
{ {
const struct ipt_tos_info *info = matchinfo; const struct ipt_tos_info *info = matchinfo;
const struct iphdr *iph = skb->nh.iph;
return (iph->tos == info->tos) ^ info->invert; return (skb->nh.iph->tos == info->tos) ^ info->invert;
} }
static int static int
......
...@@ -19,24 +19,22 @@ MODULE_LICENSE("GPL"); ...@@ -19,24 +19,22 @@ MODULE_LICENSE("GPL");
static int match(const struct sk_buff *skb, const struct net_device *in, static int match(const struct sk_buff *skb, const struct net_device *in,
const struct net_device *out, const void *matchinfo, const struct net_device *out, const void *matchinfo,
int offset, const void *hdr, u_int16_t datalen, int offset, int *hotdrop)
int *hotdrop)
{ {
const struct ipt_ttl_info *info = matchinfo; const struct ipt_ttl_info *info = matchinfo;
const struct iphdr *iph = skb->nh.iph;
switch (info->mode) { switch (info->mode) {
case IPT_TTL_EQ: case IPT_TTL_EQ:
return (iph->ttl == info->ttl); return (skb->nh.iph->ttl == info->ttl);
break; break;
case IPT_TTL_NE: case IPT_TTL_NE:
return (!(iph->ttl == info->ttl)); return (!(skb->nh.iph->ttl == info->ttl));
break; break;
case IPT_TTL_LT: case IPT_TTL_LT:
return (iph->ttl < info->ttl); return (skb->nh.iph->ttl < info->ttl);
break; break;
case IPT_TTL_GT: case IPT_TTL_GT:
return (iph->ttl > info->ttl); return (skb->nh.iph->ttl > info->ttl);
break; break;
default: default:
printk(KERN_WARNING "ipt_ttl: unknown mode %d\n", printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
......
This diff is collapsed.
...@@ -127,8 +127,8 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -127,8 +127,8 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
dev_hold(dev); dev_hold(dev);
dst_release(&rt->u.dst); dst_release(&rt->u.dst);
} else if (ishost) { } else if (ishost) {
sock_kfree_s(sk, pac, sizeof(*pac)); err = -EADDRNOTAVAIL;
return -EADDRNOTAVAIL; goto out_free_pac;
} else { } else {
/* router, no matching interface: just pick one */ /* router, no matching interface: just pick one */
...@@ -138,18 +138,17 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -138,18 +138,17 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
dev = dev_get_by_index(ifindex); dev = dev_get_by_index(ifindex);
if (dev == NULL) { if (dev == NULL) {
sock_kfree_s(sk, pac, sizeof(*pac)); err = -ENODEV;
return -ENODEV; goto out_free_pac;
} }
idev = in6_dev_get(dev); idev = in6_dev_get(dev);
if (!idev) { if (!idev) {
sock_kfree_s(sk, pac, sizeof(*pac));
dev_put(dev);
if (ifindex) if (ifindex)
return -ENODEV; err = -ENODEV;
else else
return -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto out_dev_put;
} }
/* reset ishost, now that we have a specific device */ /* reset ishost, now that we have a specific device */
ishost = !idev->cnf.forwarding; ishost = !idev->cnf.forwarding;
...@@ -170,21 +169,17 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -170,21 +169,17 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
else if (!capable(CAP_NET_ADMIN)) else if (!capable(CAP_NET_ADMIN))
err = -EPERM; err = -EPERM;
if (err) { if (err)
sock_kfree_s(sk, pac, sizeof(*pac)); goto out_dev_put;
dev_put(dev);
return err;
}
} else if (!(ipv6_addr_type(addr) & IPV6_ADDR_ANYCAST) && } else if (!(ipv6_addr_type(addr) & IPV6_ADDR_ANYCAST) &&
!capable(CAP_NET_ADMIN)) !capable(CAP_NET_ADMIN)) {
return -EPERM; err = -EPERM;
goto out_dev_put;
}
err = ipv6_dev_ac_inc(dev, addr); err = ipv6_dev_ac_inc(dev, addr);
if (err) { if (err)
sock_kfree_s(sk, pac, sizeof(*pac)); goto out_dev_put;
dev_put(dev);
return err;
}
write_lock_bh(&ipv6_sk_ac_lock); write_lock_bh(&ipv6_sk_ac_lock);
pac->acl_next = np->ipv6_ac_list; pac->acl_next = np->ipv6_ac_list;
...@@ -194,6 +189,12 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr) ...@@ -194,6 +189,12 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, struct in6_addr *addr)
dev_put(dev); dev_put(dev);
return 0; return 0;
out_dev_put:
dev_put(dev);
out_free_pac:
sock_kfree_s(sk, pac, sizeof(*pac));
return err;
} }
/* /*
......
...@@ -441,8 +441,10 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -441,8 +441,10 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
src_addr = solicited_addr; src_addr = solicited_addr;
in6_ifa_put(ifp); in6_ifa_put(ifp);
} else { } else {
if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, 0)) if (ipv6_dev_get_saddr(dev, daddr, &tmpaddr, 0)) {
dst_free(dst);
return; return;
}
src_addr = &tmpaddr; src_addr = &tmpaddr;
} }
...@@ -450,11 +452,10 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -450,11 +452,10 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
ndisc_rt_init(rt, dev, neigh); ndisc_rt_init(rt, dev, neigh);
dst = (struct dst_entry*)rt; dst = (struct dst_entry*)rt;
dst_clone(dst);
err = xfrm_lookup(&dst, &fl, NULL, 0); err = xfrm_lookup(&dst, &fl, NULL, 0);
if (err < 0) { if (err < 0) {
dst_release(dst); dst_free(dst);
return; return;
} }
...@@ -470,6 +471,7 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh, ...@@ -470,6 +471,7 @@ static void ndisc_send_na(struct net_device *dev, struct neighbour *neigh,
if (skb == NULL) { if (skb == NULL) {
ND_PRINTK1("send_na: alloc skb failed\n"); ND_PRINTK1("send_na: alloc skb failed\n");
dst_free(dst);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment