* ip_queue questions
@ 2005-03-26 7:08 Peter Enderborg
2005-03-26 7:54 ` Jonas Berlin
2005-03-26 11:46 ` Pablo Neira
0 siblings, 2 replies; 4+ messages in thread
From: Peter Enderborg @ 2005-03-26 7:08 UTC (permalink / raw)
To: netfilter
Is there any non trivial example of howto use netlink?
A non trivial is something that use do something with the packet and
returns a modifyed packet form userland.
And is there any way to do matching rule in userland? ipq_set_verdict()
must have NF_ACCEPT or NF_DROP.
I whould like to do something similar to the MARK, just modify the data
and then continue.
--
foo!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ip_queue questions
2005-03-26 7:08 ip_queue questions Peter Enderborg
@ 2005-03-26 7:54 ` Jonas Berlin
2005-03-26 10:04 ` Peter Enderborg
2005-03-26 11:46 ` Pablo Neira
1 sibling, 1 reply; 4+ messages in thread
From: Jonas Berlin @ 2005-03-26 7:54 UTC (permalink / raw)
To: Peter Enderborg; +Cc: netfilter
Peter Enderborg wrote:
> Is there any non trivial example of howto use netlink?
No, it's pretty trivial to do anything with libipq imo :D
> A non trivial is something that use do something with the packet and
> returns a modifyed packet form userland.
This code has never been used, I just wrote it for you :)
void handle(void)
{
static unsigned char packet[65536];
// fetch data
if(ipq_read(ipq_h, packet, sizeof(packet), 0) < 0) {
ipq_perror("ipq_read");
return;
}
// check type
if (ipq_message_type(packet) != IPQM_PACKET) {
fprintf(stderr, "Received error message %d\n",
ipq_get_msgerr(packet));
return;
}
ipq_packet_msg_t *msg = ipq_get_packet(packet);
// ensure we got some data (maybe I'm paranoid)
if(msg->data_len == 0) {
ipq_set_verdict(ipq_h, msg->packet_id, NF_DROP, 0, 0);
return;
}
// IP, TCP etc structs I have copypasted from /usr/include/linux/ip.h etc
struct iphdr *iph = (struct iphdr *)msg->payload;
// let's say we want to remove all ip options
// get pointer to start of ip options..
unsigned char *options = &iph[1];
// .. and current end of ip header = end of ip options
unsigned char *options_end = ((unsigned *)iph) + iph->ihl;
if(end_of_options == options) {
// no options, do nothing and accept
ipq_set_verdict(ipq_h, msg->packet_id, NF_ACCEPT, 0, 0);
return;
}
// kill!
memmove(options, options_end,
(unsigned char *)iph + msg->data_len - options_end);
// update lengths
iph->ihl = sizeof(struct iphdr) / 4;
iph->tot_len -= options_end - options;
// ##TODO## update checksum maybe
ipq_set_verdict(ipq_h, msg->packet_id, NF_ACCEPT,
msg->data_len - (options_end - options), msg->payload);
}
Hope you get some idea.. And hope I didn't do it the wrong way or something :)
> And is there any way to do matching rule in userland? ipq_set_verdict()
> must have NF_ACCEPT or NF_DROP.
> I whould like to do something similar to the MARK, just modify the data
> and then continue.
Currently, no :/
Maybe some day.. I don't know enough (yet) to do it myself..
--
- xkr47
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ip_queue questions
2005-03-26 7:54 ` Jonas Berlin
@ 2005-03-26 10:04 ` Peter Enderborg
0 siblings, 0 replies; 4+ messages in thread
From: Peter Enderborg @ 2005-03-26 10:04 UTC (permalink / raw)
To: Jonas Berlin; +Cc: netfilter
Jonas Berlin wrote:
> Peter Enderborg wrote:
>
>> Is there any non trivial example of howto use netlink?
>
>
> No, it's pretty trivial to do anything with libipq imo :D
>
>> A non trivial is something that use do something with the packet and
>> returns a modifyed packet form userland.
>
>
> This code has never been used, I just wrote it for you :)
>
> void handle(void)
> {
> static unsigned char packet[65536];
>
> // fetch data
> if(ipq_read(ipq_h, packet, sizeof(packet), 0) < 0) {
> ipq_perror("ipq_read");
> return;
> }
>
> // check type
> if (ipq_message_type(packet) != IPQM_PACKET) {
> fprintf(stderr, "Received error message %d\n",
> ipq_get_msgerr(packet));
> return;
> }
>
> ipq_packet_msg_t *msg = ipq_get_packet(packet);
>
> // ensure we got some data (maybe I'm paranoid)
> if(msg->data_len == 0) {
> ipq_set_verdict(ipq_h, msg->packet_id, NF_DROP, 0, 0);
> return;
> }
>
> // IP, TCP etc structs I have copypasted from
> /usr/include/linux/ip.h etc
> struct iphdr *iph = (struct iphdr *)msg->payload;
>
> // let's say we want to remove all ip options
> // get pointer to start of ip options..
> unsigned char *options = &iph[1];
> // .. and current end of ip header = end of ip options
> unsigned char *options_end = ((unsigned *)iph) + iph->ihl;
>
> if(end_of_options == options) {
> // no options, do nothing and accept
> ipq_set_verdict(ipq_h, msg->packet_id, NF_ACCEPT, 0, 0);
> return;
> }
>
> // kill!
> memmove(options, options_end,
> (unsigned char *)iph + msg->data_len - options_end);
>
> // update lengths
> iph->ihl = sizeof(struct iphdr) / 4;
> iph->tot_len -= options_end - options;
>
> // ##TODO## update checksum maybe
>
> ipq_set_verdict(ipq_h, msg->packet_id, NF_ACCEPT,
> msg->data_len - (options_end - options),
> msg->payload);
> }
>
> Hope you get some idea.. And hope I didn't do it the wrong way or
> something :)
>
Thanks. I think on track now. But this makes it imposible to modify
mark. (in ipq_packet_msg_t)
And the MARK target is not avaible in "-t filter" section. The idea is
to have diffrent rules in the
QUEUE for userland. But I can only have one netlink queue, right? And I
can't tag my pakets in the
"filter FORWARD" section where I need to have my userland QUEUE's. Hmm,
life is hard :-(
>> And is there any way to do matching rule in userland?
>> ipq_set_verdict() must have NF_ACCEPT or NF_DROP.
>> I whould like to do something similar to the MARK, just modify the
>> data and then continue.
>
>
> Currently, no :/
>
> Maybe some day.. I don't know enough (yet) to do it myself..
>
--
foo!
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ip_queue questions
2005-03-26 7:08 ip_queue questions Peter Enderborg
2005-03-26 7:54 ` Jonas Berlin
@ 2005-03-26 11:46 ` Pablo Neira
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira @ 2005-03-26 11:46 UTC (permalink / raw)
To: Peter Enderborg; +Cc: netfilter
Peter Enderborg wrote:
> I whould like to do something similar to the MARK, just modify the data
> and then continue.
Look for ip_queue_vwmark in pom-ng, that enables the nfmark modification.
AFAIK that patch surely won't ever get in kernel mainline since there's
a more simple way to export nfmark (just adding it to the message). This
breaks backward compatibility with current application though.
--
Pablo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-03-26 11:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-26 7:08 ip_queue questions Peter Enderborg
2005-03-26 7:54 ` Jonas Berlin
2005-03-26 10:04 ` Peter Enderborg
2005-03-26 11:46 ` Pablo Neira
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.