?? pppoe.h
字號:
/************************************************************************* pppoe.h** Declaration of various PPPoE constants** Copyright (C) 2000 Roaring Penguin Software Inc.** This program may be distributed according to the terms of the GNU* General Public License, version 2 or (at your option) any later version.** LIC: GPL** $Id: pppoe.h,v 1.25 2002/07/05 19:32:50 dfs Exp $************************************************************************/#include <stdio.h> /* For FILE */#include <tmlib/dprintf.h>#include "sys_conf.h"#define PPPOED_NAME "PPPOED"#define ETH_DATA_LEN BSP_LAN1_MTU#define ETH_ALEN BSP_LAN1_HWALEN /* Define various integer types -- assumes a char is 8 bits */typedef unsigned short UINT16_t;typedef unsigned int UINT32_t;/* Ethernet frame types according to RFC 2516 */#define ETH_PPPOE_DISCOVERY 0x8863#define ETH_PPPOE_SESSION 0x8864/* PPPoE codes */#define CODE_PADI 0x09#define CODE_PADO 0x07#define CODE_PADR 0x19#define CODE_PADS 0x65#define CODE_PADT 0xA7#define CODE_SESS 0x00/* PPPoE Tags */#define TAG_END_OF_LIST 0x0000#define TAG_SERVICE_NAME 0x0101#define TAG_AC_NAME 0x0102#define TAG_HOST_UNIQ 0x0103#define TAG_AC_COOKIE 0x0104#define TAG_VENDOR_SPECIFIC 0x0105#define TAG_RELAY_SESSION_ID 0x0110#define TAG_SERVICE_NAME_ERROR 0x0201#define TAG_AC_SYSTEM_ERROR 0x0202#define TAG_GENERIC_ERROR 0x0203/* Discovery phase states */#define STATE_SENT_PADI 0#define STATE_RECEIVED_PADO 1#define STATE_SENT_PADR 2#define STATE_SESSION 3#define STATE_TERMINATED 4/* How many PADI/PADS attempts? */#define MAX_PADI_ATTEMPTS 3/* Initial timeout for PADO/PADS */#define PADI_TIMEOUT 5/* States for scanning PPP frames */#define STATE_WAITFOR_FRAME_ADDR 0#define STATE_DROP_PROTO 1#define STATE_BUILDING_PACKET 2/* Ethernet headers */struct ethhdr { char h_dest[ETH_ALEN]; char h_source[ETH_ALEN]; unsigned int eth_type:16;}; /* PPPoE Header, include eth type, but not include Ethernet header & payload */typedef struct PPPoEHeaderStruct { unsigned int eth_type:16; #ifdef PACK_BITFIELDS_REVERSED unsigned int type:4; /* PPPoE Type (must be 1) */ unsigned int ver:4; /* PPPoE Version (must be 1) */#else unsigned int ver:4; /* PPPoE Version (must be 1) */ unsigned int type:4; /* PPPoE Type (must be 1) */#endif unsigned int code:8; /* PPPoE code */ unsigned int session:16; /* PPPoE session */ unsigned int length:16; /* Payload length */ unsigned int protocol:16;} PPPoEHeader; /* A PPPoE Packet, including Ethernet headers */typedef struct PPPoEPacketStruct { char h_dest[ETH_ALEN]; char h_source[ETH_ALEN]; unsigned int eth_type:16; /*struct ethhdr ethHdr;*/ /* Ethernet header */#ifdef PACK_BITFIELDS_REVERSED unsigned int type:4; /* PPPoE Type (must be 1) */ unsigned int ver:4; /* PPPoE Version (must be 1) */#else unsigned int ver:4; /* PPPoE Version (must be 1) */ unsigned int type:4; /* PPPoE Type (must be 1) */#endif unsigned int code:8; /* PPPoE code */ unsigned int session:16; /* PPPoE session */ unsigned int length:16; /* Payload length */ unsigned char payload[ETH_DATA_LEN]; /* A bit of room to spare */} PPPoEPacket;/* Header size of a PPPoE packet */#define PPPOE_OVERHEAD 6 /* type, code, session, length */#define HDR_SIZE (sizeof(struct ethhdr) + PPPOE_OVERHEAD)#define MAX_PPPOE_PAYLOAD (ETH_DATA_LEN - PPPOE_OVERHEAD)#define MAX_PPPOE_MTU (MAX_PPPOE_PAYLOAD - 2)/* PPPoE Tag */typedef struct PPPoETagStruct { unsigned int type:16; /* tag type */ unsigned int length:16; /* Length of payload */ unsigned char payload[ETH_DATA_LEN]; /* A LOT of room to spare */} PPPoETag;/* Header size of a PPPoE tag */#define TAG_HDR_SIZE 4/* Chunk to read from stdin */#define READ_CHUNK 4096/* Function passed to parsePacket */typedef void ParseFunc(UINT16_t type, UINT16_t len, unsigned char *data, void *extra);#define PPPINITFCS16 0xffff /* Initial FCS value *//* Keep track of the state of a connection -- collect everything in one spot */typedef struct PPPoEConnectionStruct { int discoveryState; /* Where we are in discovery */ int discoverySocket; /* Raw socket for discovery frames */ int sessionSocket; /* Raw socket for session frames */ char myEth[ETH_ALEN]; /* My MAC address */ char peerEth[ETH_ALEN]; /* Peer's MAC address */ UINT16_t session; /* Session ID */ char *ifName; /* Interface name */ char *serviceName; /* Desired service name, if any */ char *acName; /* Desired AC name, if any */ int synchronous; /* Use synchronous PPP */ int useHostUniq; /* Use Host-Uniq tag */ int printACNames; /* Just print AC names */ int skipDiscovery; /* Skip discovery */ int noDiscoverySocket; /* Don't even open discovery socket */ int killSession; /* Kill session and exit */ FILE *debugFile; /* Debug file for dumping packets */ int numPADOs; /* Number of PADO packets received */ PPPoETag cookie; /* We have to send this if we get it */ PPPoETag relayId; /* Ditto */ int padi_trans; /*number of padi's transmit*/ int padr_trans; /*number of padr's transmit*/} PPPoEConnection;/* Structure used to determine acceptable PADO or PADS packet */struct PacketCriteria { PPPoEConnection *conn; int acNameOK; int serviceNameOK; int seenACName; int seenServiceName;};extern PPPoEConnection Connection;/* Function Prototypes */int parsePacket(PPPoEPacket *packet, ParseFunc *func, void *extra);void parsePADOTags(UINT16_t type, UINT16_t len, unsigned char *data, void *extra);void parsePADSTags(UINT16_t type, UINT16_t len, unsigned char *data, void *extra);void parseLogErrs(UINT16_t type, UINT16_t len, unsigned char *data, void *extra);void sendPADI(PPPoEConnection *conn);void recvPADO(PPPoEConnection *conn, unsigned char *ptr, unsigned int num);void sendPADR(PPPoEConnection *conn);void recvPADS(PPPoEConnection *conn, unsigned char *ptr, unsigned int num);void sendPADT(PPPoEConnection *conn, char const *msg);void recvPADT(PPPoEConnection *conn, unsigned char *ptr, unsigned int num);static void padi_timeout(caddr_t arg);static void padr_timeout(caddr_t arg);#define SET_STRING(var, val) do { if (var) free(var); var = strDup(val); } while(0);#define CHECK_ROOM(cursor, start, len) \do {\ if (((cursor)-(start))+(len) > MAX_PPPOE_PAYLOAD) { \ syslog(LOG_ERR, "Would create too-long packet"); \ return; \ } \} while(0)/* True if Ethernet address is broadcast or multicast */#define NOT_UNICAST(e) ((e[0] & 0x01) != 0)#define BROADCAST(e) ((e[0] & e[1] & e[2] & e[3] & e[4] & e[5]) == 0xFF)#define NOT_BROADCAST(e) ((e[0] & e[1] & e[2] & e[3] & e[4] & e[5]) != 0xFF)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -