Sync with trunk head
[reactos.git] / dll / win32 / iphlpapi / route_reactos.c
1 /*
2 * iphlpapi dll implementation -- Setting and storing route information
3 *
4 * These are stubs for functions that set routing information on the target
5 * operating system. They are grouped here because their implementation will
6 * vary widely by operating system.
7 *
8 * Copyright (C) 2004 Art Yerkes
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #include "config.h"
25 #include "iphlpapi_private.h"
26
27 #include <stdarg.h>
28 #include <stdlib.h>
29 #include <sys/types.h>
30 #ifdef HAVE_NETINET_IN_H
31 # include <netinet/in.h>
32 #endif
33 #ifdef HAVE_ARPA_INET_H
34 # include <arpa/inet.h>
35 #endif
36 #ifdef HAVE_ARPA_NAMESER_H
37 # include <arpa/nameser.h>
38 #endif
39 #ifdef HAVE_RESOLV_H
40 # include <resolv.h>
41 #endif
42
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winreg.h"
46 #include "resinfo.h"
47 #include "iphlpapi.h"
48 #include "wine/debug.h"
49
50 #define IP_FORWARD_ADD 3
51 #define IP_FORWARD_DEL 2
52
53 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
54
55 DWORD createIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
56 HANDLE tcpFile;
57 NTSTATUS status = openTcpFile( &tcpFile );
58 TCP_REQUEST_SET_INFORMATION_EX_ROUTE_ENTRY req =
59 TCP_REQUEST_SET_INFORMATION_INIT;
60 IPRouteEntry *rte;
61 TDIEntityID id;
62 DWORD returnSize = 0;
63
64 TRACE("Called.\n");
65
66 if( NT_SUCCESS(status) ) {
67 status = getNthIpEntity( tcpFile, pRoute->dwForwardIfIndex, &id );
68
69 if( NT_SUCCESS(status) ) {
70 req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
71 req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
72 req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID;
73 req.Req.ID.toi_entity.tei_instance = id.tei_instance;
74 req.Req.ID.toi_entity.tei_entity = CL_NL_ENTITY;
75 req.Req.BufferSize = sizeof(*rte);
76 rte =
77 (IPRouteEntry *)&req.Req.Buffer[0];
78
79 // dwForwardPolicy
80 // dwForwardNextHopAS
81 rte->ire_dest = pRoute->dwForwardDest;
82 rte->ire_mask = pRoute->dwForwardMask;
83 rte->ire_gw = pRoute->dwForwardNextHop;
84 rte->ire_index = pRoute->dwForwardIfIndex;
85 rte->ire_type = IP_FORWARD_ADD;
86 rte->ire_proto = pRoute->dwForwardProto;
87 rte->ire_age = pRoute->dwForwardAge;
88 rte->ire_metric1 = pRoute->dwForwardMetric1;
89 rte->ire_metric2 = pRoute->dwForwardMetric2;
90 rte->ire_metric3 = pRoute->dwForwardMetric3;
91 rte->ire_metric4 = pRoute->dwForwardMetric4;
92 rte->ire_metric5 = pRoute->dwForwardMetric5;
93
94 status = DeviceIoControl( tcpFile,
95 IOCTL_TCP_SET_INFORMATION_EX,
96 &req,
97 sizeof(req),
98 NULL,
99 0,
100 &returnSize,
101 NULL );
102 }
103
104 closeTcpFile( tcpFile );
105 }
106
107 TRACE("Returning: %08x (IOCTL was %08x)\n", status, IOCTL_TCP_SET_INFORMATION_EX);
108
109 if( NT_SUCCESS(status) )
110 return NO_ERROR;
111 else
112 return status;
113 }
114
115 DWORD setIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
116 FIXME(":stub\n");
117 return (DWORD) 0;
118 }
119
120 DWORD deleteIpForwardEntry( PMIB_IPFORWARDROW pRoute ) {
121 HANDLE tcpFile;
122 NTSTATUS status = openTcpFile( &tcpFile );
123 TCP_REQUEST_SET_INFORMATION_EX_ROUTE_ENTRY req =
124 TCP_REQUEST_SET_INFORMATION_INIT;
125 IPRouteEntry *rte;
126 TDIEntityID id;
127 DWORD returnSize = 0;
128
129 TRACE("Called.\n");
130
131 if( NT_SUCCESS(status) ) {
132 status = getNthIpEntity( tcpFile, pRoute->dwForwardIfIndex, &id );
133
134 if( NT_SUCCESS(status) ) {
135 req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
136 req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
137 req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID;
138 req.Req.ID.toi_entity.tei_instance = id.tei_instance;
139 req.Req.ID.toi_entity.tei_entity = CL_NL_ENTITY;
140 req.Req.BufferSize = sizeof(*rte);
141 rte =
142 (IPRouteEntry *)&req.Req.Buffer[0];
143
144 // dwForwardPolicy
145 // dwForwardNextHopAS
146 rte->ire_dest = pRoute->dwForwardDest;
147 rte->ire_mask = INADDR_NONE;
148 rte->ire_gw = pRoute->dwForwardNextHop;
149 rte->ire_index = pRoute->dwForwardIfIndex;
150 rte->ire_type = IP_FORWARD_DEL;
151 rte->ire_proto = pRoute->dwForwardProto;
152 rte->ire_age = pRoute->dwForwardAge;
153 rte->ire_metric1 = pRoute->dwForwardMetric1;
154 rte->ire_metric2 = INADDR_NONE;
155 rte->ire_metric3 = INADDR_NONE;
156 rte->ire_metric4 = INADDR_NONE;
157 rte->ire_metric5 = INADDR_NONE;
158
159 status = DeviceIoControl( tcpFile,
160 IOCTL_TCP_SET_INFORMATION_EX,
161 &req,
162 sizeof(req),
163 NULL,
164 0,
165 &returnSize,
166 NULL );
167 }
168
169 closeTcpFile( tcpFile );
170 }
171
172 TRACE("Returning: %08x (IOCTL was %08x)\n", status, IOCTL_TCP_SET_INFORMATION_EX);
173
174 if( NT_SUCCESS(status) )
175 return NO_ERROR;
176 else
177 return status;
178 }