Skip to contentSkip to conversation

Handling of subnets grammar in Packet filter file

PATCH chantra 4 participants 6 messages Jun 3, 2010 – Jun 11, 2010 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): mailman.487721.1275403360.5170.openvpn-devel@lists.sourceforge.net

chantra

author
#1 lore raw

Please find below a patch to correct the behaviour.

I have also opened a trac ticket :
https://community.openvpn.net/openvpn/ticket/14

chantra

----
http://www.debuntu.org

Quoted 38 lines

Hi all,

It seems that openvpn is not handling properly non-standard subnets in pf_file.
This issue happened on debian etch openvpn 2.1 rc11

Today, while I made a typo, the following rule did not work properly:

        # cat /dev/shm/openvpn_pf_73f2c3256a50371f057d5c0db97ede2f.tmp
        [CLIENTS DROP]
        [SUBNETS ACCEPT]
        +192.168.100.0/29
        -192.168.100.8/28
        
        [END]

-192.168.100.8/28 was simply ignored which basically allowed the client to ping the whole subnet

The following rule behaved properly though.

        # cat /dev/shm/openvpn_pf_f2b43d3cb1acd5a2720c01559cb03dc3.tmp
        [CLIENTS DROP]
        [SUBNETS ACCEPT]
        +192.168.100.0/29
        -192.168.100.0/28
        [END]

I agree it is not a really bug as it is a user error in the first place and openvpn carried on happily discarding this rule.
But maybe openvpn could try to handle such subnets and translate it as 192.168.100.0/8.

Quoted 7 lines

I could try to look into it if you guys believe it should be handled by openvpn (or maybe this has already been fixed?)

Regards,

chantra

!DSPAM:4c07c0c661671935912581!

From 09ddcf75171804503119912b45876d92c3476cbc Mon Sep 17 00:00:00 2001
From: chantra <[email protected]...>
Date: Wed, 2 Jun 2010 12:44:26 +0200
Subject: [PATCH] Handle non standard subnets in PF grammar

Allow subnets for like 192.168.100.8/28 to be understood

---
 pf.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
pf.c +1 -1
index 3ce2ef2..f16ec9c 100644
@@ -121,7 +121,7 @@ add_subnet (const char *line, const char *prefix, const int line_num, struct pf_
     struct pf_subnet *e;
     ALLOC_OBJ_CLEAR (e, struct pf_subnet);
     e->rule.exclude = exclude;
-    e->rule.network = ntohl (network.s_addr);
+    e->rule.network = ntohl (network.s_addr) & netmask;
     e->rule.netmask = netmask;
     **next = e;
     *next = &e->next;
Signature · 1 line
1.5.6.5
#2 lore raw

Hi,

Quoted 4 lines · chantra

Please find below a patch to correct the behaviour.

I have also opened a trac ticket :
https://community.openvpn.net/openvpn/ticket/14

The patch itself looks good.

It's a bit of a philosophical issue what to do with network specifications given like this - one approach would be to *reject* as a config error ("a /28 network cannot start at .8"), the other approach is what you have done, to silently mask out the host bits, changing the .8/28 to .0/28.

Both have merits, your fix is somewhat less code then adding an extra input validation check

if ((network.s_addr & netmask) != network.s_addr )

    { complain; }

- so: ACK from me.

(Since OpenVPN likes to print warnings, we *could* add code to print a warning in this case - "warning: subnet address changed to match /%d, new value is %s/%d").

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
author
#3 lore raw
Quoted 6 lines · Gert Doering <gert <at> greenie.muc.de> writes:

Both have merits, your fix is somewhat less code then adding an extra input validation check

if ((network.s_addr & netmask) != network.s_addr )

    { complain; }
Quoted 7 lines

- so: ACK from me.

(Since OpenVPN likes to print warnings, we *could* add code to print a warning in this case - "warning: subnet address changed to match /%d, new value is %s/%d").

gert

Gert,

As discussed on IRC, it make sense to "warn" the admin, but it seems it is all that can be done as this is being going on at runtime.

I upated the patch and it will now display something like:
WARNING: PF: /dev/shm/openvpn_pf_ff18e7030fd03ce91bd0432563e4eb1a.tmp/5:
incorrect subnet 192.168.100.8/28 changed to 192.168.100.0/28

#4 lore raw
Quoted 19 lines · chantra
Quoted 6 lines · Gert Doering <gert <at> greenie.muc.de> writes:

Both have merits, your fix is somewhat less code then adding an extra input validation check

if ((network.s_addr & netmask) != network.s_addr )
{ complain; }

Quoted 7 lines

- so: ACK from me.

(Since OpenVPN likes to print warnings, we *could* add code to print a warning in this case - "warning: subnet address changed to match /%d, new value is %s/%d").

gert

Gert,

Quoted 7 lines

As discussed on IRC, it make sense to "warn" the admin, but it seems it is all that can be done as this is being going on at runtime.

I upated the patch and it will now display something like:
WARNING: PF: /dev/shm/openvpn_pf_ff18e7030fd03ce91bd0432563e4eb1a.tmp/5:
incorrect subnet 192.168.100.8/28 changed to 192.168.100.0/28

This seems rather pedantic to me...

---
Eric Crist

#5 lore raw

Hi,

Quoted 5 lines · Eric F Crist
Quoted 3 lines

I upated the patch and it will now display something like:
WARNING: PF: /dev/shm/openvpn_pf_ff18e7030fd03ce91bd0432563e4eb1a.tmp/5:
incorrect subnet 192.168.100.8/28 changed to 192.168.100.0/28

This seems rather pedantic to me...

Well, it is, but it's in line with the rest of OpenVPN - there are many places where a (percieved) user error results in a warning, explaining the situation...

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...
#6 lore raw
In reply to chantra

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · chantra

Please find below a patch to correct the behaviour.

I have also opened a trac ticket :
https://community.openvpn.net/openvpn/ticket/14

chantra

Thank you very much for your patch! It's been accepted and merged into bugfix2.1 and allmerged.

Commit a881843bf2101e77d15cb88105684288655055cb

kind regards,

David Sommerseth

Quoted 58 lines
Quoted 38 lines

Hi all,

It seems that openvpn is not handling properly non-standard subnets in pf_file.
This issue happened on debian etch openvpn 2.1 rc11

Today, while I made a typo, the following rule did not work properly:

        # cat /dev/shm/openvpn_pf_73f2c3256a50371f057d5c0db97ede2f.tmp
        [CLIENTS DROP]
        [SUBNETS ACCEPT]
        +192.168.100.0/29
        -192.168.100.8/28
        
        [END]

-192.168.100.8/28 was simply ignored which basically allowed the client to ping the whole subnet

The following rule behaved properly though.

        # cat /dev/shm/openvpn_pf_f2b43d3cb1acd5a2720c01559cb03dc3.tmp
        [CLIENTS DROP]
        [SUBNETS ACCEPT]
        +192.168.100.0/29
        -192.168.100.0/28
        [END]

I agree it is not a really bug as it is a user error in the first place and openvpn carried on happily discarding this rule.
But maybe openvpn could try to handle such subnets and translate it as 192.168.100.0/8.

Quoted 7 lines

I could try to look into it if you guys believe it should be handled by openvpn (or maybe this has already been fixed?)

Regards,

chantra

!DSPAM:4c07c0c661671935912581!

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo

Quoted 4 lines

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkwSSMsACgkQDC186MBRfrpVKwCfTR1/SMT5AoWCtW77D0vlmaMI nEUAoKvVbt6KBglP0kVJbWqDUlUSMh6d
=8Ocg
-----END PGP SIGNATURE-----