xorp

windows_routing_socket.h

00001 /* -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*- */
00002 /* vim:set sts=4 ts=8: */
00003 
00004 /*
00005  * Copyright (c) 2001-2011 XORP, Inc and Others
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License, Version 2, June
00009  * 1991 as published by the Free Software Foundation. Redistribution
00010  * and/or modification of this program under the terms of any other
00011  * version of the GNU General Public License is not permitted.
00012  * 
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016  * see the GNU General Public License, Version 2, a copy of which can be
00017  * found in the XORP LICENSE.gpl file.
00018  * 
00019  * XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020  * http://xorp.net
00021  */
00022 
00023 /*
00024  * $XORP: xorp/fea/data_plane/control_socket/windows_routing_socket.h,v 1.7 2008/10/02 21:56:54 bms Exp $
00025  */
00026 
00027 /*
00028  * This header contains definitions and structures for XORP's adapter
00029  * code for Microsoft's Router Manager V2 API. A pair of DLLs is installed
00030  * into the Routing and Remote Access Service by the FEA which communicate
00031  * Windows internal routing information to XORP using the BSD routing
00032  * socket message format over named pipes.
00033  */
00034 
00035 /*-
00036  * Copyright (c) 1980, 1986, 1993
00037  *  The Regents of the University of California.  All rights reserved.
00038  *
00039  * Redistribution and use in source and binary forms, with or without
00040  * modification, are permitted provided that the following conditions
00041  * are met:
00042  * 1. Redistributions of source code must retain the above copyright
00043  *    notice, this list of conditions and the following disclaimer.
00044  * 2. Redistributions in binary form must reproduce the above copyright
00045  *    notice, this list of conditions and the following disclaimer in the
00046  *    documentation and/or other materials provided with the distribution.
00047  * 4. Neither the name of the University nor the names of its contributors
00048  *    may be used to endorse or promote products derived from this software
00049  *    without specific prior written permission.
00050  *
00051  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00052  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00053  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00054  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00055  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00056  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00057  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00058  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00059  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00060  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00061  * SUCH DAMAGE.
00062  *
00063  *  @(#)route.h 8.4 (Berkeley) 1/9/95
00064  * $FreeBSD: src/sys/net/route.h,v 1.63.2.1 2006/04/04 20:07:23 andre Exp $
00065  */
00066 
00067 #ifndef __FEA_DATA_PLANE_CONTROL_SOCKET_WINDOWS_ROUTING_SOCKET_HH__
00068 #define __FEA_DATA_PLANE_CONTROL_SOCKET_WINDOWS_ROUTING_SOCKET_HH__
00069 
00070 #include "libxorp/xorp.h"
00071 
00072 #ifdef HOST_OS_WINDOWS
00073 
00074 #ifdef  __cplusplus
00075 extern "C" {
00076 #endif
00077 
00078 #define XORPRTM4_PIPENAME   "\\\\.\\pipe\\XorpRtm4"
00079 #define XORPRTM4_LOGNAME    "XORPRTM4"
00080 
00081 #define XORPRTM6_PIPENAME   "\\\\.\\pipe\\XorpRtm6"
00082 #define XORPRTM6_LOGNAME    "XORPRTM6"
00083 
00084 #ifdef IPV6_DLL
00085 #define XORPRTM_PIPENAME    XORPRTM6_PIPENAME
00086 #define XORPRTM_LOGNAME     XORPRTM6_LOGNAME
00087 #define XORPRTM_TRACENAME   XORPRTM6_LOGNAME
00088 #else
00089 #define XORPRTM_PIPENAME    XORPRTM4_PIPENAME
00090 #define XORPRTM_LOGNAME     XORPRTM4_LOGNAME
00091 #define XORPRTM_TRACENAME   XORPRTM4_LOGNAME
00092 #endif
00093 
00094 /*
00095  * Registry glue for Router Manager
00096  */
00097 #define HKLM_XORPRTM4_NAME \
00098 "SOFTWARE\\Microsoft\\Router\\CurrentVersion\\RouterManagers\\Ip\\XORPRTM4"
00099 #define HKLM_XORPRTM6_NAME \
00100 "SOFTWARE\\Microsoft\\Router\\CurrentVersion\\RouterManagers\\Ipv6\\XORPRTM6"
00101 #define HKLM_XORPRTM4_TRACING_NAME \
00102     "SOFTWARE\\Microsoft\\Tracing\\XORPRTM4"
00103 #define HKLM_XORPRTM6_TRACING_NAME \
00104     "SOFTWARE\\Microsoft\\Tracing\\XORPRTM6"
00105 
00106 #define RTMV2_CLSID_IPV4        "{C2FE450A-D6C2-11D0-A37B-00C04FC9DA04}"
00107 #define RTMV2_CLSID_IPV6        "{C2FE451A-D6C2-11D0-A37B-00C04FC9DA04}"
00108 
00109 #define XORPRTM_DLL_VENDOR      "www.xorp.org"
00110 #define XORPRTM_DLL_FLAGS       0x00000002
00111 #define XORPRTM_CONFIG_DLL_NAME "nonexistent.dll"
00112 #define XORPRTM4_DLL_NAME       "xorprtm4.dll"
00113 #define XORPRTM4_DLL_TITLE      "Router Manager V2 adapter for XORP (IPv4)"
00114 #define XORPRTM6_DLL_NAME       "xorprtm6.dll"
00115 #define XORPRTM6_DLL_TITLE      "Router Manager V2 adapter for XORP (IPv6)"
00116 #define XORPRTM_TRACING_PATH    "%windir%\\Tracing"
00117 
00118 /*
00119  * Router Manager V2 IDs for XORP
00120  */
00121 
00122 #define PROTO_IP_XORPRTM    7
00123 #define XORPRTM_PROTOCOL_ID    \
00124     PROTOCOL_ID(PROTO_TYPE_UCAST, PROTO_VENDOR_MS0, PROTO_IP_XORPRTM)
00125 
00126 #define XORPRTM_GLOBAL_CONFIG_ID       1
00127 
00128 /*
00129  * MS Router Manager info structures
00130  */
00131 
00132 typedef struct _XORPRTM_GLOBAL_CONFIG {
00133     DWORD       dummy;
00134 } XORPRTM_GLOBAL_CONFIG, *PXORPRTM_GLOBAL_CONFIG;
00135 
00136 typedef struct _XORPRTM_MIB_SET_INPUT_DATA {
00137     DWORD       IMSID_TypeID;
00138     DWORD       IMSID_IfIndex;
00139     DWORD       IMSID_BufferSize;
00140     BYTE        IMSID_Buffer[0];
00141 } XORPRTM_MIB_SET_INPUT_DATA, *PXORPRTM_MIB_SET_INPUT_DATA;
00142 
00143 typedef struct _XORPRTM_MIB_GET_INPUT_DATA {
00144     DWORD   IMGID_TypeID;
00145     DWORD   IMGID_IfIndex;
00146 } XORPRTM_MIB_GET_INPUT_DATA, *PXORPRTM_MIB_GET_INPUT_DATA;
00147 
00148 typedef struct _XORPRTM_MIB_GET_OUTPUT_DATA {
00149     DWORD   IMGOD_TypeID;
00150     DWORD   IMGOD_IfIndex;
00151     BYTE    IMGOD_Buffer[0];
00152 } XORPRTM_MIB_GET_OUTPUT_DATA, *PXORPRTM_MIB_GET_OUTPUT_DATA;
00153 
00154 /*
00155  * BSD routing socket interface
00156  */
00157 
00158 #define RTF_UP      0x1     /* route usable */
00159 #define RTF_GATEWAY 0x2     /* destination is a gateway */
00160 #define RTF_HOST    0x4     /* host entry (net otherwise) */
00161 #define RTF_REJECT  0x8     /* host or net unreachable */
00162 #define RTF_DYNAMIC 0x10        /* created dynamically (by redirect) */
00163 #define RTF_MODIFIED    0x20        /* modified dynamically (by redirect) */
00164 #define RTF_DONE    0x40        /* message confirmed */
00165 /*          0x80           unused, was RTF_DELCLONE */
00166 #define RTF_CLONING 0x100       /* generate new routes on use */
00167 #define RTF_XRESOLVE    0x200       /* external daemon resolves name */
00168 #define RTF_LLINFO  0x400       /* generated by link layer (e.g. ARP) */
00169 #define RTF_STATIC  0x800       /* manually added */
00170 #define RTF_BLACKHOLE   0x1000      /* just discard pkts (during updates) */
00171 #define RTF_PROTO2  0x4000      /* protocol specific routing flag */
00172 #define RTF_PROTO1  0x8000      /* protocol specific routing flag */
00173 
00174 #define RTF_WASCLONED   0x20000     /* route generated through cloning */
00175 #define RTF_PROTO3  0x40000     /* protocol specific routing flag */
00176 /*          0x80000        unused */
00177 #define RTF_PINNED  0x100000    /* future use */
00178 #define RTF_LOCAL   0x200000    /* route represents a local address */
00179 #define RTF_BROADCAST   0x400000    /* route represents a bcast address */
00180 #define RTF_MULTICAST   0x800000    /* route represents a mcast address */
00181                     /* 0x1000000 and up unassigned */
00182 
00183 /* Mask of RTF flags that are allowed to be modified by RTM_CHANGE. */
00184 #define RTF_FMASK   \
00185     (RTF_PROTO1 | RTF_PROTO2 | RTF_PROTO3 | RTF_BLACKHOLE | \
00186      RTF_REJECT | RTF_STATIC)
00187 
00188 struct rt_metrics {
00189     DWORD rmx_filler[14];   /* Ignore field names but pad in same way */
00190 };
00191 
00192 /*
00193  * Structures for routing messages.
00194  */
00195 struct rt_msghdr {
00196     USHORT  rtm_msglen; /* to skip over non-understood messages */
00197     BYTE    rtm_version;    /* future binary compatibility */
00198     BYTE    rtm_type;   /* message type */
00199     USHORT  rtm_index;  /* index for associated ifp */
00200     DWORD   rtm_flags;  /* flags, incl. kern & message, e.g. DONE */
00201     DWORD   rtm_addrs;  /* bitmask identifying sockaddrs in msg */
00202     LONG    rtm_pid;    /* identify sender */
00203     LONG    rtm_seq;    /* for sender to identify action */
00204     DWORD   rtm_errno;  /* why failed */
00205     DWORD   rtm_fmask;  /* bitmask used in RTM_CHANGE message */
00206 #define rtm_use rtm_fmask   /* deprecated, use rtm_rmx->rmx_pksent */
00207     DWORD   rtm_inits;  /* which metrics we are initializing */
00208     struct  rt_metrics rtm_rmx; /* metrics themselves */
00209 };
00210 
00211 #define RTM_VERSION 66  /* Unique to XORP/Win32 */
00212 
00213 /*
00214  * Message types.
00215  * Only those supported by the Windows subsystem are provided.
00216  */
00217 #define RTM_ADD     0x1 /* Add Route */
00218 #define RTM_DELETE  0x2 /* Delete Route */
00219 #define RTM_CHANGE  0x3 /* Change Metrics or flags */
00220 #define RTM_NEWADDR 0xc /* address being added to iface */
00221 #define RTM_DELADDR 0xd /* address being removed from iface */
00222 #define RTM_IFINFO  0xe /* iface going up/down etc. */
00223 #define RTM_IFANNOUNCE  0x11    /* iface arrival/departure */
00224 
00225 /*
00226  * Bitmask values for rtm_addrs.
00227  */
00228 #define RTA_DST     0x1 /* destination sockaddr present */
00229 #define RTA_GATEWAY 0x2 /* gateway sockaddr present */
00230 #define RTA_NETMASK 0x4 /* netmask sockaddr present */
00231 #define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
00232 #define RTA_IFP     0x10    /* interface name sockaddr present */
00233 #define RTA_IFA     0x20    /* interface addr sockaddr present */
00234 #define RTA_AUTHOR  0x40    /* sockaddr for author of redirect */
00235 #define RTA_BRD     0x80    /* for NEWADDR, broadcast or p-p dest addr */
00236 
00237 /*
00238  * Index offsets for sockaddr array for alternate internal encoding.
00239  */
00240 #define RTAX_DST    0   /* destination sockaddr present */
00241 #define RTAX_GATEWAY    1   /* gateway sockaddr present */
00242 #define RTAX_NETMASK    2   /* netmask sockaddr present */
00243 #define RTAX_GENMASK    3   /* cloning mask sockaddr present */
00244 #define RTAX_IFP    4   /* interface name sockaddr present */
00245 #define RTAX_IFA    5   /* interface addr sockaddr present */
00246 #define RTAX_AUTHOR 6   /* sockaddr for author of redirect */
00247 #define RTAX_BRD    7   /* for NEWADDR, broadcast or p-p dest addr */
00248 #define RTAX_MAX    8   /* size of array to allocate */
00249 
00250 /*
00251  * XXX: The Winsock definition of struct sockaddr does not have
00252  * a size value, therefore we use struct sockaddr_storage in its entirety.
00253  */
00254 #define SA_SIZE(sa) sizeof(struct sockaddr_storage)
00255 
00256 /*
00257  * XXX: The length of IFNAMSIZ must be consistent across the ABI.
00258  * It's different from BSDs to allow for arbitrary FriendlyNames,
00259  * up to a length of 256 bytes.
00260  */
00261 #ifdef IFNAMSIZ
00262 #undef IFNAMSIZ
00263 #endif
00264 #ifndef IFNAMSIZ
00265 #define IFNAMSIZ 256
00266 #endif
00267 
00268 #define IFAN_ARRIVAL    0       /* interface arrival */
00269 #define IFAN_DEPARTURE  1       /* interface departure */
00270 
00271 struct if_announcemsghdr {
00272     USHORT  ifan_msglen;
00273     BYTE    ifan_version;    
00274     BYTE    ifan_type;
00275     DWORD   ifan_index;         /* XXX: This is now 32-bits wide */
00276     BYTE    ifan_name[IFNAMSIZ];    /* FriendlyName in ANSI text. */
00277     BYTE    ifan_what;
00278 };
00279 
00280 /*
00281  * Values for if_link_state.
00282  */
00283 #define LINK_STATE_UNKNOWN      0       /* link invalid/unknown */
00284 #define LINK_STATE_DOWN         1       /* link is down */
00285 #define LINK_STATE_UP           2       /* link is up */
00286 
00287 /*
00288  * XXX: Most of the fields in the original BSD if_data
00289  * structure can't be obtained on Windows from the
00290  * RTMv2 interface status callback,
00291  */
00292 struct if_data {
00293     BYTE    ifi_link_state;
00294 };
00295 
00296 struct if_msghdr {
00297     USHORT  ifm_msglen;
00298     BYTE    ifm_version;
00299     BYTE    ifm_type;
00300     DWORD   ifm_addrs;
00301     DWORD   ifm_flags;
00302     DWORD   ifm_index;
00303     struct  if_data ifm_data;
00304 };
00305 
00306 struct ifa_msghdr {
00307     USHORT  ifam_msglen;
00308     BYTE    ifam_version;
00309     BYTE    ifam_type;
00310     DWORD   ifam_addrs;
00311     DWORD   ifam_flags;
00312     DWORD   ifam_index;
00313     DWORD   ifam_metric;
00314 };
00315 
00316 #ifdef  __cplusplus
00317 }
00318 #endif
00319 
00320 #endif // HOST_OS_WINDOWS
00321 
00322 #endif /* __FEA_DATA_PLANE_CONTROL_SOCKET_WINDOWS_ROUTING_SOCKET_HH__ */
 All Classes Namespaces Functions Variables Typedefs Enumerations