File: SrvOptLQ.cpp

package info (click to toggle)
dibbler 0.7.3-1.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,148 kB
  • ctags: 8,720
  • sloc: cpp: 54,863; sh: 9,389; ansic: 8,659; yacc: 2,570; makefile: 1,061; lex: 842; perl: 49; xml: 6
file content (156 lines) | stat: -rw-r--r-- 3,482 bytes parent folder | download
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Dibbler - a portable DHCPv6
 *
 * author: Tomasz Mrugalski <thomson@klub.com.pl>
 * 
 * released under GNU GPL v2 only licence
 *
 */


#include "Msg.h"
#include "Logger.h"
#include "SrvOptLQ.h"
#include "SrvOptIAAddress.h"
#include "SrvOptClientIdentifier.h"
#include "Portable.h"

// --- TSrvOptLQ ---
TSrvOptLQ::TSrvOptLQ(char * buf, int bufsize, TMsg* parent)
    :TOpt(OPTION_LQ_QUERY, parent)
{
    IsValid = true;

    // @TODO parse
    if (bufsize<17) {
	Log(Warning) << "Truncated (len=" << bufsize << ", at least 17 required) option OPTION_LQ_QUERY received." << LogEnd;
	IsValid = false;
	return;
    }
    QueryType = (ELeaseQueryType)buf[0];
    Addr = new TIPv6Addr(buf+1);
    int pos = 17;

    while (pos<bufsize) {
	if (pos+4>bufsize) {
	    IsValid = false;
	    Log(Warning) << "Truncated IA_NA option received." << LogEnd;
	    return;
	}
        int code=buf[pos]*256+buf[pos+1];
        pos+=2;
        int length=buf[pos]*256+buf[pos+1];
        pos+=2;

	if (allowOptInOpt(parent->getType(), OPTION_LQ_QUERY, code)) {
	    switch (code) {
	    case OPTION_IAADDR:
		SubOptions.append( new TSrvOptIAAddress(buf+pos,length,this->Parent));
		break;
	    case OPTION_CLIENTID:
		SubOptions.append( new TSrvOptClientIdentifier(buf+pos, length, this->Parent) );
		break;
	    default:
		Log(Warning) << "Not supported option " << code << " received in LQ_QUERY option." << LogEnd;
	    }
	} else {
	    Log(Warning) << "Illegal option " << code << " received inside LQ_QUERY option." << LogEnd;
	}

	pos += length;
	continue;
    }

}

bool TSrvOptLQ::doDuties() {
    return true;
}

ELeaseQueryType TSrvOptLQ::getQueryType() {
    return QueryType;
}

SPtr<TIPv6Addr> TSrvOptLQ::getLinkAddr() {
    return Addr;
}

int TSrvOptLQ::getSize() {
    SPtr<TOpt> opt;
    int len = 17;
    SubOptions.first();
    while (opt = SubOptions.get() ) {
	len += opt->getSize();
    }
    return len;
}

char * TSrvOptLQ::storeSelf(char* buf)
{
    Log(Error) << "LQ: Something is wrong. Server was trying to send OPTION_LQ_QUERY option." << LogEnd;
    return buf;
}


// -----------------------------------------------------------------------------------

TSrvOptLQClientData::TSrvOptLQClientData(TMsg * parent) 
    :TOpt(OPTION_CLIENT_DATA, parent)
{
}

int TSrvOptLQClientData::getSize()
{
    int cnt = 0;
    SPtr<TOpt> x;
    SubOptions.first();
    while ( x=SubOptions.get() ) {
	cnt += x->getSize();
    }
    return cnt+4;
}

char* TSrvOptLQClientData::storeSelf(char* buf)
{
    *(uint16_t*)buf = htons(OptType);
    buf+=2;
    *(uint16_t*)buf = htons( getSize()-4 );
    buf+=2;

    buf = storeSubOpt(buf);
    return buf;
}

bool TSrvOptLQClientData::doDuties()
{
    return true;
}

// -----------------------------------------------------------------------------------

TSrvOptLQClientTime::TSrvOptLQClientTime(unsigned int value, TMsg* parent)
    :TOptInteger(OPTION_CLT_TIME, 4, value, parent)
{

}

bool TSrvOptLQClientTime::doDuties()
{
    return true;
}

// -----------------------------------------------------------------------------------

TSrvOptLQRelayData::TSrvOptLQRelayData(SPtr<TIPv6Addr> addr, TMsg* parent)
    :TOptGeneric(OPTION_LQ_RELAY_DATA, parent)
{
    // @TODO - implement this
}

// -----------------------------------------------------------------------------------

TSrvOptLQClientLink::TSrvOptLQClientLink(List(TIPv6Addr) AddrLst, TMsg * parent)
    :TOpt(OPTION_LQ_CLIENT_LINK, parent)
{
    LinkAddrLst = AddrLst;
}