1*67d75188Sjsg /* $OpenBSD: if_etherbridge.h,v 1.5 2024/11/04 00:13:15 jsg Exp $ */ 25a88a734Sdlg 35a88a734Sdlg /* 45a88a734Sdlg * Copyright (c) 2018, 2021 David Gwynne <dlg@openbsd.org> 55a88a734Sdlg * 65a88a734Sdlg * Permission to use, copy, modify, and distribute this software for any 75a88a734Sdlg * purpose with or without fee is hereby granted, provided that the above 85a88a734Sdlg * copyright notice and this permission notice appear in all copies. 95a88a734Sdlg * 105a88a734Sdlg * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 115a88a734Sdlg * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 125a88a734Sdlg * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 135a88a734Sdlg * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 145a88a734Sdlg * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 155a88a734Sdlg * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 165a88a734Sdlg * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 175a88a734Sdlg */ 185a88a734Sdlg 195a88a734Sdlg #ifndef _NET_ETHERBRIDGE_H_ 205a88a734Sdlg #define _NET_ETHERBRIDGE_H_ 215a88a734Sdlg 225a88a734Sdlg #define ETHERBRIDGE_TABLE_BITS 8 235a88a734Sdlg #define ETHERBRIDGE_TABLE_SIZE (1U << ETHERBRIDGE_TABLE_BITS) 245a88a734Sdlg #define ETHERBRIDGE_TABLE_MASK (ETHERBRIDGE_TABLE_SIZE - 1) 255a88a734Sdlg 265a88a734Sdlg struct etherbridge_ops { 275a88a734Sdlg int (*eb_op_port_eq)(void *, void *, void *); 285a88a734Sdlg void *(*eb_op_port_take)(void *, void *); 295a88a734Sdlg void (*eb_op_port_rele)(void *, void *); 305a88a734Sdlg size_t (*eb_op_port_ifname)(void *, char *, size_t, void *); 315a88a734Sdlg void (*eb_op_port_sa)(void *, struct sockaddr_storage *, void *); 325a88a734Sdlg }; 335a88a734Sdlg 345a88a734Sdlg struct etherbridge; 355a88a734Sdlg 365a88a734Sdlg struct eb_entry { 375a88a734Sdlg SMR_TAILQ_ENTRY(eb_entry) ebe_lentry; 385a88a734Sdlg union { 395a88a734Sdlg RBT_ENTRY(eb_entry) _ebe_tentry; 405a88a734Sdlg TAILQ_ENTRY(eb_entry) _ebe_qentry; 415a88a734Sdlg } _ebe_entries; 425a88a734Sdlg #define ebe_tentry _ebe_entries._ebe_tentry 435a88a734Sdlg #define ebe_qentry _ebe_entries._ebe_qentry 445a88a734Sdlg 459703528fSdlg uint64_t ebe_addr; 465a88a734Sdlg void *ebe_port; 475a88a734Sdlg unsigned int ebe_type; 485a88a734Sdlg #define EBE_DYNAMIC 0x0 495a88a734Sdlg #define EBE_STATIC 0x1 505a88a734Sdlg #define EBE_DEAD 0xdead 515a88a734Sdlg time_t ebe_age; 525a88a734Sdlg 535a88a734Sdlg struct etherbridge *ebe_etherbridge; 545a88a734Sdlg struct smr_entry ebe_smr_entry; 555a88a734Sdlg }; 565a88a734Sdlg 575a88a734Sdlg SMR_TAILQ_HEAD(eb_list, eb_entry); 585a88a734Sdlg RBT_HEAD(eb_tree, eb_entry); 595a88a734Sdlg TAILQ_HEAD(eb_queue, eb_entry); 605a88a734Sdlg 615a88a734Sdlg struct etherbridge { 625a88a734Sdlg const char *eb_name; 635a88a734Sdlg const struct etherbridge_ops *eb_ops; 645a88a734Sdlg void *eb_cookie; 655a88a734Sdlg 665a88a734Sdlg struct mutex eb_lock; 675a88a734Sdlg unsigned int eb_num; 685a88a734Sdlg unsigned int eb_max; 695a88a734Sdlg int eb_max_age; /* seconds */ 705a88a734Sdlg struct timeout eb_tmo_age; 715a88a734Sdlg 725a88a734Sdlg struct eb_list *eb_table; 735a88a734Sdlg struct eb_tree eb_tree; 745a88a734Sdlg 755a88a734Sdlg }; 765a88a734Sdlg 775a88a734Sdlg int etherbridge_init(struct etherbridge *, const char *, 785a88a734Sdlg const struct etherbridge_ops *, void *); 795a88a734Sdlg int etherbridge_up(struct etherbridge *); 805a88a734Sdlg int etherbridge_down(struct etherbridge *); 815a88a734Sdlg void etherbridge_destroy(struct etherbridge *); 825a88a734Sdlg 839703528fSdlg void etherbridge_map(struct etherbridge *, void *, uint64_t); 849703528fSdlg void etherbridge_map_ea(struct etherbridge *, void *, 855a88a734Sdlg const struct ether_addr *); 869703528fSdlg void *etherbridge_resolve(struct etherbridge *, uint64_t); 879703528fSdlg void *etherbridge_resolve_ea(struct etherbridge *, 889703528fSdlg const struct ether_addr *); 895a88a734Sdlg void etherbridge_detach_port(struct etherbridge *, void *); 905a88a734Sdlg 915a88a734Sdlg /* ioctl support */ 925a88a734Sdlg int etherbridge_set_max(struct etherbridge *, struct ifbrparam *); 935a88a734Sdlg int etherbridge_get_max(struct etherbridge *, struct ifbrparam *); 945a88a734Sdlg int etherbridge_set_tmo(struct etherbridge *, struct ifbrparam *); 955a88a734Sdlg int etherbridge_get_tmo(struct etherbridge *, struct ifbrparam *); 965a88a734Sdlg int etherbridge_rtfind(struct etherbridge *, struct ifbaconf *); 9753d80efbSdlg int etherbridge_add_addr(struct etherbridge *, void *, 9853d80efbSdlg const struct ether_addr *, unsigned int); 9953d80efbSdlg int etherbridge_del_addr(struct etherbridge *, const struct ether_addr *); 1005a88a734Sdlg void etherbridge_flush(struct etherbridge *, uint32_t); 1015a88a734Sdlg 1025a88a734Sdlg #endif /* _NET_ETHERBRIDGE_H_ */ 103