1*46527f68SHugo Santos /* 2*46527f68SHugo Santos * Copyright 2007, Haiku, Inc. All Rights Reserved. 3*46527f68SHugo Santos * Distributed under the terms of the MIT License. 4*46527f68SHugo Santos * 5*46527f68SHugo Santos * Authors: 6*46527f68SHugo Santos * Hugo Santos, hugosantos@gmail.com 7*46527f68SHugo Santos */ 8*46527f68SHugo Santos 9*46527f68SHugo Santos #ifndef _PRIVATE_MULTICAST_H_ 10*46527f68SHugo Santos #define _PRIVATE_MULTICAST_H_ 11*46527f68SHugo Santos 12*46527f68SHugo Santos #include <util/DoublyLinkedList.h> 13*46527f68SHugo Santos #include <util/list.h> 14*46527f68SHugo Santos 15*46527f68SHugo Santos struct net_interface; 16*46527f68SHugo Santos 17*46527f68SHugo Santos template<typename AddressType> 18*46527f68SHugo Santos struct MulticastSource { 19*46527f68SHugo Santos AddressType address; 20*46527f68SHugo Santos list_link link; 21*46527f68SHugo Santos }; 22*46527f68SHugo Santos 23*46527f68SHugo Santos template<typename AddressType> 24*46527f68SHugo Santos class MulticastGroupInterfaceState { 25*46527f68SHugo Santos public: 26*46527f68SHugo Santos MulticastGroupInterfaceState(net_interface *interface); 27*46527f68SHugo Santos ~MulticastGroupInterfaceState(); 28*46527f68SHugo Santos 29*46527f68SHugo Santos net_interface *Interface() const { return fInterface; } 30*46527f68SHugo Santos 31*46527f68SHugo Santos status_t Add(const AddressType &address); 32*46527f68SHugo Santos status_t Remove(const AddressType &address); 33*46527f68SHugo Santos 34*46527f68SHugo Santos list_link link; 35*46527f68SHugo Santos private: 36*46527f68SHugo Santos typedef MulticastSource<AddressType> Source; 37*46527f68SHugo Santos typedef DoublyLinkedListCLink<Source> SourceLink; 38*46527f68SHugo Santos typedef DoublyLinkedList<Source, SourceLink> SourceList; 39*46527f68SHugo Santos 40*46527f68SHugo Santos Source *_Get(const AddressType &address, bool create); 41*46527f68SHugo Santos void _Remove(Source *state); 42*46527f68SHugo Santos 43*46527f68SHugo Santos net_interface *fInterface; 44*46527f68SHugo Santos // TODO make this an hash table as well 45*46527f68SHugo Santos SourceList fSources; 46*46527f68SHugo Santos }; 47*46527f68SHugo Santos 48*46527f68SHugo Santos template<typename AddressType> 49*46527f68SHugo Santos class MulticastGroupState { 50*46527f68SHugo Santos public: 51*46527f68SHugo Santos MulticastGroupState(const AddressType &address); 52*46527f68SHugo Santos ~MulticastGroupState(); 53*46527f68SHugo Santos 54*46527f68SHugo Santos const AddressType &Address() const { return fMulticastAddress; } 55*46527f68SHugo Santos bool IsEmpty() const 56*46527f68SHugo Santos { return fFilterMode == kInclude && fInterfaces.IsEmpty(); } 57*46527f68SHugo Santos 58*46527f68SHugo Santos status_t Add(net_interface *interface); 59*46527f68SHugo Santos status_t Drop(net_interface *interface); 60*46527f68SHugo Santos status_t BlockSource(net_interface *interface, 61*46527f68SHugo Santos const AddressType &sourceAddress); 62*46527f68SHugo Santos status_t UnblockSource(net_interface *interface, 63*46527f68SHugo Santos const AddressType &sourceAddress); 64*46527f68SHugo Santos status_t AddSSM(net_interface *interface, 65*46527f68SHugo Santos const AddressType &sourceAddress); 66*46527f68SHugo Santos status_t DropSSM(net_interface *interface, 67*46527f68SHugo Santos const AddressType &sourceAddress); 68*46527f68SHugo Santos 69*46527f68SHugo Santos list_link link; 70*46527f68SHugo Santos private: 71*46527f68SHugo Santos typedef MulticastGroupInterfaceState<AddressType> InterfaceState; 72*46527f68SHugo Santos typedef DoublyLinkedListCLink<InterfaceState> InterfaceStateLink; 73*46527f68SHugo Santos typedef DoublyLinkedList<InterfaceState, InterfaceStateLink> InterfaceList; 74*46527f68SHugo Santos 75*46527f68SHugo Santos InterfaceState *_GetInterface(net_interface *interface, bool create); 76*46527f68SHugo Santos void _RemoveInterface(InterfaceState *state); 77*46527f68SHugo Santos 78*46527f68SHugo Santos enum FilterMode { 79*46527f68SHugo Santos kInclude, 80*46527f68SHugo Santos kExclude 81*46527f68SHugo Santos }; 82*46527f68SHugo Santos 83*46527f68SHugo Santos AddressType fMulticastAddress; 84*46527f68SHugo Santos FilterMode fFilterMode; 85*46527f68SHugo Santos InterfaceList fInterfaces; 86*46527f68SHugo Santos }; 87*46527f68SHugo Santos 88*46527f68SHugo Santos template<typename AddressType> 89*46527f68SHugo Santos class MulticastFilter { 90*46527f68SHugo Santos public: 91*46527f68SHugo Santos typedef MulticastGroupState<AddressType> GroupState; 92*46527f68SHugo Santos 93*46527f68SHugo Santos ~MulticastFilter(); 94*46527f68SHugo Santos 95*46527f68SHugo Santos GroupState *GetGroup(const AddressType &groupAddress, bool create); 96*46527f68SHugo Santos void ReturnGroup(GroupState *group); 97*46527f68SHugo Santos 98*46527f68SHugo Santos private: 99*46527f68SHugo Santos typedef DoublyLinkedListCLink<GroupState> GroupStateLink; 100*46527f68SHugo Santos typedef DoublyLinkedList<GroupState, GroupStateLink> States; 101*46527f68SHugo Santos 102*46527f68SHugo Santos // TODO change this into an hash table or tree 103*46527f68SHugo Santos States fStates; 104*46527f68SHugo Santos }; 105*46527f68SHugo Santos 106*46527f68SHugo Santos #endif 107