@@ -111,7 +111,7 @@ use crate::switch_port::FixedSideDevice;
111111use crate :: switch_port:: LedState ;
112112use crate :: transceivers:: PowerState ;
113113use crate :: types:: DpdError ;
114- use crate :: { Switch , arp, loopback, nat , ports, route} ;
114+ use crate :: { Switch , arp, loopback, ports, route} ;
115115use common:: attached_subnet:: AttachedSubnetEntry ;
116116use common:: nat:: { Ipv4Nat , Ipv6Nat } ;
117117use common:: network:: { InstanceTarget , MacAddr , NatTarget } ;
@@ -1422,8 +1422,7 @@ impl DpdApi for DpdApiImpl {
14221422 WhichPage :: Next ( Ipv6Token { ip } ) => Some ( * ip) ,
14231423 } ;
14241424
1425- let entries = nat:: get_ipv6_addrs_range (
1426- switch,
1425+ let entries = switch. nat . get_addrs_range (
14271426 last_addr,
14281427 usize:: try_from ( max) . expect ( "invalid usize" ) ,
14291428 ) ;
@@ -1449,8 +1448,7 @@ impl DpdApi for DpdApiImpl {
14491448 WhichPage :: Next ( NatToken { port } ) => Some ( * port) ,
14501449 } ;
14511450
1452- let entries = nat:: get_ipv6_mappings_range (
1453- switch,
1451+ let entries = switch. nat . get_mappings_range (
14541452 params. ipv6 ,
14551453 port,
14561454 usize:: try_from ( max) . expect ( "invalid usize" ) ,
@@ -1469,8 +1467,7 @@ impl DpdApi for DpdApiImpl {
14691467 ) -> Result < HttpResponseOk < NatTarget > , HttpError > {
14701468 let switch: & Switch = rqctx. context ( ) ;
14711469 let params = path. into_inner ( ) ;
1472- match nat:: get_ipv6_mapping ( switch, params. ipv6 , params. low , params. low )
1473- {
1470+ match switch. nat . get_mapping ( params. ipv6 , params. low , params. low ) {
14741471 Ok ( tgt) => Ok ( HttpResponseOk ( tgt) ) ,
14751472 Err ( e) => Err ( e. into ( ) ) ,
14761473 }
@@ -1483,7 +1480,7 @@ impl DpdApi for DpdApiImpl {
14831480 ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
14841481 let switch: & Switch = rqctx. context ( ) ;
14851482 let params = path. into_inner ( ) ;
1486- match nat:: set_ipv6_mapping (
1483+ match switch . nat . add_mapping (
14871484 switch,
14881485 params. ipv6 ,
14891486 params. low ,
@@ -1501,7 +1498,9 @@ impl DpdApi for DpdApiImpl {
15011498 ) -> Result < HttpResponseDeleted , HttpError > {
15021499 let switch: & Switch = rqctx. context ( ) ;
15031500 let params = path. into_inner ( ) ;
1504- nat:: clear_ipv6_mapping ( switch, params. ipv6 , params. low , params. low )
1501+ switch
1502+ . nat
1503+ . remove_mapping ( switch, params. ipv6 , params. low , params. low )
15051504 . map ( |_| HttpResponseDeleted ( ) )
15061505 . map_err ( HttpError :: from)
15071506 }
@@ -1511,7 +1510,7 @@ impl DpdApi for DpdApiImpl {
15111510 ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
15121511 let switch: & Switch = rqctx. context ( ) ;
15131512
1514- match nat:: reset_ipv6 ( switch) {
1513+ match switch . nat . reset :: < Ipv6Addr > ( switch) {
15151514 Ok ( _) => Ok ( HttpResponseUpdatedNoContent ( ) ) ,
15161515 Err ( e) => Err ( e. into ( ) ) ,
15171516 }
@@ -1530,8 +1529,7 @@ impl DpdApi for DpdApiImpl {
15301529 WhichPage :: Next ( Ipv4Token { ip } ) => Some ( * ip) ,
15311530 } ;
15321531
1533- let entries = nat:: get_ipv4_addrs_range (
1534- switch,
1532+ let entries = switch. nat . get_addrs_range (
15351533 last_addr,
15361534 usize:: try_from ( max) . expect ( "invalid usize" ) ,
15371535 ) ;
@@ -1558,8 +1556,7 @@ impl DpdApi for DpdApiImpl {
15581556 WhichPage :: Next ( NatToken { port } ) => Some ( * port) ,
15591557 } ;
15601558
1561- let entries = nat:: get_ipv4_mappings_range (
1562- switch,
1559+ let entries = switch. nat . get_mappings_range (
15631560 params. ipv4 ,
15641561 port,
15651562 usize:: try_from ( max) . expect ( "invalid usize" ) ,
@@ -1578,8 +1575,7 @@ impl DpdApi for DpdApiImpl {
15781575 ) -> Result < HttpResponseOk < NatTarget > , HttpError > {
15791576 let switch: & Switch = rqctx. context ( ) ;
15801577 let params = path. into_inner ( ) ;
1581- match nat:: get_ipv4_mapping ( switch, params. ipv4 , params. low , params. low )
1582- {
1578+ match switch. nat . get_mapping ( params. ipv4 , params. low , params. low ) {
15831579 Ok ( tgt) => Ok ( HttpResponseOk ( tgt) ) ,
15841580 Err ( e) => Err ( e. into ( ) ) ,
15851581 }
@@ -1592,7 +1588,7 @@ impl DpdApi for DpdApiImpl {
15921588 ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
15931589 let switch: & Switch = rqctx. context ( ) ;
15941590 let params = path. into_inner ( ) ;
1595- match nat:: set_ipv4_mapping (
1591+ match switch . nat . add_mapping (
15961592 switch,
15971593 params. ipv4 ,
15981594 params. low ,
@@ -1610,7 +1606,9 @@ impl DpdApi for DpdApiImpl {
16101606 ) -> Result < HttpResponseDeleted , HttpError > {
16111607 let switch: & Switch = rqctx. context ( ) ;
16121608 let params = path. into_inner ( ) ;
1613- nat:: clear_ipv4_mapping ( switch, params. ipv4 , params. low , params. low )
1609+ switch
1610+ . nat
1611+ . remove_mapping ( switch, params. ipv4 , params. low , params. low )
16141612 . map ( |_| HttpResponseDeleted ( ) )
16151613 . map_err ( HttpError :: from)
16161614 }
@@ -1620,7 +1618,7 @@ impl DpdApi for DpdApiImpl {
16201618 ) -> Result < HttpResponseUpdatedNoContent , HttpError > {
16211619 let switch: & Switch = rqctx. context ( ) ;
16221620
1623- match nat:: reset_ipv4 ( switch) {
1621+ match switch . nat . reset :: < Ipv4Addr > ( switch) {
16241622 Ok ( _) => Ok ( HttpResponseUpdatedNoContent ( ) ) ,
16251623 Err ( e) => Err ( e. into ( ) ) ,
16261624 }
@@ -1744,11 +1742,11 @@ impl DpdApi for DpdApiImpl {
17441742 error ! ( switch. log, "failed to clear all link state: {:?}" , e) ;
17451743 err = Some ( e) ;
17461744 }
1747- if let Err ( e) = nat:: reset_ipv4 ( switch) {
1745+ if let Err ( e) = switch . nat . reset :: < Ipv4Addr > ( switch) {
17481746 error ! ( switch. log, "failed to reset ipv4 nat table: {:?}" , e) ;
17491747 err = Some ( e) ;
17501748 }
1751- if let Err ( e) = nat:: reset_ipv6 ( switch) {
1749+ if let Err ( e) = switch . nat . reset :: < Ipv6Addr > ( switch) {
17521750 error ! ( switch. log, "failed to reset ipv6 nat table: {:?}" , e) ;
17531751 err = Some ( e) ;
17541752 }
@@ -1913,7 +1911,7 @@ impl DpdApi for DpdApiImpl {
19131911 ) -> Result < HttpResponseOk < i64 > , HttpError > {
19141912 let switch = rqctx. context ( ) ;
19151913
1916- Ok ( HttpResponseOk ( nat:: get_nat_generation ( switch ) ) )
1914+ Ok ( HttpResponseOk ( switch . nat . generation ( ) ) )
19171915 }
19181916
19191917 async fn nat_trigger_update (
0 commit comments