+ if (!ip_is_zero (&tc->lcl_ip, 1))
+ {
+ ip_copy (&lcl_pref.fp_addr, &tc->lcl_ip, is_ip4);
+ lcl_pref.fp_len = is_ip4 ? 32 : 128;
+ lcl_pref.fp_proto = fib_proto;
+ memset (&rmt_pref.fp_addr, 0, sizeof (rmt_pref.fp_addr));
+ rmt_pref.fp_len = 0;
+ rmt_pref.fp_proto = fib_proto;
+
+ args.table_args.lcl = lcl_pref;
+ args.table_args.rmt = rmt_pref;
+ args.table_args.lcl_port = 0;
+ args.table_args.rmt_port = 0;
+ args.table_args.action_index = app->index;
+ args.table_args.is_add = is_start;
+ args.table_args.transport_proto = transport_proto;
+ args.appns_index = app->ns_index;
+ args.scope = SESSION_RULE_SCOPE_GLOBAL;
+ return vnet_session_rule_add_del (&args);
+ }
+ return 0;
+}
+
+void
+application_start_stop_proxy (application_t * app, u8 transport_proto,
+ u8 is_start)
+{
+ session_rule_add_del_args_t args;
+
+ if (application_has_local_scope (app))
+ {
+ memset (&args, 0, sizeof (args));
+ args.table_args.lcl.fp_proto = FIB_PROTOCOL_IP4;
+ args.table_args.rmt.fp_proto = FIB_PROTOCOL_IP4;
+ args.table_args.lcl_port = 0;
+ args.table_args.rmt_port = 0;
+ args.table_args.action_index = app->index;
+ args.table_args.is_add = is_start;
+ args.table_args.transport_proto = transport_proto;
+ args.appns_index = app->ns_index;
+ args.scope = SESSION_RULE_SCOPE_LOCAL;
+ vnet_session_rule_add_del (&args);
+
+ args.table_args.lcl.fp_proto = FIB_PROTOCOL_IP6;
+ args.table_args.rmt.fp_proto = FIB_PROTOCOL_IP6;
+ vnet_session_rule_add_del (&args);
+ }
+
+ if (application_has_global_scope (app))
+ {
+ application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP4,
+ transport_proto, is_start);
+ application_start_stop_proxy_fib_proto (app, FIB_PROTOCOL_IP6,
+ transport_proto, is_start);
+ }
+}
+
+void
+application_setup_proxy (application_t * app)
+{
+ u16 transports = app->proxied_transports;
+ ASSERT (application_is_proxy (app));
+ if (application_is_builtin (app))
+ return;
+ if (transports & (1 << TRANSPORT_PROTO_TCP))
+ application_start_stop_proxy (app, TRANSPORT_PROTO_TCP, 1);
+ if (transports & (1 << TRANSPORT_PROTO_UDP))
+ application_start_stop_proxy (app, TRANSPORT_PROTO_UDP, 1);
+}
+
+void
+application_remove_proxy (application_t * app)
+{
+ u16 transports = app->proxied_transports;
+ ASSERT (application_is_proxy (app));
+ if (transports & (1 << TRANSPORT_PROTO_TCP))
+ application_start_stop_proxy (app, TRANSPORT_PROTO_TCP, 0);
+ if (transports & (1 << TRANSPORT_PROTO_UDP))
+ application_start_stop_proxy (app, TRANSPORT_PROTO_UDP, 0);