Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mod driver; is not public #16

Closed
kgv opened this issue Jan 9, 2024 · 3 comments · Fixed by #18
Closed

mod driver; is not public #16

kgv opened this issue Jan 9, 2024 · 3 comments · Fixed by #18

Comments

@kgv
Copy link
Contributor

kgv commented Jan 9, 2024

Is there any reason why mod driver; is not public?
StaticFilter is not available without it.

This will make the code less verbose:

filter_table.static_filters[1].adapter_handle = 0; // applied to all adapters
filter_table.static_filters[1].valid_fields = FilterLayerFlags::empty();
filter_table.static_filters[1].filter_action = FILTER_PACKET_PASS;
filter_table.static_filters[1].direction_flags = DirectionFlags::PACKET_FLAG_ON_RECEIVE | DirectionFlags::PACKET_FLAG_ON_SEND;
wiresock added a commit that referenced this issue Jan 9, 2024
wiresock added a commit that referenced this issue Jan 9, 2024
@wiresock
Copy link
Owner

wiresock commented Jan 9, 2024

Thank you for highlighting this. Our initial intention was to selectively re-export essential structures and functions from ndisapi, rather than setting everything to public. Following this approach, I've now re-exported StaticFilter. Your input is valuable to us, so if you have any further ideas or suggestions, I would greatly appreciate your contributions.

P.S. Please note that there are currently some ongoing issues with GitHub Actions, which may delay the publication of the new release. I'll make sure to update and publish it as soon as these issues are resolved. Thank you for your patience and understanding.

@kgv
Copy link
Contributor Author

kgv commented Jan 9, 2024

@wiresock Thank you for such a prompt response.
In my opinion all internal data structures that are used inside StaticFilterTable should be reexported.
IpAddressV4, IpAddressV4Union, IpSubnetV4, IpV4Filter, NetworkLayerFilter, NetworkLayerFilterUnion, PortRange, StaticFilter, TcpUdpFilter, TransportLayerFilter, TransportLayerFilterUnion, ...

With public filters (less repetition):

filter_table.static_filters[1] = StaticFilter {
    adapter_handle: 0, // applied to all adapters
    valid_fields: FilterLayerFlags::NETWORK_LAYER_VALID
        | FilterLayerFlags::TRANSPORT_LAYER_VALID,
    filter_action: FILTER_PACKET_DROP,
    direction_flags: DirectionFlags::PACKET_FLAG_ON_SEND,
    // Network layer filter
    network_filter: NetworkLayerFilter {
        union_selector: IPV4,
        network_layer: NetworkLayerFilterUnion {
            ipv4: IpV4Filter {
                valid_fields: IpV4FilterFlags::IP_V4_FILTER_PROTOCOL
                    | IpV4FilterFlags::IP_V4_FILTER_DEST_ADDRESS,
                dest_address: IpAddressV4 {
                    address_type: IP_SUBNET_V4_TYPE,
                    address: IpAddressV4Union {
                        ip_subnet: IpSubnetV4 {
                            ip: IN_ADDR {
                                S_un: IN_ADDR_0 {
                                    S_un_b: IN_ADDR_0_0 {
                                        s_b1: 95,
                                        s_b2: 179,
                                        s_b3: 146,
                                        s_b4: 125,
                                    },
                                },
                            },
                            ip_mask: IN_ADDR {
                                S_un: IN_ADDR_0 {
                                    S_un_b: IN_ADDR_0_0 {
                                        s_b1: 255,
                                        s_b2: 255,
                                        s_b3: 255,
                                        s_b4: 255,
                                    },
                                },
                            },
                        },
                    },
                },
                protocol: IPPROTO_TCP,
                ..Default::default()
            },
        },
        ..Default::default()
    },
    // Transport layer filter
    transport_filter: TransportLayerFilter {
        union_selector: TCPUDP,
        transport_layer: TransportLayerFilterUnion {
            tcp_udp: TcpUdpFilter {
                valid_fields: TcpUdpFilterFlags::TCPUDP_DEST_PORT,
                dest_port: PortRange {
                    start_range: 443,
                    end_range: 443,
                },
                ..Default::default()
            },
        },
    },
    ..Default::default()
};

Without public filters (from filter.rs example):

    filter_table.static_filters[0].adapter_handle = 0; // applied to all adapters
    filter_table.static_filters[0].valid_fields =
        FilterLayerFlags::NETWORK_LAYER_VALID | FilterLayerFlags::TRANSPORT_LAYER_VALID;
    filter_table.static_filters[0].filter_action = FILTER_PACKET_DROP;
    filter_table.static_filters[0].direction_flags = DirectionFlags::PACKET_FLAG_ON_SEND;

    // Network layer filter
    let address = IN_ADDR {
        S_un: IN_ADDR_0 {
            S_un_b: IN_ADDR_0_0 {
                s_b1: 95,
                s_b2: 179,
                s_b3: 146,
                s_b4: 125,
            },
        },
    };

    let mask = IN_ADDR {
        S_un: IN_ADDR_0 {
            S_un_b: IN_ADDR_0_0 {
                s_b1: 255,
                s_b2: 255,
                s_b3: 255,
                s_b4: 255,
            },
        },
    };

    filter_table.static_filters[0].network_filter.union_selector = IPV4;
    filter_table.static_filters[0]
        .network_filter
        .network_layer
        .ipv4
        .valid_fields =
        IpV4FilterFlags::IP_V4_FILTER_PROTOCOL | IpV4FilterFlags::IP_V4_FILTER_DEST_ADDRESS;
    filter_table.static_filters[0]
        .network_filter
        .network_layer
        .ipv4
        .dest_address
        .address_type = IP_SUBNET_V4_TYPE;
    filter_table.static_filters[0]
        .network_filter
        .network_layer
        .ipv4
        .dest_address
        .address
        .ip_subnet
        .ip = address; // IP address
    filter_table.static_filters[0]
        .network_filter
        .network_layer
        .ipv4
        .dest_address
        .address
        .ip_subnet
        .ip_mask = mask; // network mask
    filter_table.static_filters[0]
        .network_filter
        .network_layer
        .ipv4
        .protocol = IPPROTO_TCP;

    // Transport layer filter
    filter_table.static_filters[0]
        .transport_filter
        .union_selector = TCPUDP;
    filter_table.static_filters[0]
        .transport_filter
        .transport_layer
        .tcp_udp
        .valid_fields = TcpUdpFilterFlags::TCPUDP_DEST_PORT;
    filter_table.static_filters[0]
        .transport_filter
        .transport_layer
        .tcp_udp
        .dest_port
        .start_range = 443; // HTTPS
    filter_table.static_filters[0]
        .transport_filter
        .transport_layer
        .tcp_udp
        .dest_port
        .end_range = 443;

@wiresock
Copy link
Owner

wiresock commented Jan 9, 2024

Would you be willing to create a pull request incorporating all the aforementioned changes? As soon as GitHub resolves the current issues it's experiencing, I'll proceed to merge your contributions and release an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants