File: ClntOptFQDN.cpp

package info (click to toggle)
dibbler 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,352 kB
  • sloc: cpp: 60,323; ansic: 12,235; sh: 11,951; yacc: 3,418; lex: 969; makefile: 940; perl: 319; xml: 116; python: 74
file content (70 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download | duplicates (3)
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
/*
 * Dibbler - a portable DHCPv6
 *
 * author: Krzysztof Wnuk <keczi@poczta.onet.pl>
 *
 * released under GNU GPL v2 licence
 *
 */

#include "ClntOptFQDN.h"
#include "OptDUID.h"
#include "Logger.h"

using namespace std;

TClntOptFQDN::TClntOptFQDN(const std::string& domain, TMsg* parent)
    :TOptFQDN(domain, parent) {
    if (domain == "") {
	// The domain is empty but client request FQDN, so we let the server make the update
	setSFlag(true);
    }
}

TClntOptFQDN::TClntOptFQDN(char *buf, int bufsize, TMsg* parent)
    :TOptFQDN(buf, bufsize, parent) {
    /// @todo: do some validity check

}

bool TClntOptFQDN::doDuties() {
    if (getSFlag()) {
	Log(Notice) << "FQDN: DHCPv6 server made the DNS update for my name: " 
		    << getFQDN() << " ." << LogEnd;
	/// @todo: Check the DNS server with the given name.
	return true;
    }
	
    string reason = "trying to set FQDN.";
    if (!Parent) {
        Log(Error) << "Unable to set FQDN: option parent not set." << LogEnd;
        return false;
    }

    int ifindex = this->Parent->getIface();
    SPtr<TIPv6Addr> addr = this->Parent->getRemoteAddr();
    
    SPtr<TClntIfaceIface> iface = (Ptr*)ClntIfaceMgr().getIfaceByID(ifindex);
    
    if (!iface) {
	Log(Error) << "Unable to find interface with ifindex=" << ifindex 
		   << " while " << reason << LogEnd;
	return false;
    }

    SPtr<TOptDUID> duid = (Ptr*)Parent->getOption(OPTION_SERVERID);

    if (!duid) {
	Log(Error) << "Unable to find proper DUID while " << reason << LogEnd;
	return false;
    }
    
    // this runs only when client is gonna update DNS server 
    return iface->setFQDN(duid->getDUID(), addr,getFQDN());
}

void TClntOptFQDN::setSrvDuid(SPtr<TDUID> duid) {
    SrvDUID=duid;
}