|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : 6to4_listener.cpp |
|
15 // Part of : 6to4 plugin / 6to4.prt |
|
16 // Implements 6to4 automatic and configured tunnels, see |
|
17 // RFC 3056 & RFC 2893 |
|
18 // Version : 0.2 |
|
19 // |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 // INCLUDE FILES |
|
25 #include <inet6log.h> |
|
26 #include <in6_opt.h> |
|
27 #include "6to4_listener.h" |
|
28 |
|
29 // EXTERNAL DATA STRUCTURES |
|
30 // EXTERNAL FUNCTION PROTOTYPES |
|
31 // CONSTANTS |
|
32 // MACROS |
|
33 // LOCAL CONSTANTS AND MACROS |
|
34 // MODULE DATA STRUCTURES |
|
35 // LOCAL FUNCTION PROTOTYPES |
|
36 // FORWARD DECLARATIONS |
|
37 |
|
38 // ============================= LOCAL FUNCTIONS ============================== |
|
39 |
|
40 // ---------------------------------------------------------------------------- |
|
41 // UpdateAddress |
|
42 // ---------------------------------------------------------------------------- |
|
43 static void UpdateAddress(MInterfaceManager &aIfMgr, const TIp6Addr &aAddr, TBool aDelete) |
|
44 { |
|
45 // Add or delete address to/from 6to4 interface |
|
46 TPckgBuf<TSoInet6InterfaceInfo> opt; |
|
47 TSoInet6InterfaceInfo &inf = opt(); |
|
48 inf.iName = K6to4; |
|
49 inf.iDoState = 0; |
|
50 inf.iDoId = 1; |
|
51 inf.iDoPrefix = 0; |
|
52 inf.iDoAnycast = 0; |
|
53 inf.iDoProxy = 0; |
|
54 inf.iAlias = 0; |
|
55 inf.iDelete = aDelete; |
|
56 inf.iAddress.SetAddress(aAddr); |
|
57 inf.iDefGate.SetFamily(0); |
|
58 inf.iNetMask.SetFamily(0); |
|
59 inf.iNameSer1.SetFamily(0); |
|
60 inf.iNameSer2.SetFamily(0); |
|
61 inf.iMtu = 0; |
|
62 inf.iSpeedMetric = 0; |
|
63 |
|
64 const TInt res = aIfMgr.SetOption(KSolInetIfCtrl, KSoInetConfigInterface, opt); |
|
65 #ifdef _LOG |
|
66 _LIT(KDelete, "Deleted"); |
|
67 _LIT(KAdded, "Added"); |
|
68 TBuf<70> tmp; |
|
69 inf.iAddress.Output(tmp); |
|
70 Log::Printf(_L("%S 6to4 address %S (result=%d)"), aDelete ? &KDelete() : &KAdded(), &tmp, res); |
|
71 #else |
|
72 (void)res; // (silence unused warning) |
|
73 #endif |
|
74 } |
|
75 |
|
76 |
|
77 // ============================ MEMBER FUNCTIONS ============================== |
|
78 |
|
79 C6to4Listener::C6to4Listener (MNetworkService *const aNetwork, MEventService &aService) : |
|
80 CBase (), iNetwork(aNetwork), iService(aService) |
|
81 { |
|
82 // Register the listener to get the events when addresses are added/deleted |
|
83 // to/from an interface. |
|
84 iService.RegisterListener (this, EClassAddress); |
|
85 } |
|
86 |
|
87 C6to4Listener::~C6to4Listener() |
|
88 { |
|
89 // Unregister the listener to not get the events anymore when addresses |
|
90 // are added/deleted to/from an interface. |
|
91 iService.RemoveListener (this); |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // C6to4Listener::Notify |
|
96 // Notification handler. Handles interface address addings and deletions. |
|
97 // |
|
98 // ---------------------------------------------------------------------------- |
|
99 // |
|
100 void C6to4Listener::Notify (TUint aEventClass, TUint aEventType, |
|
101 const void *aData) |
|
102 { |
|
103 if (aEventClass == EClassAddress) |
|
104 { |
|
105 TInetAddressInfo *info = (TInetAddressInfo *) aData; |
|
106 |
|
107 if (info->iPrefixLen != 0 || !info->iAddress.IsV4Mapped()) |
|
108 // Only interested in IPv4 addressess |
|
109 return; |
|
110 |
|
111 const TBool remove = aEventType == EventTypeDelete; |
|
112 if (!remove && aEventType != EventTypeAdd) |
|
113 return; |
|
114 |
|
115 // Only Delete or Add events processed |
|
116 |
|
117 // Build the ip address for the 6to4 virtual interface |
|
118 // and just for automatic tunnels, since the 6to4 address |
|
119 // for each interface IPv4 address has to be known by the |
|
120 // system for it to accept the packet. |
|
121 |
|
122 TIp6Addr addr; |
|
123 addr.u.iAddr8[0] = 0x20; |
|
124 addr.u.iAddr8[1] = 0x02; |
|
125 addr.u.iAddr8[2] = info->iAddress.u.iAddr8[12]; |
|
126 addr.u.iAddr8[3] = info->iAddress.u.iAddr8[13]; |
|
127 addr.u.iAddr8[4] = info->iAddress.u.iAddr8[14]; |
|
128 addr.u.iAddr8[5] = info->iAddress.u.iAddr8[15]; |
|
129 addr.u.iAddr8[6] = 0; |
|
130 addr.u.iAddr8[7] = 0; |
|
131 addr.u.iAddr8[8] = 0; |
|
132 addr.u.iAddr8[9] = 0; |
|
133 addr.u.iAddr8[10] = 0; |
|
134 addr.u.iAddr8[11] = 0; |
|
135 addr.u.iAddr8[12] = 0; |
|
136 addr.u.iAddr8[13] = 0; |
|
137 addr.u.iAddr8[14] = 0; |
|
138 addr.u.iAddr8[15] = 1; |
|
139 |
|
140 UpdateAddress(*NetworkService ()->Interfacer (), addr, remove); |
|
141 } |
|
142 } |
|
143 |
|
144 |
|
145 // ========================== OTHER EXPORTED FUNCTIONS ======================== |
|
146 |
|
147 // End of File |