@@ -16,6 +16,7 @@ use alloc::string::String;
16
16
use alloc:: string:: ToString ;
17
17
use alloc:: sync:: Arc ;
18
18
use bitflags:: bitflags;
19
+ use ingot:: ip:: IpProtocol ;
19
20
use core:: ffi:: CStr ;
20
21
use core:: fmt;
21
22
use core:: mem:: MaybeUninit ;
@@ -616,7 +617,7 @@ impl OffloadInfo {
616
617
pub struct MacFlowDesc {
617
618
mask : flow_mask_t ,
618
619
ip_ver : Option < u8 > ,
619
- proto : Option < opte_core :: ip4 :: Protocol > ,
620
+ proto : Option < IpProtocol > ,
620
621
local_port : Option < u16 > ,
621
622
}
622
623
@@ -647,7 +648,7 @@ impl MacFlowDesc {
647
648
self
648
649
}
649
650
650
- pub fn set_proto ( & mut self , proto : opte_core :: ip4 :: Protocol ) -> & mut Self {
651
+ pub fn set_proto ( & mut self , proto : IpProtocol ) -> & mut Self {
651
652
self . mask |= FLOW_IP_PROTOCOL ;
652
653
self . proto = Some ( proto) ;
653
654
self
@@ -663,18 +664,18 @@ impl MacFlowDesc {
663
664
flow_desc_t:: from ( self . clone ( ) )
664
665
}
665
666
666
- pub fn new_flow < ' a > (
667
+ pub fn new_flow < ' a , P > (
667
668
& ' a self ,
668
669
flow_name : & ' a str ,
669
670
link_id : LinkId ,
670
- ) -> Result < MacFlow , FlowCreateError > {
671
+ ) -> Result < MacFlow < P > , FlowCreateError > {
671
672
let name = CString :: new ( flow_name)
672
673
. map_err ( |_| FlowCreateError :: InvalidFlowName ( flow_name) ) ?;
673
674
let desc = self . to_desc ( ) ;
674
675
675
676
match unsafe {
676
677
mac_link_flow_add (
677
- link_id. 0 ,
678
+ link_id. into ( ) ,
678
679
name. as_ptr ( ) ,
679
680
& desc,
680
681
& MAC_RESOURCE_PROPS_DEF ,
@@ -686,7 +687,7 @@ impl MacFlowDesc {
686
687
687
688
let mut flent = ptr:: null_mut ( ) ;
688
689
match unsafe { mac_flow_lookup_byname ( name. as_ptr ( ) , & mut flent) } {
689
- 0 => Ok ( MacFlow { name, flent, cb_mch : None } ) ,
690
+ 0 => Ok ( MacFlow { name, flent, parent : None } ) ,
690
691
err => Err ( FlowCreateError :: CreateFailed ( flow_name, err) ) ,
691
692
}
692
693
}
@@ -700,7 +701,7 @@ impl From<MacFlowDesc> for flow_desc_t {
700
701
// The mac flow subsystem uses 0 as sentinel to indicate no
701
702
// filtering on protocol.
702
703
let fd_protocol = match mf. proto {
703
- Some ( p) => p as u8 ,
704
+ Some ( p) => p. 0 ,
704
705
None => 0 ,
705
706
} ;
706
707
@@ -773,7 +774,6 @@ impl<P> MacFlow<P> {
773
774
new_fn : mac_rx_fn ,
774
775
parent : Arc < P > ,
775
776
) {
776
- let mch = cb_mch. clone ( ) ;
777
777
let parent = Arc :: into_raw ( parent) ;
778
778
let arg = parent as * mut c_void ;
779
779
@@ -791,12 +791,12 @@ impl<P> MacFlow<P> {
791
791
// flow_cb_pre_srs(self.flent, new_fn);
792
792
flow_cb_post_srs ( self . flent , new_fn, arg) ;
793
793
}
794
- self . cb_mch = Some ( mch ) ;
794
+ self . parent = Some ( parent ) ;
795
795
}
796
796
}
797
797
798
798
/// Insert a flow callback which replaces `mac_rx_srs_subflow_process`.
799
- #[ no_mangle]
799
+ #[ unsafe ( no_mangle) ]
800
800
pub unsafe fn flow_cb_pre_srs ( flent : * mut flow_entry_t , new_fn : mac_rx_fn ) {
801
801
// TODO: locks, negative handling, ...
802
802
( * flent) . fe_cb_fn = new_fn;
@@ -806,7 +806,7 @@ pub unsafe fn flow_cb_pre_srs(flent: *mut flow_entry_t, new_fn: mac_rx_fn) {
806
806
///
807
807
/// This will usually replace `mac_rx_deliver`, which will call into the mac_rx
808
808
/// callback on the *parent device* (i.e., i_dls_link_rx).
809
- #[ no_mangle]
809
+ #[ unsafe ( no_mangle) ]
810
810
pub unsafe fn flow_cb_post_srs (
811
811
flent : * mut flow_entry_t ,
812
812
new_fn : mac_rx_fn ,
@@ -834,14 +834,14 @@ unsafe fn flow_user_refrele(flent: *mut flow_entry_t) {
834
834
mutex_exit ( & mut ( * flent) . fe_lock ) ;
835
835
}
836
836
837
- impl Drop for MacFlow {
837
+ impl < P > Drop for MacFlow < P > {
838
838
fn drop ( & mut self ) {
839
839
unsafe {
840
840
// TODO: need to reimplement FLOW_USER_REFRELE in here...
841
841
flow_user_refrele ( self . flent ) ;
842
842
mac_link_flow_remove ( self . name . as_ptr ( ) ) ;
843
843
if let Some ( parent) = self . parent {
844
- Arc :: from_raw ( self . parent ) ; // dropped immediately
844
+ Arc :: from_raw ( parent) ; // dropped immediately
845
845
}
846
846
}
847
847
}
0 commit comments