vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / network / ppp / pppoe / DiscoveryPacket.h
blob1e1f6500622a5f8d5cebf4adb7a52e389e551f14
1 /*
2 * Copyright 2003-2004, Waldemar Kornewald <wkornew@gmx.net>
3 * Distributed under the terms of the MIT License.
4 */
6 #ifndef DISCOVERY_PACKET__H
7 #define DISCOVERY_PACKET__H
9 #include "PPPoE.h"
11 #include <TemplateList.h>
13 #define ETHER_HDR_LEN 14
15 enum PPPoE_TAG_TYPE {
16 END_OF_LIST = 0x0000,
17 SERVICE_NAME = 0x0101,
18 AC_NAME = 0x0102,
19 HOST_UNIQ = 0x0103,
20 AC_COOKIE = 0x0104,
21 VENDOR_SPECIFIC = 0x0105,
22 RELAY_SESSION_ID = 0x0110,
23 SERVICE_NAME_ERROR = 0x0201,
24 AC_SYSTEM_ERROR = 0x0202,
25 GENERIC_ERROR = 0x0203
28 enum PPPoE_CODE {
29 PADI = 0x09,
30 PADO = 0x07,
31 PADR = 0x19,
32 PADS = 0x65,
33 PADT = 0xA7
37 typedef struct pppoe_tag {
38 uint16 type;
39 uint16 length;
40 uint8 data[0];
41 } pppoe_tag;
44 class DiscoveryPacket {
45 public:
46 DiscoveryPacket(uint8 code, uint16 sessionID = 0x0000);
47 DiscoveryPacket(net_buffer *packet, uint32 start = 0);
48 ~DiscoveryPacket();
50 status_t InitCheck() const
51 { return fInitStatus; }
53 void SetCode(uint8 code)
54 { fCode = code; }
55 uint8 Code() const
56 { return fCode; }
58 void SetSessionID(uint16 sessionID)
59 { fSessionID = sessionID; }
60 uint16 SessionID() const
61 { return fSessionID; }
63 bool AddTag(uint16 type, const void *data, uint16 length, int32 index = -1);
64 bool RemoveTag(pppoe_tag *tag);
65 int32 CountTags() const
66 { return fTags.CountItems(); }
67 pppoe_tag *TagAt(int32 index) const;
68 pppoe_tag *TagWithType(uint16 type) const;
70 net_buffer *ToNetBuffer(uint32 MTU);
71 // the user is responsible for freeing the net_buffer
73 private:
74 uint8 fCode;
75 uint16 fSessionID;
76 TemplateList<pppoe_tag*> fTags;
77 status_t fInitStatus;
81 #endif