diff options
author | Jeff Garzik <jgarzik@pobox.com> | 2005-10-06 05:51:07 -0400 |
---|---|---|
committer | Jeff Garzik <jgarzik@pobox.com> | 2005-10-06 05:51:07 -0400 |
commit | 012e060c95e547eceea4a12c6f58592473bf4011 (patch) | |
tree | b57d3eafb50ce517577d2cf366c9ef0b4b286589 /net/ipv4 | |
parent | 923f122573851d18a3832ca808269fa2d5046fb1 (diff) | |
parent | ed39f731ab2e77e58122232f6e27333331d7793d (diff) |
Merge branch 'master'
Diffstat (limited to 'net/ipv4')
43 files changed, 2186 insertions, 309 deletions
diff --git a/net/ipv4/arp.c b/net/ipv4/arp.c index 8bf312bdea13..b425748f02d7 100644 --- a/net/ipv4/arp.c +++ b/net/ipv4/arp.c | |||
@@ -241,7 +241,7 @@ static int arp_constructor(struct neighbour *neigh) | |||
241 | neigh->type = inet_addr_type(addr); | 241 | neigh->type = inet_addr_type(addr); |
242 | 242 | ||
243 | rcu_read_lock(); | 243 | rcu_read_lock(); |
244 | in_dev = rcu_dereference(__in_dev_get(dev)); | 244 | in_dev = __in_dev_get_rcu(dev); |
245 | if (in_dev == NULL) { | 245 | if (in_dev == NULL) { |
246 | rcu_read_unlock(); | 246 | rcu_read_unlock(); |
247 | return -EINVAL; | 247 | return -EINVAL; |
@@ -697,12 +697,6 @@ void arp_send(int type, int ptype, u32 dest_ip, | |||
697 | arp_xmit(skb); | 697 | arp_xmit(skb); |
698 | } | 698 | } |
699 | 699 | ||
700 | static void parp_redo(struct sk_buff *skb) | ||
701 | { | ||
702 | nf_reset(skb); | ||
703 | arp_rcv(skb, skb->dev, NULL, skb->dev); | ||
704 | } | ||
705 | |||
706 | /* | 700 | /* |
707 | * Process an arp request. | 701 | * Process an arp request. |
708 | */ | 702 | */ |
@@ -922,6 +916,11 @@ out: | |||
922 | return 0; | 916 | return 0; |
923 | } | 917 | } |
924 | 918 | ||
919 | static void parp_redo(struct sk_buff *skb) | ||
920 | { | ||
921 | arp_process(skb); | ||
922 | } | ||
923 | |||
925 | 924 | ||
926 | /* | 925 | /* |
927 | * Receive an arp request from the device layer. | 926 | * Receive an arp request from the device layer. |
@@ -990,8 +989,8 @@ static int arp_req_set(struct arpreq *r, struct net_device * dev) | |||
990 | ipv4_devconf.proxy_arp = 1; | 989 | ipv4_devconf.proxy_arp = 1; |
991 | return 0; | 990 | return 0; |
992 | } | 991 | } |
993 | if (__in_dev_get(dev)) { | 992 | if (__in_dev_get_rtnl(dev)) { |
994 | __in_dev_get(dev)->cnf.proxy_arp = 1; | 993 | __in_dev_get_rtnl(dev)->cnf.proxy_arp = 1; |
995 | return 0; | 994 | return 0; |
996 | } | 995 | } |
997 | return -ENXIO; | 996 | return -ENXIO; |
@@ -1096,8 +1095,8 @@ static int arp_req_delete(struct arpreq *r, struct net_device * dev) | |||
1096 | ipv4_devconf.proxy_arp = 0; | 1095 | ipv4_devconf.proxy_arp = 0; |
1097 | return 0; | 1096 | return 0; |
1098 | } | 1097 | } |
1099 | if (__in_dev_get(dev)) { | 1098 | if (__in_dev_get_rtnl(dev)) { |
1100 | __in_dev_get(dev)->cnf.proxy_arp = 0; | 1099 | __in_dev_get_rtnl(dev)->cnf.proxy_arp = 0; |
1101 | return 0; | 1100 | return 0; |
1102 | } | 1101 | } |
1103 | return -ENXIO; | 1102 | return -ENXIO; |
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index ba2895ae8151..74f2207e131a 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c | |||
@@ -351,7 +351,7 @@ static int inet_insert_ifa(struct in_ifaddr *ifa) | |||
351 | 351 | ||
352 | static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa) | 352 | static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa) |
353 | { | 353 | { |
354 | struct in_device *in_dev = __in_dev_get(dev); | 354 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
355 | 355 | ||
356 | ASSERT_RTNL(); | 356 | ASSERT_RTNL(); |
357 | 357 | ||
@@ -449,7 +449,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg | |||
449 | goto out; | 449 | goto out; |
450 | 450 | ||
451 | rc = -ENOBUFS; | 451 | rc = -ENOBUFS; |
452 | if ((in_dev = __in_dev_get(dev)) == NULL) { | 452 | if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) { |
453 | in_dev = inetdev_init(dev); | 453 | in_dev = inetdev_init(dev); |
454 | if (!in_dev) | 454 | if (!in_dev) |
455 | goto out; | 455 | goto out; |
@@ -584,7 +584,7 @@ int devinet_ioctl(unsigned int cmd, void __user *arg) | |||
584 | if (colon) | 584 | if (colon) |
585 | *colon = ':'; | 585 | *colon = ':'; |
586 | 586 | ||
587 | if ((in_dev = __in_dev_get(dev)) != NULL) { | 587 | if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) { |
588 | if (tryaddrmatch) { | 588 | if (tryaddrmatch) { |
589 | /* Matthias Andree */ | 589 | /* Matthias Andree */ |
590 | /* compare label and address (4.4BSD style) */ | 590 | /* compare label and address (4.4BSD style) */ |
@@ -748,7 +748,7 @@ rarok: | |||
748 | 748 | ||
749 | static int inet_gifconf(struct net_device *dev, char __user *buf, int len) | 749 | static int inet_gifconf(struct net_device *dev, char __user *buf, int len) |
750 | { | 750 | { |
751 | struct in_device *in_dev = __in_dev_get(dev); | 751 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
752 | struct in_ifaddr *ifa; | 752 | struct in_ifaddr *ifa; |
753 | struct ifreq ifr; | 753 | struct ifreq ifr; |
754 | int done = 0; | 754 | int done = 0; |
@@ -791,7 +791,7 @@ u32 inet_select_addr(const struct net_device *dev, u32 dst, int scope) | |||
791 | struct in_device *in_dev; | 791 | struct in_device *in_dev; |
792 | 792 | ||
793 | rcu_read_lock(); | 793 | rcu_read_lock(); |
794 | in_dev = __in_dev_get(dev); | 794 | in_dev = __in_dev_get_rcu(dev); |
795 | if (!in_dev) | 795 | if (!in_dev) |
796 | goto no_in_dev; | 796 | goto no_in_dev; |
797 | 797 | ||
@@ -818,7 +818,7 @@ no_in_dev: | |||
818 | read_lock(&dev_base_lock); | 818 | read_lock(&dev_base_lock); |
819 | rcu_read_lock(); | 819 | rcu_read_lock(); |
820 | for (dev = dev_base; dev; dev = dev->next) { | 820 | for (dev = dev_base; dev; dev = dev->next) { |
821 | if ((in_dev = __in_dev_get(dev)) == NULL) | 821 | if ((in_dev = __in_dev_get_rcu(dev)) == NULL) |
822 | continue; | 822 | continue; |
823 | 823 | ||
824 | for_primary_ifa(in_dev) { | 824 | for_primary_ifa(in_dev) { |
@@ -887,7 +887,7 @@ u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scop | |||
887 | 887 | ||
888 | if (dev) { | 888 | if (dev) { |
889 | rcu_read_lock(); | 889 | rcu_read_lock(); |
890 | if ((in_dev = __in_dev_get(dev))) | 890 | if ((in_dev = __in_dev_get_rcu(dev))) |
891 | addr = confirm_addr_indev(in_dev, dst, local, scope); | 891 | addr = confirm_addr_indev(in_dev, dst, local, scope); |
892 | rcu_read_unlock(); | 892 | rcu_read_unlock(); |
893 | 893 | ||
@@ -897,7 +897,7 @@ u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scop | |||
897 | read_lock(&dev_base_lock); | 897 | read_lock(&dev_base_lock); |
898 | rcu_read_lock(); | 898 | rcu_read_lock(); |
899 | for (dev = dev_base; dev; dev = dev->next) { | 899 | for (dev = dev_base; dev; dev = dev->next) { |
900 | if ((in_dev = __in_dev_get(dev))) { | 900 | if ((in_dev = __in_dev_get_rcu(dev))) { |
901 | addr = confirm_addr_indev(in_dev, dst, local, scope); | 901 | addr = confirm_addr_indev(in_dev, dst, local, scope); |
902 | if (addr) | 902 | if (addr) |
903 | break; | 903 | break; |
@@ -957,7 +957,7 @@ static int inetdev_event(struct notifier_block *this, unsigned long event, | |||
957 | void *ptr) | 957 | void *ptr) |
958 | { | 958 | { |
959 | struct net_device *dev = ptr; | 959 | struct net_device *dev = ptr; |
960 | struct in_device *in_dev = __in_dev_get(dev); | 960 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
961 | 961 | ||
962 | ASSERT_RTNL(); | 962 | ASSERT_RTNL(); |
963 | 963 | ||
@@ -1078,7 +1078,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb) | |||
1078 | if (idx > s_idx) | 1078 | if (idx > s_idx) |
1079 | s_ip_idx = 0; | 1079 | s_ip_idx = 0; |
1080 | rcu_read_lock(); | 1080 | rcu_read_lock(); |
1081 | if ((in_dev = __in_dev_get(dev)) == NULL) { | 1081 | if ((in_dev = __in_dev_get_rcu(dev)) == NULL) { |
1082 | rcu_read_unlock(); | 1082 | rcu_read_unlock(); |
1083 | continue; | 1083 | continue; |
1084 | } | 1084 | } |
@@ -1149,7 +1149,7 @@ void inet_forward_change(void) | |||
1149 | for (dev = dev_base; dev; dev = dev->next) { | 1149 | for (dev = dev_base; dev; dev = dev->next) { |
1150 | struct in_device *in_dev; | 1150 | struct in_device *in_dev; |
1151 | rcu_read_lock(); | 1151 | rcu_read_lock(); |
1152 | in_dev = __in_dev_get(dev); | 1152 | in_dev = __in_dev_get_rcu(dev); |
1153 | if (in_dev) | 1153 | if (in_dev) |
1154 | in_dev->cnf.forwarding = on; | 1154 | in_dev->cnf.forwarding = on; |
1155 | rcu_read_unlock(); | 1155 | rcu_read_unlock(); |
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c index 4e1379f71269..e61bc7177eb1 100644 --- a/net/ipv4/fib_frontend.c +++ b/net/ipv4/fib_frontend.c | |||
@@ -173,7 +173,7 @@ int fib_validate_source(u32 src, u32 dst, u8 tos, int oif, | |||
173 | 173 | ||
174 | no_addr = rpf = 0; | 174 | no_addr = rpf = 0; |
175 | rcu_read_lock(); | 175 | rcu_read_lock(); |
176 | in_dev = __in_dev_get(dev); | 176 | in_dev = __in_dev_get_rcu(dev); |
177 | if (in_dev) { | 177 | if (in_dev) { |
178 | no_addr = in_dev->ifa_list == NULL; | 178 | no_addr = in_dev->ifa_list == NULL; |
179 | rpf = IN_DEV_RPFILTER(in_dev); | 179 | rpf = IN_DEV_RPFILTER(in_dev); |
@@ -607,7 +607,7 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event, | |||
607 | static int fib_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) | 607 | static int fib_netdev_event(struct notifier_block *this, unsigned long event, void *ptr) |
608 | { | 608 | { |
609 | struct net_device *dev = ptr; | 609 | struct net_device *dev = ptr; |
610 | struct in_device *in_dev = __in_dev_get(dev); | 610 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
611 | 611 | ||
612 | if (event == NETDEV_UNREGISTER) { | 612 | if (event == NETDEV_UNREGISTER) { |
613 | fib_disable_ip(dev, 2); | 613 | fib_disable_ip(dev, 2); |
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index d41219e8037c..186f20c4a45e 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c | |||
@@ -1087,7 +1087,7 @@ fib_convert_rtentry(int cmd, struct nlmsghdr *nl, struct rtmsg *rtm, | |||
1087 | rta->rta_oif = &dev->ifindex; | 1087 | rta->rta_oif = &dev->ifindex; |
1088 | if (colon) { | 1088 | if (colon) { |
1089 | struct in_ifaddr *ifa; | 1089 | struct in_ifaddr *ifa; |
1090 | struct in_device *in_dev = __in_dev_get(dev); | 1090 | struct in_device *in_dev = __in_dev_get_rtnl(dev); |
1091 | if (!in_dev) | 1091 | if (!in_dev) |
1092 | return -ENODEV; | 1092 | return -ENODEV; |
1093 | *colon = ':'; | 1093 | *colon = ':'; |
@@ -1268,7 +1268,7 @@ int fib_sync_up(struct net_device *dev) | |||
1268 | } | 1268 | } |
1269 | if (nh->nh_dev == NULL || !(nh->nh_dev->flags&IFF_UP)) | 1269 | if (nh->nh_dev == NULL || !(nh->nh_dev->flags&IFF_UP)) |
1270 | continue; | 1270 | continue; |
1271 | if (nh->nh_dev != dev || __in_dev_get(dev) == NULL) | 1271 | if (nh->nh_dev != dev || !__in_dev_get_rtnl(dev)) |
1272 | continue; | 1272 | continue; |
1273 | alive++; | 1273 | alive++; |
1274 | spin_lock_bh(&fib_multipath_lock); | 1274 | spin_lock_bh(&fib_multipath_lock); |
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 1b63b4824164..50c0519cd70d 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c | |||
@@ -43,7 +43,7 @@ | |||
43 | * 2 of the License, or (at your option) any later version. | 43 | * 2 of the License, or (at your option) any later version. |
44 | */ | 44 | */ |
45 | 45 | ||
46 | #define VERSION "0.403" | 46 | #define VERSION "0.404" |
47 | 47 | ||
48 | #include <linux/config.h> | 48 | #include <linux/config.h> |
49 | #include <asm/uaccess.h> | 49 | #include <asm/uaccess.h> |
@@ -224,7 +224,7 @@ static inline int tkey_mismatch(t_key a, int offset, t_key b) | |||
224 | Consider a node 'n' and its parent 'tp'. | 224 | Consider a node 'n' and its parent 'tp'. |
225 | 225 | ||
226 | If n is a leaf, every bit in its key is significant. Its presence is | 226 | If n is a leaf, every bit in its key is significant. Its presence is |
227 | necessitaded by path compression, since during a tree traversal (when | 227 | necessitated by path compression, since during a tree traversal (when |
228 | searching for a leaf - unless we are doing an insertion) we will completely | 228 | searching for a leaf - unless we are doing an insertion) we will completely |
229 | ignore all skipped bits we encounter. Thus we need to verify, at the end of | 229 | ignore all skipped bits we encounter. Thus we need to verify, at the end of |
230 | a potentially successful search, that we have indeed been walking the | 230 | a potentially successful search, that we have indeed been walking the |
@@ -836,11 +836,12 @@ static void trie_init(struct trie *t) | |||
836 | #endif | 836 | #endif |
837 | } | 837 | } |
838 | 838 | ||
839 | /* readside most use rcu_read_lock currently dump routines | 839 | /* readside must use rcu_read_lock currently dump routines |
840 | via get_fa_head and dump */ | 840 | via get_fa_head and dump */ |
841 | 841 | ||
842 | static struct leaf_info *find_leaf_info(struct hlist_head *head, int plen) | 842 | static struct leaf_info *find_leaf_info(struct leaf *l, int plen) |
843 | { | 843 | { |
844 | struct hlist_head *head = &l->list; | ||
844 | struct hlist_node *node; | 845 | struct hlist_node *node; |
845 | struct leaf_info *li; | 846 | struct leaf_info *li; |
846 | 847 | ||
@@ -853,7 +854,7 @@ static struct leaf_info *find_leaf_info(struct hlist_head *head, int plen) | |||
853 | 854 | ||
854 | static inline struct list_head * get_fa_head(struct leaf *l, int plen) | 855 | static inline struct list_head * get_fa_head(struct leaf *l, int plen) |
855 | { | 856 | { |
856 | struct leaf_info *li = find_leaf_info(&l->list, plen); | 857 | struct leaf_info *li = find_leaf_info(l, plen); |
857 | 858 | ||
858 | if (!li) | 859 | if (!li) |
859 | return NULL; | 860 | return NULL; |
@@ -1085,7 +1086,7 @@ fib_insert_node(struct trie *t, int *err, u32 key, int plen) | |||
1085 | } | 1086 | } |
1086 | 1087 | ||
1087 | if (tp && tp->pos + tp->bits > 32) | 1088 | if (tp && tp->pos + tp->bits > 32) |
1088 | printk("ERROR tp=%p pos=%d, bits=%d, key=%0x plen=%d\n", | 1089 | printk(KERN_WARNING "fib_trie tp=%p pos=%d, bits=%d, key=%0x plen=%d\n", |
1089 | tp, tp->pos, tp->bits, key, plen); | 1090 | tp, tp->pos, tp->bits, key, plen); |
1090 | 1091 | ||
1091 | /* Rebalance the trie */ | 1092 | /* Rebalance the trie */ |
@@ -1248,7 +1249,7 @@ err: | |||
1248 | } | 1249 | } |
1249 | 1250 | ||
1250 | 1251 | ||
1251 | /* should be clalled with rcu_read_lock */ | 1252 | /* should be called with rcu_read_lock */ |
1252 | static inline int check_leaf(struct trie *t, struct leaf *l, | 1253 | static inline int check_leaf(struct trie *t, struct leaf *l, |
1253 | t_key key, int *plen, const struct flowi *flp, | 1254 | t_key key, int *plen, const struct flowi *flp, |
1254 | struct fib_result *res) | 1255 | struct fib_result *res) |
@@ -1590,7 +1591,7 @@ fn_trie_delete(struct fib_table *tb, struct rtmsg *r, struct kern_rta *rta, | |||
1590 | rtmsg_fib(RTM_DELROUTE, htonl(key), fa, plen, tb->tb_id, nlhdr, req); | 1591 | rtmsg_fib(RTM_DELROUTE, htonl(key), fa, plen, tb->tb_id, nlhdr, req); |
1591 | 1592 | ||
1592 | l = fib_find_node(t, key); | 1593 | l = fib_find_node(t, key); |
1593 | li = find_leaf_info(&l->list, plen); | 1594 | li = find_leaf_info(l, plen); |
1594 | 1595 | ||
1595 | list_del_rcu(&fa->fa_list); | 1596 | list_del_rcu(&fa->fa_list); |
1596 | 1597 | ||
@@ -1714,7 +1715,6 @@ static int fn_trie_flush(struct fib_table *tb) | |||
1714 | 1715 | ||
1715 | t->revision++; | 1716 | t->revision++; |
1716 | 1717 | ||
1717 | rcu_read_lock(); | ||
1718 | for (h = 0; (l = nextleaf(t, l)) != NULL; h++) { | 1718 | for (h = 0; (l = nextleaf(t, l)) != NULL; h++) { |
1719 | found += trie_flush_leaf(t, l); | 1719 | found += trie_flush_leaf(t, l); |
1720 | 1720 | ||
@@ -1722,7 +1722,6 @@ static int fn_trie_flush(struct fib_table *tb) | |||
1722 | trie_leaf_remove(t, ll->key); | 1722 | trie_leaf_remove(t, ll->key); |
1723 | ll = l; | 1723 | ll = l; |
1724 | } | 1724 | } |
1725 | rcu_read_unlock(); | ||
1726 | 1725 | ||
1727 | if (ll && hlist_empty(&ll->list)) | 1726 | if (ll && hlist_empty(&ll->list)) |
1728 | trie_leaf_remove(t, ll->key); | 1727 | trie_leaf_remove(t, ll->key); |
@@ -1833,16 +1832,7 @@ static int fn_trie_dump_fa(t_key key, int plen, struct list_head *fah, struct fi | |||
1833 | i++; | 1832 | i++; |
1834 | continue; | 1833 | continue; |
1835 | } | 1834 | } |
1836 | if (fa->fa_info->fib_nh == NULL) { | 1835 | BUG_ON(!fa->fa_info); |
1837 | printk("Trie error _fib_nh=NULL in fa[%d] k=%08x plen=%d\n", i, key, plen); | ||
1838 | i++; | ||
1839 | continue; | ||
1840 | } | ||
1841 | if (fa->fa_info == NULL) { | ||
1842 | printk("Trie error fa_info=NULL in fa[%d] k=%08x plen=%d\n", i, key, plen); | ||
1843 | i++; | ||
1844 | continue; | ||
1845 | } | ||
1846 | 1836 | ||
1847 | if (fib_dump_info(skb, NETLINK_CB(cb->skb).pid, | 1837 | if (fib_dump_info(skb, NETLINK_CB(cb->skb).pid, |
1848 | cb->nlh->nlmsg_seq, | 1838 | cb->nlh->nlmsg_seq, |
@@ -1965,7 +1955,7 @@ struct fib_table * __init fib_hash_init(int id) | |||
1965 | trie_main = t; | 1955 | trie_main = t; |
1966 | 1956 | ||
1967 | if (id == RT_TABLE_LOCAL) | 1957 | if (id == RT_TABLE_LOCAL) |
1968 | printk("IPv4 FIB: Using LC-trie version %s\n", VERSION); | 1958 | printk(KERN_INFO "IPv4 FIB: Using LC-trie version %s\n", VERSION); |
1969 | 1959 | ||
1970 | return tb; | 1960 | return tb; |
1971 | } | 1961 | } |
@@ -2029,7 +2019,7 @@ static struct node *fib_trie_get_first(struct fib_trie_iter *iter, | |||
2029 | iter->tnode = (struct tnode *) n; | 2019 | iter->tnode = (struct tnode *) n; |
2030 | iter->trie = t; | 2020 | iter->trie = t; |
2031 | iter->index = 0; | 2021 | iter->index = 0; |
2032 | iter->depth = 0; | 2022 | iter->depth = 1; |
2033 | return n; | 2023 | return n; |
2034 | } | 2024 | } |
2035 | return NULL; | 2025 | return NULL; |
@@ -2274,11 +2264,12 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v) | |||
2274 | seq_puts(seq, "<local>:\n"); | 2264 | seq_puts(seq, "<local>:\n"); |
2275 | else | 2265 | else |
2276 | seq_puts(seq, "<main>:\n"); | 2266 | seq_puts(seq, "<main>:\n"); |
2277 | } else { | 2267 | } |
2278 | seq_indent(seq, iter->depth-1); | 2268 | seq_indent(seq, iter->depth-1); |
2279 | seq_printf(seq, " +-- %d.%d.%d.%d/%d\n", | 2269 | seq_printf(seq, " +-- %d.%d.%d.%d/%d %d %d %d\n", |
2280 | NIPQUAD(prf), tn->pos); | 2270 | NIPQUAD(prf), tn->pos, tn->bits, tn->full_children, |
2281 | } | 2271 | tn->empty_children); |
2272 | |||
2282 | } else { | 2273 | } else { |
2283 | struct leaf *l = (struct leaf *) n; | 2274 | struct leaf *l = (struct leaf *) n; |
2284 | int i; | 2275 | int i; |
@@ -2287,7 +2278,7 @@ static int fib_trie_seq_show(struct seq_file *seq, void *v) | |||
2287 | seq_indent(seq, iter->depth); | 2278 | seq_indent(seq, iter->depth); |
2288 | seq_printf(seq, " |-- %d.%d.%d.%d\n", NIPQUAD(val)); | 2279 | seq_printf(seq, " |-- %d.%d.%d.%d\n", NIPQUAD(val)); |
2289 | for (i = 32; i >= 0; i--) { | 2280 | for (i = 32; i >= 0; i--) { |
2290 | struct leaf_info *li = find_leaf_info(&l->list, i); | 2281 | struct leaf_info *li = find_leaf_info(l, i); |
2291 | if (li) { | 2282 | if (li) { |
2292 | struct fib_alias *fa; | 2283 | struct fib_alias *fa; |
2293 | list_for_each_entry_rcu(fa, &li->falh, fa_list) { | 2284 | list_for_each_entry_rcu(fa, &li->falh, fa_list) { |
@@ -2383,7 +2374,7 @@ static int fib_route_seq_show(struct seq_file *seq, void *v) | |||
2383 | return 0; | 2374 | return 0; |
2384 | 2375 | ||
2385 | for (i=32; i>=0; i--) { | 2376 | for (i=32; i>=0; i--) { |
2386 | struct leaf_info *li = find_leaf_info(&l->list, i); | 2377 | struct leaf_info *li = find_leaf_info(l, i); |
2387 | struct fib_alias *fa; | 2378 | struct fib_alias *fa; |
2388 | u32 mask, prefix; | 2379 | u32 mask, prefix; |
2389 | 2380 | ||
diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c index 24eb56ae1b5a..90dca711ac9f 100644 --- a/net/ipv4/icmp.c +++ b/net/ipv4/icmp.c | |||
@@ -188,7 +188,7 @@ struct icmp_err icmp_err_convert[] = { | |||
188 | 188 | ||
189 | /* Control parameters for ECHO replies. */ | 189 | /* Control parameters for ECHO replies. */ |
190 | int sysctl_icmp_echo_ignore_all; | 190 | int sysctl_icmp_echo_ignore_all; |
191 | int sysctl_icmp_echo_ignore_broadcasts; | 191 | int sysctl_icmp_echo_ignore_broadcasts = 1; |
192 | 192 | ||
193 | /* Control parameter - ignore bogus broadcast responses? */ | 193 | /* Control parameter - ignore bogus broadcast responses? */ |
194 | int sysctl_icmp_ignore_bogus_error_responses; | 194 | int sysctl_icmp_ignore_bogus_error_responses; |
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index 44607f4767b8..8b6d3939e1e6 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -1323,7 +1323,7 @@ static struct in_device * ip_mc_find_dev(struct ip_mreqn *imr) | |||
1323 | } | 1323 | } |
1324 | if (dev) { | 1324 | if (dev) { |
1325 | imr->imr_ifindex = dev->ifindex; | 1325 | imr->imr_ifindex = dev->ifindex; |
1326 | idev = __in_dev_get(dev); | 1326 | idev = __in_dev_get_rtnl(dev); |
1327 | } | 1327 | } |
1328 | return idev; | 1328 | return idev; |
1329 | } | 1329 | } |
@@ -1603,7 +1603,7 @@ static void ip_mc_clear_src(struct ip_mc_list *pmc) | |||
1603 | } | 1603 | } |
1604 | pmc->sources = NULL; | 1604 | pmc->sources = NULL; |
1605 | pmc->sfmode = MCAST_EXCLUDE; | 1605 | pmc->sfmode = MCAST_EXCLUDE; |
1606 | pmc->sfcount[MCAST_EXCLUDE] = 0; | 1606 | pmc->sfcount[MCAST_INCLUDE] = 0; |
1607 | pmc->sfcount[MCAST_EXCLUDE] = 1; | 1607 | pmc->sfcount[MCAST_EXCLUDE] = 1; |
1608 | } | 1608 | } |
1609 | 1609 | ||
diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c index 4d1502a49852..f9076ef3a1a8 100644 --- a/net/ipv4/inet_timewait_sock.c +++ b/net/ipv4/inet_timewait_sock.c | |||
@@ -20,7 +20,7 @@ void __inet_twsk_kill(struct inet_timewait_sock *tw, struct inet_hashinfo *hashi | |||
20 | struct inet_bind_hashbucket *bhead; | 20 | struct inet_bind_hashbucket *bhead; |
21 | struct inet_bind_bucket *tb; | 21 | struct inet_bind_bucket *tb; |
22 | /* Unlink from established hashes. */ | 22 | /* Unlink from established hashes. */ |
23 | struct inet_ehash_bucket *ehead = &hashinfo->ehash[tw->tw_hashent]; | 23 | struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, tw->tw_hash); |
24 | 24 | ||
25 | write_lock(&ehead->lock); | 25 | write_lock(&ehead->lock); |
26 | if (hlist_unhashed(&tw->tw_node)) { | 26 | if (hlist_unhashed(&tw->tw_node)) { |
@@ -60,7 +60,7 @@ void __inet_twsk_hashdance(struct inet_timewait_sock *tw, struct sock *sk, | |||
60 | { | 60 | { |
61 | const struct inet_sock *inet = inet_sk(sk); | 61 | const struct inet_sock *inet = inet_sk(sk); |
62 | const struct inet_connection_sock *icsk = inet_csk(sk); | 62 | const struct inet_connection_sock *icsk = inet_csk(sk); |
63 | struct inet_ehash_bucket *ehead = &hashinfo->ehash[sk->sk_hashent]; | 63 | struct inet_ehash_bucket *ehead = inet_ehash_bucket(hashinfo, sk->sk_hash); |
64 | struct inet_bind_hashbucket *bhead; | 64 | struct inet_bind_hashbucket *bhead; |
65 | /* Step 1: Put TW into bind hash. Original socket stays there too. | 65 | /* Step 1: Put TW into bind hash. Original socket stays there too. |
66 | Note, that any socket with inet->num != 0 MUST be bound in | 66 | Note, that any socket with inet->num != 0 MUST be bound in |
@@ -106,7 +106,7 @@ struct inet_timewait_sock *inet_twsk_alloc(const struct sock *sk, const int stat | |||
106 | tw->tw_dport = inet->dport; | 106 | tw->tw_dport = inet->dport; |
107 | tw->tw_family = sk->sk_family; | 107 | tw->tw_family = sk->sk_family; |
108 | tw->tw_reuse = sk->sk_reuse; | 108 | tw->tw_reuse = sk->sk_reuse; |
109 | tw->tw_hashent = sk->sk_hashent; | 109 | tw->tw_hash = sk->sk_hash; |
110 | tw->tw_ipv6only = 0; | 110 | tw->tw_ipv6only = 0; |
111 | tw->tw_prot = sk->sk_prot_creator; | 111 | tw->tw_prot = sk->sk_prot_creator; |
112 | atomic_set(&tw->tw_refcnt, 1); | 112 | atomic_set(&tw->tw_refcnt, 1); |
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index f0d5740d7e22..896ce3f8f53a 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c | |||
@@ -1104,10 +1104,10 @@ static int ipgre_open(struct net_device *dev) | |||
1104 | return -EADDRNOTAVAIL; | 1104 | return -EADDRNOTAVAIL; |
1105 | dev = rt->u.dst.dev; | 1105 | dev = rt->u.dst.dev; |
1106 | ip_rt_put(rt); | 1106 | ip_rt_put(rt); |
1107 | if (__in_dev_get(dev) == NULL) | 1107 | if (__in_dev_get_rtnl(dev) == NULL) |
1108 | return -EADDRNOTAVAIL; | 1108 | return -EADDRNOTAVAIL; |
1109 | t->mlink = dev->ifindex; | 1109 | t->mlink = dev->ifindex; |
1110 | ip_mc_inc_group(__in_dev_get(dev), t->parms.iph.daddr); | 1110 | ip_mc_inc_group(__in_dev_get_rtnl(dev), t->parms.iph.daddr); |
1111 | } | 1111 | } |
1112 | return 0; | 1112 | return 0; |
1113 | } | 1113 | } |
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 9dbf5909f3a6..302b7eb507c9 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -149,7 +149,7 @@ struct net_device *ipmr_new_tunnel(struct vifctl *v) | |||
149 | if (err == 0 && (dev = __dev_get_by_name(p.name)) != NULL) { | 149 | if (err == 0 && (dev = __dev_get_by_name(p.name)) != NULL) { |
150 | dev->flags |= IFF_MULTICAST; | 150 | dev->flags |= IFF_MULTICAST; |
151 | 151 | ||
152 | in_dev = __in_dev_get(dev); | 152 | in_dev = __in_dev_get_rtnl(dev); |
153 | if (in_dev == NULL && (in_dev = inetdev_init(dev)) == NULL) | 153 | if (in_dev == NULL && (in_dev = inetdev_init(dev)) == NULL) |
154 | goto failure; | 154 | goto failure; |
155 | in_dev->cnf.rp_filter = 0; | 155 | in_dev->cnf.rp_filter = 0; |
@@ -278,7 +278,7 @@ static int vif_delete(int vifi) | |||
278 | 278 | ||
279 | dev_set_allmulti(dev, -1); | 279 | dev_set_allmulti(dev, -1); |
280 | 280 | ||
281 | if ((in_dev = __in_dev_get(dev)) != NULL) { | 281 | if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) { |
282 | in_dev->cnf.mc_forwarding--; | 282 | in_dev->cnf.mc_forwarding--; |
283 | ip_rt_multicast_event(in_dev); | 283 | ip_rt_multicast_event(in_dev); |
284 | } | 284 | } |
@@ -421,7 +421,7 @@ static int vif_add(struct vifctl *vifc, int mrtsock) | |||
421 | return -EINVAL; | 421 | return -EINVAL; |
422 | } | 422 | } |
423 | 423 | ||
424 | if ((in_dev = __in_dev_get(dev)) == NULL) | 424 | if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) |
425 | return -EADDRNOTAVAIL; | 425 | return -EADDRNOTAVAIL; |
426 | in_dev->cnf.mc_forwarding++; | 426 | in_dev->cnf.mc_forwarding++; |
427 | dev_set_allmulti(dev, +1); | 427 | dev_set_allmulti(dev, +1); |
diff --git a/net/ipv4/ipvs/ip_vs_conn.c b/net/ipv4/ipvs/ip_vs_conn.c index e11952ea17af..f828fa2eb7de 100644 --- a/net/ipv4/ipvs/ip_vs_conn.c +++ b/net/ipv4/ipvs/ip_vs_conn.c | |||
@@ -196,6 +196,7 @@ static inline struct ip_vs_conn *__ip_vs_conn_in_get | |||
196 | list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { | 196 | list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { |
197 | if (s_addr==cp->caddr && s_port==cp->cport && | 197 | if (s_addr==cp->caddr && s_port==cp->cport && |
198 | d_port==cp->vport && d_addr==cp->vaddr && | 198 | d_port==cp->vport && d_addr==cp->vaddr && |
199 | ((!s_port) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) && | ||
199 | protocol==cp->protocol) { | 200 | protocol==cp->protocol) { |
200 | /* HIT */ | 201 | /* HIT */ |
201 | atomic_inc(&cp->refcnt); | 202 | atomic_inc(&cp->refcnt); |
@@ -227,6 +228,40 @@ struct ip_vs_conn *ip_vs_conn_in_get | |||
227 | return cp; | 228 | return cp; |
228 | } | 229 | } |
229 | 230 | ||
231 | /* Get reference to connection template */ | ||
232 | struct ip_vs_conn *ip_vs_ct_in_get | ||
233 | (int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port) | ||
234 | { | ||
235 | unsigned hash; | ||
236 | struct ip_vs_conn *cp; | ||
237 | |||
238 | hash = ip_vs_conn_hashkey(protocol, s_addr, s_port); | ||
239 | |||
240 | ct_read_lock(hash); | ||
241 | |||
242 | list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { | ||
243 | if (s_addr==cp->caddr && s_port==cp->cport && | ||
244 | d_port==cp->vport && d_addr==cp->vaddr && | ||
245 | cp->flags & IP_VS_CONN_F_TEMPLATE && | ||
246 | protocol==cp->protocol) { | ||
247 | /* HIT */ | ||
248 | atomic_inc(&cp->refcnt); | ||
249 | goto out; | ||
250 | } | ||
251 | } | ||
252 | cp = NULL; | ||
253 | |||
254 | out: | ||
255 | ct_read_unlock(hash); | ||
256 | |||
257 | IP_VS_DBG(7, "template lookup/in %s %u.%u.%u.%u:%d->%u.%u.%u.%u:%d %s\n", | ||
258 | ip_vs_proto_name(protocol), | ||
259 | NIPQUAD(s_addr), ntohs(s_port), | ||
260 | NIPQUAD(d_addr), ntohs(d_port), | ||
261 | cp?"hit":"not hit"); | ||
262 | |||
263 | return cp; | ||
264 | } | ||
230 | 265 | ||
231 | /* | 266 | /* |
232 | * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab. | 267 | * Gets ip_vs_conn associated with supplied parameters in the ip_vs_conn_tab. |
@@ -367,7 +402,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest) | |||
367 | atomic_read(&dest->refcnt)); | 402 | atomic_read(&dest->refcnt)); |
368 | 403 | ||
369 | /* Update the connection counters */ | 404 | /* Update the connection counters */ |
370 | if (cp->cport || (cp->flags & IP_VS_CONN_F_NO_CPORT)) { | 405 | if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) { |
371 | /* It is a normal connection, so increase the inactive | 406 | /* It is a normal connection, so increase the inactive |
372 | connection counter because it is in TCP SYNRECV | 407 | connection counter because it is in TCP SYNRECV |
373 | state (inactive) or other protocol inacive state */ | 408 | state (inactive) or other protocol inacive state */ |
@@ -406,7 +441,7 @@ static inline void ip_vs_unbind_dest(struct ip_vs_conn *cp) | |||
406 | atomic_read(&dest->refcnt)); | 441 | atomic_read(&dest->refcnt)); |
407 | 442 | ||
408 | /* Update the connection counters */ | 443 | /* Update the connection counters */ |
409 | if (cp->cport || (cp->flags & IP_VS_CONN_F_NO_CPORT)) { | 444 | if (!(cp->flags & IP_VS_CONN_F_TEMPLATE)) { |
410 | /* It is a normal connection, so decrease the inactconns | 445 | /* It is a normal connection, so decrease the inactconns |
411 | or activeconns counter */ | 446 | or activeconns counter */ |
412 | if (cp->flags & IP_VS_CONN_F_INACTIVE) { | 447 | if (cp->flags & IP_VS_CONN_F_INACTIVE) { |
@@ -467,7 +502,7 @@ int ip_vs_check_template(struct ip_vs_conn *ct) | |||
467 | /* | 502 | /* |
468 | * Invalidate the connection template | 503 | * Invalidate the connection template |
469 | */ | 504 | */ |
470 | if (ct->cport) { | 505 | if (ct->vport != 65535) { |
471 | if (ip_vs_conn_unhash(ct)) { | 506 | if (ip_vs_conn_unhash(ct)) { |
472 | ct->dport = 65535; | 507 | ct->dport = 65535; |
473 | ct->vport = 65535; | 508 | ct->vport = 65535; |
@@ -776,7 +811,7 @@ void ip_vs_random_dropentry(void) | |||
776 | ct_write_lock_bh(hash); | 811 | ct_write_lock_bh(hash); |
777 | 812 | ||
778 | list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { | 813 | list_for_each_entry(cp, &ip_vs_conn_tab[hash], c_list) { |
779 | if (!cp->cport && !(cp->flags & IP_VS_CONN_F_NO_CPORT)) | 814 | if (cp->flags & IP_VS_CONN_F_TEMPLATE) |
780 | /* connection template */ | 815 | /* connection template */ |
781 | continue; | 816 | continue; |
782 | 817 | ||
diff --git a/net/ipv4/ipvs/ip_vs_core.c b/net/ipv4/ipvs/ip_vs_core.c index 3ac7eeca04ac..981cc3244ef2 100644 --- a/net/ipv4/ipvs/ip_vs_core.c +++ b/net/ipv4/ipvs/ip_vs_core.c | |||
@@ -243,10 +243,10 @@ ip_vs_sched_persist(struct ip_vs_service *svc, | |||
243 | if (ports[1] == svc->port) { | 243 | if (ports[1] == svc->port) { |
244 | /* Check if a template already exists */ | 244 | /* Check if a template already exists */ |
245 | if (svc->port != FTPPORT) | 245 | if (svc->port != FTPPORT) |
246 | ct = ip_vs_conn_in_get(iph->protocol, snet, 0, | 246 | ct = ip_vs_ct_in_get(iph->protocol, snet, 0, |
247 | iph->daddr, ports[1]); | 247 | iph->daddr, ports[1]); |
248 | else | 248 | else |
249 | ct = ip_vs_conn_in_get(iph->protocol, snet, 0, | 249 | ct = ip_vs_ct_in_get(iph->protocol, snet, 0, |
250 | iph->daddr, 0); | 250 | iph->daddr, 0); |
251 | 251 | ||
252 | if (!ct || !ip_vs_check_template(ct)) { | 252 | if (!ct || !ip_vs_check_template(ct)) { |
@@ -272,14 +272,14 @@ ip_vs_sched_persist(struct ip_vs_service *svc, | |||
272 | iph->daddr, | 272 | iph->daddr, |
273 | ports[1], | 273 | ports[1], |
274 | dest->addr, dest->port, | 274 | dest->addr, dest->port, |
275 | 0, | 275 | IP_VS_CONN_F_TEMPLATE, |
276 | dest); | 276 | dest); |
277 | else | 277 | else |
278 | ct = ip_vs_conn_new(iph->protocol, | 278 | ct = ip_vs_conn_new(iph->protocol, |
279 | snet, 0, | 279 | snet, 0, |
280 | iph->daddr, 0, | 280 | iph->daddr, 0, |
281 | dest->addr, 0, | 281 | dest->addr, 0, |
282 | 0, | 282 | IP_VS_CONN_F_TEMPLATE, |
283 | dest); | 283 | dest); |
284 | if (ct == NULL) | 284 | if (ct == NULL) |
285 | return NULL; | 285 | return NULL; |
@@ -298,10 +298,10 @@ ip_vs_sched_persist(struct ip_vs_service *svc, | |||
298 | * port zero template: <protocol,caddr,0,vaddr,0,daddr,0> | 298 | * port zero template: <protocol,caddr,0,vaddr,0,daddr,0> |
299 | */ | 299 | */ |
300 | if (svc->fwmark) | 300 | if (svc->fwmark) |
301 | ct = ip_vs_conn_in_get(IPPROTO_IP, snet, 0, | 301 | ct = ip_vs_ct_in_get(IPPROTO_IP, snet, 0, |
302 | htonl(svc->fwmark), 0); | 302 | htonl(svc->fwmark), 0); |
303 | else | 303 | else |
304 | ct = ip_vs_conn_in_get(iph->protocol, snet, 0, | 304 | ct = ip_vs_ct_in_get(iph->protocol, snet, 0, |
305 | iph->daddr, 0); | 305 | iph->daddr, 0); |
306 | 306 | ||
307 | if (!ct || !ip_vs_check_template(ct)) { | 307 | if (!ct || !ip_vs_check_template(ct)) { |
@@ -326,14 +326,14 @@ ip_vs_sched_persist(struct ip_vs_service *svc, | |||
326 | snet, 0, | 326 | snet, 0, |
327 | htonl(svc->fwmark), 0, | 327 | htonl(svc->fwmark), 0, |
328 | dest->addr, 0, | 328 | dest->addr, 0, |
329 | 0, | 329 | IP_VS_CONN_F_TEMPLATE, |
330 | dest); | 330 | dest); |
331 | else | 331 | else |
332 | ct = ip_vs_conn_new(iph->protocol, | 332 | ct = ip_vs_conn_new(iph->protocol, |
333 | snet, 0, | 333 | snet, 0, |
334 | iph->daddr, 0, | 334 | iph->daddr, 0, |
335 | dest->addr, 0, | 335 | dest->addr, 0, |
336 | 0, | 336 | IP_VS_CONN_F_TEMPLATE, |
337 | dest); | 337 | dest); |
338 | if (ct == NULL) | 338 | if (ct == NULL) |
339 | return NULL; | 339 | return NULL; |
diff --git a/net/ipv4/ipvs/ip_vs_sync.c b/net/ipv4/ipvs/ip_vs_sync.c index 574d1f509b46..2e5ced3d8062 100644 --- a/net/ipv4/ipvs/ip_vs_sync.c +++ b/net/ipv4/ipvs/ip_vs_sync.c | |||
@@ -297,16 +297,24 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen) | |||
297 | 297 | ||
298 | p = (char *)buffer + sizeof(struct ip_vs_sync_mesg); | 298 | p = (char *)buffer + sizeof(struct ip_vs_sync_mesg); |
299 | for (i=0; i<m->nr_conns; i++) { | 299 | for (i=0; i<m->nr_conns; i++) { |
300 | unsigned flags; | ||
301 | |||
300 | s = (struct ip_vs_sync_conn *)p; | 302 | s = (struct ip_vs_sync_conn *)p; |
301 | cp = ip_vs_conn_in_get(s->protocol, | 303 | flags = ntohs(s->flags); |
302 | s->caddr, s->cport, | 304 | if (!(flags & IP_VS_CONN_F_TEMPLATE)) |
303 | s->vaddr, s->vport); | 305 | cp = ip_vs_conn_in_get(s->protocol, |
306 | s->caddr, s->cport, | ||
307 | s->vaddr, s->vport); | ||
308 | else | ||
309 | cp = ip_vs_ct_in_get(s->protocol, | ||
310 | s->caddr, s->cport, | ||
311 | s->vaddr, s->vport); | ||
304 | if (!cp) { | 312 | if (!cp) { |
305 | cp = ip_vs_conn_new(s->protocol, | 313 | cp = ip_vs_conn_new(s->protocol, |
306 | s->caddr, s->cport, | 314 | s->caddr, s->cport, |
307 | s->vaddr, s->vport, | 315 | s->vaddr, s->vport, |
308 | s->daddr, s->dport, | 316 | s->daddr, s->dport, |
309 | ntohs(s->flags), NULL); | 317 | flags, NULL); |
310 | if (!cp) { | 318 | if (!cp) { |
311 | IP_VS_ERR("ip_vs_conn_new failed\n"); | 319 | IP_VS_ERR("ip_vs_conn_new failed\n"); |
312 | return; | 320 | return; |
@@ -315,11 +323,11 @@ static void ip_vs_process_message(const char *buffer, const size_t buflen) | |||
315 | } else if (!cp->dest) { | 323 | } else if (!cp->dest) { |
316 | /* it is an entry created by the synchronization */ | 324 | /* it is an entry created by the synchronization */ |
317 | cp->state = ntohs(s->state); | 325 | cp->state = ntohs(s->state); |
318 | cp->flags = ntohs(s->flags) | IP_VS_CONN_F_HASHED; | 326 | cp->flags = flags | IP_VS_CONN_F_HASHED; |
319 | } /* Note that we don't touch its state and flags | 327 | } /* Note that we don't touch its state and flags |
320 | if it is a normal entry. */ | 328 | if it is a normal entry. */ |
321 | 329 | ||
322 | if (ntohs(s->flags) & IP_VS_CONN_F_SEQ_MASK) { | 330 | if (flags & IP_VS_CONN_F_SEQ_MASK) { |
323 | opt = (struct ip_vs_sync_conn_options *)&s[1]; | 331 | opt = (struct ip_vs_sync_conn_options *)&s[1]; |
324 | memcpy(&cp->in_seq, opt, sizeof(*opt)); | 332 | memcpy(&cp->in_seq, opt, sizeof(*opt)); |
325 | p += FULL_CONN_SIZE; | 333 | p += FULL_CONN_SIZE; |
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig index 30aa8e2ee214..2cd7e7d1ac90 100644 --- a/net/ipv4/netfilter/Kconfig +++ b/net/ipv4/netfilter/Kconfig | |||
@@ -51,6 +51,14 @@ config IP_NF_CONNTRACK_EVENTS | |||
51 | 51 | ||
52 | IF unsure, say `N'. | 52 | IF unsure, say `N'. |
53 | 53 | ||
54 | config IP_NF_CONNTRACK_NETLINK | ||
55 | tristate 'Connection tracking netlink interface' | ||
56 | depends on IP_NF_CONNTRACK && NETFILTER_NETLINK | ||
57 | depends on IP_NF_CONNTRACK!=y || NETFILTER_NETLINK!=m | ||
58 | help | ||
59 | This option enables support for a netlink-based userspace interface | ||
60 | |||
61 | |||
54 | config IP_NF_CT_PROTO_SCTP | 62 | config IP_NF_CT_PROTO_SCTP |
55 | tristate 'SCTP protocol connection tracking support (EXPERIMENTAL)' | 63 | tristate 'SCTP protocol connection tracking support (EXPERIMENTAL)' |
56 | depends on IP_NF_CONNTRACK && EXPERIMENTAL | 64 | depends on IP_NF_CONNTRACK && EXPERIMENTAL |
@@ -129,6 +137,22 @@ config IP_NF_AMANDA | |||
129 | 137 | ||
130 | To compile it as a module, choose M here. If unsure, say Y. | 138 | To compile it as a module, choose M here. If unsure, say Y. |
131 | 139 | ||
140 | config IP_NF_PPTP | ||
141 | tristate 'PPTP protocol support' | ||
142 | help | ||
143 | This module adds support for PPTP (Point to Point Tunnelling | ||
144 | Protocol, RFC2637) conncection tracking and NAT. | ||
145 | |||
146 | If you are running PPTP sessions over a stateful firewall or NAT | ||
147 | box, you may want to enable this feature. | ||
148 | |||
149 | Please note that not all PPTP modes of operation are supported yet. | ||
150 | For more info, read top of the file | ||
151 | net/ipv4/netfilter/ip_conntrack_pptp.c | ||
152 | |||
153 | If you want to compile it as a module, say M here and read | ||
154 | Documentation/modules.txt. If unsure, say `N'. | ||
155 | |||
132 | config IP_NF_QUEUE | 156 | config IP_NF_QUEUE |
133 | tristate "IP Userspace queueing via NETLINK (OBSOLETE)" | 157 | tristate "IP Userspace queueing via NETLINK (OBSOLETE)" |
134 | help | 158 | help |
@@ -513,6 +537,17 @@ config IP_NF_TARGET_TCPMSS | |||
513 | 537 | ||
514 | To compile it as a module, choose M here. If unsure, say N. | 538 | To compile it as a module, choose M here. If unsure, say N. |
515 | 539 | ||
540 | config IP_NF_TARGET_NFQUEUE | ||
541 | tristate "NFQUEUE Target Support" | ||
542 | depends on IP_NF_IPTABLES | ||
543 | help | ||
544 | This Target replaced the old obsolete QUEUE target. | ||
545 | |||
546 | As opposed to QUEUE, it supports 65535 different queues, | ||
547 | not just one. | ||
548 | |||
549 | To compile it as a module, choose M here. If unsure, say N. | ||
550 | |||
516 | # NAT + specific targets | 551 | # NAT + specific targets |
517 | config IP_NF_NAT | 552 | config IP_NF_NAT |
518 | tristate "Full NAT" | 553 | tristate "Full NAT" |
@@ -613,6 +648,12 @@ config IP_NF_NAT_AMANDA | |||
613 | default IP_NF_NAT if IP_NF_AMANDA=y | 648 | default IP_NF_NAT if IP_NF_AMANDA=y |
614 | default m if IP_NF_AMANDA=m | 649 | default m if IP_NF_AMANDA=m |
615 | 650 | ||
651 | config IP_NF_NAT_PPTP | ||
652 | tristate | ||
653 | depends on IP_NF_NAT!=n && IP_NF_PPTP!=n | ||
654 | default IP_NF_NAT if IP_NF_PPTP=y | ||
655 | default m if IP_NF_PPTP=m | ||
656 | |||
616 | # mangle + specific targets | 657 | # mangle + specific targets |
617 | config IP_NF_MANGLE | 658 | config IP_NF_MANGLE |
618 | tristate "Packet mangling" | 659 | tristate "Packet mangling" |
@@ -774,11 +815,5 @@ config IP_NF_ARP_MANGLE | |||
774 | Allows altering the ARP packet payload: source and destination | 815 | Allows altering the ARP packet payload: source and destination |
775 | hardware and network addresses. | 816 | hardware and network addresses. |
776 | 817 | ||
777 | config IP_NF_CONNTRACK_NETLINK | ||
778 | tristate 'Connection tracking netlink interface' | ||
779 | depends on IP_NF_CONNTRACK && NETFILTER_NETLINK | ||
780 | help | ||
781 | This option enables support for a netlink-based userspace interface | ||
782 | |||
783 | endmenu | 818 | endmenu |
784 | 819 | ||
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile index 1ba0db746817..dab4b58dd31e 100644 --- a/net/ipv4/netfilter/Makefile +++ b/net/ipv4/netfilter/Makefile | |||
@@ -4,7 +4,11 @@ | |||
4 | 4 | ||
5 | # objects for the standalone - connection tracking / NAT | 5 | # objects for the standalone - connection tracking / NAT |
6 | ip_conntrack-objs := ip_conntrack_standalone.o ip_conntrack_core.o ip_conntrack_proto_generic.o ip_conntrack_proto_tcp.o ip_conntrack_proto_udp.o ip_conntrack_proto_icmp.o | 6 | ip_conntrack-objs := ip_conntrack_standalone.o ip_conntrack_core.o ip_conntrack_proto_generic.o ip_conntrack_proto_tcp.o ip_conntrack_proto_udp.o ip_conntrack_proto_icmp.o |
7 | iptable_nat-objs := ip_nat_standalone.o ip_nat_rule.o ip_nat_core.o ip_nat_helper.o ip_nat_proto_unknown.o ip_nat_proto_tcp.o ip_nat_proto_udp.o ip_nat_proto_icmp.o | 7 | ip_nat-objs := ip_nat_core.o ip_nat_helper.o ip_nat_proto_unknown.o ip_nat_proto_tcp.o ip_nat_proto_udp.o ip_nat_proto_icmp.o |
8 | iptable_nat-objs := ip_nat_rule.o ip_nat_standalone.o | ||
9 | |||
10 | ip_conntrack_pptp-objs := ip_conntrack_helper_pptp.o ip_conntrack_proto_gre.o | ||
11 | ip_nat_pptp-objs := ip_nat_helper_pptp.o ip_nat_proto_gre.o | ||
8 | 12 | ||
9 | # connection tracking | 13 | # connection tracking |
10 | obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o | 14 | obj-$(CONFIG_IP_NF_CONNTRACK) += ip_conntrack.o |
@@ -17,6 +21,7 @@ obj-$(CONFIG_IP_NF_CONNTRACK_NETLINK) += ip_conntrack_netlink.o | |||
17 | obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o | 21 | obj-$(CONFIG_IP_NF_CT_PROTO_SCTP) += ip_conntrack_proto_sctp.o |
18 | 22 | ||
19 | # connection tracking helpers | 23 | # connection tracking helpers |
24 | obj-$(CONFIG_IP_NF_PPTP) += ip_conntrack_pptp.o | ||
20 | obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o | 25 | obj-$(CONFIG_IP_NF_AMANDA) += ip_conntrack_amanda.o |
21 | obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o | 26 | obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o |
22 | obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o | 27 | obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o |
@@ -24,6 +29,7 @@ obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o | |||
24 | obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o | 29 | obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o |
25 | 30 | ||
26 | # NAT helpers | 31 | # NAT helpers |
32 | obj-$(CONFIG_IP_NF_NAT_PPTP) += ip_nat_pptp.o | ||
27 | obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o | 33 | obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o |
28 | obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o | 34 | obj-$(CONFIG_IP_NF_NAT_TFTP) += ip_nat_tftp.o |
29 | obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o | 35 | obj-$(CONFIG_IP_NF_NAT_FTP) += ip_nat_ftp.o |
@@ -35,7 +41,7 @@ obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o | |||
35 | # the three instances of ip_tables | 41 | # the three instances of ip_tables |
36 | obj-$(CONFIG_IP_NF_FILTER) += iptable_filter.o | 42 | obj-$(CONFIG_IP_NF_FILTER) += iptable_filter.o |
37 | obj-$(CONFIG_IP_NF_MANGLE) += iptable_mangle.o | 43 | obj-$(CONFIG_IP_NF_MANGLE) += iptable_mangle.o |
38 | obj-$(CONFIG_IP_NF_NAT) += iptable_nat.o | 44 | obj-$(CONFIG_IP_NF_NAT) += iptable_nat.o ip_nat.o |
39 | obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o | 45 | obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o |
40 | 46 | ||
41 | # matches | 47 | # matches |
@@ -87,6 +93,7 @@ obj-$(CONFIG_IP_NF_TARGET_TCPMSS) += ipt_TCPMSS.o | |||
87 | obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o | 93 | obj-$(CONFIG_IP_NF_TARGET_NOTRACK) += ipt_NOTRACK.o |
88 | obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o | 94 | obj-$(CONFIG_IP_NF_TARGET_CLUSTERIP) += ipt_CLUSTERIP.o |
89 | obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o | 95 | obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o |
96 | obj-$(CONFIG_IP_NF_TARGET_NFQUEUE) += ipt_NFQUEUE.o | ||
90 | 97 | ||
91 | # generic ARP tables | 98 | # generic ARP tables |
92 | obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o | 99 | obj-$(CONFIG_IP_NF_ARPTABLES) += arp_tables.o |
@@ -96,4 +103,3 @@ obj-$(CONFIG_IP_NF_ARP_MANGLE) += arpt_mangle.o | |||
96 | obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o | 103 | obj-$(CONFIG_IP_NF_ARPFILTER) += arptable_filter.o |
97 | 104 | ||
98 | obj-$(CONFIG_IP_NF_QUEUE) += ip_queue.o | 105 | obj-$(CONFIG_IP_NF_QUEUE) += ip_queue.o |
99 | obj-$(CONFIG_NETFILTER_NETLINK_QUEUE) += ipt_NFQUEUE.o | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_amanda.c b/net/ipv4/netfilter/ip_conntrack_amanda.c index dc20881004bc..fa3f914117ec 100644 --- a/net/ipv4/netfilter/ip_conntrack_amanda.c +++ b/net/ipv4/netfilter/ip_conntrack_amanda.c | |||
@@ -65,7 +65,7 @@ static int help(struct sk_buff **pskb, | |||
65 | 65 | ||
66 | /* increase the UDP timeout of the master connection as replies from | 66 | /* increase the UDP timeout of the master connection as replies from |
67 | * Amanda clients to the server can be quite delayed */ | 67 | * Amanda clients to the server can be quite delayed */ |
68 | ip_ct_refresh_acct(ct, ctinfo, NULL, master_timeout * HZ); | 68 | ip_ct_refresh(ct, *pskb, master_timeout * HZ); |
69 | 69 | ||
70 | /* No data? */ | 70 | /* No data? */ |
71 | dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr); | 71 | dataoff = (*pskb)->nh.iph->ihl*4 + sizeof(struct udphdr); |
diff --git a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c index 19cba16e6e1e..ea65dd3e517a 100644 --- a/net/ipv4/netfilter/ip_conntrack_core.c +++ b/net/ipv4/netfilter/ip_conntrack_core.c | |||
@@ -233,7 +233,7 @@ __ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple) | |||
233 | 233 | ||
234 | /* Just find a expectation corresponding to a tuple. */ | 234 | /* Just find a expectation corresponding to a tuple. */ |
235 | struct ip_conntrack_expect * | 235 | struct ip_conntrack_expect * |
236 | ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple) | 236 | ip_conntrack_expect_find(const struct ip_conntrack_tuple *tuple) |
237 | { | 237 | { |
238 | struct ip_conntrack_expect *i; | 238 | struct ip_conntrack_expect *i; |
239 | 239 | ||
@@ -1112,42 +1112,46 @@ void ip_conntrack_helper_unregister(struct ip_conntrack_helper *me) | |||
1112 | synchronize_net(); | 1112 | synchronize_net(); |
1113 | } | 1113 | } |
1114 | 1114 | ||
1115 | static inline void ct_add_counters(struct ip_conntrack *ct, | 1115 | /* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */ |
1116 | enum ip_conntrack_info ctinfo, | 1116 | void __ip_ct_refresh_acct(struct ip_conntrack *ct, |
1117 | const struct sk_buff *skb) | ||
1118 | { | ||
1119 | #ifdef CONFIG_IP_NF_CT_ACCT | ||
1120 | if (skb) { | ||
1121 | ct->counters[CTINFO2DIR(ctinfo)].packets++; | ||
1122 | ct->counters[CTINFO2DIR(ctinfo)].bytes += | ||
1123 | ntohs(skb->nh.iph->tot_len); | ||
1124 | } | ||
1125 | #endif | ||
1126 | } | ||
1127 | |||
1128 | /* Refresh conntrack for this many jiffies and do accounting (if skb != NULL) */ | ||
1129 | void ip_ct_refresh_acct(struct ip_conntrack *ct, | ||
1130 | enum ip_conntrack_info ctinfo, | 1117 | enum ip_conntrack_info ctinfo, |
1131 | const struct sk_buff *skb, | 1118 | const struct sk_buff *skb, |
1132 | unsigned long extra_jiffies) | 1119 | unsigned long extra_jiffies, |
1120 | int do_acct) | ||
1133 | { | 1121 | { |
1122 | int do_event = 0; | ||
1123 | |||
1134 | IP_NF_ASSERT(ct->timeout.data == (unsigned long)ct); | 1124 | IP_NF_ASSERT(ct->timeout.data == (unsigned long)ct); |
1125 | IP_NF_ASSERT(skb); | ||
1126 | |||
1127 | write_lock_bh(&ip_conntrack_lock); | ||
1135 | 1128 | ||
1136 | /* If not in hash table, timer will not be active yet */ | 1129 | /* If not in hash table, timer will not be active yet */ |
1137 | if (!is_confirmed(ct)) { | 1130 | if (!is_confirmed(ct)) { |
1138 | ct->timeout.expires = extra_jiffies; | 1131 | ct->timeout.expires = extra_jiffies; |
1139 | ct_add_counters(ct, ctinfo, skb); | 1132 | do_event = 1; |
1140 | } else { | 1133 | } else { |
1141 | write_lock_bh(&ip_conntrack_lock); | ||
1142 | /* Need del_timer for race avoidance (may already be dying). */ | 1134 | /* Need del_timer for race avoidance (may already be dying). */ |
1143 | if (del_timer(&ct->timeout)) { | 1135 | if (del_timer(&ct->timeout)) { |
1144 | ct->timeout.expires = jiffies + extra_jiffies; | 1136 | ct->timeout.expires = jiffies + extra_jiffies; |
1145 | add_timer(&ct->timeout); | 1137 | add_timer(&ct->timeout); |
1146 | ip_conntrack_event_cache(IPCT_REFRESH, skb); | 1138 | do_event = 1; |
1147 | } | 1139 | } |
1148 | ct_add_counters(ct, ctinfo, skb); | ||
1149 | write_unlock_bh(&ip_conntrack_lock); | ||
1150 | } | 1140 | } |
1141 | |||
1142 | #ifdef CONFIG_IP_NF_CT_ACCT | ||
1143 | if (do_acct) { | ||
1144 | ct->counters[CTINFO2DIR(ctinfo)].packets++; | ||
1145 | ct->counters[CTINFO2DIR(ctinfo)].bytes += | ||
1146 | ntohs(skb->nh.iph->tot_len); | ||
1147 | } | ||
1148 | #endif | ||
1149 | |||
1150 | write_unlock_bh(&ip_conntrack_lock); | ||
1151 | |||
1152 | /* must be unlocked when calling event cache */ | ||
1153 | if (do_event) | ||
1154 | ip_conntrack_event_cache(IPCT_REFRESH, skb); | ||
1151 | } | 1155 | } |
1152 | 1156 | ||
1153 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ | 1157 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ |
diff --git a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c index 1b79ec36085f..d77d6b3f5f80 100644 --- a/net/ipv4/netfilter/ip_conntrack_ftp.c +++ b/net/ipv4/netfilter/ip_conntrack_ftp.c | |||
@@ -29,9 +29,9 @@ static char *ftp_buffer; | |||
29 | static DEFINE_SPINLOCK(ip_ftp_lock); | 29 | static DEFINE_SPINLOCK(ip_ftp_lock); |
30 | 30 | ||
31 | #define MAX_PORTS 8 | 31 | #define MAX_PORTS 8 |
32 | static int ports[MAX_PORTS]; | 32 | static short ports[MAX_PORTS]; |
33 | static int ports_c; | 33 | static int ports_c; |
34 | module_param_array(ports, int, &ports_c, 0400); | 34 | module_param_array(ports, short, &ports_c, 0400); |
35 | 35 | ||
36 | static int loose; | 36 | static int loose; |
37 | module_param(loose, int, 0600); | 37 | module_param(loose, int, 0600); |
@@ -450,7 +450,7 @@ out_update_nl: | |||
450 | } | 450 | } |
451 | 451 | ||
452 | static struct ip_conntrack_helper ftp[MAX_PORTS]; | 452 | static struct ip_conntrack_helper ftp[MAX_PORTS]; |
453 | static char ftp_names[MAX_PORTS][10]; | 453 | static char ftp_names[MAX_PORTS][sizeof("ftp-65535")]; |
454 | 454 | ||
455 | /* Not __exit: called from init() */ | 455 | /* Not __exit: called from init() */ |
456 | static void fini(void) | 456 | static void fini(void) |
diff --git a/net/ipv4/netfilter/ip_conntrack_helper_pptp.c b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c new file mode 100644 index 000000000000..926a6684643d --- /dev/null +++ b/net/ipv4/netfilter/ip_conntrack_helper_pptp.c | |||
@@ -0,0 +1,806 @@ | |||
1 | /* | ||
2 | * ip_conntrack_pptp.c - Version 3.0 | ||
3 | * | ||
4 | * Connection tracking support for PPTP (Point to Point Tunneling Protocol). | ||
5 | * PPTP is a a protocol for creating virtual private networks. | ||
6 | * It is a specification defined by Microsoft and some vendors | ||
7 | * working with Microsoft. PPTP is built on top of a modified | ||
8 | * version of the Internet Generic Routing Encapsulation Protocol. | ||
9 | * GRE is defined in RFC 1701 and RFC 1702. Documentation of | ||
10 | * PPTP can be found in RFC 2637 | ||
11 | * | ||
12 | * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org> | ||
13 | * | ||
14 | * Development of this code funded by Astaro AG (http://www.astaro.com/) | ||
15 | * | ||
16 | * Limitations: | ||
17 | * - We blindly assume that control connections are always | ||
18 | * established in PNS->PAC direction. This is a violation | ||
19 | * of RFFC2673 | ||
20 | * - We can only support one single call within each session | ||
21 | * | ||
22 | * TODO: | ||
23 | * - testing of incoming PPTP calls | ||
24 | * | ||
25 | * Changes: | ||
26 | * 2002-02-05 - Version 1.3 | ||
27 | * - Call ip_conntrack_unexpect_related() from | ||
28 | * pptp_destroy_siblings() to destroy expectations in case | ||
29 | * CALL_DISCONNECT_NOTIFY or tcp fin packet was seen | ||
30 | * (Philip Craig <philipc@snapgear.com>) | ||
31 | * - Add Version information at module loadtime | ||
32 | * 2002-02-10 - Version 1.6 | ||
33 | * - move to C99 style initializers | ||
34 | * - remove second expectation if first arrives | ||
35 | * 2004-10-22 - Version 2.0 | ||
36 | * - merge Mandrake's 2.6.x port with recent 2.6.x API changes | ||
37 | * - fix lots of linear skb assumptions from Mandrake's port | ||
38 | * 2005-06-10 - Version 2.1 | ||
39 | * - use ip_conntrack_expect_free() instead of kfree() on the | ||
40 | * expect's (which are from the slab for quite some time) | ||
41 | * 2005-06-10 - Version 3.0 | ||
42 | * - port helper to post-2.6.11 API changes, | ||
43 | * funded by Oxcoda NetBox Blue (http://www.netboxblue.com/) | ||
44 | * 2005-07-30 - Version 3.1 | ||
45 | * - port helper to 2.6.13 API changes | ||
46 | * | ||
47 | */ | ||
48 | |||
49 | #include <linux/config.h> | ||
50 | #include <linux/module.h> | ||
51 | #include <linux/netfilter.h> | ||
52 | #include <linux/ip.h> | ||
53 | #include <net/checksum.h> | ||
54 | #include <net/tcp.h> | ||
55 | |||
56 | #include <linux/netfilter_ipv4/ip_conntrack.h> | ||
57 | #include <linux/netfilter_ipv4/ip_conntrack_core.h> | ||
58 | #include <linux/netfilter_ipv4/ip_conntrack_helper.h> | ||
59 | #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h> | ||
60 | #include <linux/netfilter_ipv4/ip_conntrack_pptp.h> | ||
61 | |||
62 | #define IP_CT_PPTP_VERSION "3.1" | ||
63 | |||
64 | MODULE_LICENSE("GPL"); | ||
65 | MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); | ||
66 | MODULE_DESCRIPTION("Netfilter connection tracking helper module for PPTP"); | ||
67 | |||
68 | static DEFINE_SPINLOCK(ip_pptp_lock); | ||
69 | |||
70 | int | ||
71 | (*ip_nat_pptp_hook_outbound)(struct sk_buff **pskb, | ||
72 | struct ip_conntrack *ct, | ||
73 | enum ip_conntrack_info ctinfo, | ||
74 | struct PptpControlHeader *ctlh, | ||
75 | union pptp_ctrl_union *pptpReq); | ||
76 | |||
77 | int | ||
78 | (*ip_nat_pptp_hook_inbound)(struct sk_buff **pskb, | ||
79 | struct ip_conntrack *ct, | ||
80 | enum ip_conntrack_info ctinfo, | ||
81 | struct PptpControlHeader *ctlh, | ||
82 | union pptp_ctrl_union *pptpReq); | ||
83 | |||
84 | int | ||
85 | (*ip_nat_pptp_hook_exp_gre)(struct ip_conntrack_expect *expect_orig, | ||
86 | struct ip_conntrack_expect *expect_reply); | ||
87 | |||
88 | void | ||
89 | (*ip_nat_pptp_hook_expectfn)(struct ip_conntrack *ct, | ||
90 | struct ip_conntrack_expect *exp); | ||
91 | |||
92 | #if 0 | ||
93 | /* PptpControlMessageType names */ | ||
94 | const char *pptp_msg_name[] = { | ||
95 | "UNKNOWN_MESSAGE", | ||
96 | "START_SESSION_REQUEST", | ||
97 | "START_SESSION_REPLY", | ||
98 | "STOP_SESSION_REQUEST", | ||
99 | "STOP_SESSION_REPLY", | ||
100 | "ECHO_REQUEST", | ||
101 | "ECHO_REPLY", | ||
102 | "OUT_CALL_REQUEST", | ||
103 | "OUT_CALL_REPLY", | ||
104 | "IN_CALL_REQUEST", | ||
105 | "IN_CALL_REPLY", | ||
106 | "IN_CALL_CONNECT", | ||
107 | "CALL_CLEAR_REQUEST", | ||
108 | "CALL_DISCONNECT_NOTIFY", | ||
109 | "WAN_ERROR_NOTIFY", | ||
110 | "SET_LINK_INFO" | ||
111 | }; | ||
112 | EXPORT_SYMBOL(pptp_msg_name); | ||
113 | #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, __FUNCTION__, ## args) | ||
114 | #else | ||
115 | #define DEBUGP(format, args...) | ||
116 | #endif | ||
117 | |||
118 | #define SECS *HZ | ||
119 | #define MINS * 60 SECS | ||
120 | #define HOURS * 60 MINS | ||
121 | |||
122 | #define PPTP_GRE_TIMEOUT (10 MINS) | ||
123 | #define PPTP_GRE_STREAM_TIMEOUT (5 HOURS) | ||
124 | |||
125 | static void pptp_expectfn(struct ip_conntrack *ct, | ||
126 | struct ip_conntrack_expect *exp) | ||
127 | { | ||
128 | DEBUGP("increasing timeouts\n"); | ||
129 | |||
130 | /* increase timeout of GRE data channel conntrack entry */ | ||
131 | ct->proto.gre.timeout = PPTP_GRE_TIMEOUT; | ||
132 | ct->proto.gre.stream_timeout = PPTP_GRE_STREAM_TIMEOUT; | ||
133 | |||
134 | /* Can you see how rusty this code is, compared with the pre-2.6.11 | ||
135 | * one? That's what happened to my shiny newnat of 2002 ;( -HW */ | ||
136 | |||
137 | if (!ip_nat_pptp_hook_expectfn) { | ||
138 | struct ip_conntrack_tuple inv_t; | ||
139 | struct ip_conntrack_expect *exp_other; | ||
140 | |||
141 | /* obviously this tuple inversion only works until you do NAT */ | ||
142 | invert_tuplepr(&inv_t, &exp->tuple); | ||
143 | DEBUGP("trying to unexpect other dir: "); | ||
144 | DUMP_TUPLE(&inv_t); | ||
145 | |||
146 | exp_other = ip_conntrack_expect_find(&inv_t); | ||
147 | if (exp_other) { | ||
148 | /* delete other expectation. */ | ||
149 | DEBUGP("found\n"); | ||
150 | ip_conntrack_unexpect_related(exp_other); | ||
151 | ip_conntrack_expect_put(exp_other); | ||
152 | } else { | ||
153 | DEBUGP("not found\n"); | ||
154 | } | ||
155 | } else { | ||
156 | /* we need more than simple inversion */ | ||
157 | ip_nat_pptp_hook_expectfn(ct, exp); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | static int destroy_sibling_or_exp(const struct ip_conntrack_tuple *t) | ||
162 | { | ||
163 | struct ip_conntrack_tuple_hash *h; | ||
164 | struct ip_conntrack_expect *exp; | ||
165 | |||
166 | DEBUGP("trying to timeout ct or exp for tuple "); | ||
167 | DUMP_TUPLE(t); | ||
168 | |||
169 | h = ip_conntrack_find_get(t, NULL); | ||
170 | if (h) { | ||
171 | struct ip_conntrack *sibling = tuplehash_to_ctrack(h); | ||
172 | DEBUGP("setting timeout of conntrack %p to 0\n", sibling); | ||
173 | sibling->proto.gre.timeout = 0; | ||
174 | sibling->proto.gre.stream_timeout = 0; | ||
175 | if (del_timer(&sibling->timeout)) | ||
176 | sibling->timeout.function((unsigned long)sibling); | ||
177 | ip_conntrack_put(sibling); | ||
178 | return 1; | ||
179 | } else { | ||
180 | exp = ip_conntrack_expect_find(t); | ||
181 | if (exp) { | ||
182 | DEBUGP("unexpect_related of expect %p\n", exp); | ||
183 | ip_conntrack_unexpect_related(exp); | ||
184 | ip_conntrack_expect_put(exp); | ||
185 | return 1; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | |||
193 | /* timeout GRE data connections */ | ||
194 | static void pptp_destroy_siblings(struct ip_conntrack *ct) | ||
195 | { | ||
196 | struct ip_conntrack_tuple t; | ||
197 | |||
198 | /* Since ct->sibling_list has literally rusted away in 2.6.11, | ||
199 | * we now need another way to find out about our sibling | ||
200 | * contrack and expects... -HW */ | ||
201 | |||
202 | /* try original (pns->pac) tuple */ | ||
203 | memcpy(&t, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, sizeof(t)); | ||
204 | t.dst.protonum = IPPROTO_GRE; | ||
205 | t.src.u.gre.key = htons(ct->help.ct_pptp_info.pns_call_id); | ||
206 | t.dst.u.gre.key = htons(ct->help.ct_pptp_info.pac_call_id); | ||
207 | |||
208 | if (!destroy_sibling_or_exp(&t)) | ||
209 | DEBUGP("failed to timeout original pns->pac ct/exp\n"); | ||
210 | |||
211 | /* try reply (pac->pns) tuple */ | ||
212 | memcpy(&t, &ct->tuplehash[IP_CT_DIR_REPLY].tuple, sizeof(t)); | ||
213 | t.dst.protonum = IPPROTO_GRE; | ||
214 | t.src.u.gre.key = htons(ct->help.ct_pptp_info.pac_call_id); | ||
215 | t.dst.u.gre.key = htons(ct->help.ct_pptp_info.pns_call_id); | ||
216 | |||
217 | if (!destroy_sibling_or_exp(&t)) | ||
218 | DEBUGP("failed to timeout reply pac->pns ct/exp\n"); | ||
219 | } | ||
220 | |||
221 | /* expect GRE connections (PNS->PAC and PAC->PNS direction) */ | ||
222 | static inline int | ||
223 | exp_gre(struct ip_conntrack *master, | ||
224 | u_int32_t seq, | ||
225 | __be16 callid, | ||
226 | __be16 peer_callid) | ||
227 | { | ||
228 | struct ip_conntrack_tuple inv_tuple; | ||
229 | struct ip_conntrack_tuple exp_tuples[] = { | ||
230 | /* tuple in original direction, PNS->PAC */ | ||
231 | { .src = { .ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip, | ||
232 | .u = { .gre = { .key = peer_callid } } | ||
233 | }, | ||
234 | .dst = { .ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip, | ||
235 | .u = { .gre = { .key = callid } }, | ||
236 | .protonum = IPPROTO_GRE | ||
237 | }, | ||
238 | }, | ||
239 | /* tuple in reply direction, PAC->PNS */ | ||
240 | { .src = { .ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip, | ||
241 | .u = { .gre = { .key = callid } } | ||
242 | }, | ||
243 | .dst = { .ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip, | ||
244 | .u = { .gre = { .key = peer_callid } }, | ||
245 | .protonum = IPPROTO_GRE | ||
246 | }, | ||
247 | } | ||
248 | }; | ||
249 | struct ip_conntrack_expect *exp_orig, *exp_reply; | ||
250 | int ret = 1; | ||
251 | |||
252 | exp_orig = ip_conntrack_expect_alloc(master); | ||
253 | if (exp_orig == NULL) | ||
254 | goto out; | ||
255 | |||
256 | exp_reply = ip_conntrack_expect_alloc(master); | ||
257 | if (exp_reply == NULL) | ||
258 | goto out_put_orig; | ||
259 | |||
260 | memcpy(&exp_orig->tuple, &exp_tuples[0], sizeof(exp_orig->tuple)); | ||
261 | |||
262 | exp_orig->mask.src.ip = 0xffffffff; | ||
263 | exp_orig->mask.src.u.all = 0; | ||
264 | exp_orig->mask.dst.u.all = 0; | ||
265 | exp_orig->mask.dst.u.gre.key = htons(0xffff); | ||
266 | exp_orig->mask.dst.ip = 0xffffffff; | ||
267 | exp_orig->mask.dst.protonum = 0xff; | ||
268 | |||
269 | exp_orig->master = master; | ||
270 | exp_orig->expectfn = pptp_expectfn; | ||
271 | exp_orig->flags = 0; | ||
272 | |||
273 | exp_orig->dir = IP_CT_DIR_ORIGINAL; | ||
274 | |||
275 | /* both expectations are identical apart from tuple */ | ||
276 | memcpy(exp_reply, exp_orig, sizeof(*exp_reply)); | ||
277 | memcpy(&exp_reply->tuple, &exp_tuples[1], sizeof(exp_reply->tuple)); | ||
278 | |||
279 | exp_reply->dir = !exp_orig->dir; | ||
280 | |||
281 | if (ip_nat_pptp_hook_exp_gre) | ||
282 | ret = ip_nat_pptp_hook_exp_gre(exp_orig, exp_reply); | ||
283 | else { | ||
284 | |||
285 | DEBUGP("calling expect_related PNS->PAC"); | ||
286 | DUMP_TUPLE(&exp_orig->tuple); | ||
287 | |||
288 | if (ip_conntrack_expect_related(exp_orig) != 0) { | ||
289 | DEBUGP("cannot expect_related()\n"); | ||
290 | goto out_put_both; | ||
291 | } | ||
292 | |||
293 | DEBUGP("calling expect_related PAC->PNS"); | ||
294 | DUMP_TUPLE(&exp_reply->tuple); | ||
295 | |||
296 | if (ip_conntrack_expect_related(exp_reply) != 0) { | ||
297 | DEBUGP("cannot expect_related()\n"); | ||
298 | goto out_unexpect_orig; | ||
299 | } | ||
300 | |||
301 | /* Add GRE keymap entries */ | ||
302 | if (ip_ct_gre_keymap_add(master, &exp_reply->tuple, 0) != 0) { | ||
303 | DEBUGP("cannot keymap_add() exp\n"); | ||
304 | goto out_unexpect_both; | ||
305 | } | ||
306 | |||
307 | invert_tuplepr(&inv_tuple, &exp_reply->tuple); | ||
308 | if (ip_ct_gre_keymap_add(master, &inv_tuple, 1) != 0) { | ||
309 | ip_ct_gre_keymap_destroy(master); | ||
310 | DEBUGP("cannot keymap_add() exp_inv\n"); | ||
311 | goto out_unexpect_both; | ||
312 | } | ||
313 | ret = 0; | ||
314 | } | ||
315 | |||
316 | out_put_both: | ||
317 | ip_conntrack_expect_put(exp_reply); | ||
318 | out_put_orig: | ||
319 | ip_conntrack_expect_put(exp_orig); | ||
320 | out: | ||
321 | return ret; | ||
322 | |||
323 | out_unexpect_both: | ||
324 | ip_conntrack_unexpect_related(exp_reply); | ||
325 | out_unexpect_orig: | ||
326 | ip_conntrack_unexpect_related(exp_orig); | ||
327 | goto out_put_both; | ||
328 | } | ||
329 | |||
330 | static inline int | ||
331 | pptp_inbound_pkt(struct sk_buff **pskb, | ||
332 | struct tcphdr *tcph, | ||
333 | unsigned int nexthdr_off, | ||
334 | unsigned int datalen, | ||
335 | struct ip_conntrack *ct, | ||
336 | enum ip_conntrack_info ctinfo) | ||
337 | { | ||
338 | struct PptpControlHeader _ctlh, *ctlh; | ||
339 | unsigned int reqlen; | ||
340 | union pptp_ctrl_union _pptpReq, *pptpReq; | ||
341 | struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info; | ||
342 | u_int16_t msg; | ||
343 | __be16 *cid, *pcid; | ||
344 | u_int32_t seq; | ||
345 | |||
346 | ctlh = skb_header_pointer(*pskb, nexthdr_off, sizeof(_ctlh), &_ctlh); | ||
347 | if (!ctlh) { | ||
348 | DEBUGP("error during skb_header_pointer\n"); | ||
349 | return NF_ACCEPT; | ||
350 | } | ||
351 | nexthdr_off += sizeof(_ctlh); | ||
352 | datalen -= sizeof(_ctlh); | ||
353 | |||
354 | reqlen = datalen; | ||
355 | if (reqlen > sizeof(*pptpReq)) | ||
356 | reqlen = sizeof(*pptpReq); | ||
357 | pptpReq = skb_header_pointer(*pskb, nexthdr_off, reqlen, &_pptpReq); | ||
358 | if (!pptpReq) { | ||
359 | DEBUGP("error during skb_header_pointer\n"); | ||
360 | return NF_ACCEPT; | ||
361 | } | ||
362 | |||
363 | msg = ntohs(ctlh->messageType); | ||
364 | DEBUGP("inbound control message %s\n", pptp_msg_name[msg]); | ||
365 | |||
366 | switch (msg) { | ||
367 | case PPTP_START_SESSION_REPLY: | ||
368 | if (reqlen < sizeof(_pptpReq.srep)) { | ||
369 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
370 | break; | ||
371 | } | ||
372 | |||
373 | /* server confirms new control session */ | ||
374 | if (info->sstate < PPTP_SESSION_REQUESTED) { | ||
375 | DEBUGP("%s without START_SESS_REQUEST\n", | ||
376 | pptp_msg_name[msg]); | ||
377 | break; | ||
378 | } | ||
379 | if (pptpReq->srep.resultCode == PPTP_START_OK) | ||
380 | info->sstate = PPTP_SESSION_CONFIRMED; | ||
381 | else | ||
382 | info->sstate = PPTP_SESSION_ERROR; | ||
383 | break; | ||
384 | |||
385 | case PPTP_STOP_SESSION_REPLY: | ||
386 | if (reqlen < sizeof(_pptpReq.strep)) { | ||
387 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
388 | break; | ||
389 | } | ||
390 | |||
391 | /* server confirms end of control session */ | ||
392 | if (info->sstate > PPTP_SESSION_STOPREQ) { | ||
393 | DEBUGP("%s without STOP_SESS_REQUEST\n", | ||
394 | pptp_msg_name[msg]); | ||
395 | break; | ||
396 | } | ||
397 | if (pptpReq->strep.resultCode == PPTP_STOP_OK) | ||
398 | info->sstate = PPTP_SESSION_NONE; | ||
399 | else | ||
400 | info->sstate = PPTP_SESSION_ERROR; | ||
401 | break; | ||
402 | |||
403 | case PPTP_OUT_CALL_REPLY: | ||
404 | if (reqlen < sizeof(_pptpReq.ocack)) { | ||
405 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
406 | break; | ||
407 | } | ||
408 | |||
409 | /* server accepted call, we now expect GRE frames */ | ||
410 | if (info->sstate != PPTP_SESSION_CONFIRMED) { | ||
411 | DEBUGP("%s but no session\n", pptp_msg_name[msg]); | ||
412 | break; | ||
413 | } | ||
414 | if (info->cstate != PPTP_CALL_OUT_REQ && | ||
415 | info->cstate != PPTP_CALL_OUT_CONF) { | ||
416 | DEBUGP("%s without OUTCALL_REQ\n", pptp_msg_name[msg]); | ||
417 | break; | ||
418 | } | ||
419 | if (pptpReq->ocack.resultCode != PPTP_OUTCALL_CONNECT) { | ||
420 | info->cstate = PPTP_CALL_NONE; | ||
421 | break; | ||
422 | } | ||
423 | |||
424 | cid = &pptpReq->ocack.callID; | ||
425 | pcid = &pptpReq->ocack.peersCallID; | ||
426 | |||
427 | info->pac_call_id = ntohs(*cid); | ||
428 | |||
429 | if (htons(info->pns_call_id) != *pcid) { | ||
430 | DEBUGP("%s for unknown callid %u\n", | ||
431 | pptp_msg_name[msg], ntohs(*pcid)); | ||
432 | break; | ||
433 | } | ||
434 | |||
435 | DEBUGP("%s, CID=%X, PCID=%X\n", pptp_msg_name[msg], | ||
436 | ntohs(*cid), ntohs(*pcid)); | ||
437 | |||
438 | info->cstate = PPTP_CALL_OUT_CONF; | ||
439 | |||
440 | seq = ntohl(tcph->seq) + sizeof(struct pptp_pkt_hdr) | ||
441 | + sizeof(struct PptpControlHeader) | ||
442 | + ((void *)pcid - (void *)pptpReq); | ||
443 | |||
444 | if (exp_gre(ct, seq, *cid, *pcid) != 0) | ||
445 | printk("ip_conntrack_pptp: error during exp_gre\n"); | ||
446 | break; | ||
447 | |||
448 | case PPTP_IN_CALL_REQUEST: | ||
449 | if (reqlen < sizeof(_pptpReq.icack)) { | ||
450 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
451 | break; | ||
452 | } | ||
453 | |||
454 | /* server tells us about incoming call request */ | ||
455 | if (info->sstate != PPTP_SESSION_CONFIRMED) { | ||
456 | DEBUGP("%s but no session\n", pptp_msg_name[msg]); | ||
457 | break; | ||
458 | } | ||
459 | pcid = &pptpReq->icack.peersCallID; | ||
460 | DEBUGP("%s, PCID=%X\n", pptp_msg_name[msg], ntohs(*pcid)); | ||
461 | info->cstate = PPTP_CALL_IN_REQ; | ||
462 | info->pac_call_id = ntohs(*pcid); | ||
463 | break; | ||
464 | |||
465 | case PPTP_IN_CALL_CONNECT: | ||
466 | if (reqlen < sizeof(_pptpReq.iccon)) { | ||
467 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
468 | break; | ||
469 | } | ||
470 | |||
471 | /* server tells us about incoming call established */ | ||
472 | if (info->sstate != PPTP_SESSION_CONFIRMED) { | ||
473 | DEBUGP("%s but no session\n", pptp_msg_name[msg]); | ||
474 | break; | ||
475 | } | ||
476 | if (info->sstate != PPTP_CALL_IN_REP | ||
477 | && info->sstate != PPTP_CALL_IN_CONF) { | ||
478 | DEBUGP("%s but never sent IN_CALL_REPLY\n", | ||
479 | pptp_msg_name[msg]); | ||
480 | break; | ||
481 | } | ||
482 | |||
483 | pcid = &pptpReq->iccon.peersCallID; | ||
484 | cid = &info->pac_call_id; | ||
485 | |||
486 | if (info->pns_call_id != ntohs(*pcid)) { | ||
487 | DEBUGP("%s for unknown CallID %u\n", | ||
488 | pptp_msg_name[msg], ntohs(*pcid)); | ||
489 | break; | ||
490 | } | ||
491 | |||
492 | DEBUGP("%s, PCID=%X\n", pptp_msg_name[msg], ntohs(*pcid)); | ||
493 | info->cstate = PPTP_CALL_IN_CONF; | ||
494 | |||
495 | /* we expect a GRE connection from PAC to PNS */ | ||
496 | seq = ntohl(tcph->seq) + sizeof(struct pptp_pkt_hdr) | ||
497 | + sizeof(struct PptpControlHeader) | ||
498 | + ((void *)pcid - (void *)pptpReq); | ||
499 | |||
500 | if (exp_gre(ct, seq, *cid, *pcid) != 0) | ||
501 | printk("ip_conntrack_pptp: error during exp_gre\n"); | ||
502 | |||
503 | break; | ||
504 | |||
505 | case PPTP_CALL_DISCONNECT_NOTIFY: | ||
506 | if (reqlen < sizeof(_pptpReq.disc)) { | ||
507 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
508 | break; | ||
509 | } | ||
510 | |||
511 | /* server confirms disconnect */ | ||
512 | cid = &pptpReq->disc.callID; | ||
513 | DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(*cid)); | ||
514 | info->cstate = PPTP_CALL_NONE; | ||
515 | |||
516 | /* untrack this call id, unexpect GRE packets */ | ||
517 | pptp_destroy_siblings(ct); | ||
518 | break; | ||
519 | |||
520 | case PPTP_WAN_ERROR_NOTIFY: | ||
521 | break; | ||
522 | |||
523 | case PPTP_ECHO_REQUEST: | ||
524 | case PPTP_ECHO_REPLY: | ||
525 | /* I don't have to explain these ;) */ | ||
526 | break; | ||
527 | default: | ||
528 | DEBUGP("invalid %s (TY=%d)\n", (msg <= PPTP_MSG_MAX) | ||
529 | ? pptp_msg_name[msg]:pptp_msg_name[0], msg); | ||
530 | break; | ||
531 | } | ||
532 | |||
533 | |||
534 | if (ip_nat_pptp_hook_inbound) | ||
535 | return ip_nat_pptp_hook_inbound(pskb, ct, ctinfo, ctlh, | ||
536 | pptpReq); | ||
537 | |||
538 | return NF_ACCEPT; | ||
539 | |||
540 | } | ||
541 | |||
542 | static inline int | ||
543 | pptp_outbound_pkt(struct sk_buff **pskb, | ||
544 | struct tcphdr *tcph, | ||
545 | unsigned int nexthdr_off, | ||
546 | unsigned int datalen, | ||
547 | struct ip_conntrack *ct, | ||
548 | enum ip_conntrack_info ctinfo) | ||
549 | { | ||
550 | struct PptpControlHeader _ctlh, *ctlh; | ||
551 | unsigned int reqlen; | ||
552 | union pptp_ctrl_union _pptpReq, *pptpReq; | ||
553 | struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info; | ||
554 | u_int16_t msg; | ||
555 | __be16 *cid, *pcid; | ||
556 | |||
557 | ctlh = skb_header_pointer(*pskb, nexthdr_off, sizeof(_ctlh), &_ctlh); | ||
558 | if (!ctlh) | ||
559 | return NF_ACCEPT; | ||
560 | nexthdr_off += sizeof(_ctlh); | ||
561 | datalen -= sizeof(_ctlh); | ||
562 | |||
563 | reqlen = datalen; | ||
564 | if (reqlen > sizeof(*pptpReq)) | ||
565 | reqlen = sizeof(*pptpReq); | ||
566 | pptpReq = skb_header_pointer(*pskb, nexthdr_off, reqlen, &_pptpReq); | ||
567 | if (!pptpReq) | ||
568 | return NF_ACCEPT; | ||
569 | |||
570 | msg = ntohs(ctlh->messageType); | ||
571 | DEBUGP("outbound control message %s\n", pptp_msg_name[msg]); | ||
572 | |||
573 | switch (msg) { | ||
574 | case PPTP_START_SESSION_REQUEST: | ||
575 | /* client requests for new control session */ | ||
576 | if (info->sstate != PPTP_SESSION_NONE) { | ||
577 | DEBUGP("%s but we already have one", | ||
578 | pptp_msg_name[msg]); | ||
579 | } | ||
580 | info->sstate = PPTP_SESSION_REQUESTED; | ||
581 | break; | ||
582 | case PPTP_STOP_SESSION_REQUEST: | ||
583 | /* client requests end of control session */ | ||
584 | info->sstate = PPTP_SESSION_STOPREQ; | ||
585 | break; | ||
586 | |||
587 | case PPTP_OUT_CALL_REQUEST: | ||
588 | if (reqlen < sizeof(_pptpReq.ocreq)) { | ||
589 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
590 | /* FIXME: break; */ | ||
591 | } | ||
592 | |||
593 | /* client initiating connection to server */ | ||
594 | if (info->sstate != PPTP_SESSION_CONFIRMED) { | ||
595 | DEBUGP("%s but no session\n", | ||
596 | pptp_msg_name[msg]); | ||
597 | break; | ||
598 | } | ||
599 | info->cstate = PPTP_CALL_OUT_REQ; | ||
600 | /* track PNS call id */ | ||
601 | cid = &pptpReq->ocreq.callID; | ||
602 | DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(*cid)); | ||
603 | info->pns_call_id = ntohs(*cid); | ||
604 | break; | ||
605 | case PPTP_IN_CALL_REPLY: | ||
606 | if (reqlen < sizeof(_pptpReq.icack)) { | ||
607 | DEBUGP("%s: short packet\n", pptp_msg_name[msg]); | ||
608 | break; | ||
609 | } | ||
610 | |||
611 | /* client answers incoming call */ | ||
612 | if (info->cstate != PPTP_CALL_IN_REQ | ||
613 | && info->cstate != PPTP_CALL_IN_REP) { | ||
614 | DEBUGP("%s without incall_req\n", | ||
615 | pptp_msg_name[msg]); | ||
616 | break; | ||
617 | } | ||
618 | if (pptpReq->icack.resultCode != PPTP_INCALL_ACCEPT) { | ||
619 | info->cstate = PPTP_CALL_NONE; | ||
620 | break; | ||
621 | } | ||
622 | pcid = &pptpReq->icack.peersCallID; | ||
623 | if (info->pac_call_id != ntohs(*pcid)) { | ||
624 | DEBUGP("%s for unknown call %u\n", | ||
625 | pptp_msg_name[msg], ntohs(*pcid)); | ||
626 | break; | ||
627 | } | ||
628 | DEBUGP("%s, CID=%X\n", pptp_msg_name[msg], ntohs(*pcid)); | ||
629 | /* part two of the three-way handshake */ | ||
630 | info->cstate = PPTP_CALL_IN_REP; | ||
631 | info->pns_call_id = ntohs(pptpReq->icack.callID); | ||
632 | break; | ||
633 | |||
634 | case PPTP_CALL_CLEAR_REQUEST: | ||
635 | /* client requests hangup of call */ | ||
636 | if (info->sstate != PPTP_SESSION_CONFIRMED) { | ||
637 | DEBUGP("CLEAR_CALL but no session\n"); | ||
638 | break; | ||
639 | } | ||
640 | /* FUTURE: iterate over all calls and check if | ||
641 | * call ID is valid. We don't do this without newnat, | ||
642 | * because we only know about last call */ | ||
643 | info->cstate = PPTP_CALL_CLEAR_REQ; | ||
644 | break; | ||
645 | case PPTP_SET_LINK_INFO: | ||
646 | break; | ||
647 | case PPTP_ECHO_REQUEST: | ||
648 | case PPTP_ECHO_REPLY: | ||
649 | /* I don't have to explain these ;) */ | ||
650 | break; | ||
651 | default: | ||
652 | DEBUGP("invalid %s (TY=%d)\n", (msg <= PPTP_MSG_MAX)? | ||
653 | pptp_msg_name[msg]:pptp_msg_name[0], msg); | ||
654 | /* unknown: no need to create GRE masq table entry */ | ||
655 | break; | ||
656 | } | ||
657 | |||
658 | if (ip_nat_pptp_hook_outbound) | ||
659 | return ip_nat_pptp_hook_outbound(pskb, ct, ctinfo, ctlh, | ||
660 | pptpReq); | ||
661 | |||
662 | return NF_ACCEPT; | ||
663 | } | ||
664 | |||
665 | |||
666 | /* track caller id inside control connection, call expect_related */ | ||
667 | static int | ||
668 | conntrack_pptp_help(struct sk_buff **pskb, | ||
669 | struct ip_conntrack *ct, enum ip_conntrack_info ctinfo) | ||
670 | |||
671 | { | ||
672 | struct pptp_pkt_hdr _pptph, *pptph; | ||
673 | struct tcphdr _tcph, *tcph; | ||
674 | u_int32_t tcplen = (*pskb)->len - (*pskb)->nh.iph->ihl * 4; | ||
675 | u_int32_t datalen; | ||
676 | int dir = CTINFO2DIR(ctinfo); | ||
677 | struct ip_ct_pptp_master *info = &ct->help.ct_pptp_info; | ||
678 | unsigned int nexthdr_off; | ||
679 | |||
680 | int oldsstate, oldcstate; | ||
681 | int ret; | ||
682 | |||
683 | /* don't do any tracking before tcp handshake complete */ | ||
684 | if (ctinfo != IP_CT_ESTABLISHED | ||
685 | && ctinfo != IP_CT_ESTABLISHED+IP_CT_IS_REPLY) { | ||
686 | DEBUGP("ctinfo = %u, skipping\n", ctinfo); | ||
687 | return NF_ACCEPT; | ||
688 | } | ||
689 | |||
690 | nexthdr_off = (*pskb)->nh.iph->ihl*4; | ||
691 | tcph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_tcph), &_tcph); | ||
692 | BUG_ON(!tcph); | ||
693 | nexthdr_off += tcph->doff * 4; | ||
694 | datalen = tcplen - tcph->doff * 4; | ||
695 | |||
696 | if (tcph->fin || tcph->rst) { | ||
697 | DEBUGP("RST/FIN received, timeouting GRE\n"); | ||
698 | /* can't do this after real newnat */ | ||
699 | info->cstate = PPTP_CALL_NONE; | ||
700 | |||
701 | /* untrack this call id, unexpect GRE packets */ | ||
702 | pptp_destroy_siblings(ct); | ||
703 | } | ||
704 | |||
705 | pptph = skb_header_pointer(*pskb, nexthdr_off, sizeof(_pptph), &_pptph); | ||
706 | if (!pptph) { | ||
707 | DEBUGP("no full PPTP header, can't track\n"); | ||
708 | return NF_ACCEPT; | ||
709 | } | ||
710 | nexthdr_off += sizeof(_pptph); | ||
711 | datalen -= sizeof(_pptph); | ||
712 | |||
713 | /* if it's not a control message we can't do anything with it */ | ||
714 | if (ntohs(pptph->packetType) != PPTP_PACKET_CONTROL || | ||
715 | ntohl(pptph->magicCookie) != PPTP_MAGIC_COOKIE) { | ||
716 | DEBUGP("not a control packet\n"); | ||
717 | return NF_ACCEPT; | ||
718 | } | ||
719 | |||
720 | oldsstate = info->sstate; | ||
721 | oldcstate = info->cstate; | ||
722 | |||
723 | spin_lock_bh(&ip_pptp_lock); | ||
724 | |||
725 | /* FIXME: We just blindly assume that the control connection is always | ||
726 | * established from PNS->PAC. However, RFC makes no guarantee */ | ||
727 | if (dir == IP_CT_DIR_ORIGINAL) | ||
728 | /* client -> server (PNS -> PAC) */ | ||
729 | ret = pptp_outbound_pkt(pskb, tcph, nexthdr_off, datalen, ct, | ||
730 | ctinfo); | ||
731 | else | ||
732 | /* server -> client (PAC -> PNS) */ | ||
733 | ret = pptp_inbound_pkt(pskb, tcph, nexthdr_off, datalen, ct, | ||
734 | ctinfo); | ||
735 | DEBUGP("sstate: %d->%d, cstate: %d->%d\n", | ||
736 | oldsstate, info->sstate, oldcstate, info->cstate); | ||
737 | spin_unlock_bh(&ip_pptp_lock); | ||
738 | |||
739 | return ret; | ||
740 | } | ||
741 | |||
742 | /* control protocol helper */ | ||
743 | static struct ip_conntrack_helper pptp = { | ||
744 | .list = { NULL, NULL }, | ||
745 | .name = "pptp", | ||
746 | .me = THIS_MODULE, | ||
747 | .max_expected = 2, | ||
748 | .timeout = 5 * 60, | ||
749 | .tuple = { .src = { .ip = 0, | ||
750 | .u = { .tcp = { .port = | ||
751 | __constant_htons(PPTP_CONTROL_PORT) } } | ||
752 | }, | ||
753 | .dst = { .ip = 0, | ||
754 | .u = { .all = 0 }, | ||
755 | .protonum = IPPROTO_TCP | ||
756 | } | ||
757 | }, | ||
758 | .mask = { .src = { .ip = 0, | ||
759 | .u = { .tcp = { .port = __constant_htons(0xffff) } } | ||
760 | }, | ||
761 | .dst = { .ip = 0, | ||
762 | .u = { .all = 0 }, | ||
763 | .protonum = 0xff | ||
764 | } | ||
765 | }, | ||
766 | .help = conntrack_pptp_help | ||
767 | }; | ||
768 | |||
769 | extern void __exit ip_ct_proto_gre_fini(void); | ||
770 | extern int __init ip_ct_proto_gre_init(void); | ||
771 | |||
772 | /* ip_conntrack_pptp initialization */ | ||
773 | static int __init init(void) | ||
774 | { | ||
775 | int retcode; | ||
776 | |||
777 | retcode = ip_ct_proto_gre_init(); | ||
778 | if (retcode < 0) | ||
779 | return retcode; | ||
780 | |||
781 | DEBUGP(" registering helper\n"); | ||
782 | if ((retcode = ip_conntrack_helper_register(&pptp))) { | ||
783 | printk(KERN_ERR "Unable to register conntrack application " | ||
784 | "helper for pptp: %d\n", retcode); | ||
785 | ip_ct_proto_gre_fini(); | ||
786 | return retcode; | ||
787 | } | ||
788 | |||
789 | printk("ip_conntrack_pptp version %s loaded\n", IP_CT_PPTP_VERSION); | ||
790 | return 0; | ||
791 | } | ||
792 | |||
793 | static void __exit fini(void) | ||
794 | { | ||
795 | ip_conntrack_helper_unregister(&pptp); | ||
796 | ip_ct_proto_gre_fini(); | ||
797 | printk("ip_conntrack_pptp version %s unloaded\n", IP_CT_PPTP_VERSION); | ||
798 | } | ||
799 | |||
800 | module_init(init); | ||
801 | module_exit(fini); | ||
802 | |||
803 | EXPORT_SYMBOL(ip_nat_pptp_hook_outbound); | ||
804 | EXPORT_SYMBOL(ip_nat_pptp_hook_inbound); | ||
805 | EXPORT_SYMBOL(ip_nat_pptp_hook_exp_gre); | ||
806 | EXPORT_SYMBOL(ip_nat_pptp_hook_expectfn); | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_irc.c b/net/ipv4/netfilter/ip_conntrack_irc.c index d7a8a98c05e1..15457415a4f3 100644 --- a/net/ipv4/netfilter/ip_conntrack_irc.c +++ b/net/ipv4/netfilter/ip_conntrack_irc.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include <linux/moduleparam.h> | 34 | #include <linux/moduleparam.h> |
35 | 35 | ||
36 | #define MAX_PORTS 8 | 36 | #define MAX_PORTS 8 |
37 | static int ports[MAX_PORTS]; | 37 | static short ports[MAX_PORTS]; |
38 | static int ports_c; | 38 | static int ports_c; |
39 | static int max_dcc_channels = 8; | 39 | static int max_dcc_channels = 8; |
40 | static unsigned int dcc_timeout = 300; | 40 | static unsigned int dcc_timeout = 300; |
@@ -52,7 +52,7 @@ EXPORT_SYMBOL_GPL(ip_nat_irc_hook); | |||
52 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); | 52 | MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); |
53 | MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); | 53 | MODULE_DESCRIPTION("IRC (DCC) connection tracking helper"); |
54 | MODULE_LICENSE("GPL"); | 54 | MODULE_LICENSE("GPL"); |
55 | module_param_array(ports, int, &ports_c, 0400); | 55 | module_param_array(ports, short, &ports_c, 0400); |
56 | MODULE_PARM_DESC(ports, "port numbers of IRC servers"); | 56 | MODULE_PARM_DESC(ports, "port numbers of IRC servers"); |
57 | module_param(max_dcc_channels, int, 0400); | 57 | module_param(max_dcc_channels, int, 0400); |
58 | MODULE_PARM_DESC(max_dcc_channels, "max number of expected DCC channels per IRC session"); | 58 | MODULE_PARM_DESC(max_dcc_channels, "max number of expected DCC channels per IRC session"); |
@@ -240,7 +240,7 @@ static int help(struct sk_buff **pskb, | |||
240 | } | 240 | } |
241 | 241 | ||
242 | static struct ip_conntrack_helper irc_helpers[MAX_PORTS]; | 242 | static struct ip_conntrack_helper irc_helpers[MAX_PORTS]; |
243 | static char irc_names[MAX_PORTS][10]; | 243 | static char irc_names[MAX_PORTS][sizeof("irc-65535")]; |
244 | 244 | ||
245 | static void fini(void); | 245 | static void fini(void); |
246 | 246 | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c index bb7246683b74..186646eb249f 100644 --- a/net/ipv4/netfilter/ip_conntrack_netbios_ns.c +++ b/net/ipv4/netfilter/ip_conntrack_netbios_ns.c | |||
@@ -23,7 +23,6 @@ | |||
23 | #include <linux/inetdevice.h> | 23 | #include <linux/inetdevice.h> |
24 | #include <linux/in.h> | 24 | #include <linux/in.h> |
25 | #include <linux/ip.h> | 25 | #include <linux/ip.h> |
26 | #include <linux/udp.h> | ||
27 | #include <net/route.h> | 26 | #include <net/route.h> |
28 | 27 | ||
29 | #include <linux/netfilter.h> | 28 | #include <linux/netfilter.h> |
@@ -31,6 +30,8 @@ | |||
31 | #include <linux/netfilter_ipv4/ip_conntrack.h> | 30 | #include <linux/netfilter_ipv4/ip_conntrack.h> |
32 | #include <linux/netfilter_ipv4/ip_conntrack_helper.h> | 31 | #include <linux/netfilter_ipv4/ip_conntrack_helper.h> |
33 | 32 | ||
33 | #define NMBD_PORT 137 | ||
34 | |||
34 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); | 35 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); |
35 | MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper"); | 36 | MODULE_DESCRIPTION("NetBIOS name service broadcast connection tracking helper"); |
36 | MODULE_LICENSE("GPL"); | 37 | MODULE_LICENSE("GPL"); |
@@ -44,7 +45,6 @@ static int help(struct sk_buff **pskb, | |||
44 | { | 45 | { |
45 | struct ip_conntrack_expect *exp; | 46 | struct ip_conntrack_expect *exp; |
46 | struct iphdr *iph = (*pskb)->nh.iph; | 47 | struct iphdr *iph = (*pskb)->nh.iph; |
47 | struct udphdr _uh, *uh; | ||
48 | struct rtable *rt = (struct rtable *)(*pskb)->dst; | 48 | struct rtable *rt = (struct rtable *)(*pskb)->dst; |
49 | struct in_device *in_dev; | 49 | struct in_device *in_dev; |
50 | u_int32_t mask = 0; | 50 | u_int32_t mask = 0; |
@@ -58,7 +58,7 @@ static int help(struct sk_buff **pskb, | |||
58 | goto out; | 58 | goto out; |
59 | 59 | ||
60 | rcu_read_lock(); | 60 | rcu_read_lock(); |
61 | in_dev = __in_dev_get(rt->u.dst.dev); | 61 | in_dev = __in_dev_get_rcu(rt->u.dst.dev); |
62 | if (in_dev != NULL) { | 62 | if (in_dev != NULL) { |
63 | for_primary_ifa(in_dev) { | 63 | for_primary_ifa(in_dev) { |
64 | if (ifa->ifa_broadcast == iph->daddr) { | 64 | if (ifa->ifa_broadcast == iph->daddr) { |
@@ -72,20 +72,15 @@ static int help(struct sk_buff **pskb, | |||
72 | if (mask == 0) | 72 | if (mask == 0) |
73 | goto out; | 73 | goto out; |
74 | 74 | ||
75 | uh = skb_header_pointer(*pskb, iph->ihl * 4, sizeof(_uh), &_uh); | ||
76 | BUG_ON(uh == NULL); | ||
77 | |||
78 | exp = ip_conntrack_expect_alloc(ct); | 75 | exp = ip_conntrack_expect_alloc(ct); |
79 | if (exp == NULL) | 76 | if (exp == NULL) |
80 | goto out; | 77 | goto out; |
81 | memset(&exp->tuple, 0, sizeof(exp->tuple)); | ||
82 | exp->tuple.src.ip = iph->daddr & mask; | ||
83 | exp->tuple.dst.ip = iph->saddr; | ||
84 | exp->tuple.dst.u.udp.port = uh->source; | ||
85 | exp->tuple.dst.protonum = IPPROTO_UDP; | ||
86 | 78 | ||
87 | memset(&exp->mask, 0, sizeof(exp->mask)); | 79 | exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple; |
80 | exp->tuple.src.u.udp.port = ntohs(NMBD_PORT); | ||
81 | |||
88 | exp->mask.src.ip = mask; | 82 | exp->mask.src.ip = mask; |
83 | exp->mask.src.u.udp.port = 0xFFFF; | ||
89 | exp->mask.dst.ip = 0xFFFFFFFF; | 84 | exp->mask.dst.ip = 0xFFFFFFFF; |
90 | exp->mask.dst.u.udp.port = 0xFFFF; | 85 | exp->mask.dst.u.udp.port = 0xFFFF; |
91 | exp->mask.dst.protonum = 0xFF; | 86 | exp->mask.dst.protonum = 0xFF; |
@@ -96,7 +91,7 @@ static int help(struct sk_buff **pskb, | |||
96 | ip_conntrack_expect_related(exp); | 91 | ip_conntrack_expect_related(exp); |
97 | ip_conntrack_expect_put(exp); | 92 | ip_conntrack_expect_put(exp); |
98 | 93 | ||
99 | ip_ct_refresh_acct(ct, ctinfo, NULL, timeout * HZ); | 94 | ip_ct_refresh(ct, *pskb, timeout * HZ); |
100 | out: | 95 | out: |
101 | return NF_ACCEPT; | 96 | return NF_ACCEPT; |
102 | } | 97 | } |
@@ -107,7 +102,7 @@ static struct ip_conntrack_helper helper = { | |||
107 | .src = { | 102 | .src = { |
108 | .u = { | 103 | .u = { |
109 | .udp = { | 104 | .udp = { |
110 | .port = __constant_htons(137), | 105 | .port = __constant_htons(NMBD_PORT), |
111 | } | 106 | } |
112 | } | 107 | } |
113 | }, | 108 | }, |
diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c b/net/ipv4/netfilter/ip_conntrack_netlink.c index 15aef3564742..b08a432efcf8 100644 --- a/net/ipv4/netfilter/ip_conntrack_netlink.c +++ b/net/ipv4/netfilter/ip_conntrack_netlink.c | |||
@@ -1270,7 +1270,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1270 | if (err < 0) | 1270 | if (err < 0) |
1271 | return err; | 1271 | return err; |
1272 | 1272 | ||
1273 | exp = ip_conntrack_expect_find_get(&tuple); | 1273 | exp = ip_conntrack_expect_find(&tuple); |
1274 | if (!exp) | 1274 | if (!exp) |
1275 | return -ENOENT; | 1275 | return -ENOENT; |
1276 | 1276 | ||
@@ -1318,7 +1318,7 @@ ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, | |||
1318 | return err; | 1318 | return err; |
1319 | 1319 | ||
1320 | /* bump usage count to 2 */ | 1320 | /* bump usage count to 2 */ |
1321 | exp = ip_conntrack_expect_find_get(&tuple); | 1321 | exp = ip_conntrack_expect_find(&tuple); |
1322 | if (!exp) | 1322 | if (!exp) |
1323 | return -ENOENT; | 1323 | return -ENOENT; |
1324 | 1324 | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_gre.c b/net/ipv4/netfilter/ip_conntrack_proto_gre.c new file mode 100644 index 000000000000..744abb9d377a --- /dev/null +++ b/net/ipv4/netfilter/ip_conntrack_proto_gre.c | |||
@@ -0,0 +1,328 @@ | |||
1 | /* | ||
2 | * ip_conntrack_proto_gre.c - Version 3.0 | ||
3 | * | ||
4 | * Connection tracking protocol helper module for GRE. | ||
5 | * | ||
6 | * GRE is a generic encapsulation protocol, which is generally not very | ||
7 | * suited for NAT, as it has no protocol-specific part as port numbers. | ||
8 | * | ||
9 | * It has an optional key field, which may help us distinguishing two | ||
10 | * connections between the same two hosts. | ||
11 | * | ||
12 | * GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 | ||
13 | * | ||
14 | * PPTP is built on top of a modified version of GRE, and has a mandatory | ||
15 | * field called "CallID", which serves us for the same purpose as the key | ||
16 | * field in plain GRE. | ||
17 | * | ||
18 | * Documentation about PPTP can be found in RFC 2637 | ||
19 | * | ||
20 | * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org> | ||
21 | * | ||
22 | * Development of this code funded by Astaro AG (http://www.astaro.com/) | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/config.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/types.h> | ||
29 | #include <linux/timer.h> | ||
30 | #include <linux/netfilter.h> | ||
31 | #include <linux/ip.h> | ||
32 | #include <linux/in.h> | ||
33 | #include <linux/list.h> | ||
34 | |||
35 | static DEFINE_RWLOCK(ip_ct_gre_lock); | ||
36 | #define ASSERT_READ_LOCK(x) | ||
37 | #define ASSERT_WRITE_LOCK(x) | ||
38 | |||
39 | #include <linux/netfilter_ipv4/listhelp.h> | ||
40 | #include <linux/netfilter_ipv4/ip_conntrack_protocol.h> | ||
41 | #include <linux/netfilter_ipv4/ip_conntrack_helper.h> | ||
42 | #include <linux/netfilter_ipv4/ip_conntrack_core.h> | ||
43 | |||
44 | #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h> | ||
45 | #include <linux/netfilter_ipv4/ip_conntrack_pptp.h> | ||
46 | |||
47 | MODULE_LICENSE("GPL"); | ||
48 | MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); | ||
49 | MODULE_DESCRIPTION("netfilter connection tracking protocol helper for GRE"); | ||
50 | |||
51 | /* shamelessly stolen from ip_conntrack_proto_udp.c */ | ||
52 | #define GRE_TIMEOUT (30*HZ) | ||
53 | #define GRE_STREAM_TIMEOUT (180*HZ) | ||
54 | |||
55 | #if 0 | ||
56 | #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, __FUNCTION__, ## args) | ||
57 | #define DUMP_TUPLE_GRE(x) printk("%u.%u.%u.%u:0x%x -> %u.%u.%u.%u:0x%x\n", \ | ||
58 | NIPQUAD((x)->src.ip), ntohs((x)->src.u.gre.key), \ | ||
59 | NIPQUAD((x)->dst.ip), ntohs((x)->dst.u.gre.key)) | ||
60 | #else | ||
61 | #define DEBUGP(x, args...) | ||
62 | #define DUMP_TUPLE_GRE(x) | ||
63 | #endif | ||
64 | |||
65 | /* GRE KEYMAP HANDLING FUNCTIONS */ | ||
66 | static LIST_HEAD(gre_keymap_list); | ||
67 | |||
68 | static inline int gre_key_cmpfn(const struct ip_ct_gre_keymap *km, | ||
69 | const struct ip_conntrack_tuple *t) | ||
70 | { | ||
71 | return ((km->tuple.src.ip == t->src.ip) && | ||
72 | (km->tuple.dst.ip == t->dst.ip) && | ||
73 | (km->tuple.dst.protonum == t->dst.protonum) && | ||
74 | (km->tuple.dst.u.all == t->dst.u.all)); | ||
75 | } | ||
76 | |||
77 | /* look up the source key for a given tuple */ | ||
78 | static u_int32_t gre_keymap_lookup(struct ip_conntrack_tuple *t) | ||
79 | { | ||
80 | struct ip_ct_gre_keymap *km; | ||
81 | u_int32_t key = 0; | ||
82 | |||
83 | read_lock_bh(&ip_ct_gre_lock); | ||
84 | km = LIST_FIND(&gre_keymap_list, gre_key_cmpfn, | ||
85 | struct ip_ct_gre_keymap *, t); | ||
86 | if (km) | ||
87 | key = km->tuple.src.u.gre.key; | ||
88 | read_unlock_bh(&ip_ct_gre_lock); | ||
89 | |||
90 | DEBUGP("lookup src key 0x%x up key for ", key); | ||
91 | DUMP_TUPLE_GRE(t); | ||
92 | |||
93 | return key; | ||
94 | } | ||
95 | |||
96 | /* add a single keymap entry, associate with specified master ct */ | ||
97 | int | ||
98 | ip_ct_gre_keymap_add(struct ip_conntrack *ct, | ||
99 | struct ip_conntrack_tuple *t, int reply) | ||
100 | { | ||
101 | struct ip_ct_gre_keymap **exist_km, *km, *old; | ||
102 | |||
103 | if (!ct->helper || strcmp(ct->helper->name, "pptp")) { | ||
104 | DEBUGP("refusing to add GRE keymap to non-pptp session\n"); | ||
105 | return -1; | ||
106 | } | ||
107 | |||
108 | if (!reply) | ||
109 | exist_km = &ct->help.ct_pptp_info.keymap_orig; | ||
110 | else | ||
111 | exist_km = &ct->help.ct_pptp_info.keymap_reply; | ||
112 | |||
113 | if (*exist_km) { | ||
114 | /* check whether it's a retransmission */ | ||
115 | old = LIST_FIND(&gre_keymap_list, gre_key_cmpfn, | ||
116 | struct ip_ct_gre_keymap *, t); | ||
117 | if (old == *exist_km) { | ||
118 | DEBUGP("retransmission\n"); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | DEBUGP("trying to override keymap_%s for ct %p\n", | ||
123 | reply? "reply":"orig", ct); | ||
124 | return -EEXIST; | ||
125 | } | ||
126 | |||
127 | km = kmalloc(sizeof(*km), GFP_ATOMIC); | ||
128 | if (!km) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | memcpy(&km->tuple, t, sizeof(*t)); | ||
132 | *exist_km = km; | ||
133 | |||
134 | DEBUGP("adding new entry %p: ", km); | ||
135 | DUMP_TUPLE_GRE(&km->tuple); | ||
136 | |||
137 | write_lock_bh(&ip_ct_gre_lock); | ||
138 | list_append(&gre_keymap_list, km); | ||
139 | write_unlock_bh(&ip_ct_gre_lock); | ||
140 | |||
141 | return 0; | ||
142 | } | ||
143 | |||
144 | /* destroy the keymap entries associated with specified master ct */ | ||
145 | void ip_ct_gre_keymap_destroy(struct ip_conntrack *ct) | ||
146 | { | ||
147 | DEBUGP("entering for ct %p\n", ct); | ||
148 | |||
149 | if (!ct->helper || strcmp(ct->helper->name, "pptp")) { | ||
150 | DEBUGP("refusing to destroy GRE keymap to non-pptp session\n"); | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | write_lock_bh(&ip_ct_gre_lock); | ||
155 | if (ct->help.ct_pptp_info.keymap_orig) { | ||
156 | DEBUGP("removing %p from list\n", | ||
157 | ct->help.ct_pptp_info.keymap_orig); | ||
158 | list_del(&ct->help.ct_pptp_info.keymap_orig->list); | ||
159 | kfree(ct->help.ct_pptp_info.keymap_orig); | ||
160 | ct->help.ct_pptp_info.keymap_orig = NULL; | ||
161 | } | ||
162 | if (ct->help.ct_pptp_info.keymap_reply) { | ||
163 | DEBUGP("removing %p from list\n", | ||
164 | ct->help.ct_pptp_info.keymap_reply); | ||
165 | list_del(&ct->help.ct_pptp_info.keymap_reply->list); | ||
166 | kfree(ct->help.ct_pptp_info.keymap_reply); | ||
167 | ct->help.ct_pptp_info.keymap_reply = NULL; | ||
168 | } | ||
169 | write_unlock_bh(&ip_ct_gre_lock); | ||
170 | } | ||
171 | |||
172 | |||
173 | /* PUBLIC CONNTRACK PROTO HELPER FUNCTIONS */ | ||
174 | |||
175 | /* invert gre part of tuple */ | ||
176 | static int gre_invert_tuple(struct ip_conntrack_tuple *tuple, | ||
177 | const struct ip_conntrack_tuple *orig) | ||
178 | { | ||
179 | tuple->dst.u.gre.key = orig->src.u.gre.key; | ||
180 | tuple->src.u.gre.key = orig->dst.u.gre.key; | ||
181 | |||
182 | return 1; | ||
183 | } | ||
184 | |||
185 | /* gre hdr info to tuple */ | ||
186 | static int gre_pkt_to_tuple(const struct sk_buff *skb, | ||
187 | unsigned int dataoff, | ||
188 | struct ip_conntrack_tuple *tuple) | ||
189 | { | ||
190 | struct gre_hdr_pptp _pgrehdr, *pgrehdr; | ||
191 | u_int32_t srckey; | ||
192 | struct gre_hdr _grehdr, *grehdr; | ||
193 | |||
194 | /* first only delinearize old RFC1701 GRE header */ | ||
195 | grehdr = skb_header_pointer(skb, dataoff, sizeof(_grehdr), &_grehdr); | ||
196 | if (!grehdr || grehdr->version != GRE_VERSION_PPTP) { | ||
197 | /* try to behave like "ip_conntrack_proto_generic" */ | ||
198 | tuple->src.u.all = 0; | ||
199 | tuple->dst.u.all = 0; | ||
200 | return 1; | ||
201 | } | ||
202 | |||
203 | /* PPTP header is variable length, only need up to the call_id field */ | ||
204 | pgrehdr = skb_header_pointer(skb, dataoff, 8, &_pgrehdr); | ||
205 | if (!pgrehdr) | ||
206 | return 1; | ||
207 | |||
208 | if (ntohs(grehdr->protocol) != GRE_PROTOCOL_PPTP) { | ||
209 | DEBUGP("GRE_VERSION_PPTP but unknown proto\n"); | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | tuple->dst.u.gre.key = pgrehdr->call_id; | ||
214 | srckey = gre_keymap_lookup(tuple); | ||
215 | tuple->src.u.gre.key = srckey; | ||
216 | |||
217 | return 1; | ||
218 | } | ||
219 | |||
220 | /* print gre part of tuple */ | ||
221 | static int gre_print_tuple(struct seq_file *s, | ||
222 | const struct ip_conntrack_tuple *tuple) | ||
223 | { | ||
224 | return seq_printf(s, "srckey=0x%x dstkey=0x%x ", | ||
225 | ntohs(tuple->src.u.gre.key), | ||
226 | ntohs(tuple->dst.u.gre.key)); | ||
227 | } | ||
228 | |||
229 | /* print private data for conntrack */ | ||
230 | static int gre_print_conntrack(struct seq_file *s, | ||
231 | const struct ip_conntrack *ct) | ||
232 | { | ||
233 | return seq_printf(s, "timeout=%u, stream_timeout=%u ", | ||
234 | (ct->proto.gre.timeout / HZ), | ||
235 | (ct->proto.gre.stream_timeout / HZ)); | ||
236 | } | ||
237 | |||
238 | /* Returns verdict for packet, and may modify conntrack */ | ||
239 | static int gre_packet(struct ip_conntrack *ct, | ||
240 | const struct sk_buff *skb, | ||
241 | enum ip_conntrack_info conntrackinfo) | ||
242 | { | ||
243 | /* If we've seen traffic both ways, this is a GRE connection. | ||
244 | * Extend timeout. */ | ||
245 | if (ct->status & IPS_SEEN_REPLY) { | ||
246 | ip_ct_refresh_acct(ct, conntrackinfo, skb, | ||
247 | ct->proto.gre.stream_timeout); | ||
248 | /* Also, more likely to be important, and not a probe. */ | ||
249 | set_bit(IPS_ASSURED_BIT, &ct->status); | ||
250 | ip_conntrack_event_cache(IPCT_STATUS, skb); | ||
251 | } else | ||
252 | ip_ct_refresh_acct(ct, conntrackinfo, skb, | ||
253 | ct->proto.gre.timeout); | ||
254 | |||
255 | return NF_ACCEPT; | ||
256 | } | ||
257 | |||
258 | /* Called when a new connection for this protocol found. */ | ||
259 | static int gre_new(struct ip_conntrack *ct, | ||
260 | const struct sk_buff *skb) | ||
261 | { | ||
262 | DEBUGP(": "); | ||
263 | DUMP_TUPLE_GRE(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple); | ||
264 | |||
265 | /* initialize to sane value. Ideally a conntrack helper | ||
266 | * (e.g. in case of pptp) is increasing them */ | ||
267 | ct->proto.gre.stream_timeout = GRE_STREAM_TIMEOUT; | ||
268 | ct->proto.gre.timeout = GRE_TIMEOUT; | ||
269 | |||
270 | return 1; | ||
271 | } | ||
272 | |||
273 | /* Called when a conntrack entry has already been removed from the hashes | ||
274 | * and is about to be deleted from memory */ | ||
275 | static void gre_destroy(struct ip_conntrack *ct) | ||
276 | { | ||
277 | struct ip_conntrack *master = ct->master; | ||
278 | DEBUGP(" entering\n"); | ||
279 | |||
280 | if (!master) | ||
281 | DEBUGP("no master !?!\n"); | ||
282 | else | ||
283 | ip_ct_gre_keymap_destroy(master); | ||
284 | } | ||
285 | |||
286 | /* protocol helper struct */ | ||
287 | static struct ip_conntrack_protocol gre = { | ||
288 | .proto = IPPROTO_GRE, | ||
289 | .name = "gre", | ||
290 | .pkt_to_tuple = gre_pkt_to_tuple, | ||
291 | .invert_tuple = gre_invert_tuple, | ||
292 | .print_tuple = gre_print_tuple, | ||
293 | .print_conntrack = gre_print_conntrack, | ||
294 | .packet = gre_packet, | ||
295 | .new = gre_new, | ||
296 | .destroy = gre_destroy, | ||
297 | .me = THIS_MODULE, | ||
298 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ | ||
299 | defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) | ||
300 | .tuple_to_nfattr = ip_ct_port_tuple_to_nfattr, | ||
301 | .nfattr_to_tuple = ip_ct_port_nfattr_to_tuple, | ||
302 | #endif | ||
303 | }; | ||
304 | |||
305 | /* ip_conntrack_proto_gre initialization */ | ||
306 | int __init ip_ct_proto_gre_init(void) | ||
307 | { | ||
308 | return ip_conntrack_protocol_register(&gre); | ||
309 | } | ||
310 | |||
311 | void __exit ip_ct_proto_gre_fini(void) | ||
312 | { | ||
313 | struct list_head *pos, *n; | ||
314 | |||
315 | /* delete all keymap entries */ | ||
316 | write_lock_bh(&ip_ct_gre_lock); | ||
317 | list_for_each_safe(pos, n, &gre_keymap_list) { | ||
318 | DEBUGP("deleting keymap %p at module unload time\n", pos); | ||
319 | list_del(pos); | ||
320 | kfree(pos); | ||
321 | } | ||
322 | write_unlock_bh(&ip_ct_gre_lock); | ||
323 | |||
324 | ip_conntrack_protocol_unregister(&gre); | ||
325 | } | ||
326 | |||
327 | EXPORT_SYMBOL(ip_ct_gre_keymap_add); | ||
328 | EXPORT_SYMBOL(ip_ct_gre_keymap_destroy); | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c index a875f35e576d..59a4a0111dd3 100644 --- a/net/ipv4/netfilter/ip_conntrack_proto_sctp.c +++ b/net/ipv4/netfilter/ip_conntrack_proto_sctp.c | |||
@@ -416,6 +416,7 @@ static int sctp_packet(struct ip_conntrack *conntrack, | |||
416 | && newconntrack == SCTP_CONNTRACK_ESTABLISHED) { | 416 | && newconntrack == SCTP_CONNTRACK_ESTABLISHED) { |
417 | DEBUGP("Setting assured bit\n"); | 417 | DEBUGP("Setting assured bit\n"); |
418 | set_bit(IPS_ASSURED_BIT, &conntrack->status); | 418 | set_bit(IPS_ASSURED_BIT, &conntrack->status); |
419 | ip_conntrack_event_cache(IPCT_STATUS, skb); | ||
419 | } | 420 | } |
420 | 421 | ||
421 | return NF_ACCEPT; | 422 | return NF_ACCEPT; |
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c index 1985abc59d24..121760d6cc50 100644 --- a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c +++ b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c | |||
@@ -1014,7 +1014,8 @@ static int tcp_packet(struct ip_conntrack *conntrack, | |||
1014 | /* Set ASSURED if we see see valid ack in ESTABLISHED | 1014 | /* Set ASSURED if we see see valid ack in ESTABLISHED |
1015 | after SYN_RECV or a valid answer for a picked up | 1015 | after SYN_RECV or a valid answer for a picked up |
1016 | connection. */ | 1016 | connection. */ |
1017 | set_bit(IPS_ASSURED_BIT, &conntrack->status); | 1017 | set_bit(IPS_ASSURED_BIT, &conntrack->status); |
1018 | ip_conntrack_event_cache(IPCT_STATUS, skb); | ||
1018 | } | 1019 | } |
1019 | ip_ct_refresh_acct(conntrack, ctinfo, skb, timeout); | 1020 | ip_ct_refresh_acct(conntrack, ctinfo, skb, timeout); |
1020 | 1021 | ||
diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c index ae3e3e655db5..dd476b191f4b 100644 --- a/net/ipv4/netfilter/ip_conntrack_standalone.c +++ b/net/ipv4/netfilter/ip_conntrack_standalone.c | |||
@@ -989,15 +989,15 @@ EXPORT_SYMBOL(need_ip_conntrack); | |||
989 | EXPORT_SYMBOL(ip_conntrack_helper_register); | 989 | EXPORT_SYMBOL(ip_conntrack_helper_register); |
990 | EXPORT_SYMBOL(ip_conntrack_helper_unregister); | 990 | EXPORT_SYMBOL(ip_conntrack_helper_unregister); |
991 | EXPORT_SYMBOL(ip_ct_iterate_cleanup); | 991 | EXPORT_SYMBOL(ip_ct_iterate_cleanup); |
992 | EXPORT_SYMBOL(ip_ct_refresh_acct); | 992 | EXPORT_SYMBOL(__ip_ct_refresh_acct); |
993 | 993 | ||
994 | EXPORT_SYMBOL(ip_conntrack_expect_alloc); | 994 | EXPORT_SYMBOL(ip_conntrack_expect_alloc); |
995 | EXPORT_SYMBOL(ip_conntrack_expect_put); | 995 | EXPORT_SYMBOL(ip_conntrack_expect_put); |
996 | EXPORT_SYMBOL_GPL(ip_conntrack_expect_find_get); | 996 | EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find); |
997 | EXPORT_SYMBOL_GPL(ip_conntrack_expect_find); | ||
997 | EXPORT_SYMBOL(ip_conntrack_expect_related); | 998 | EXPORT_SYMBOL(ip_conntrack_expect_related); |
998 | EXPORT_SYMBOL(ip_conntrack_unexpect_related); | 999 | EXPORT_SYMBOL(ip_conntrack_unexpect_related); |
999 | EXPORT_SYMBOL_GPL(ip_conntrack_expect_list); | 1000 | EXPORT_SYMBOL_GPL(ip_conntrack_expect_list); |
1000 | EXPORT_SYMBOL_GPL(__ip_conntrack_expect_find); | ||
1001 | EXPORT_SYMBOL_GPL(ip_ct_unlink_expect); | 1001 | EXPORT_SYMBOL_GPL(ip_ct_unlink_expect); |
1002 | 1002 | ||
1003 | EXPORT_SYMBOL(ip_conntrack_tuple_taken); | 1003 | EXPORT_SYMBOL(ip_conntrack_tuple_taken); |
diff --git a/net/ipv4/netfilter/ip_conntrack_tftp.c b/net/ipv4/netfilter/ip_conntrack_tftp.c index d2b590533452..a78736b8525d 100644 --- a/net/ipv4/netfilter/ip_conntrack_tftp.c +++ b/net/ipv4/netfilter/ip_conntrack_tftp.c | |||
@@ -26,9 +26,9 @@ MODULE_DESCRIPTION("tftp connection tracking helper"); | |||
26 | MODULE_LICENSE("GPL"); | 26 | MODULE_LICENSE("GPL"); |
27 | 27 | ||
28 | #define MAX_PORTS 8 | 28 | #define MAX_PORTS 8 |
29 | static int ports[MAX_PORTS]; | 29 | static short ports[MAX_PORTS]; |
30 | static int ports_c; | 30 | static int ports_c; |
31 | module_param_array(ports, int, &ports_c, 0400); | 31 | module_param_array(ports, short, &ports_c, 0400); |
32 | MODULE_PARM_DESC(ports, "port numbers of tftp servers"); | 32 | MODULE_PARM_DESC(ports, "port numbers of tftp servers"); |
33 | 33 | ||
34 | #if 0 | 34 | #if 0 |
@@ -100,7 +100,7 @@ static int tftp_help(struct sk_buff **pskb, | |||
100 | } | 100 | } |
101 | 101 | ||
102 | static struct ip_conntrack_helper tftp[MAX_PORTS]; | 102 | static struct ip_conntrack_helper tftp[MAX_PORTS]; |
103 | static char tftp_names[MAX_PORTS][10]; | 103 | static char tftp_names[MAX_PORTS][sizeof("tftp-65535")]; |
104 | 104 | ||
105 | static void fini(void) | 105 | static void fini(void) |
106 | { | 106 | { |
diff --git a/net/ipv4/netfilter/ip_nat_core.c b/net/ipv4/netfilter/ip_nat_core.c index 1adedb743f60..c5e3abd24672 100644 --- a/net/ipv4/netfilter/ip_nat_core.c +++ b/net/ipv4/netfilter/ip_nat_core.c | |||
@@ -74,12 +74,14 @@ ip_nat_proto_find_get(u_int8_t protonum) | |||
74 | 74 | ||
75 | return p; | 75 | return p; |
76 | } | 76 | } |
77 | EXPORT_SYMBOL_GPL(ip_nat_proto_find_get); | ||
77 | 78 | ||
78 | void | 79 | void |
79 | ip_nat_proto_put(struct ip_nat_protocol *p) | 80 | ip_nat_proto_put(struct ip_nat_protocol *p) |
80 | { | 81 | { |
81 | module_put(p->me); | 82 | module_put(p->me); |
82 | } | 83 | } |
84 | EXPORT_SYMBOL_GPL(ip_nat_proto_put); | ||
83 | 85 | ||
84 | /* We keep an extra hash for each conntrack, for fast searching. */ | 86 | /* We keep an extra hash for each conntrack, for fast searching. */ |
85 | static inline unsigned int | 87 | static inline unsigned int |
@@ -111,6 +113,7 @@ ip_nat_cheat_check(u_int32_t oldvalinv, u_int32_t newval, u_int16_t oldcheck) | |||
111 | return csum_fold(csum_partial((char *)diffs, sizeof(diffs), | 113 | return csum_fold(csum_partial((char *)diffs, sizeof(diffs), |
112 | oldcheck^0xFFFF)); | 114 | oldcheck^0xFFFF)); |
113 | } | 115 | } |
116 | EXPORT_SYMBOL(ip_nat_cheat_check); | ||
114 | 117 | ||
115 | /* Is this tuple already taken? (not by us) */ | 118 | /* Is this tuple already taken? (not by us) */ |
116 | int | 119 | int |
@@ -127,6 +130,7 @@ ip_nat_used_tuple(const struct ip_conntrack_tuple *tuple, | |||
127 | invert_tuplepr(&reply, tuple); | 130 | invert_tuplepr(&reply, tuple); |
128 | return ip_conntrack_tuple_taken(&reply, ignored_conntrack); | 131 | return ip_conntrack_tuple_taken(&reply, ignored_conntrack); |
129 | } | 132 | } |
133 | EXPORT_SYMBOL(ip_nat_used_tuple); | ||
130 | 134 | ||
131 | /* If we source map this tuple so reply looks like reply_tuple, will | 135 | /* If we source map this tuple so reply looks like reply_tuple, will |
132 | * that meet the constraints of range. */ | 136 | * that meet the constraints of range. */ |
@@ -347,6 +351,7 @@ ip_nat_setup_info(struct ip_conntrack *conntrack, | |||
347 | 351 | ||
348 | return NF_ACCEPT; | 352 | return NF_ACCEPT; |
349 | } | 353 | } |
354 | EXPORT_SYMBOL(ip_nat_setup_info); | ||
350 | 355 | ||
351 | /* Returns true if succeeded. */ | 356 | /* Returns true if succeeded. */ |
352 | static int | 357 | static int |
@@ -387,10 +392,10 @@ manip_pkt(u_int16_t proto, | |||
387 | } | 392 | } |
388 | 393 | ||
389 | /* Do packet manipulations according to ip_nat_setup_info. */ | 394 | /* Do packet manipulations according to ip_nat_setup_info. */ |
390 | unsigned int nat_packet(struct ip_conntrack *ct, | 395 | unsigned int ip_nat_packet(struct ip_conntrack *ct, |
391 | enum ip_conntrack_info ctinfo, | 396 | enum ip_conntrack_info ctinfo, |
392 | unsigned int hooknum, | 397 | unsigned int hooknum, |
393 | struct sk_buff **pskb) | 398 | struct sk_buff **pskb) |
394 | { | 399 | { |
395 | enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); | 400 | enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); |
396 | unsigned long statusbit; | 401 | unsigned long statusbit; |
@@ -417,12 +422,13 @@ unsigned int nat_packet(struct ip_conntrack *ct, | |||
417 | } | 422 | } |
418 | return NF_ACCEPT; | 423 | return NF_ACCEPT; |
419 | } | 424 | } |
425 | EXPORT_SYMBOL_GPL(ip_nat_packet); | ||
420 | 426 | ||
421 | /* Dir is direction ICMP is coming from (opposite to packet it contains) */ | 427 | /* Dir is direction ICMP is coming from (opposite to packet it contains) */ |
422 | int icmp_reply_translation(struct sk_buff **pskb, | 428 | int ip_nat_icmp_reply_translation(struct sk_buff **pskb, |
423 | struct ip_conntrack *ct, | 429 | struct ip_conntrack *ct, |
424 | enum ip_nat_manip_type manip, | 430 | enum ip_nat_manip_type manip, |
425 | enum ip_conntrack_dir dir) | 431 | enum ip_conntrack_dir dir) |
426 | { | 432 | { |
427 | struct { | 433 | struct { |
428 | struct icmphdr icmp; | 434 | struct icmphdr icmp; |
@@ -509,6 +515,7 @@ int icmp_reply_translation(struct sk_buff **pskb, | |||
509 | 515 | ||
510 | return 1; | 516 | return 1; |
511 | } | 517 | } |
518 | EXPORT_SYMBOL_GPL(ip_nat_icmp_reply_translation); | ||
512 | 519 | ||
513 | /* Protocol registration. */ | 520 | /* Protocol registration. */ |
514 | int ip_nat_protocol_register(struct ip_nat_protocol *proto) | 521 | int ip_nat_protocol_register(struct ip_nat_protocol *proto) |
@@ -525,6 +532,7 @@ int ip_nat_protocol_register(struct ip_nat_protocol *proto) | |||
525 | write_unlock_bh(&ip_nat_lock); | 532 | write_unlock_bh(&ip_nat_lock); |
526 | return ret; | 533 | return ret; |
527 | } | 534 | } |
535 | EXPORT_SYMBOL(ip_nat_protocol_register); | ||
528 | 536 | ||
529 | /* Noone stores the protocol anywhere; simply delete it. */ | 537 | /* Noone stores the protocol anywhere; simply delete it. */ |
530 | void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) | 538 | void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) |
@@ -536,6 +544,7 @@ void ip_nat_protocol_unregister(struct ip_nat_protocol *proto) | |||
536 | /* Someone could be still looking at the proto in a bh. */ | 544 | /* Someone could be still looking at the proto in a bh. */ |
537 | synchronize_net(); | 545 | synchronize_net(); |
538 | } | 546 | } |
547 | EXPORT_SYMBOL(ip_nat_protocol_unregister); | ||
539 | 548 | ||
540 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ | 549 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ |
541 | defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) | 550 | defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) |
@@ -578,9 +587,11 @@ ip_nat_port_nfattr_to_range(struct nfattr *tb[], struct ip_nat_range *range) | |||
578 | 587 | ||
579 | return ret; | 588 | return ret; |
580 | } | 589 | } |
590 | EXPORT_SYMBOL_GPL(ip_nat_port_nfattr_to_range); | ||
591 | EXPORT_SYMBOL_GPL(ip_nat_port_range_to_nfattr); | ||
581 | #endif | 592 | #endif |
582 | 593 | ||
583 | int __init ip_nat_init(void) | 594 | static int __init ip_nat_init(void) |
584 | { | 595 | { |
585 | size_t i; | 596 | size_t i; |
586 | 597 | ||
@@ -622,10 +633,14 @@ static int clean_nat(struct ip_conntrack *i, void *data) | |||
622 | return 0; | 633 | return 0; |
623 | } | 634 | } |
624 | 635 | ||
625 | /* Not __exit: called from ip_nat_standalone.c:init_or_cleanup() --RR */ | 636 | static void __exit ip_nat_cleanup(void) |
626 | void ip_nat_cleanup(void) | ||
627 | { | 637 | { |
628 | ip_ct_iterate_cleanup(&clean_nat, NULL); | 638 | ip_ct_iterate_cleanup(&clean_nat, NULL); |
629 | ip_conntrack_destroyed = NULL; | 639 | ip_conntrack_destroyed = NULL; |
630 | vfree(bysource); | 640 | vfree(bysource); |
631 | } | 641 | } |
642 | |||
643 | MODULE_LICENSE("GPL"); | ||
644 | |||
645 | module_init(ip_nat_init); | ||
646 | module_exit(ip_nat_cleanup); | ||
diff --git a/net/ipv4/netfilter/ip_nat_helper.c b/net/ipv4/netfilter/ip_nat_helper.c index d2dd5d313556..5d506e0564d5 100644 --- a/net/ipv4/netfilter/ip_nat_helper.c +++ b/net/ipv4/netfilter/ip_nat_helper.c | |||
@@ -199,6 +199,7 @@ ip_nat_mangle_tcp_packet(struct sk_buff **pskb, | |||
199 | } | 199 | } |
200 | return 1; | 200 | return 1; |
201 | } | 201 | } |
202 | EXPORT_SYMBOL(ip_nat_mangle_tcp_packet); | ||
202 | 203 | ||
203 | /* Generic function for mangling variable-length address changes inside | 204 | /* Generic function for mangling variable-length address changes inside |
204 | * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX | 205 | * NATed UDP connections (like the CONNECT DATA XXXXX MESG XXXXX INDEX XXXXX |
@@ -256,6 +257,7 @@ ip_nat_mangle_udp_packet(struct sk_buff **pskb, | |||
256 | 257 | ||
257 | return 1; | 258 | return 1; |
258 | } | 259 | } |
260 | EXPORT_SYMBOL(ip_nat_mangle_udp_packet); | ||
259 | 261 | ||
260 | /* Adjust one found SACK option including checksum correction */ | 262 | /* Adjust one found SACK option including checksum correction */ |
261 | static void | 263 | static void |
@@ -399,6 +401,7 @@ ip_nat_seq_adjust(struct sk_buff **pskb, | |||
399 | 401 | ||
400 | return 1; | 402 | return 1; |
401 | } | 403 | } |
404 | EXPORT_SYMBOL(ip_nat_seq_adjust); | ||
402 | 405 | ||
403 | /* Setup NAT on this expected conntrack so it follows master. */ | 406 | /* Setup NAT on this expected conntrack so it follows master. */ |
404 | /* If we fail to get a free NAT slot, we'll get dropped on confirm */ | 407 | /* If we fail to get a free NAT slot, we'll get dropped on confirm */ |
@@ -425,3 +428,4 @@ void ip_nat_follow_master(struct ip_conntrack *ct, | |||
425 | /* hook doesn't matter, but it has to do destination manip */ | 428 | /* hook doesn't matter, but it has to do destination manip */ |
426 | ip_nat_setup_info(ct, &range, NF_IP_PRE_ROUTING); | 429 | ip_nat_setup_info(ct, &range, NF_IP_PRE_ROUTING); |
427 | } | 430 | } |
431 | EXPORT_SYMBOL(ip_nat_follow_master); | ||
diff --git a/net/ipv4/netfilter/ip_nat_helper_pptp.c b/net/ipv4/netfilter/ip_nat_helper_pptp.c new file mode 100644 index 000000000000..3cdd0684d30d --- /dev/null +++ b/net/ipv4/netfilter/ip_nat_helper_pptp.c | |||
@@ -0,0 +1,401 @@ | |||
1 | /* | ||
2 | * ip_nat_pptp.c - Version 3.0 | ||
3 | * | ||
4 | * NAT support for PPTP (Point to Point Tunneling Protocol). | ||
5 | * PPTP is a a protocol for creating virtual private networks. | ||
6 | * It is a specification defined by Microsoft and some vendors | ||
7 | * working with Microsoft. PPTP is built on top of a modified | ||
8 | * version of the Internet Generic Routing Encapsulation Protocol. | ||
9 | * GRE is defined in RFC 1701 and RFC 1702. Documentation of | ||
10 | * PPTP can be found in RFC 2637 | ||
11 | * | ||
12 | * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org> | ||
13 | * | ||
14 | * Development of this code funded by Astaro AG (http://www.astaro.com/) | ||
15 | * | ||
16 | * TODO: - NAT to a unique tuple, not to TCP source port | ||
17 | * (needs netfilter tuple reservation) | ||
18 | * | ||
19 | * Changes: | ||
20 | * 2002-02-10 - Version 1.3 | ||
21 | * - Use ip_nat_mangle_tcp_packet() because of cloned skb's | ||
22 | * in local connections (Philip Craig <philipc@snapgear.com>) | ||
23 | * - add checks for magicCookie and pptp version | ||
24 | * - make argument list of pptp_{out,in}bound_packet() shorter | ||
25 | * - move to C99 style initializers | ||
26 | * - print version number at module loadtime | ||
27 | * 2003-09-22 - Version 1.5 | ||
28 | * - use SNATed tcp sourceport as callid, since we get called before | ||
29 | * TCP header is mangled (Philip Craig <philipc@snapgear.com>) | ||
30 | * 2004-10-22 - Version 2.0 | ||
31 | * - kernel 2.6.x version | ||
32 | * 2005-06-10 - Version 3.0 | ||
33 | * - kernel >= 2.6.11 version, | ||
34 | * funded by Oxcoda NetBox Blue (http://www.netboxblue.com/) | ||
35 | * | ||
36 | */ | ||
37 | |||
38 | #include <linux/config.h> | ||
39 | #include <linux/module.h> | ||
40 | #include <linux/ip.h> | ||
41 | #include <linux/tcp.h> | ||
42 | #include <net/tcp.h> | ||
43 | |||
44 | #include <linux/netfilter_ipv4/ip_nat.h> | ||
45 | #include <linux/netfilter_ipv4/ip_nat_rule.h> | ||
46 | #include <linux/netfilter_ipv4/ip_nat_helper.h> | ||
47 | #include <linux/netfilter_ipv4/ip_nat_pptp.h> | ||
48 | #include <linux/netfilter_ipv4/ip_conntrack_core.h> | ||
49 | #include <linux/netfilter_ipv4/ip_conntrack_helper.h> | ||
50 | #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h> | ||
51 | #include <linux/netfilter_ipv4/ip_conntrack_pptp.h> | ||
52 | |||
53 | #define IP_NAT_PPTP_VERSION "3.0" | ||
54 | |||
55 | MODULE_LICENSE("GPL"); | ||
56 | MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); | ||
57 | MODULE_DESCRIPTION("Netfilter NAT helper module for PPTP"); | ||
58 | |||
59 | |||
60 | #if 0 | ||
61 | extern const char *pptp_msg_name[]; | ||
62 | #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, \ | ||
63 | __FUNCTION__, ## args) | ||
64 | #else | ||
65 | #define DEBUGP(format, args...) | ||
66 | #endif | ||
67 | |||
68 | static void pptp_nat_expected(struct ip_conntrack *ct, | ||
69 | struct ip_conntrack_expect *exp) | ||
70 | { | ||
71 | struct ip_conntrack *master = ct->master; | ||
72 | struct ip_conntrack_expect *other_exp; | ||
73 | struct ip_conntrack_tuple t; | ||
74 | struct ip_ct_pptp_master *ct_pptp_info; | ||
75 | struct ip_nat_pptp *nat_pptp_info; | ||
76 | |||
77 | ct_pptp_info = &master->help.ct_pptp_info; | ||
78 | nat_pptp_info = &master->nat.help.nat_pptp_info; | ||
79 | |||
80 | /* And here goes the grand finale of corrosion... */ | ||
81 | |||
82 | if (exp->dir == IP_CT_DIR_ORIGINAL) { | ||
83 | DEBUGP("we are PNS->PAC\n"); | ||
84 | /* therefore, build tuple for PAC->PNS */ | ||
85 | t.src.ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.src.ip; | ||
86 | t.src.u.gre.key = htons(master->help.ct_pptp_info.pac_call_id); | ||
87 | t.dst.ip = master->tuplehash[IP_CT_DIR_REPLY].tuple.dst.ip; | ||
88 | t.dst.u.gre.key = htons(master->help.ct_pptp_info.pns_call_id); | ||
89 | t.dst.protonum = IPPROTO_GRE; | ||
90 | } else { | ||
91 | DEBUGP("we are PAC->PNS\n"); | ||
92 | /* build tuple for PNS->PAC */ | ||
93 | t.src.ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip; | ||
94 | t.src.u.gre.key = | ||
95 | htons(master->nat.help.nat_pptp_info.pns_call_id); | ||
96 | t.dst.ip = master->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.ip; | ||
97 | t.dst.u.gre.key = | ||
98 | htons(master->nat.help.nat_pptp_info.pac_call_id); | ||
99 | t.dst.protonum = IPPROTO_GRE; | ||
100 | } | ||
101 | |||
102 | DEBUGP("trying to unexpect other dir: "); | ||
103 | DUMP_TUPLE(&t); | ||
104 | other_exp = ip_conntrack_expect_find(&t); | ||
105 | if (other_exp) { | ||
106 | ip_conntrack_unexpect_related(other_exp); | ||
107 | ip_conntrack_expect_put(other_exp); | ||
108 | DEBUGP("success\n"); | ||
109 | } else { | ||
110 | DEBUGP("not found!\n"); | ||
111 | } | ||
112 | |||
113 | ip_nat_follow_master(ct, exp); | ||
114 | } | ||
115 | |||
116 | /* outbound packets == from PNS to PAC */ | ||
117 | static int | ||
118 | pptp_outbound_pkt(struct sk_buff **pskb, | ||
119 | struct ip_conntrack *ct, | ||
120 | enum ip_conntrack_info ctinfo, | ||
121 | struct PptpControlHeader *ctlh, | ||
122 | union pptp_ctrl_union *pptpReq) | ||
123 | |||
124 | { | ||
125 | struct ip_ct_pptp_master *ct_pptp_info = &ct->help.ct_pptp_info; | ||
126 | struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info; | ||
127 | |||
128 | u_int16_t msg, *cid = NULL, new_callid; | ||
129 | |||
130 | new_callid = htons(ct_pptp_info->pns_call_id); | ||
131 | |||
132 | switch (msg = ntohs(ctlh->messageType)) { | ||
133 | case PPTP_OUT_CALL_REQUEST: | ||
134 | cid = &pptpReq->ocreq.callID; | ||
135 | /* FIXME: ideally we would want to reserve a call ID | ||
136 | * here. current netfilter NAT core is not able to do | ||
137 | * this :( For now we use TCP source port. This breaks | ||
138 | * multiple calls within one control session */ | ||
139 | |||
140 | /* save original call ID in nat_info */ | ||
141 | nat_pptp_info->pns_call_id = ct_pptp_info->pns_call_id; | ||
142 | |||
143 | /* don't use tcph->source since we are at a DSTmanip | ||
144 | * hook (e.g. PREROUTING) and pkt is not mangled yet */ | ||
145 | new_callid = ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u.tcp.port; | ||
146 | |||
147 | /* save new call ID in ct info */ | ||
148 | ct_pptp_info->pns_call_id = ntohs(new_callid); | ||
149 | break; | ||
150 | case PPTP_IN_CALL_REPLY: | ||
151 | cid = &pptpReq->icreq.callID; | ||
152 | break; | ||
153 | case PPTP_CALL_CLEAR_REQUEST: | ||
154 | cid = &pptpReq->clrreq.callID; | ||
155 | break; | ||
156 | default: | ||
157 | DEBUGP("unknown outbound packet 0x%04x:%s\n", msg, | ||
158 | (msg <= PPTP_MSG_MAX)? | ||
159 | pptp_msg_name[msg]:pptp_msg_name[0]); | ||
160 | /* fall through */ | ||
161 | |||
162 | case PPTP_SET_LINK_INFO: | ||
163 | /* only need to NAT in case PAC is behind NAT box */ | ||
164 | case PPTP_START_SESSION_REQUEST: | ||
165 | case PPTP_START_SESSION_REPLY: | ||
166 | case PPTP_STOP_SESSION_REQUEST: | ||
167 | case PPTP_STOP_SESSION_REPLY: | ||
168 | case PPTP_ECHO_REQUEST: | ||
169 | case PPTP_ECHO_REPLY: | ||
170 | /* no need to alter packet */ | ||
171 | return NF_ACCEPT; | ||
172 | } | ||
173 | |||
174 | /* only OUT_CALL_REQUEST, IN_CALL_REPLY, CALL_CLEAR_REQUEST pass | ||
175 | * down to here */ | ||
176 | |||
177 | IP_NF_ASSERT(cid); | ||
178 | |||
179 | DEBUGP("altering call id from 0x%04x to 0x%04x\n", | ||
180 | ntohs(*cid), ntohs(new_callid)); | ||
181 | |||
182 | /* mangle packet */ | ||
183 | if (ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, | ||
184 | (void *)cid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)), | ||
185 | sizeof(new_callid), | ||
186 | (char *)&new_callid, | ||
187 | sizeof(new_callid)) == 0) | ||
188 | return NF_DROP; | ||
189 | |||
190 | return NF_ACCEPT; | ||
191 | } | ||
192 | |||
193 | static int | ||
194 | pptp_exp_gre(struct ip_conntrack_expect *expect_orig, | ||
195 | struct ip_conntrack_expect *expect_reply) | ||
196 | { | ||
197 | struct ip_ct_pptp_master *ct_pptp_info = | ||
198 | &expect_orig->master->help.ct_pptp_info; | ||
199 | struct ip_nat_pptp *nat_pptp_info = | ||
200 | &expect_orig->master->nat.help.nat_pptp_info; | ||
201 | |||
202 | struct ip_conntrack *ct = expect_orig->master; | ||
203 | |||
204 | struct ip_conntrack_tuple inv_t; | ||
205 | struct ip_conntrack_tuple *orig_t, *reply_t; | ||
206 | |||
207 | /* save original PAC call ID in nat_info */ | ||
208 | nat_pptp_info->pac_call_id = ct_pptp_info->pac_call_id; | ||
209 | |||
210 | /* alter expectation */ | ||
211 | orig_t = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; | ||
212 | reply_t = &ct->tuplehash[IP_CT_DIR_REPLY].tuple; | ||
213 | |||
214 | /* alter expectation for PNS->PAC direction */ | ||
215 | invert_tuplepr(&inv_t, &expect_orig->tuple); | ||
216 | expect_orig->saved_proto.gre.key = htons(nat_pptp_info->pac_call_id); | ||
217 | expect_orig->tuple.src.u.gre.key = htons(nat_pptp_info->pns_call_id); | ||
218 | expect_orig->tuple.dst.u.gre.key = htons(ct_pptp_info->pac_call_id); | ||
219 | inv_t.src.ip = reply_t->src.ip; | ||
220 | inv_t.dst.ip = reply_t->dst.ip; | ||
221 | inv_t.src.u.gre.key = htons(nat_pptp_info->pac_call_id); | ||
222 | inv_t.dst.u.gre.key = htons(ct_pptp_info->pns_call_id); | ||
223 | |||
224 | if (!ip_conntrack_expect_related(expect_orig)) { | ||
225 | DEBUGP("successfully registered expect\n"); | ||
226 | } else { | ||
227 | DEBUGP("can't expect_related(expect_orig)\n"); | ||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | /* alter expectation for PAC->PNS direction */ | ||
232 | invert_tuplepr(&inv_t, &expect_reply->tuple); | ||
233 | expect_reply->saved_proto.gre.key = htons(nat_pptp_info->pns_call_id); | ||
234 | expect_reply->tuple.src.u.gre.key = htons(nat_pptp_info->pac_call_id); | ||
235 | expect_reply->tuple.dst.u.gre.key = htons(ct_pptp_info->pns_call_id); | ||
236 | inv_t.src.ip = orig_t->src.ip; | ||
237 | inv_t.dst.ip = orig_t->dst.ip; | ||
238 | inv_t.src.u.gre.key = htons(nat_pptp_info->pns_call_id); | ||
239 | inv_t.dst.u.gre.key = htons(ct_pptp_info->pac_call_id); | ||
240 | |||
241 | if (!ip_conntrack_expect_related(expect_reply)) { | ||
242 | DEBUGP("successfully registered expect\n"); | ||
243 | } else { | ||
244 | DEBUGP("can't expect_related(expect_reply)\n"); | ||
245 | ip_conntrack_unexpect_related(expect_orig); | ||
246 | return 1; | ||
247 | } | ||
248 | |||
249 | if (ip_ct_gre_keymap_add(ct, &expect_reply->tuple, 0) < 0) { | ||
250 | DEBUGP("can't register original keymap\n"); | ||
251 | ip_conntrack_unexpect_related(expect_orig); | ||
252 | ip_conntrack_unexpect_related(expect_reply); | ||
253 | return 1; | ||
254 | } | ||
255 | |||
256 | if (ip_ct_gre_keymap_add(ct, &inv_t, 1) < 0) { | ||
257 | DEBUGP("can't register reply keymap\n"); | ||
258 | ip_conntrack_unexpect_related(expect_orig); | ||
259 | ip_conntrack_unexpect_related(expect_reply); | ||
260 | ip_ct_gre_keymap_destroy(ct); | ||
261 | return 1; | ||
262 | } | ||
263 | |||
264 | return 0; | ||
265 | } | ||
266 | |||
267 | /* inbound packets == from PAC to PNS */ | ||
268 | static int | ||
269 | pptp_inbound_pkt(struct sk_buff **pskb, | ||
270 | struct ip_conntrack *ct, | ||
271 | enum ip_conntrack_info ctinfo, | ||
272 | struct PptpControlHeader *ctlh, | ||
273 | union pptp_ctrl_union *pptpReq) | ||
274 | { | ||
275 | struct ip_nat_pptp *nat_pptp_info = &ct->nat.help.nat_pptp_info; | ||
276 | u_int16_t msg, new_cid = 0, new_pcid, *pcid = NULL, *cid = NULL; | ||
277 | |||
278 | int ret = NF_ACCEPT, rv; | ||
279 | |||
280 | new_pcid = htons(nat_pptp_info->pns_call_id); | ||
281 | |||
282 | switch (msg = ntohs(ctlh->messageType)) { | ||
283 | case PPTP_OUT_CALL_REPLY: | ||
284 | pcid = &pptpReq->ocack.peersCallID; | ||
285 | cid = &pptpReq->ocack.callID; | ||
286 | break; | ||
287 | case PPTP_IN_CALL_CONNECT: | ||
288 | pcid = &pptpReq->iccon.peersCallID; | ||
289 | break; | ||
290 | case PPTP_IN_CALL_REQUEST: | ||
291 | /* only need to nat in case PAC is behind NAT box */ | ||
292 | break; | ||
293 | case PPTP_WAN_ERROR_NOTIFY: | ||
294 | pcid = &pptpReq->wanerr.peersCallID; | ||
295 | break; | ||
296 | case PPTP_CALL_DISCONNECT_NOTIFY: | ||
297 | pcid = &pptpReq->disc.callID; | ||
298 | break; | ||
299 | case PPTP_SET_LINK_INFO: | ||
300 | pcid = &pptpReq->setlink.peersCallID; | ||
301 | break; | ||
302 | |||
303 | default: | ||
304 | DEBUGP("unknown inbound packet %s\n", (msg <= PPTP_MSG_MAX)? | ||
305 | pptp_msg_name[msg]:pptp_msg_name[0]); | ||
306 | /* fall through */ | ||
307 | |||
308 | case PPTP_START_SESSION_REQUEST: | ||
309 | case PPTP_START_SESSION_REPLY: | ||
310 | case PPTP_STOP_SESSION_REQUEST: | ||
311 | case PPTP_STOP_SESSION_REPLY: | ||
312 | case PPTP_ECHO_REQUEST: | ||
313 | case PPTP_ECHO_REPLY: | ||
314 | /* no need to alter packet */ | ||
315 | return NF_ACCEPT; | ||
316 | } | ||
317 | |||
318 | /* only OUT_CALL_REPLY, IN_CALL_CONNECT, IN_CALL_REQUEST, | ||
319 | * WAN_ERROR_NOTIFY, CALL_DISCONNECT_NOTIFY pass down here */ | ||
320 | |||
321 | /* mangle packet */ | ||
322 | IP_NF_ASSERT(pcid); | ||
323 | DEBUGP("altering peer call id from 0x%04x to 0x%04x\n", | ||
324 | ntohs(*pcid), ntohs(new_pcid)); | ||
325 | |||
326 | rv = ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, | ||
327 | (void *)pcid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)), | ||
328 | sizeof(new_pcid), (char *)&new_pcid, | ||
329 | sizeof(new_pcid)); | ||
330 | if (rv != NF_ACCEPT) | ||
331 | return rv; | ||
332 | |||
333 | if (new_cid) { | ||
334 | IP_NF_ASSERT(cid); | ||
335 | DEBUGP("altering call id from 0x%04x to 0x%04x\n", | ||
336 | ntohs(*cid), ntohs(new_cid)); | ||
337 | rv = ip_nat_mangle_tcp_packet(pskb, ct, ctinfo, | ||
338 | (void *)cid - ((void *)ctlh - sizeof(struct pptp_pkt_hdr)), | ||
339 | sizeof(new_cid), | ||
340 | (char *)&new_cid, | ||
341 | sizeof(new_cid)); | ||
342 | if (rv != NF_ACCEPT) | ||
343 | return rv; | ||
344 | } | ||
345 | |||
346 | /* check for earlier return value of 'switch' above */ | ||
347 | if (ret != NF_ACCEPT) | ||
348 | return ret; | ||
349 | |||
350 | /* great, at least we don't need to resize packets */ | ||
351 | return NF_ACCEPT; | ||
352 | } | ||
353 | |||
354 | |||
355 | extern int __init ip_nat_proto_gre_init(void); | ||
356 | extern void __exit ip_nat_proto_gre_fini(void); | ||
357 | |||
358 | static int __init init(void) | ||
359 | { | ||
360 | int ret; | ||
361 | |||
362 | DEBUGP("%s: registering NAT helper\n", __FILE__); | ||
363 | |||
364 | ret = ip_nat_proto_gre_init(); | ||
365 | if (ret < 0) | ||
366 | return ret; | ||
367 | |||
368 | BUG_ON(ip_nat_pptp_hook_outbound); | ||
369 | ip_nat_pptp_hook_outbound = &pptp_outbound_pkt; | ||
370 | |||
371 | BUG_ON(ip_nat_pptp_hook_inbound); | ||
372 | ip_nat_pptp_hook_inbound = &pptp_inbound_pkt; | ||
373 | |||
374 | BUG_ON(ip_nat_pptp_hook_exp_gre); | ||
375 | ip_nat_pptp_hook_exp_gre = &pptp_exp_gre; | ||
376 | |||
377 | BUG_ON(ip_nat_pptp_hook_expectfn); | ||
378 | ip_nat_pptp_hook_expectfn = &pptp_nat_expected; | ||
379 | |||
380 | printk("ip_nat_pptp version %s loaded\n", IP_NAT_PPTP_VERSION); | ||
381 | return 0; | ||
382 | } | ||
383 | |||
384 | static void __exit fini(void) | ||
385 | { | ||
386 | DEBUGP("cleanup_module\n" ); | ||
387 | |||
388 | ip_nat_pptp_hook_expectfn = NULL; | ||
389 | ip_nat_pptp_hook_exp_gre = NULL; | ||
390 | ip_nat_pptp_hook_inbound = NULL; | ||
391 | ip_nat_pptp_hook_outbound = NULL; | ||
392 | |||
393 | ip_nat_proto_gre_fini(); | ||
394 | /* Make sure noone calls it, meanwhile */ | ||
395 | synchronize_net(); | ||
396 | |||
397 | printk("ip_nat_pptp version %s unloaded\n", IP_NAT_PPTP_VERSION); | ||
398 | } | ||
399 | |||
400 | module_init(init); | ||
401 | module_exit(fini); | ||
diff --git a/net/ipv4/netfilter/ip_nat_proto_gre.c b/net/ipv4/netfilter/ip_nat_proto_gre.c new file mode 100644 index 000000000000..7c1285401672 --- /dev/null +++ b/net/ipv4/netfilter/ip_nat_proto_gre.c | |||
@@ -0,0 +1,214 @@ | |||
1 | /* | ||
2 | * ip_nat_proto_gre.c - Version 2.0 | ||
3 | * | ||
4 | * NAT protocol helper module for GRE. | ||
5 | * | ||
6 | * GRE is a generic encapsulation protocol, which is generally not very | ||
7 | * suited for NAT, as it has no protocol-specific part as port numbers. | ||
8 | * | ||
9 | * It has an optional key field, which may help us distinguishing two | ||
10 | * connections between the same two hosts. | ||
11 | * | ||
12 | * GRE is defined in RFC 1701 and RFC 1702, as well as RFC 2784 | ||
13 | * | ||
14 | * PPTP is built on top of a modified version of GRE, and has a mandatory | ||
15 | * field called "CallID", which serves us for the same purpose as the key | ||
16 | * field in plain GRE. | ||
17 | * | ||
18 | * Documentation about PPTP can be found in RFC 2637 | ||
19 | * | ||
20 | * (C) 2000-2005 by Harald Welte <laforge@gnumonks.org> | ||
21 | * | ||
22 | * Development of this code funded by Astaro AG (http://www.astaro.com/) | ||
23 | * | ||
24 | */ | ||
25 | |||
26 | #include <linux/config.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/ip.h> | ||
29 | #include <linux/netfilter_ipv4/ip_nat.h> | ||
30 | #include <linux/netfilter_ipv4/ip_nat_rule.h> | ||
31 | #include <linux/netfilter_ipv4/ip_nat_protocol.h> | ||
32 | #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h> | ||
33 | |||
34 | MODULE_LICENSE("GPL"); | ||
35 | MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>"); | ||
36 | MODULE_DESCRIPTION("Netfilter NAT protocol helper module for GRE"); | ||
37 | |||
38 | #if 0 | ||
39 | #define DEBUGP(format, args...) printk(KERN_DEBUG "%s:%s: " format, __FILE__, \ | ||
40 | __FUNCTION__, ## args) | ||
41 | #else | ||
42 | #define DEBUGP(x, args...) | ||
43 | #endif | ||
44 | |||
45 | /* is key in given range between min and max */ | ||
46 | static int | ||
47 | gre_in_range(const struct ip_conntrack_tuple *tuple, | ||
48 | enum ip_nat_manip_type maniptype, | ||
49 | const union ip_conntrack_manip_proto *min, | ||
50 | const union ip_conntrack_manip_proto *max) | ||
51 | { | ||
52 | u_int32_t key; | ||
53 | |||
54 | if (maniptype == IP_NAT_MANIP_SRC) | ||
55 | key = tuple->src.u.gre.key; | ||
56 | else | ||
57 | key = tuple->dst.u.gre.key; | ||
58 | |||
59 | return ntohl(key) >= ntohl(min->gre.key) | ||
60 | && ntohl(key) <= ntohl(max->gre.key); | ||
61 | } | ||
62 | |||
63 | /* generate unique tuple ... */ | ||
64 | static int | ||
65 | gre_unique_tuple(struct ip_conntrack_tuple *tuple, | ||
66 | const struct ip_nat_range *range, | ||
67 | enum ip_nat_manip_type maniptype, | ||
68 | const struct ip_conntrack *conntrack) | ||
69 | { | ||
70 | static u_int16_t key; | ||
71 | u_int16_t *keyptr; | ||
72 | unsigned int min, i, range_size; | ||
73 | |||
74 | if (maniptype == IP_NAT_MANIP_SRC) | ||
75 | keyptr = &tuple->src.u.gre.key; | ||
76 | else | ||
77 | keyptr = &tuple->dst.u.gre.key; | ||
78 | |||
79 | if (!(range->flags & IP_NAT_RANGE_PROTO_SPECIFIED)) { | ||
80 | DEBUGP("%p: NATing GRE PPTP\n", conntrack); | ||
81 | min = 1; | ||
82 | range_size = 0xffff; | ||
83 | } else { | ||
84 | min = ntohl(range->min.gre.key); | ||
85 | range_size = ntohl(range->max.gre.key) - min + 1; | ||
86 | } | ||
87 | |||
88 | DEBUGP("min = %u, range_size = %u\n", min, range_size); | ||
89 | |||
90 | for (i = 0; i < range_size; i++, key++) { | ||
91 | *keyptr = htonl(min + key % range_size); | ||
92 | if (!ip_nat_used_tuple(tuple, conntrack)) | ||
93 | return 1; | ||
94 | } | ||
95 | |||
96 | DEBUGP("%p: no NAT mapping\n", conntrack); | ||
97 | |||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | /* manipulate a GRE packet according to maniptype */ | ||
102 | static int | ||
103 | gre_manip_pkt(struct sk_buff **pskb, | ||
104 | unsigned int iphdroff, | ||
105 | const struct ip_conntrack_tuple *tuple, | ||
106 | enum ip_nat_manip_type maniptype) | ||
107 | { | ||
108 | struct gre_hdr *greh; | ||
109 | struct gre_hdr_pptp *pgreh; | ||
110 | struct iphdr *iph = (struct iphdr *)((*pskb)->data + iphdroff); | ||
111 | unsigned int hdroff = iphdroff + iph->ihl*4; | ||
112 | |||
113 | /* pgreh includes two optional 32bit fields which are not required | ||
114 | * to be there. That's where the magic '8' comes from */ | ||
115 | if (!skb_make_writable(pskb, hdroff + sizeof(*pgreh)-8)) | ||
116 | return 0; | ||
117 | |||
118 | greh = (void *)(*pskb)->data + hdroff; | ||
119 | pgreh = (struct gre_hdr_pptp *) greh; | ||
120 | |||
121 | /* we only have destination manip of a packet, since 'source key' | ||
122 | * is not present in the packet itself */ | ||
123 | if (maniptype == IP_NAT_MANIP_DST) { | ||
124 | /* key manipulation is always dest */ | ||
125 | switch (greh->version) { | ||
126 | case 0: | ||
127 | if (!greh->key) { | ||
128 | DEBUGP("can't nat GRE w/o key\n"); | ||
129 | break; | ||
130 | } | ||
131 | if (greh->csum) { | ||
132 | /* FIXME: Never tested this code... */ | ||
133 | *(gre_csum(greh)) = | ||
134 | ip_nat_cheat_check(~*(gre_key(greh)), | ||
135 | tuple->dst.u.gre.key, | ||
136 | *(gre_csum(greh))); | ||
137 | } | ||
138 | *(gre_key(greh)) = tuple->dst.u.gre.key; | ||
139 | break; | ||
140 | case GRE_VERSION_PPTP: | ||
141 | DEBUGP("call_id -> 0x%04x\n", | ||
142 | ntohl(tuple->dst.u.gre.key)); | ||
143 | pgreh->call_id = htons(ntohl(tuple->dst.u.gre.key)); | ||
144 | break; | ||
145 | default: | ||
146 | DEBUGP("can't nat unknown GRE version\n"); | ||
147 | return 0; | ||
148 | break; | ||
149 | } | ||
150 | } | ||
151 | return 1; | ||
152 | } | ||
153 | |||
154 | /* print out a nat tuple */ | ||
155 | static unsigned int | ||
156 | gre_print(char *buffer, | ||
157 | const struct ip_conntrack_tuple *match, | ||
158 | const struct ip_conntrack_tuple *mask) | ||
159 | { | ||
160 | unsigned int len = 0; | ||
161 | |||
162 | if (mask->src.u.gre.key) | ||
163 | len += sprintf(buffer + len, "srckey=0x%x ", | ||
164 | ntohl(match->src.u.gre.key)); | ||
165 | |||
166 | if (mask->dst.u.gre.key) | ||
167 | len += sprintf(buffer + len, "dstkey=0x%x ", | ||
168 | ntohl(match->src.u.gre.key)); | ||
169 | |||
170 | return len; | ||
171 | } | ||
172 | |||
173 | /* print a range of keys */ | ||
174 | static unsigned int | ||
175 | gre_print_range(char *buffer, const struct ip_nat_range *range) | ||
176 | { | ||
177 | if (range->min.gre.key != 0 | ||
178 | || range->max.gre.key != 0xFFFF) { | ||
179 | if (range->min.gre.key == range->max.gre.key) | ||
180 | return sprintf(buffer, "key 0x%x ", | ||
181 | ntohl(range->min.gre.key)); | ||
182 | else | ||
183 | return sprintf(buffer, "keys 0x%u-0x%u ", | ||
184 | ntohl(range->min.gre.key), | ||
185 | ntohl(range->max.gre.key)); | ||
186 | } else | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | /* nat helper struct */ | ||
191 | static struct ip_nat_protocol gre = { | ||
192 | .name = "GRE", | ||
193 | .protonum = IPPROTO_GRE, | ||
194 | .manip_pkt = gre_manip_pkt, | ||
195 | .in_range = gre_in_range, | ||
196 | .unique_tuple = gre_unique_tuple, | ||
197 | .print = gre_print, | ||
198 | .print_range = gre_print_range, | ||
199 | #if defined(CONFIG_IP_NF_CONNTRACK_NETLINK) || \ | ||
200 | defined(CONFIG_IP_NF_CONNTRACK_NETLINK_MODULE) | ||
201 | .range_to_nfattr = ip_nat_port_range_to_nfattr, | ||
202 | .nfattr_to_range = ip_nat_port_nfattr_to_range, | ||
203 | #endif | ||
204 | }; | ||
205 | |||
206 | int __init ip_nat_proto_gre_init(void) | ||
207 | { | ||
208 | return ip_nat_protocol_register(&gre); | ||
209 | } | ||
210 | |||
211 | void __exit ip_nat_proto_gre_fini(void) | ||
212 | { | ||
213 | ip_nat_protocol_unregister(&gre); | ||
214 | } | ||
diff --git a/net/ipv4/netfilter/ip_nat_standalone.c b/net/ipv4/netfilter/ip_nat_standalone.c index 0ff368b131f6..30cd4e18c129 100644 --- a/net/ipv4/netfilter/ip_nat_standalone.c +++ b/net/ipv4/netfilter/ip_nat_standalone.c | |||
@@ -108,8 +108,8 @@ ip_nat_fn(unsigned int hooknum, | |||
108 | case IP_CT_RELATED: | 108 | case IP_CT_RELATED: |
109 | case IP_CT_RELATED+IP_CT_IS_REPLY: | 109 | case IP_CT_RELATED+IP_CT_IS_REPLY: |
110 | if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) { | 110 | if ((*pskb)->nh.iph->protocol == IPPROTO_ICMP) { |
111 | if (!icmp_reply_translation(pskb, ct, maniptype, | 111 | if (!ip_nat_icmp_reply_translation(pskb, ct, maniptype, |
112 | CTINFO2DIR(ctinfo))) | 112 | CTINFO2DIR(ctinfo))) |
113 | return NF_DROP; | 113 | return NF_DROP; |
114 | else | 114 | else |
115 | return NF_ACCEPT; | 115 | return NF_ACCEPT; |
@@ -152,7 +152,7 @@ ip_nat_fn(unsigned int hooknum, | |||
152 | } | 152 | } |
153 | 153 | ||
154 | IP_NF_ASSERT(info); | 154 | IP_NF_ASSERT(info); |
155 | return nat_packet(ct, ctinfo, hooknum, pskb); | 155 | return ip_nat_packet(ct, ctinfo, hooknum, pskb); |
156 | } | 156 | } |
157 | 157 | ||
158 | static unsigned int | 158 | static unsigned int |
@@ -325,15 +325,10 @@ static int init_or_cleanup(int init) | |||
325 | printk("ip_nat_init: can't setup rules.\n"); | 325 | printk("ip_nat_init: can't setup rules.\n"); |
326 | goto cleanup_nothing; | 326 | goto cleanup_nothing; |
327 | } | 327 | } |
328 | ret = ip_nat_init(); | ||
329 | if (ret < 0) { | ||
330 | printk("ip_nat_init: can't setup rules.\n"); | ||
331 | goto cleanup_rule_init; | ||
332 | } | ||
333 | ret = nf_register_hook(&ip_nat_in_ops); | 328 | ret = nf_register_hook(&ip_nat_in_ops); |
334 | if (ret < 0) { | 329 | if (ret < 0) { |
335 | printk("ip_nat_init: can't register in hook.\n"); | 330 | printk("ip_nat_init: can't register in hook.\n"); |
336 | goto cleanup_nat; | 331 | goto cleanup_rule_init; |
337 | } | 332 | } |
338 | ret = nf_register_hook(&ip_nat_out_ops); | 333 | ret = nf_register_hook(&ip_nat_out_ops); |
339 | if (ret < 0) { | 334 | if (ret < 0) { |
@@ -374,8 +369,6 @@ static int init_or_cleanup(int init) | |||
374 | nf_unregister_hook(&ip_nat_out_ops); | 369 | nf_unregister_hook(&ip_nat_out_ops); |
375 | cleanup_inops: | 370 | cleanup_inops: |
376 | nf_unregister_hook(&ip_nat_in_ops); | 371 | nf_unregister_hook(&ip_nat_in_ops); |
377 | cleanup_nat: | ||
378 | ip_nat_cleanup(); | ||
379 | cleanup_rule_init: | 372 | cleanup_rule_init: |
380 | ip_nat_rule_cleanup(); | 373 | ip_nat_rule_cleanup(); |
381 | cleanup_nothing: | 374 | cleanup_nothing: |
@@ -395,14 +388,4 @@ static void __exit fini(void) | |||
395 | module_init(init); | 388 | module_init(init); |
396 | module_exit(fini); | 389 | module_exit(fini); |
397 | 390 | ||
398 | EXPORT_SYMBOL(ip_nat_setup_info); | ||
399 | EXPORT_SYMBOL(ip_nat_protocol_register); | ||
400 | EXPORT_SYMBOL(ip_nat_protocol_unregister); | ||
401 | EXPORT_SYMBOL_GPL(ip_nat_proto_find_get); | ||
402 | EXPORT_SYMBOL_GPL(ip_nat_proto_put); | ||
403 | EXPORT_SYMBOL(ip_nat_cheat_check); | ||
404 | EXPORT_SYMBOL(ip_nat_mangle_tcp_packet); | ||
405 | EXPORT_SYMBOL(ip_nat_mangle_udp_packet); | ||
406 | EXPORT_SYMBOL(ip_nat_used_tuple); | ||
407 | EXPORT_SYMBOL(ip_nat_follow_master); | ||
408 | MODULE_LICENSE("GPL"); | 391 | MODULE_LICENSE("GPL"); |
diff --git a/net/ipv4/netfilter/ip_queue.c b/net/ipv4/netfilter/ip_queue.c index d54f14d926f6..36339eb39e17 100644 --- a/net/ipv4/netfilter/ip_queue.c +++ b/net/ipv4/netfilter/ip_queue.c | |||
@@ -240,8 +240,8 @@ ipq_build_packet_message(struct ipq_queue_entry *entry, int *errp) | |||
240 | 240 | ||
241 | pmsg->packet_id = (unsigned long )entry; | 241 | pmsg->packet_id = (unsigned long )entry; |
242 | pmsg->data_len = data_len; | 242 | pmsg->data_len = data_len; |
243 | pmsg->timestamp_sec = skb_tv_base.tv_sec + entry->skb->tstamp.off_sec; | 243 | pmsg->timestamp_sec = entry->skb->tstamp.off_sec; |
244 | pmsg->timestamp_usec = skb_tv_base.tv_usec + entry->skb->tstamp.off_usec; | 244 | pmsg->timestamp_usec = entry->skb->tstamp.off_usec; |
245 | pmsg->mark = entry->skb->nfmark; | 245 | pmsg->mark = entry->skb->nfmark; |
246 | pmsg->hook = entry->info->hook; | 246 | pmsg->hook = entry->info->hook; |
247 | pmsg->hw_protocol = entry->skb->protocol; | 247 | pmsg->hw_protocol = entry->skb->protocol; |
diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c index 7d38913754b1..9bcb398fbc1f 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/config.h> | 13 | #include <linux/config.h> |
14 | #include <linux/proc_fs.h> | 14 | #include <linux/proc_fs.h> |
15 | #include <linux/jhash.h> | 15 | #include <linux/jhash.h> |
16 | #include <linux/bitops.h> | ||
16 | #include <linux/skbuff.h> | 17 | #include <linux/skbuff.h> |
17 | #include <linux/ip.h> | 18 | #include <linux/ip.h> |
18 | #include <linux/tcp.h> | 19 | #include <linux/tcp.h> |
@@ -30,7 +31,7 @@ | |||
30 | #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> | 31 | #include <linux/netfilter_ipv4/ipt_CLUSTERIP.h> |
31 | #include <linux/netfilter_ipv4/ip_conntrack.h> | 32 | #include <linux/netfilter_ipv4/ip_conntrack.h> |
32 | 33 | ||
33 | #define CLUSTERIP_VERSION "0.7" | 34 | #define CLUSTERIP_VERSION "0.8" |
34 | 35 | ||
35 | #define DEBUG_CLUSTERIP | 36 | #define DEBUG_CLUSTERIP |
36 | 37 | ||
@@ -49,13 +50,14 @@ MODULE_DESCRIPTION("iptables target for CLUSTERIP"); | |||
49 | struct clusterip_config { | 50 | struct clusterip_config { |
50 | struct list_head list; /* list of all configs */ | 51 | struct list_head list; /* list of all configs */ |
51 | atomic_t refcount; /* reference count */ | 52 | atomic_t refcount; /* reference count */ |
53 | atomic_t entries; /* number of entries/rules | ||
54 | * referencing us */ | ||
52 | 55 | ||
53 | u_int32_t clusterip; /* the IP address */ | 56 | u_int32_t clusterip; /* the IP address */ |
54 | u_int8_t clustermac[ETH_ALEN]; /* the MAC address */ | 57 | u_int8_t clustermac[ETH_ALEN]; /* the MAC address */ |
55 | struct net_device *dev; /* device */ | 58 | struct net_device *dev; /* device */ |
56 | u_int16_t num_total_nodes; /* total number of nodes */ | 59 | u_int16_t num_total_nodes; /* total number of nodes */ |
57 | u_int16_t num_local_nodes; /* number of local nodes */ | 60 | unsigned long local_nodes; /* node number array */ |
58 | u_int16_t local_nodes[CLUSTERIP_MAX_NODES]; /* node number array */ | ||
59 | 61 | ||
60 | #ifdef CONFIG_PROC_FS | 62 | #ifdef CONFIG_PROC_FS |
61 | struct proc_dir_entry *pde; /* proc dir entry */ | 63 | struct proc_dir_entry *pde; /* proc dir entry */ |
@@ -66,8 +68,7 @@ struct clusterip_config { | |||
66 | 68 | ||
67 | static LIST_HEAD(clusterip_configs); | 69 | static LIST_HEAD(clusterip_configs); |
68 | 70 | ||
69 | /* clusterip_lock protects the clusterip_configs list _AND_ the configurable | 71 | /* clusterip_lock protects the clusterip_configs list */ |
70 | * data within all structurses (num_local_nodes, local_nodes[]) */ | ||
71 | static DEFINE_RWLOCK(clusterip_lock); | 72 | static DEFINE_RWLOCK(clusterip_lock); |
72 | 73 | ||
73 | #ifdef CONFIG_PROC_FS | 74 | #ifdef CONFIG_PROC_FS |
@@ -76,23 +77,48 @@ static struct proc_dir_entry *clusterip_procdir; | |||
76 | #endif | 77 | #endif |
77 | 78 | ||
78 | static inline void | 79 | static inline void |
79 | clusterip_config_get(struct clusterip_config *c) { | 80 | clusterip_config_get(struct clusterip_config *c) |
81 | { | ||
80 | atomic_inc(&c->refcount); | 82 | atomic_inc(&c->refcount); |
81 | } | 83 | } |
82 | 84 | ||
83 | static inline void | 85 | static inline void |
84 | clusterip_config_put(struct clusterip_config *c) { | 86 | clusterip_config_put(struct clusterip_config *c) |
85 | if (atomic_dec_and_test(&c->refcount)) { | 87 | { |
88 | if (atomic_dec_and_test(&c->refcount)) | ||
89 | kfree(c); | ||
90 | } | ||
91 | |||
92 | /* increase the count of entries(rules) using/referencing this config */ | ||
93 | static inline void | ||
94 | clusterip_config_entry_get(struct clusterip_config *c) | ||
95 | { | ||
96 | atomic_inc(&c->entries); | ||
97 | } | ||
98 | |||
99 | /* decrease the count of entries using/referencing this config. If last | ||
100 | * entry(rule) is removed, remove the config from lists, but don't free it | ||
101 | * yet, since proc-files could still be holding references */ | ||
102 | static inline void | ||
103 | clusterip_config_entry_put(struct clusterip_config *c) | ||
104 | { | ||
105 | if (atomic_dec_and_test(&c->entries)) { | ||
86 | write_lock_bh(&clusterip_lock); | 106 | write_lock_bh(&clusterip_lock); |
87 | list_del(&c->list); | 107 | list_del(&c->list); |
88 | write_unlock_bh(&clusterip_lock); | 108 | write_unlock_bh(&clusterip_lock); |
109 | |||
89 | dev_mc_delete(c->dev, c->clustermac, ETH_ALEN, 0); | 110 | dev_mc_delete(c->dev, c->clustermac, ETH_ALEN, 0); |
90 | dev_put(c->dev); | 111 | dev_put(c->dev); |
91 | kfree(c); | 112 | |
113 | /* In case anyone still accesses the file, the open/close | ||
114 | * functions are also incrementing the refcount on their own, | ||
115 | * so it's safe to remove the entry even if it's in use. */ | ||
116 | #ifdef CONFIG_PROC_FS | ||
117 | remove_proc_entry(c->pde->name, c->pde->parent); | ||
118 | #endif | ||
92 | } | 119 | } |
93 | } | 120 | } |
94 | 121 | ||
95 | |||
96 | static struct clusterip_config * | 122 | static struct clusterip_config * |
97 | __clusterip_config_find(u_int32_t clusterip) | 123 | __clusterip_config_find(u_int32_t clusterip) |
98 | { | 124 | { |
@@ -111,7 +137,7 @@ __clusterip_config_find(u_int32_t clusterip) | |||
111 | } | 137 | } |
112 | 138 | ||
113 | static inline struct clusterip_config * | 139 | static inline struct clusterip_config * |
114 | clusterip_config_find_get(u_int32_t clusterip) | 140 | clusterip_config_find_get(u_int32_t clusterip, int entry) |
115 | { | 141 | { |
116 | struct clusterip_config *c; | 142 | struct clusterip_config *c; |
117 | 143 | ||
@@ -122,11 +148,24 @@ clusterip_config_find_get(u_int32_t clusterip) | |||
122 | return NULL; | 148 | return NULL; |
123 | } | 149 | } |
124 | atomic_inc(&c->refcount); | 150 | atomic_inc(&c->refcount); |
151 | if (entry) | ||
152 | atomic_inc(&c->entries); | ||
125 | read_unlock_bh(&clusterip_lock); | 153 | read_unlock_bh(&clusterip_lock); |
126 | 154 | ||
127 | return c; | 155 | return c; |
128 | } | 156 | } |
129 | 157 | ||
158 | static void | ||
159 | clusterip_config_init_nodelist(struct clusterip_config *c, | ||
160 | const struct ipt_clusterip_tgt_info *i) | ||
161 | { | ||
162 | int n; | ||
163 | |||
164 | for (n = 0; n < i->num_local_nodes; n++) { | ||
165 | set_bit(i->local_nodes[n] - 1, &c->local_nodes); | ||
166 | } | ||
167 | } | ||
168 | |||
130 | static struct clusterip_config * | 169 | static struct clusterip_config * |
131 | clusterip_config_init(struct ipt_clusterip_tgt_info *i, u_int32_t ip, | 170 | clusterip_config_init(struct ipt_clusterip_tgt_info *i, u_int32_t ip, |
132 | struct net_device *dev) | 171 | struct net_device *dev) |
@@ -143,11 +182,11 @@ clusterip_config_init(struct ipt_clusterip_tgt_info *i, u_int32_t ip, | |||
143 | c->clusterip = ip; | 182 | c->clusterip = ip; |
144 | memcpy(&c->clustermac, &i->clustermac, ETH_ALEN); | 183 | memcpy(&c->clustermac, &i->clustermac, ETH_ALEN); |
145 | c->num_total_nodes = i->num_total_nodes; | 184 | c->num_total_nodes = i->num_total_nodes; |
146 | c->num_local_nodes = i->num_local_nodes; | 185 | clusterip_config_init_nodelist(c, i); |
147 | memcpy(&c->local_nodes, &i->local_nodes, sizeof(c->local_nodes)); | ||
148 | c->hash_mode = i->hash_mode; | 186 | c->hash_mode = i->hash_mode; |
149 | c->hash_initval = i->hash_initval; | 187 | c->hash_initval = i->hash_initval; |
150 | atomic_set(&c->refcount, 1); | 188 | atomic_set(&c->refcount, 1); |
189 | atomic_set(&c->entries, 1); | ||
151 | 190 | ||
152 | #ifdef CONFIG_PROC_FS | 191 | #ifdef CONFIG_PROC_FS |
153 | /* create proc dir entry */ | 192 | /* create proc dir entry */ |
@@ -171,53 +210,28 @@ clusterip_config_init(struct ipt_clusterip_tgt_info *i, u_int32_t ip, | |||
171 | static int | 210 | static int |
172 | clusterip_add_node(struct clusterip_config *c, u_int16_t nodenum) | 211 | clusterip_add_node(struct clusterip_config *c, u_int16_t nodenum) |
173 | { | 212 | { |
174 | int i; | ||
175 | |||
176 | write_lock_bh(&clusterip_lock); | ||
177 | 213 | ||
178 | if (c->num_local_nodes >= CLUSTERIP_MAX_NODES | 214 | if (nodenum == 0 || |
179 | || nodenum > CLUSTERIP_MAX_NODES) { | 215 | nodenum > c->num_total_nodes) |
180 | write_unlock_bh(&clusterip_lock); | ||
181 | return 1; | 216 | return 1; |
182 | } | ||
183 | |||
184 | /* check if we alrady have this number in our array */ | ||
185 | for (i = 0; i < c->num_local_nodes; i++) { | ||
186 | if (c->local_nodes[i] == nodenum) { | ||
187 | write_unlock_bh(&clusterip_lock); | ||
188 | return 1; | ||
189 | } | ||
190 | } | ||
191 | 217 | ||
192 | c->local_nodes[c->num_local_nodes++] = nodenum; | 218 | /* check if we already have this number in our bitfield */ |
219 | if (test_and_set_bit(nodenum - 1, &c->local_nodes)) | ||
220 | return 1; | ||
193 | 221 | ||
194 | write_unlock_bh(&clusterip_lock); | ||
195 | return 0; | 222 | return 0; |
196 | } | 223 | } |
197 | 224 | ||
198 | static int | 225 | static int |
199 | clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum) | 226 | clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum) |
200 | { | 227 | { |
201 | int i; | 228 | if (nodenum == 0 || |
202 | 229 | nodenum > c->num_total_nodes) | |
203 | write_lock_bh(&clusterip_lock); | ||
204 | |||
205 | if (c->num_local_nodes <= 1 || nodenum > CLUSTERIP_MAX_NODES) { | ||
206 | write_unlock_bh(&clusterip_lock); | ||
207 | return 1; | 230 | return 1; |
208 | } | ||
209 | 231 | ||
210 | for (i = 0; i < c->num_local_nodes; i++) { | 232 | if (test_and_clear_bit(nodenum - 1, &c->local_nodes)) |
211 | if (c->local_nodes[i] == nodenum) { | 233 | return 0; |
212 | int size = sizeof(u_int16_t)*(c->num_local_nodes-(i+1)); | ||
213 | memmove(&c->local_nodes[i], &c->local_nodes[i+1], size); | ||
214 | c->num_local_nodes--; | ||
215 | write_unlock_bh(&clusterip_lock); | ||
216 | return 0; | ||
217 | } | ||
218 | } | ||
219 | 234 | ||
220 | write_unlock_bh(&clusterip_lock); | ||
221 | return 1; | 235 | return 1; |
222 | } | 236 | } |
223 | 237 | ||
@@ -285,25 +299,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config) | |||
285 | static inline int | 299 | static inline int |
286 | clusterip_responsible(struct clusterip_config *config, u_int32_t hash) | 300 | clusterip_responsible(struct clusterip_config *config, u_int32_t hash) |
287 | { | 301 | { |
288 | int i; | 302 | return test_bit(hash - 1, &config->local_nodes); |
289 | |||
290 | read_lock_bh(&clusterip_lock); | ||
291 | |||
292 | if (config->num_local_nodes == 0) { | ||
293 | read_unlock_bh(&clusterip_lock); | ||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | for (i = 0; i < config->num_local_nodes; i++) { | ||
298 | if (config->local_nodes[i] == hash) { | ||
299 | read_unlock_bh(&clusterip_lock); | ||
300 | return 1; | ||
301 | } | ||
302 | } | ||
303 | |||
304 | read_unlock_bh(&clusterip_lock); | ||
305 | |||
306 | return 0; | ||
307 | } | 303 | } |
308 | 304 | ||
309 | /*********************************************************************** | 305 | /*********************************************************************** |
@@ -415,8 +411,26 @@ checkentry(const char *tablename, | |||
415 | 411 | ||
416 | /* FIXME: further sanity checks */ | 412 | /* FIXME: further sanity checks */ |
417 | 413 | ||
418 | config = clusterip_config_find_get(e->ip.dst.s_addr); | 414 | config = clusterip_config_find_get(e->ip.dst.s_addr, 1); |
419 | if (!config) { | 415 | if (config) { |
416 | if (cipinfo->config != NULL) { | ||
417 | /* Case A: This is an entry that gets reloaded, since | ||
418 | * it still has a cipinfo->config pointer. Simply | ||
419 | * increase the entry refcount and return */ | ||
420 | if (cipinfo->config != config) { | ||
421 | printk(KERN_ERR "CLUSTERIP: Reloaded entry " | ||
422 | "has invalid config pointer!\n"); | ||
423 | return 0; | ||
424 | } | ||
425 | clusterip_config_entry_get(cipinfo->config); | ||
426 | } else { | ||
427 | /* Case B: This is a new rule referring to an existing | ||
428 | * clusterip config. */ | ||
429 | cipinfo->config = config; | ||
430 | clusterip_config_entry_get(cipinfo->config); | ||
431 | } | ||
432 | } else { | ||
433 | /* Case C: This is a completely new clusterip config */ | ||
420 | if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) { | 434 | if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) { |
421 | printk(KERN_WARNING "CLUSTERIP: no config found for %u.%u.%u.%u, need 'new'\n", NIPQUAD(e->ip.dst.s_addr)); | 435 | printk(KERN_WARNING "CLUSTERIP: no config found for %u.%u.%u.%u, need 'new'\n", NIPQUAD(e->ip.dst.s_addr)); |
422 | return 0; | 436 | return 0; |
@@ -443,10 +457,9 @@ checkentry(const char *tablename, | |||
443 | } | 457 | } |
444 | dev_mc_add(config->dev,config->clustermac, ETH_ALEN, 0); | 458 | dev_mc_add(config->dev,config->clustermac, ETH_ALEN, 0); |
445 | } | 459 | } |
460 | cipinfo->config = config; | ||
446 | } | 461 | } |
447 | 462 | ||
448 | cipinfo->config = config; | ||
449 | |||
450 | return 1; | 463 | return 1; |
451 | } | 464 | } |
452 | 465 | ||
@@ -455,13 +468,10 @@ static void destroy(void *matchinfo, unsigned int matchinfosize) | |||
455 | { | 468 | { |
456 | struct ipt_clusterip_tgt_info *cipinfo = matchinfo; | 469 | struct ipt_clusterip_tgt_info *cipinfo = matchinfo; |
457 | 470 | ||
458 | /* we first remove the proc entry and then drop the reference | 471 | /* if no more entries are referencing the config, remove it |
459 | * count. In case anyone still accesses the file, the open/close | 472 | * from the list and destroy the proc entry */ |
460 | * functions are also incrementing the refcount on their own */ | 473 | clusterip_config_entry_put(cipinfo->config); |
461 | #ifdef CONFIG_PROC_FS | 474 | |
462 | remove_proc_entry(cipinfo->config->pde->name, | ||
463 | cipinfo->config->pde->parent); | ||
464 | #endif | ||
465 | clusterip_config_put(cipinfo->config); | 475 | clusterip_config_put(cipinfo->config); |
466 | } | 476 | } |
467 | 477 | ||
@@ -533,7 +543,7 @@ arp_mangle(unsigned int hook, | |||
533 | 543 | ||
534 | /* if there is no clusterip configuration for the arp reply's | 544 | /* if there is no clusterip configuration for the arp reply's |
535 | * source ip, we don't want to mangle it */ | 545 | * source ip, we don't want to mangle it */ |
536 | c = clusterip_config_find_get(payload->src_ip); | 546 | c = clusterip_config_find_get(payload->src_ip, 0); |
537 | if (!c) | 547 | if (!c) |
538 | return NF_ACCEPT; | 548 | return NF_ACCEPT; |
539 | 549 | ||
@@ -574,56 +584,69 @@ static struct nf_hook_ops cip_arp_ops = { | |||
574 | 584 | ||
575 | #ifdef CONFIG_PROC_FS | 585 | #ifdef CONFIG_PROC_FS |
576 | 586 | ||
587 | struct clusterip_seq_position { | ||
588 | unsigned int pos; /* position */ | ||
589 | unsigned int weight; /* number of bits set == size */ | ||
590 | unsigned int bit; /* current bit */ | ||
591 | unsigned long val; /* current value */ | ||
592 | }; | ||
593 | |||
577 | static void *clusterip_seq_start(struct seq_file *s, loff_t *pos) | 594 | static void *clusterip_seq_start(struct seq_file *s, loff_t *pos) |
578 | { | 595 | { |
579 | struct proc_dir_entry *pde = s->private; | 596 | struct proc_dir_entry *pde = s->private; |
580 | struct clusterip_config *c = pde->data; | 597 | struct clusterip_config *c = pde->data; |
581 | unsigned int *nodeidx; | 598 | unsigned int weight; |
582 | 599 | u_int32_t local_nodes; | |
583 | read_lock_bh(&clusterip_lock); | 600 | struct clusterip_seq_position *idx; |
584 | if (*pos >= c->num_local_nodes) | 601 | |
602 | /* FIXME: possible race */ | ||
603 | local_nodes = c->local_nodes; | ||
604 | weight = hweight32(local_nodes); | ||
605 | if (*pos >= weight) | ||
585 | return NULL; | 606 | return NULL; |
586 | 607 | ||
587 | nodeidx = kmalloc(sizeof(unsigned int), GFP_KERNEL); | 608 | idx = kmalloc(sizeof(struct clusterip_seq_position), GFP_KERNEL); |
588 | if (!nodeidx) | 609 | if (!idx) |
589 | return ERR_PTR(-ENOMEM); | 610 | return ERR_PTR(-ENOMEM); |
590 | 611 | ||
591 | *nodeidx = *pos; | 612 | idx->pos = *pos; |
592 | return nodeidx; | 613 | idx->weight = weight; |
614 | idx->bit = ffs(local_nodes); | ||
615 | idx->val = local_nodes; | ||
616 | clear_bit(idx->bit - 1, &idx->val); | ||
617 | |||
618 | return idx; | ||
593 | } | 619 | } |
594 | 620 | ||
595 | static void *clusterip_seq_next(struct seq_file *s, void *v, loff_t *pos) | 621 | static void *clusterip_seq_next(struct seq_file *s, void *v, loff_t *pos) |
596 | { | 622 | { |
597 | struct proc_dir_entry *pde = s->private; | 623 | struct clusterip_seq_position *idx = (struct clusterip_seq_position *)v; |
598 | struct clusterip_config *c = pde->data; | ||
599 | unsigned int *nodeidx = (unsigned int *)v; | ||
600 | 624 | ||
601 | *pos = ++(*nodeidx); | 625 | *pos = ++idx->pos; |
602 | if (*pos >= c->num_local_nodes) { | 626 | if (*pos >= idx->weight) { |
603 | kfree(v); | 627 | kfree(v); |
604 | return NULL; | 628 | return NULL; |
605 | } | 629 | } |
606 | return nodeidx; | 630 | idx->bit = ffs(idx->val); |
631 | clear_bit(idx->bit - 1, &idx->val); | ||
632 | return idx; | ||
607 | } | 633 | } |
608 | 634 | ||
609 | static void clusterip_seq_stop(struct seq_file *s, void *v) | 635 | static void clusterip_seq_stop(struct seq_file *s, void *v) |
610 | { | 636 | { |
611 | kfree(v); | 637 | kfree(v); |
612 | |||
613 | read_unlock_bh(&clusterip_lock); | ||
614 | } | 638 | } |
615 | 639 | ||
616 | static int clusterip_seq_show(struct seq_file *s, void *v) | 640 | static int clusterip_seq_show(struct seq_file *s, void *v) |
617 | { | 641 | { |
618 | struct proc_dir_entry *pde = s->private; | 642 | struct clusterip_seq_position *idx = (struct clusterip_seq_position *)v; |
619 | struct clusterip_config *c = pde->data; | ||
620 | unsigned int *nodeidx = (unsigned int *)v; | ||
621 | 643 | ||
622 | if (*nodeidx != 0) | 644 | if (idx->pos != 0) |
623 | seq_putc(s, ','); | 645 | seq_putc(s, ','); |
624 | seq_printf(s, "%u", c->local_nodes[*nodeidx]); | ||
625 | 646 | ||
626 | if (*nodeidx == c->num_local_nodes-1) | 647 | seq_printf(s, "%u", idx->bit); |
648 | |||
649 | if (idx->pos == idx->weight - 1) | ||
627 | seq_putc(s, '\n'); | 650 | seq_putc(s, '\n'); |
628 | 651 | ||
629 | return 0; | 652 | return 0; |
diff --git a/net/ipv4/netfilter/ipt_MASQUERADE.c b/net/ipv4/netfilter/ipt_MASQUERADE.c index 2f3e181c8e97..275a174c6fe6 100644 --- a/net/ipv4/netfilter/ipt_MASQUERADE.c +++ b/net/ipv4/netfilter/ipt_MASQUERADE.c | |||
@@ -90,6 +90,12 @@ masquerade_target(struct sk_buff **pskb, | |||
90 | IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED | 90 | IP_NF_ASSERT(ct && (ctinfo == IP_CT_NEW || ctinfo == IP_CT_RELATED |
91 | || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); | 91 | || ctinfo == IP_CT_RELATED + IP_CT_IS_REPLY)); |
92 | 92 | ||
93 | /* Source address is 0.0.0.0 - locally generated packet that is | ||
94 | * probably not supposed to be masqueraded. | ||
95 | */ | ||
96 | if (ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.ip == 0) | ||
97 | return NF_ACCEPT; | ||
98 | |||
93 | mr = targinfo; | 99 | mr = targinfo; |
94 | rt = (struct rtable *)(*pskb)->dst; | 100 | rt = (struct rtable *)(*pskb)->dst; |
95 | newsrc = inet_select_addr(out, rt->rt_gateway, RT_SCOPE_UNIVERSE); | 101 | newsrc = inet_select_addr(out, rt->rt_gateway, RT_SCOPE_UNIVERSE); |
diff --git a/net/ipv4/netfilter/ipt_REDIRECT.c b/net/ipv4/netfilter/ipt_REDIRECT.c index d2e13447678e..5245bfd33d52 100644 --- a/net/ipv4/netfilter/ipt_REDIRECT.c +++ b/net/ipv4/netfilter/ipt_REDIRECT.c | |||
@@ -88,14 +88,18 @@ redirect_target(struct sk_buff **pskb, | |||
88 | newdst = htonl(0x7F000001); | 88 | newdst = htonl(0x7F000001); |
89 | else { | 89 | else { |
90 | struct in_device *indev; | 90 | struct in_device *indev; |
91 | struct in_ifaddr *ifa; | ||
91 | 92 | ||
92 | /* Device might not have an associated in_device. */ | 93 | newdst = 0; |
93 | indev = (struct in_device *)(*pskb)->dev->ip_ptr; | 94 | |
94 | if (indev == NULL || indev->ifa_list == NULL) | 95 | rcu_read_lock(); |
95 | return NF_DROP; | 96 | indev = __in_dev_get_rcu((*pskb)->dev); |
97 | if (indev && (ifa = indev->ifa_list)) | ||
98 | newdst = ifa->ifa_local; | ||
99 | rcu_read_unlock(); | ||
96 | 100 | ||
97 | /* Grab first address on interface. */ | 101 | if (!newdst) |
98 | newdst = indev->ifa_list->ifa_local; | 102 | return NF_DROP; |
99 | } | 103 | } |
100 | 104 | ||
101 | /* Transfer from original range. */ | 105 | /* Transfer from original range. */ |
diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c index e2c14f3cb2fc..2883ccd8a91d 100644 --- a/net/ipv4/netfilter/ipt_ULOG.c +++ b/net/ipv4/netfilter/ipt_ULOG.c | |||
@@ -225,8 +225,8 @@ static void ipt_ulog_packet(unsigned int hooknum, | |||
225 | 225 | ||
226 | /* copy hook, prefix, timestamp, payload, etc. */ | 226 | /* copy hook, prefix, timestamp, payload, etc. */ |
227 | pm->data_len = copy_len; | 227 | pm->data_len = copy_len; |
228 | pm->timestamp_sec = skb_tv_base.tv_sec + skb->tstamp.off_sec; | 228 | pm->timestamp_sec = skb->tstamp.off_sec; |
229 | pm->timestamp_usec = skb_tv_base.tv_usec + skb->tstamp.off_usec; | 229 | pm->timestamp_usec = skb->tstamp.off_usec; |
230 | pm->mark = skb->nfmark; | 230 | pm->mark = skb->nfmark; |
231 | pm->hook = hooknum; | 231 | pm->hook = hooknum; |
232 | if (prefix != NULL) | 232 | if (prefix != NULL) |
diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 304bb0a1d4f0..4b0d7e4d6269 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c | |||
@@ -361,7 +361,7 @@ static void raw_probe_proto_opt(struct flowi *fl, struct msghdr *msg) | |||
361 | 361 | ||
362 | if (type && code) { | 362 | if (type && code) { |
363 | get_user(fl->fl_icmp_type, type); | 363 | get_user(fl->fl_icmp_type, type); |
364 | __get_user(fl->fl_icmp_code, code); | 364 | get_user(fl->fl_icmp_code, code); |
365 | probed = 1; | 365 | probed = 1; |
366 | } | 366 | } |
367 | break; | 367 | break; |
diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 8549f26e2495..381dd6a6aebb 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c | |||
@@ -2128,7 +2128,7 @@ int ip_route_input(struct sk_buff *skb, u32 daddr, u32 saddr, | |||
2128 | struct in_device *in_dev; | 2128 | struct in_device *in_dev; |
2129 | 2129 | ||
2130 | rcu_read_lock(); | 2130 | rcu_read_lock(); |
2131 | if ((in_dev = __in_dev_get(dev)) != NULL) { | 2131 | if ((in_dev = __in_dev_get_rcu(dev)) != NULL) { |
2132 | int our = ip_check_mc(in_dev, daddr, saddr, | 2132 | int our = ip_check_mc(in_dev, daddr, saddr, |
2133 | skb->nh.iph->protocol); | 2133 | skb->nh.iph->protocol); |
2134 | if (our | 2134 | if (our |
@@ -2443,7 +2443,9 @@ static int ip_route_output_slow(struct rtable **rp, const struct flowi *oldflp) | |||
2443 | err = -ENODEV; | 2443 | err = -ENODEV; |
2444 | if (dev_out == NULL) | 2444 | if (dev_out == NULL) |
2445 | goto out; | 2445 | goto out; |
2446 | if (__in_dev_get(dev_out) == NULL) { | 2446 | |
2447 | /* RACE: Check return value of inet_select_addr instead. */ | ||
2448 | if (__in_dev_get_rtnl(dev_out) == NULL) { | ||
2447 | dev_put(dev_out); | 2449 | dev_put(dev_out); |
2448 | goto out; /* Wrong error code */ | 2450 | goto out; /* Wrong error code */ |
2449 | } | 2451 | } |
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index 29222b964951..677419d0c9ad 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c | |||
@@ -355,8 +355,6 @@ static void tcp_clamp_window(struct sock *sk, struct tcp_sock *tp) | |||
355 | app_win -= icsk->icsk_ack.rcv_mss; | 355 | app_win -= icsk->icsk_ack.rcv_mss; |
356 | app_win = max(app_win, 2U*tp->advmss); | 356 | app_win = max(app_win, 2U*tp->advmss); |
357 | 357 | ||
358 | if (!ofo_win) | ||
359 | tp->window_clamp = min(tp->window_clamp, app_win); | ||
360 | tp->rcv_ssthresh = min(tp->window_clamp, 2U*tp->advmss); | 358 | tp->rcv_ssthresh = min(tp->window_clamp, 2U*tp->advmss); |
361 | } | 359 | } |
362 | } | 360 | } |
@@ -979,14 +977,19 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_ | |||
979 | if (!before(TCP_SKB_CB(skb)->seq, end_seq)) | 977 | if (!before(TCP_SKB_CB(skb)->seq, end_seq)) |
980 | break; | 978 | break; |
981 | 979 | ||
980 | in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) && | ||
981 | !before(end_seq, TCP_SKB_CB(skb)->end_seq); | ||
982 | |||
982 | pcount = tcp_skb_pcount(skb); | 983 | pcount = tcp_skb_pcount(skb); |
983 | 984 | ||
984 | if (pcount > 1 && | 985 | if (pcount > 1 && !in_sack && |
985 | (after(start_seq, TCP_SKB_CB(skb)->seq) || | 986 | after(TCP_SKB_CB(skb)->end_seq, start_seq)) { |
986 | before(end_seq, TCP_SKB_CB(skb)->end_seq))) { | ||
987 | unsigned int pkt_len; | 987 | unsigned int pkt_len; |
988 | 988 | ||
989 | if (after(start_seq, TCP_SKB_CB(skb)->seq)) | 989 | in_sack = !after(start_seq, |
990 | TCP_SKB_CB(skb)->seq); | ||
991 | |||
992 | if (!in_sack) | ||
990 | pkt_len = (start_seq - | 993 | pkt_len = (start_seq - |
991 | TCP_SKB_CB(skb)->seq); | 994 | TCP_SKB_CB(skb)->seq); |
992 | else | 995 | else |
@@ -999,9 +1002,6 @@ tcp_sacktag_write_queue(struct sock *sk, struct sk_buff *ack_skb, u32 prior_snd_ | |||
999 | 1002 | ||
1000 | fack_count += pcount; | 1003 | fack_count += pcount; |
1001 | 1004 | ||
1002 | in_sack = !after(start_seq, TCP_SKB_CB(skb)->seq) && | ||
1003 | !before(end_seq, TCP_SKB_CB(skb)->end_seq); | ||
1004 | |||
1005 | sacked = TCP_SKB_CB(skb)->sacked; | 1005 | sacked = TCP_SKB_CB(skb)->sacked; |
1006 | 1006 | ||
1007 | /* Account D-SACK for retransmitted packet. */ | 1007 | /* Account D-SACK for retransmitted packet. */ |
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 13dfb391cdf1..c85819d8474b 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c | |||
@@ -130,19 +130,20 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport, | |||
130 | int dif = sk->sk_bound_dev_if; | 130 | int dif = sk->sk_bound_dev_if; |
131 | INET_ADDR_COOKIE(acookie, saddr, daddr) | 131 | INET_ADDR_COOKIE(acookie, saddr, daddr) |
132 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); | 132 | const __u32 ports = INET_COMBINED_PORTS(inet->dport, lport); |
133 | const int hash = inet_ehashfn(daddr, lport, saddr, inet->dport, tcp_hashinfo.ehash_size); | 133 | unsigned int hash = inet_ehashfn(daddr, lport, saddr, inet->dport); |
134 | struct inet_ehash_bucket *head = &tcp_hashinfo.ehash[hash]; | 134 | struct inet_ehash_bucket *head = inet_ehash_bucket(&tcp_hashinfo, hash); |
135 | struct sock *sk2; | 135 | struct sock *sk2; |
136 | const struct hlist_node *node; | 136 | const struct hlist_node *node; |
137 | struct inet_timewait_sock *tw; | 137 | struct inet_timewait_sock *tw; |
138 | 138 | ||
139 | prefetch(head->chain.first); | ||
139 | write_lock(&head->lock); | 140 | write_lock(&head->lock); |
140 | 141 | ||
141 | /* Check TIME-WAIT sockets first. */ | 142 | /* Check TIME-WAIT sockets first. */ |
142 | sk_for_each(sk2, node, &(head + tcp_hashinfo.ehash_size)->chain) { | 143 | sk_for_each(sk2, node, &(head + tcp_hashinfo.ehash_size)->chain) { |
143 | tw = inet_twsk(sk2); | 144 | tw = inet_twsk(sk2); |
144 | 145 | ||
145 | if (INET_TW_MATCH(sk2, acookie, saddr, daddr, ports, dif)) { | 146 | if (INET_TW_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) { |
146 | const struct tcp_timewait_sock *tcptw = tcp_twsk(sk2); | 147 | const struct tcp_timewait_sock *tcptw = tcp_twsk(sk2); |
147 | struct tcp_sock *tp = tcp_sk(sk); | 148 | struct tcp_sock *tp = tcp_sk(sk); |
148 | 149 | ||
@@ -179,7 +180,7 @@ static int __tcp_v4_check_established(struct sock *sk, __u16 lport, | |||
179 | 180 | ||
180 | /* And established part... */ | 181 | /* And established part... */ |
181 | sk_for_each(sk2, node, &head->chain) { | 182 | sk_for_each(sk2, node, &head->chain) { |
182 | if (INET_MATCH(sk2, acookie, saddr, daddr, ports, dif)) | 183 | if (INET_MATCH(sk2, hash, acookie, saddr, daddr, ports, dif)) |
183 | goto not_unique; | 184 | goto not_unique; |
184 | } | 185 | } |
185 | 186 | ||
@@ -188,7 +189,7 @@ unique: | |||
188 | * in hash table socket with a funny identity. */ | 189 | * in hash table socket with a funny identity. */ |
189 | inet->num = lport; | 190 | inet->num = lport; |
190 | inet->sport = htons(lport); | 191 | inet->sport = htons(lport); |
191 | sk->sk_hashent = hash; | 192 | sk->sk_hash = hash; |
192 | BUG_TRAP(sk_unhashed(sk)); | 193 | BUG_TRAP(sk_unhashed(sk)); |
193 | __sk_add_node(sk, &head->chain); | 194 | __sk_add_node(sk, &head->chain); |
194 | sock_prot_inc_use(sk->sk_prot); | 195 | sock_prot_inc_use(sk->sk_prot); |
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index a88db28b0af7..b1a63b2c6b4a 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c | |||
@@ -384,7 +384,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req, | |||
384 | newtp->frto_counter = 0; | 384 | newtp->frto_counter = 0; |
385 | newtp->frto_highmark = 0; | 385 | newtp->frto_highmark = 0; |
386 | 386 | ||
387 | newicsk->icsk_ca_ops = &tcp_reno; | 387 | newicsk->icsk_ca_ops = &tcp_init_congestion_ops; |
388 | 388 | ||
389 | tcp_set_ca_state(newsk, TCP_CA_Open); | 389 | tcp_set_ca_state(newsk, TCP_CA_Open); |
390 | tcp_init_xmit_timers(newsk); | 390 | tcp_init_xmit_timers(newsk); |
diff --git a/net/ipv4/tcp_output.c b/net/ipv4/tcp_output.c index c10e4435e3b1..c5b911f9b662 100644 --- a/net/ipv4/tcp_output.c +++ b/net/ipv4/tcp_output.c | |||
@@ -190,7 +190,7 @@ void tcp_select_initial_window(int __space, __u32 mss, | |||
190 | } | 190 | } |
191 | 191 | ||
192 | /* Set initial window to value enough for senders, | 192 | /* Set initial window to value enough for senders, |
193 | * following RFC1414. Senders, not following this RFC, | 193 | * following RFC2414. Senders, not following this RFC, |
194 | * will be satisfied with 2. | 194 | * will be satisfied with 2. |
195 | */ | 195 | */ |
196 | if (mss > (1<<*rcv_wscale)) { | 196 | if (mss > (1<<*rcv_wscale)) { |
@@ -435,6 +435,8 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss | |||
435 | int nsize, old_factor; | 435 | int nsize, old_factor; |
436 | u16 flags; | 436 | u16 flags; |
437 | 437 | ||
438 | BUG_ON(len >= skb->len); | ||
439 | |||
438 | nsize = skb_headlen(skb) - len; | 440 | nsize = skb_headlen(skb) - len; |
439 | if (nsize < 0) | 441 | if (nsize < 0) |
440 | nsize = 0; | 442 | nsize = 0; |
@@ -459,9 +461,7 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss | |||
459 | flags = TCP_SKB_CB(skb)->flags; | 461 | flags = TCP_SKB_CB(skb)->flags; |
460 | TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH); | 462 | TCP_SKB_CB(skb)->flags = flags & ~(TCPCB_FLAG_FIN|TCPCB_FLAG_PSH); |
461 | TCP_SKB_CB(buff)->flags = flags; | 463 | TCP_SKB_CB(buff)->flags = flags; |
462 | TCP_SKB_CB(buff)->sacked = | 464 | TCP_SKB_CB(buff)->sacked = TCP_SKB_CB(skb)->sacked; |
463 | (TCP_SKB_CB(skb)->sacked & | ||
464 | (TCPCB_LOST | TCPCB_EVER_RETRANS | TCPCB_AT_TAIL)); | ||
465 | TCP_SKB_CB(skb)->sacked &= ~TCPCB_AT_TAIL; | 465 | TCP_SKB_CB(skb)->sacked &= ~TCPCB_AT_TAIL; |
466 | 466 | ||
467 | if (!skb_shinfo(skb)->nr_frags && skb->ip_summed != CHECKSUM_HW) { | 467 | if (!skb_shinfo(skb)->nr_frags && skb->ip_summed != CHECKSUM_HW) { |
@@ -499,11 +499,26 @@ int tcp_fragment(struct sock *sk, struct sk_buff *skb, u32 len, unsigned int mss | |||
499 | tcp_skb_pcount(buff); | 499 | tcp_skb_pcount(buff); |
500 | 500 | ||
501 | tp->packets_out -= diff; | 501 | tp->packets_out -= diff; |
502 | |||
503 | if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_ACKED) | ||
504 | tp->sacked_out -= diff; | ||
505 | if (TCP_SKB_CB(skb)->sacked & TCPCB_SACKED_RETRANS) | ||
506 | tp->retrans_out -= diff; | ||
507 | |||
502 | if (TCP_SKB_CB(skb)->sacked & TCPCB_LOST) { | 508 | if (TCP_SKB_CB(skb)->sacked & TCPCB_LOST) { |
503 | tp->lost_out -= diff; | 509 | tp->lost_out -= diff; |
504 | tp->left_out -= diff; | 510 | tp->left_out -= diff; |
505 | } | 511 | } |
512 | |||
506 | if (diff > 0) { | 513 | if (diff > 0) { |
514 | /* Adjust Reno SACK estimate. */ | ||
515 | if (!tp->rx_opt.sack_ok) { | ||
516 | tp->sacked_out -= diff; | ||
517 | if ((int)tp->sacked_out < 0) | ||
518 | tp->sacked_out = 0; | ||
519 | tcp_sync_left_out(tp); | ||
520 | } | ||
521 | |||
507 | tp->fackets_out -= diff; | 522 | tp->fackets_out -= diff; |
508 | if ((int)tp->fackets_out < 0) | 523 | if ((int)tp->fackets_out < 0) |
509 | tp->fackets_out = 0; | 524 | tp->fackets_out = 0; |