[00d7e1b] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Radim Vansa
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /**
|
---|
| 30 | * @addtogroup libnic
|
---|
| 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /**
|
---|
| 34 | * @file
|
---|
| 35 | * @brief Incoming packets (frames) filtering control structures
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #ifndef __NIC_FILTERS_H__
|
---|
| 39 | #define __NIC_FILTERS_H__
|
---|
| 40 |
|
---|
| 41 | #ifndef LIBNIC_INTERNAL
|
---|
| 42 | #error "This is internal libnic's header, please do not include it"
|
---|
| 43 | #endif
|
---|
| 44 |
|
---|
| 45 | #include <adt/hash_table.h>
|
---|
| 46 | #include <fibril_synch.h>
|
---|
[cf9cb36] | 47 | #include <nic/nic.h>
|
---|
[00d7e1b] | 48 |
|
---|
| 49 | #include "nic_addr_db.h"
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * General structure describing receive control.
|
---|
| 53 | * The structure is not synchronized inside, the nic_driver should provide
|
---|
| 54 | * a synchronized facade.
|
---|
| 55 | */
|
---|
| 56 | typedef struct nic_rxc {
|
---|
| 57 | /**
|
---|
| 58 | * Allowed unicast destination MAC addresses
|
---|
| 59 | */
|
---|
| 60 | nic_addr_db_t unicast_addrs;
|
---|
| 61 | /**
|
---|
| 62 | * Allowed unicast destination MAC addresses
|
---|
| 63 | */
|
---|
| 64 | nic_addr_db_t multicast_addrs;
|
---|
| 65 | /**
|
---|
| 66 | * Single flag if any source is blocked
|
---|
| 67 | */
|
---|
| 68 | int block_sources;
|
---|
| 69 | /**
|
---|
| 70 | * Blocked source MAC addresses
|
---|
| 71 | */
|
---|
| 72 | nic_addr_db_t blocked_sources;
|
---|
| 73 | /**
|
---|
| 74 | * Selected mode for unicast frames
|
---|
| 75 | */
|
---|
| 76 | nic_unicast_mode_t unicast_mode;
|
---|
| 77 | /**
|
---|
| 78 | * Selected mode for multicast frames
|
---|
| 79 | */
|
---|
| 80 | nic_multicast_mode_t multicast_mode;
|
---|
| 81 | /**
|
---|
| 82 | * Selected mode for broadcast frames
|
---|
| 83 | */
|
---|
| 84 | nic_broadcast_mode_t broadcast_mode;
|
---|
| 85 | /**
|
---|
| 86 | * Mask for VLAN tags. This vector must be at least 512 bytes long.
|
---|
| 87 | */
|
---|
| 88 | nic_vlan_mask_t *vlan_mask;
|
---|
| 89 | /**
|
---|
| 90 | * If true, the NIC is receiving only unicast frames which we really want to
|
---|
| 91 | * receive (the filtering is perfect).
|
---|
| 92 | */
|
---|
| 93 | int unicast_exact;
|
---|
| 94 | /**
|
---|
| 95 | * If true, the NIC is receiving only multicast frames which we really want
|
---|
| 96 | * to receive (the filtering is perfect).
|
---|
| 97 | */
|
---|
| 98 | int multicast_exact;
|
---|
| 99 | /**
|
---|
| 100 | * If true, the NIC is receiving only frames with VLAN tags which we really
|
---|
| 101 | * want to receive (the filtering is perfect).
|
---|
| 102 | */
|
---|
| 103 | int vlan_exact;
|
---|
| 104 | } nic_rxc_t;
|
---|
| 105 |
|
---|
| 106 | #define VLAN_TPID_UPPER 0x81
|
---|
| 107 | #define VLAN_TPID_LOWER 0x00
|
---|
| 108 |
|
---|
| 109 | typedef struct vlan_header {
|
---|
| 110 | uint8_t tpid_upper;
|
---|
| 111 | uint8_t tpid_lower;
|
---|
| 112 | uint8_t vid_upper;
|
---|
| 113 | uint8_t vid_lower;
|
---|
| 114 | } __attribute__ ((packed)) vlan_header_t;
|
---|
| 115 |
|
---|
| 116 | extern int nic_rxc_init(nic_rxc_t *rxc);
|
---|
| 117 | extern int nic_rxc_clear(nic_rxc_t *rxc);
|
---|
| 118 | extern int nic_rxc_set_addr(nic_rxc_t *rxc,
|
---|
| 119 | const nic_address_t *prev_addr, const nic_address_t *curr_addr);
|
---|
| 120 | extern int nic_rxc_check(const nic_rxc_t *rxc,
|
---|
[1bc35b5] | 121 | const void *data, size_t size, nic_frame_type_t *frame_type);
|
---|
[00d7e1b] | 122 | extern void nic_rxc_hw_filtering(nic_rxc_t *rxc,
|
---|
| 123 | int unicast_exact, int multicast_exact, int vlan_exact);
|
---|
| 124 | extern uint64_t nic_rxc_mcast_hash(const nic_address_t *list, size_t count);
|
---|
| 125 | extern uint64_t nic_rxc_multicast_get_hash(const nic_rxc_t *rxc);
|
---|
| 126 | extern void nic_rxc_unicast_get_mode(const nic_rxc_t *, nic_unicast_mode_t *,
|
---|
| 127 | size_t max_count, nic_address_t *address_list, size_t *address_count);
|
---|
| 128 | extern int nic_rxc_unicast_set_mode(nic_rxc_t *rxc, nic_unicast_mode_t mode,
|
---|
| 129 | const nic_address_t *address_list, size_t address_count);
|
---|
| 130 | extern void nic_rxc_multicast_get_mode(const nic_rxc_t *,
|
---|
| 131 | nic_multicast_mode_t *, size_t, nic_address_t *, size_t *);
|
---|
| 132 | extern int nic_rxc_multicast_set_mode(nic_rxc_t *, nic_multicast_mode_t mode,
|
---|
| 133 | const nic_address_t *address_list, size_t address_count);
|
---|
| 134 | extern void nic_rxc_broadcast_get_mode(const nic_rxc_t *,
|
---|
| 135 | nic_broadcast_mode_t *mode);
|
---|
| 136 | extern int nic_rxc_broadcast_set_mode(nic_rxc_t *,
|
---|
| 137 | nic_broadcast_mode_t mode);
|
---|
| 138 | extern void nic_rxc_blocked_sources_get(const nic_rxc_t *,
|
---|
| 139 | size_t max_count, nic_address_t *address_list, size_t *address_count);
|
---|
| 140 | extern int nic_rxc_blocked_sources_set(nic_rxc_t *,
|
---|
| 141 | const nic_address_t *address_list, size_t address_count);
|
---|
| 142 | extern int nic_rxc_vlan_get_mask(const nic_rxc_t *rxc, nic_vlan_mask_t *mask);
|
---|
| 143 | extern int nic_rxc_vlan_set_mask(nic_rxc_t *rxc, const nic_vlan_mask_t *mask);
|
---|
| 144 |
|
---|
| 145 | #endif
|
---|
| 146 |
|
---|
| 147 | /** @}
|
---|
| 148 | */
|
---|