input_vlan.h 5.61 KB
Newer Older
Michel Kaempf's avatar
Michel Kaempf committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/*******************************************************************************
 * input_vlan.h: vlan input method
 * (c)1999 VideoLAN
 *******************************************************************************
 * ?? 
 *******************************************************************************
 * Required headers:
 * <netinet/in.h>
 *******************************************************************************/

/*******************************************************************************
 * Vlan server related constants
 *******************************************************************************/

#define VLAN_SERVER_MSG_LENGTH  256             /* maximum length of a message */
#define VLAN_CLIENT_VERSION     "1.3.0"                 /* vlan client version */

/* Messages codes */
#define VLAN_LOGIN_REQUEST      98        /* login: <version> <login> <passwd> */
#define VLAN_LOGIN_ANSWER       97                    /* login accepted: [msg] */
#define VLAN_LOGIN_REJECTED     96                    /* login rejected: [msg] */

#define VLAN_LOGOUT             99                                   /* logout */

#define VLAN_INFO_REQUEST       31                        /* info: no argument */
#define VLAN_INFO_ANSWER        32/* info ok: <switch> <port> <vlan> <sharers> */
#define VLAN_INFO_REJECTED      33                     /* info rejected: [msg] */

#define VLAN_CHANGE_REQUEST     21/* change: <mac> [ip] <vlan dest> [vlan src] */
#define VLAN_CHANGE_ANSWER      22                         /* change ok: [msg] */
#define VLAN_CHANGE_REJECTED    23                     /* change failed: [msg] */

/*******************************************************************************
 * Macros to build/extract vlan_ids
 *******************************************************************************/
#define VLAN_ID_IFACE( vlan_id )    ( ((vlan_id) >> 8) & 0xff ) 
#define VLAN_ID_VLAN( vlan_id )     ( (vlan_id) & 0xff )
#define VLAN_ID( iface, vlan )      ( ((iface) << 8) | (vlan) )

/*******************************************************************************
 * input_vlan_server_t: vlan server
 *******************************************************************************
 * This structure describes a vlan server.
 *******************************************************************************/
typedef struct
{
    struct sockaddr_in  sa_in;                               /* server address */
    int                 i_socket;                         /* socket descriptor */

    /* Login informations */
    char *              psz_login;                             /* server login */
    char *              psz_passwd;                         /* server password */
} input_vlan_server_t;

/*******************************************************************************
 * input_vlan_iface_t: vlan-capable network interface
 *******************************************************************************
 * This structure describes the abilities of a network interface capable of
 * vlan management. Note that an interface could have several IP adresses, but
 * since only the MAC address is used to change vlan, only one needs to be
 * retrieved.
 * ?? it could be interesting to send a port id on vlan request, to know if two
 * interfaces are dependant regarding vlan changes.
 *******************************************************************************/
typedef struct
{
    char *                  psz_name;                        /* interface name */
    struct sockaddr_in      sa_in;                             /* interface IP */
    char                    psz_mac[20];                      /* interface MAC */

    /* Hardware properties */
    int                     i_master;                /* master interface index */
    int                     i_switch;                         /* switch number */
    int                     i_port;                             /* port number */
    int                     i_sharers;          /* number of MACs on this port */
    
    /* Vlan properties - these are only used if i_master is negative */
    int                     i_refcount;                       /* locks counter */
    int                     i_vlan;                            /* current vlan */
    int                     i_default_vlan;                    /* default vlan */
} input_vlan_iface_t;

/*******************************************************************************
 * vlan_method_data_t
 *******************************************************************************
 * Store global vlan library data.
 *******************************************************************************/
typedef struct
{    
    pthread_mutex_t         lock;                              /* library lock */

    /* Server */
    input_vlan_server_t     server;                             /* vlan server */
 
    /* Network interfaces */
    int                     i_ifaces;   /* number of vlan-compliant interfaces */
    input_vlan_iface_t *    p_iface;                             /* interfaces */
} input_vlan_method_t;

/*******************************************************************************
 * Prototypes
 *******************************************************************************/
int     input_VlanMethodInit    ( input_vlan_method_t *p_method,
                                  char *psz_server, int i_port);
void    input_VlanMethodFree    ( input_vlan_method_t *p_method );

int     input_VlanId            ( char *psz_iface, int i_vlan );
int     input_VlanJoin          ( int i_vlan_id );
void    input_VlanLeave         ( int i_vlan_id );
int     input_VlanRequest       ( char *psz_iface );
int     input_VlanSynchronize   ( void );