diff -purN a/filter/filter.c b/filter/filter.c
--- a/filter/filter.c	2013-08-10 10:57:35.000000000 +0300
+++ b/filter/filter.c	2013-08-13 07:04:22.250446757 +0300
@@ -853,10 +853,18 @@ interpret(struct f_inst *what)
     f_rta_cow();
     {
       struct rta *rta = (*f_rte)->attrs;
+      ip_addr ip;
+
       switch (what->aux) {
 
       case T_IP:
-	* (ip_addr *) ((char *) rta + what->a2.i) = v1.val.px.ip;
+        ip = v1.val.px.ip;
+	/* "gw" attribute? */
+	if (what->a2.i == OFFSETOF(struct rta, gw))
+	  rta_set_recursive_next_hop(rta->proto->table, rta,
+				     get_igp_table(rta->proto->cf), &ip, &ip);
+	else
+	  * (ip_addr *) ((char *) rta + what->a2.i) = ip;
 	break;
 
       case T_ENUM_SCOPE:
diff -purN a/nest/proto.c b/nest/proto.c
--- a/nest/proto.c	2013-08-10 10:57:35.000000000 +0300
+++ b/nest/proto.c	2013-08-13 09:19:59.999415710 +0300
@@ -1379,3 +1379,25 @@ proto_get_named(struct symbol *sym, cons
     }
   return p;
 }
+
+#if defined(CONFIG_STATIC) || defined(CONFIG_BGP)
+struct rtable *
+get_igp_table(const struct proto_config *pcf)
+{
+#ifdef CONFIG_STATIC
+	extern struct rtable *
+	static_get_igp_table(const struct proto_config *pcf);
+
+	if (pcf->protocol == &proto_static)
+		return static_get_igp_table(pcf);
+#endif
+#ifdef CONFIG_BGP
+	extern struct rtable *
+	bgp_get_igp_table(const struct proto_config *pcf);
+
+	if (pcf->protocol == &proto_bgp)
+		return bgp_get_igp_table(pcf);
+#endif
+	return pcf->table->table;
+}
+#endif
diff -purN a/nest/protocol.h b/nest/protocol.h
--- a/nest/protocol.h	2013-08-10 10:57:35.000000000 +0300
+++ b/nest/protocol.h	2013-08-13 09:19:19.257707503 +0300
@@ -413,7 +413,22 @@ proto_reset_limit(struct proto_limit *l)
     l->state = PLS_INITIAL;
 }
 
- 
+/*
+ *	Protocols igp table handing
+ */
+
+#if defined(CONFIG_STATIC) || defined(CONFIG_BGP)
+struct rtable *
+get_igp_table(const struct proto_config *pcf);
+#else
+static inline struct rtable *
+get_igp_table(const struct proto_config *pcf)
+{
+	return pcf->table->table;
+}
+#endif
+
+
 /*
  *	Route Announcement Hook
  */
diff -purN a/proto/bgp/bgp.c b/proto/bgp/bgp.c
--- a/proto/bgp/bgp.c	2013-08-10 10:57:35.000000000 +0300
+++ b/proto/bgp/bgp.c	2013-08-12 21:53:27.000000000 +0300
@@ -922,9 +922,10 @@ bgp_cleanup(struct proto *P)
   rt_unlock_table(p->igp_table);
 }
 
-static rtable *
-get_igp_table(struct bgp_config *cf)
+rtable *
+bgp_get_igp_table(const struct proto_config *pcf)
 {
+  const struct bgp_config *cf = (void *) pcf;
   return cf->igp_table ? cf->igp_table->table : cf->c.table->table;
 }
 
@@ -951,7 +952,7 @@ bgp_init(struct proto_config *C)
   p->is_internal = (c->local_as == c->remote_as);
   p->rs_client = c->rs_client;
   p->rr_client = c->rr_client;
-  p->igp_table = get_igp_table(c);
+  p->igp_table = bgp_get_igp_table((const struct proto_config *) c);
 
   return P;
 }
@@ -1029,7 +1030,8 @@ bgp_reconfigure(struct proto *P, struct
 		     OFFSETOF(struct bgp_config, password) - sizeof(struct proto_config))
     && ((!old->password && !new->password)
 	|| (old->password && new->password && !strcmp(old->password, new->password)))
-    && (get_igp_table(old) == get_igp_table(new));
+    && (bgp_get_igp_table((const struct proto_config *) old) ==
+        bgp_get_igp_table((const struct proto_config *) new));
 
   /* We should update our copy of configuration ptr as old configuration will be freed */
   if (same)
diff -purN a/proto/static/static.c b/proto/static/static.c
--- a/proto/static/static.c	2013-08-10 10:57:35.000000000 +0300
+++ b/proto/static/static.c	2013-08-12 21:53:27.000000000 +0300
@@ -47,14 +47,13 @@
 
 #include "static.h"
 
-static inline rtable *
-p_igp_table(const struct proto *p)
+rtable *
+static_get_igp_table(const struct proto_config *pcf)
 {
-  struct static_config *cf = (void *) p->cf;
-  return cf->igp_table ? cf->igp_table->table : p->table;
+  const struct static_config *cf = (void *) pcf;
+  return cf->igp_table ? cf->igp_table->table : cf->c.table->table;
 }
 
-
 static void
 static_install(struct proto *p, struct static_route *r, struct iface *ifa)
 {
@@ -106,7 +105,8 @@ static_install(struct proto *p, struct s
     }
 
   if (r->dest == RTDX_RECURSIVE)
-    rta_set_recursive_next_hop(p->table, &a, p_igp_table(p), &r->via, &r->via);
+    rta_set_recursive_next_hop(p->table, &a, static_get_igp_table(p->cf),
+			       &r->via, &r->via);
 
   aa = rta_lookup(&a);
   n = net_get(p->table, r->net, r->masklen);
