@@ -2047,6 +2047,49 @@ static int ipset_entry_notify_owner(int command, struct zclient *zclient,
2047
2047
return 0 ;
2048
2048
}
2049
2049
2050
+ static int iptable_notify_owner (int command , struct zclient * zclient ,
2051
+ zebra_size_t length , vrf_id_t vrf_id )
2052
+ {
2053
+ uint32_t unique ;
2054
+ enum zapi_iptable_notify_owner note ;
2055
+ struct bgp_pbr_match * bgpm ;
2056
+
2057
+ if (!zapi_iptable_notify_decode (
2058
+ zclient -> ibuf ,
2059
+ & unique ,
2060
+ & note ))
2061
+ return -1 ;
2062
+ bgpm = bgp_pbr_match_iptable_lookup (vrf_id , unique );
2063
+ if (!bgpm ) {
2064
+ if (BGP_DEBUG (zebra , ZEBRA ))
2065
+ zlog_debug ("%s: Fail to look BGP iptable (%u)" ,
2066
+ __PRETTY_FUNCTION__ , unique );
2067
+ return 0 ;
2068
+ }
2069
+ switch (note ) {
2070
+ case ZAPI_IPTABLE_FAIL_INSTALL :
2071
+ if (BGP_DEBUG (zebra , ZEBRA ))
2072
+ zlog_debug ("%s: Received IPTABLE_FAIL_INSTALL" ,
2073
+ __PRETTY_FUNCTION__ );
2074
+ bgpm -> installed_in_iptable = false;
2075
+ bgpm -> install_iptable_in_progress = false;
2076
+ break ;
2077
+ case ZAPI_IPTABLE_INSTALLED :
2078
+ bgpm -> installed_in_iptable = true;
2079
+ bgpm -> install_iptable_in_progress = false;
2080
+ if (BGP_DEBUG (zebra , ZEBRA ))
2081
+ zlog_debug ("%s: Received IPTABLE_INSTALLED" ,
2082
+ __PRETTY_FUNCTION__ );
2083
+ break ;
2084
+ case ZAPI_IPTABLE_REMOVED :
2085
+ if (BGP_DEBUG (zebra , ZEBRA ))
2086
+ zlog_debug ("%s: Received IPTABLE REMOVED" ,
2087
+ __PRETTY_FUNCTION__ );
2088
+ break ;
2089
+ }
2090
+ return 0 ;
2091
+ }
2092
+
2050
2093
static void bgp_encode_pbr_rule_action (struct stream * s ,
2051
2094
struct bgp_pbr_action * pbra )
2052
2095
{
@@ -2107,6 +2150,29 @@ static void bgp_encode_pbr_ipset_entry_match(struct stream *s,
2107
2150
stream_put (s , & pbime -> dst .u .prefix , prefix_blen (& pbime -> dst ));
2108
2151
}
2109
2152
2153
+ static void bgp_encode_pbr_iptable_match (struct stream * s ,
2154
+ struct bgp_pbr_action * bpa ,
2155
+ struct bgp_pbr_match * pbm )
2156
+ {
2157
+ stream_putl (s , pbm -> unique2 );
2158
+
2159
+ stream_putl (s , pbm -> type );
2160
+
2161
+ stream_putl (s , pbm -> flags );
2162
+
2163
+ /* TODO: correlate with what is contained
2164
+ * into bgp_pbr_action.
2165
+ * currently only forward supported
2166
+ */
2167
+ if (bpa -> nh .type == NEXTHOP_TYPE_BLACKHOLE )
2168
+ stream_putl (s , ZEBRA_IPTABLES_DROP );
2169
+ else
2170
+ stream_putl (s , ZEBRA_IPTABLES_FORWARD );
2171
+ stream_putl (s , bpa -> fwmark );
2172
+ stream_put (s , pbm -> ipset_name ,
2173
+ ZEBRA_IPSET_NAME_SIZE );
2174
+ }
2175
+
2110
2176
/* BGP has established connection with Zebra. */
2111
2177
static void bgp_zebra_connected (struct zclient * zclient )
2112
2178
{
@@ -2369,6 +2435,7 @@ void bgp_zebra_init(struct thread_master *master)
2369
2435
zclient -> rule_notify_owner = rule_notify_owner ;
2370
2436
zclient -> ipset_notify_owner = ipset_notify_owner ;
2371
2437
zclient -> ipset_entry_notify_owner = ipset_entry_notify_owner ;
2438
+ zclient -> iptable_notify_owner = iptable_notify_owner ;
2372
2439
}
2373
2440
2374
2441
void bgp_zebra_destroy (void )
@@ -2459,3 +2526,28 @@ void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry *pbrime,
2459
2526
if (!zclient_send_message (zclient ) && install )
2460
2527
pbrime -> install_in_progress = true;
2461
2528
}
2529
+
2530
+ void bgp_send_pbr_iptable (struct bgp_pbr_action * pba ,
2531
+ struct bgp_pbr_match * pbm ,
2532
+ bool install )
2533
+ {
2534
+ struct stream * s ;
2535
+
2536
+ if (pbm -> install_iptable_in_progress )
2537
+ return ;
2538
+ zlog_debug ("%s: name %s type %d mark %d %d" , __PRETTY_FUNCTION__ ,
2539
+ pbm -> ipset_name , pbm -> type , pba -> fwmark , install );
2540
+ s = zclient -> obuf ;
2541
+ stream_reset (s );
2542
+
2543
+ zclient_create_header (s ,
2544
+ install ? ZEBRA_IPTABLE_ADD :
2545
+ ZEBRA_IPTABLE_DELETE ,
2546
+ VRF_DEFAULT );
2547
+
2548
+ bgp_encode_pbr_iptable_match (s , pba , pbm );
2549
+
2550
+ stream_putw_at (s , 0 , stream_get_endp (s ));
2551
+ if (!zclient_send_message (zclient ) && install )
2552
+ pbm -> install_iptable_in_progress = true;
2553
+ }
0 commit comments