--- v2.4.7/linux/include/net/ip_fib.h Sat Jul 7 12:17:59 2001 +++ linux/include/net/ip_fib.h Wed Aug 1 20:58:50 2001 @@ -203,7 +203,7 @@ extern int inet_rtm_getroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg); extern int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb); extern int fib_validate_source(u32 src, u32 dst, u8 tos, int oif, - struct net_device *dev, u32 *spec_dst, u32 *itag); + struct net_device *dev, u32 *spec_dst, u32 *itag, int our); extern void fib_select_multipath(const struct rt_key *key, struct fib_result *res); /* Exported by fib_semantics.c */ --- v2.4.7/linux/include/linux/inetdevice.h Sat Jul 7 12:19:32 2001 +++ linux/include/linux/inetdevice.h Wed Aug 1 20:58:46 2001 @@ -17,7 +17,9 @@ int forwarding; int mc_forwarding; int tag; + int hidden; int arp_filter; + int forward_shared; void *sysctl; }; @@ -44,6 +46,7 @@ #define IN_DEV_LOG_MARTIANS(in_dev) (ipv4_devconf.log_martians || (in_dev)->cnf.log_martians) #define IN_DEV_PROXY_ARP(in_dev) (ipv4_devconf.proxy_arp || (in_dev)->cnf.proxy_arp) +#define IN_DEV_HIDDEN(in_dev) ((in_dev)->cnf.hidden && ipv4_devconf.hidden) #define IN_DEV_SHARED_MEDIA(in_dev) (ipv4_devconf.shared_media || (in_dev)->cnf.shared_media) #define IN_DEV_TX_REDIRECTS(in_dev) (ipv4_devconf.send_redirects || (in_dev)->cnf.send_redirects) #define IN_DEV_SEC_REDIRECTS(in_dev) (ipv4_devconf.secure_redirects || (in_dev)->cnf.secure_redirects) @@ -56,6 +59,8 @@ (ipv4_devconf.accept_redirects || (in_dev)->cnf.accept_redirects))) #define IN_DEV_ARPFILTER(in_dev) (ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter) + +#define IN_DEV_FORWARD_SHARED(in_dev) ((in_dev)->cnf.forward_shared && ipv4_devconf.forward_shared) struct in_ifaddr { --- v2.4.7/linux/include/linux/sysctl.h Sat Jul 7 12:19:33 2001 +++ linux/include/linux/sysctl.h Wed Aug 1 21:01:33 2001 @@ -325,7 +325,9 @@ NET_IPV4_CONF_BOOTP_RELAY=10, NET_IPV4_CONF_LOG_MARTIANS=11, NET_IPV4_CONF_TAG=12, - NET_IPV4_CONF_ARPFILTER=13 + NET_IPV4_CONF_ARPFILTER=13, + NET_IPV4_CONF_HIDDEN=14, + NET_IPV4_CONF_FORWARD_SHARED=15, }; /* /proc/sys/net/ipv6 */ --- v2.4.7/linux/net/ipv4/arp.c Sat Jul 7 12:19:33 2001 +++ linux/net/ipv4/arp.c Wed Aug 1 20:52:26 2001 @@ -66,6 +66,8 @@ * Alexey Kuznetsov: new arp state machine; * now it is in net/core/neighbour.c. * Krzysztof Halasa: Added Frame Relay ARP support. + * Julian Anastasov: "hidden" flag: hide the + * interface and don't reply for it */ #include @@ -317,12 +319,23 @@ static void arp_solicit(struct neighbour *neigh, struct sk_buff *skb) { u32 saddr; + int from_skb; + struct in_device *in_dev2 = NULL; + struct net_device *dev2 = NULL; u8 *dst_ha = NULL; struct net_device *dev = neigh->dev; u32 target = *(u32*)neigh->primary_key; int probes = atomic_read(&neigh->probes); - if (skb && inet_addr_type(skb->nh.iph->saddr) == RTN_LOCAL) + from_skb = (skb && + (dev2 = ip_dev_find(skb->nh.iph->saddr)) != NULL && + (in_dev2 = in_dev_get(dev2)) != NULL && + !IN_DEV_HIDDEN(in_dev2)); + if (dev2) { + if (in_dev2) in_dev_put(in_dev2); + dev_put(dev2); + } + if (from_skb) saddr = skb->nh.iph->saddr; else saddr = inet_select_addr(dev, target, RT_SCOPE_LINK); @@ -742,9 +755,22 @@ /* Special case: IPv4 duplicate address detection packet (RFC2131) */ if (sip == 0) { - if (arp->ar_op == __constant_htons(ARPOP_REQUEST) && - inet_addr_type(tip) == RTN_LOCAL) + int reply; + struct net_device *dev2 = NULL; + struct in_device *in_dev2 = NULL; + + reply = + (arp->ar_op == __constant_htons(ARPOP_REQUEST) && + (dev2 = ip_dev_find(tip)) != NULL && + (dev2 == dev || + ((in_dev2 = in_dev_get(dev2)) != NULL && + !IN_DEV_HIDDEN(in_dev2)))); + if (dev2) { + if (in_dev2) in_dev_put(in_dev2); + dev_put(dev2); + if (reply) arp_send(ARPOP_REPLY,ETH_P_ARP,tip,dev,tip,sha,dev->dev_addr,dev->dev_addr); + } goto out; } @@ -758,6 +784,21 @@ n = neigh_event_ns(&arp_tbl, sha, &sip, dev); if (n) { int dont_send = 0; + if (ipv4_devconf.hidden && + skb->pkt_type != PACKET_HOST) { + struct net_device *dev2 = NULL; + struct in_device *in_dev2 = NULL; + + dont_send |= + ((dev2 = ip_dev_find(tip)) != NULL && + dev2 != dev && + (in_dev2=in_dev_get(dev2)) != NULL && + IN_DEV_HIDDEN(in_dev2)); + if (dev2) { + if (in_dev2) in_dev_put(in_dev2); + dev_put(dev2); + } + } if (IN_DEV_ARPFILTER(in_dev)) dont_send |= arp_filter(sip,tip,dev); if (!dont_send) --- v2.4.7/linux/net/ipv4/devinet.c Sat Jul 7 12:19:33 2001 +++ linux/net/ipv4/devinet.c Wed Aug 1 21:03:51 2001 @@ -736,7 +736,8 @@ read_lock(&in_dev->lock); for_primary_ifa(in_dev) { - if (ifa->ifa_scope != RT_SCOPE_LINK && + if (!IN_DEV_HIDDEN(in_dev) && + ifa->ifa_scope != RT_SCOPE_LINK && ifa->ifa_scope <= scope) { read_unlock(&in_dev->lock); read_unlock(&inetdev_lock); @@ -1016,7 +1017,7 @@ static struct devinet_sysctl_table { struct ctl_table_header *sysctl_header; - ctl_table devinet_vars[14]; + ctl_table devinet_vars[16]; ctl_table devinet_dev[2]; ctl_table devinet_conf_dir[2]; ctl_table devinet_proto_dir[2]; @@ -1059,8 +1060,14 @@ {NET_IPV4_CONF_TAG, "tag", &ipv4_devconf.tag, sizeof(int), 0644, NULL, &proc_dointvec}, + {NET_IPV4_CONF_HIDDEN, "hidden", + &ipv4_devconf.hidden, sizeof(int), 0644, NULL, + &proc_dointvec}, {NET_IPV4_CONF_ARPFILTER, "arp_filter", &ipv4_devconf.arp_filter, sizeof(int), 0644, NULL, + &proc_dointvec}, + {NET_IPV4_CONF_FORWARD_SHARED, "forward_shared", + &ipv4_devconf.forward_shared, sizeof(int), 0644, NULL, &proc_dointvec}, {0}}, --- v2.4.7/linux/net/ipv4/fib_frontend.c Sat Jul 7 12:20:10 2001 +++ linux/net/ipv4/fib_frontend.c Wed Aug 1 20:58:50 2001 @@ -204,13 +204,15 @@ */ int fib_validate_source(u32 src, u32 dst, u8 tos, int oif, - struct net_device *dev, u32 *spec_dst, u32 *itag) + struct net_device *dev, u32 *spec_dst, u32 *itag, + int our) { struct in_device *in_dev; struct rt_key key; struct fib_result res; int no_addr, rpf; int ret; + int fwdsh = 0; key.dst = src; key.src = dst; @@ -225,6 +227,7 @@ if (in_dev) { no_addr = in_dev->ifa_list == NULL; rpf = IN_DEV_RPFILTER(in_dev); + fwdsh = IN_DEV_FORWARD_SHARED(in_dev); } read_unlock(&inetdev_lock); @@ -233,7 +236,12 @@ if (fib_lookup(&key, &res)) goto last_resort; - if (res.type != RTN_UNICAST) + if (fwdsh) { + fwdsh = (res.type == RTN_LOCAL && !our); + if (fwdsh) + rpf = 0; + } + if (res.type != RTN_UNICAST && !fwdsh) goto e_inval_res; *spec_dst = FIB_RES_PREFSRC(res); fib_combine_itag(itag, &res); @@ -253,6 +261,8 @@ if (rpf) goto e_inval; key.oif = dev->ifindex; + if (fwdsh) + key.iif = loopback_dev.ifindex; ret = 0; if (fib_lookup(&key, &res) == 0) { --- v2.4.7/linux/net/ipv4/route.c Sat Jul 21 09:43:10 2001 +++ linux/net/ipv4/route.c Wed Aug 1 20:58:50 2001 @@ -1244,7 +1244,7 @@ goto e_inval; spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK); } else if (fib_validate_source(saddr, 0, tos, 0, - dev, &spec_dst, &itag) < 0) + dev, &spec_dst, &itag, our) < 0) goto e_inval; rth = dst_alloc(&ipv4_dst_ops); @@ -1408,7 +1408,7 @@ int result; result = fib_validate_source(saddr, daddr, tos, loopback_dev.ifindex, - dev, &spec_dst, &itag); + dev, &spec_dst, &itag, 1); if (result < 0) goto martian_source; if (result) @@ -1435,7 +1435,7 @@ } err = fib_validate_source(saddr, daddr, tos, FIB_RES_OIF(res), dev, - &spec_dst, &itag); + &spec_dst, &itag, 0); if (err < 0) goto martian_source; @@ -1519,7 +1519,7 @@ spec_dst = inet_select_addr(dev, 0, RT_SCOPE_LINK); else { err = fib_validate_source(saddr, 0, tos, 0, dev, &spec_dst, - &itag); + &itag, 1); if (err < 0) goto martian_source; if (err) --- v2.4.7/linux/Documentation/filesystems/proc.txt Sat Jul 7 12:18:36 2001 +++ linux/Documentation/filesystems/proc.txt Wed Aug 1 20:58:50 2001 @@ -1561,6 +1561,18 @@ (external addresses can still be spoofed), without the need for additional firewall rules. +forward_shared +-------------- + +Integer value determines if a source validation should allow forwarding +of packets with local source address. 1 means yes, 0 means no. By default +the flag is disabled and such packets are not forwarded. + +If you enable this flag on internal network, the router will forward +packets from internal hosts with shared IP addresses no matter how +the rp_filter is set. This flag is activated only if it is enabled +both in specific device section and in "all" section. + secure_redirects ---------------- @@ -1577,6 +1589,16 @@ -------------- Determines whether to send ICMP redirects to other hosts. + +hidden +------ + +Hide addresses attached to this device from another devices. +Such addresses will never be selected by source address autoselection +mechanism, host does not answer broadcast ARP requests for them, +does not announce it as source address of ARP requests, but they +are still reachable via IP. This flag is activated only if it is +enabled both in specific device section and in "all" section. Routing settings ---------------- --- v2.4.7/linux/Documentation/networking/ip-sysctl.txt Sat Jul 7 12:19:14 2001 +++ linux/Documentation/networking/ip-sysctl.txt Wed Aug 1 20:58:50 2001 @@ -347,6 +347,17 @@ forwarding - BOOLEAN Enable IP forwarding on this interface. +forward_shared - BOOLEAN + Integer value determines if a source validation should allow + forwarding of packets with local source address. 1 means yes, + 0 means no. By default the flag is disabled and such packets + are not forwarded. + + If you enable this flag on internal network, the router will forward + packets from internal hosts with shared IP addresses no matter how + the rp_filter is set. This flag is activated only if it is + enabled both in specific device section and in "all" section. + mc_forwarding - BOOLEAN Do multicast routing. The kernel needs to be compiled with CONFIG_MROUTE and a multicast routing daemon is required. @@ -391,6 +402,14 @@ Default value is 0. Note that some distributions enable it in startip scripts. + +hidden - BOOLEAN + Hide addresses attached to this device from another devices. + Such addresses will never be selected by source address autoselection + mechanism, host does not answer broadcast ARP requests for them, + does not announce it as source address of ARP requests, but they + are still reachable via IP. This flag is activated only if it is + enabled both in specific device section and in "all" section. Alexey Kuznetsov. kuznet@ms2.inr.ac.ru