📄 c-tcpip3.html
字号:
routeAdd ("161.27.0.0", "150.12.0.2"); </a></b></pre></dl><dd><p class="Body"><a name="86665"> </a>Both addresses can be specified either by dotted decimal notation or by the host names defined by the routine <b class="routine"><i class="routine">hostAdd</i></b><b>(</b> <b>)</b>. If the destination address is a subnet, you can use <b class="routine"><i class="routine">routeNetAdd</i></b><b>( )</b> instead.</p><dd><p class="Body"><a name="86669"> </a>For example, consider two VxWorks machines <b class="symbol_lc">vx2</b> and <b class="symbol_lc">vx3</b> (shown in <a href="c-tcpip3.html#86673">Figure 4-3</a>), both interfaced to network 161. Suppose that <b class="symbol_lc">vx3</b> is a gateway between networks 150 and 161 and that its Internet address on network 161 is 161.27.0.3. <div class="frame"><h4 class="EntityTitle"><a name="86673"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 4-3: Routing Example</font></a></h4><dl class="margin"><div class="Anchor"><a name="86705"> </a><img class="figure" border="0" src="images/c-tcpipa5.gif"></div></dl></div></p><dd><p class="Body"><a name="86706"> </a>The following calls can then be made on <b class="symbol_lc">vx2</b> to establish <b class="symbol_lc">vx3</b> as a gateway to network 150:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86707"></b><tt class="output">-> </tt><b>routeAdd ("150.12.0.0", "vx3");</a></b></pre></dl><dd><p class="Body"><a name="86708"> </a>or:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86709"></b><tt class="output">-> </tt><b>routeAdd ("150.12.0.0", "161.27.0.3");</a></b></pre></dl><dd><p class="Body"><a name="86714"> </a>To confirm that a route is in the routing table, use the <b class="routine"><i class="routine">routeShow</i></b><b>(</b> <b>)</b> routine.<sup><a href="#foot"><b class="FootnoteMarker">4</b></a></sup> Other routing routines are available in the library <b class="library">routeLib</b>.</p><dd><p class="Body"><a name="86716"> </a>The VxWorks network startup routine, <b class="routine"><i class="routine">usrNetInit</i></b><b>(</b> <b>)</b> in <b class="file">usrNetwork.c</b>, automatically adds the gateway specified in the boot parameters (if any) to the routing tables. In this case, the address specified in the gateway field (<b class="command">g =</b> ) is added as the gateway to the network of the boot host.</p><dd><p class="Body"><a name="86717"> </a>To add the default route entry to the routing table: </p><dl class="margin"><dd><pre class="Code2"><b><a name="86718">routeAdd ("0.0.0.0", "<i class="textVariable">gatewayAddrs</i>");</a></b></pre></dl><dd><p class="Body"><a name="86719"> </a>If a default route is added to the routing table, any packet for which a host route or a network route cannot be established, is forwarded to the address provided in the default route entry. </p><dd><p class="Body"><a name="86721"> </a>To delete an entry from the routing table, use <b class="routine"><i class="routine">routeDelete</i></b><b>( )</b>. </p><dl class="margin"><dd><pre class="Code2"><b><a name="86722">/* Delete route to node 161.27.0.51 using gateway 150.12.0.2 */ routeDelete ("161.27.0.51", "150.12.0.2");</a></b></pre></dl></dl><dl class="margin"><b class="HU-bullet"><li><a name="86725"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Using <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b></font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="86727"> </a>To use <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>you need to specify a little more information than for a simple <b class="routine"><i class="routine">routeAdd</i></b><b>( )</b> call. However, this extra information does provide support for additional routing services that take into account the type of service or mask associated with a particular route. The general format of a <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b> call is as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86728">mRouteAdd ( "<i class="textVariable">destination</i>", "<i class="textVariable">gateway</i>", <i class="textVariable">netmask</i>, <i class="term">type-of-service</i>, <i class="textVariable">flags</i>)</a></b></pre></dl><dd><p class="Body"><a name="86729"> </a>Thus, to specify that the route to the 90.0.0.0 network use the 91.0.0.3 router:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86730">mRouteAdd ("90.0.0.0", "91.0.0.3", 0xffffff00, 0, 0);</a></b></pre></dl><dd><p class="Body"><a name="86732"> </a>To delete a route that was added using <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>, call <b class="routine"><i class="routine">mRouteDelete</i></b><b>( )</b>. The general format of a call to <b class="routine"><i class="routine">mRouteDelete</i></b><b>( )</b> is as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86733">mRouteDelete ("<i class="textVariable">destination</i>", <i class="textVariable">netmask</i>, <i class="textVariable">tos</i>)</a></b></pre></dl><dd><p class="Body"><a name="86734"> </a>Thus, to delete the route just added above:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86735">mRouteDelete("90.0.0.0", 0xffffff00, 0);</a></b></pre></dl><dd><p class="Body"><a name="86736"> </a>The netmask and type of service must match those of the route you want to delete. Otherwise the route is not deleted. </p><dd><p class="Body"><a name="86737"> </a>Using <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>, you can specify multiple routes to a single destination. These routes differ only in factors such as the netmask or the type of service. For example: </p><dl class="margin"><dd><pre class="Code2"><b><a name="86738">mRouteAdd ("90.0.0.0", "91.0.0.3", 0xFFFFFF00, 0, 0); mRouteAdd ("90.0.0.0", "91.0.0.254", 0xFFFF0000, 0, 0);</a></b></pre></dl><dd><p class="Body"><a name="86740"> </a>Now packets destined for "90.0.0.0" can get there using either of the two different gateways. The distinguishing factor is the netmask, although you could have used the <i class="textVariable">type-of-service</i> or <i class="textVariable">flags</i> values to distinguish the routes. For more information, see the <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b> reference entry. </p></dl><dl class="margin"><b class="HU-bullet"><li><a name="86741"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Setting the Type Of Service</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="86743"> </a>The <i class="textVariable">type-of-service</i> parameter to <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b> takes any of the following values:</p><dl class="margin"><dd><div class="Indent"><a name="86747"> </a><b class="symbol_UC">IPTOS_LOWDELAY</b><sup><a href="#foot"><b class="FootnoteMarker">5</b></a></sup> <br><b class="symbol_UC">IPTOS_THROUGHPUT</b> <br><b class="symbol_UC">IPTOS_RELIABILITY</b> <br><b class="symbol_UC">IPTOS_MINCOST</b> </div><br></dl><dd><p class="Body"><a name="86748"> </a>The routing engine uses these values to pick among multiple routes when a user application requests a certain type of service for their socket. Applications choose their type of service as input to a <b class="routine"><i class="routine">setsockopt</i></b><b>( )</b>call. See the <b class="routine"><i class="routine">setsockopt</i></b><b>( )</b> reference entry for more information.</p></dl><dl class="margin"><b class="HU-bullet"><li><a name="86750"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Setting the Routing Priority</font></li></b></dl><dl class="margin"><dd><p class="Body"><a name="86752"> </a> Within VxWorks it is now possible to have routes chosen on a priority scheme. All routes that are installed in the system have a <i class="emphasis">routing protocol type</i> associated with them. These types are as follows:</p><dl class="margin"><dd><div class="Indent"><a name="86757"> </a><b class="symbol_UC">M2_ipRouteProto_other</b><sup><a href="#foot"><b class="FootnoteMarker">6</b></a></sup> <br><b class="symbol_UC">M2_ipRouteProto_local <br>M2_ipRouteProto_netmgmt <br>M2_ipRouteProto_icmp <br>M2_ipRouteProto_egp <br>M2_ipRouteProto_ggp <br>M2_ipRouteProto_hello <br>M2_ipRouteProto_rip <br>M2_ipRouteProto_is_is <br>M2_ipRouteProto_es_is <br>M2_ipRouteProto_ciscoIgrp <br>M2_ipRouteProto_bbnSpfIgp <br>M2_ipRouteProto_ospf <br>M2_ipRouteProto_bgp</b></div><br></dl><dd><p class="Body"><a name="86759"> </a>All routes added by <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>take a protocol type of <b class="symbol_UC">M2_ipRouteProto_other</b>. </p><dd><p class="Body"><a name="86761"> </a>To set the routing priority, use <b class="routine"><i class="routine">routeProtoPrioritySet</i></b><b>( )</b>:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86762">void routeProtoPrioritySet ( int proto, /* protocol no, from m2Lib.h */ int prio /* priority, >= 0 , <= 200 */ )</a></b></pre></dl><dd><p class="Body"><a name="86767"> </a>Using this routine, you can give a certain class of routes precedence over routes of other classes. For example, you could use <b class="routine"><i class="routine">routeProtoPrioritySet</i></b><b>( )</b>to give OSPF-installed routes precedence over routes installed by RIP or <b class="routine"><i class="routine">mRouteAdd</i></b><b>( )</b>. See the <b class="routine"><i class="routine">routeProtoPrioritySet</i></b><b>( )</b> reference entry for more information.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="86771">4.3.3 Subnet Configuration </a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86773"> </a>An Internet address consists of a network address portion and a host address portion. There are different classes of Internet addresses in which different parts of the 32-bit address are assigned to each portion. This provides a great deal of flexibility in network addressing. Even so, in some environments network addresses are a scarce resource. </p><dd><p class="Body"><a name="86774"> </a>A single network address can be subdivided into multiple sub-networks using a technique called <i class="term">subnet addressing</i>. This technique involves extending the network portion of the addresses used on a particular set of physical networks. The interpretation of the Internet address is altered to include more bits in the network portion and fewer in host portion. For example, if a network uses a type B address (131.1.0.0), the third byte can be used for the subnet and the fourth byte for the host address, as shown in <a href="c-tcpip3.html#86782">Figure 4-4</a>. Internal to the subnet, the Internet address is interpreted as 131.1.7 for the network portion and 81 for the host portion. <div class="frame"><h4 class="EntityTitle"><a name="86782"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 4-4: Subnetting</font></a></h4><dl class="margin"><div class="Anchor"><a name="86800"> </a><img class="figure" border="0" src="images/c-tcpipa7.gif"></div></dl></div></p><dd><p class="Body"><a name="94965"> </a>The specification of which bits are to be interpreted as the network address is called the <i class="term">net mask.</i> A net mask is a 32-bit value with 1's in all bit positions to be interpreted as the network portion. In the example in <a href="c-tcpip3.html#86782">Figure 4-4</a>, the netmask is <b class="symbol_UC">0xFFFFFF00</b>. In VxWorks, use <b class="routine"><i class="routine">ifMaskSet</i></b><b>(</b> <b>)</b> to specify the subnet mask for a particular network interface ( see also the reference entry for <b class="routine"><i class="routine">ifMaskSet</i></b><b>(</b> <b>)</b>).</p><dd><p class="Body"><a name="86807"> </a>To specify a net mask, you must correctly access the host from which you are booting. This can be done by appending <b class="file">:</b><i class="textVariable">mask</i> to the Internet address specifications for the Ethernet and/or backplane interfaces in the boot parameters, where <i class="textVariable">mask</i> is the desired net mask in hexadecimal. For example, when entering boot parameters interactively, it might look as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="94961"></b><tt class="output">inet on ethernet (e) : </tt><b>131.1.7.81:ffffff00 </b><tt class="output">inet on backplane (b) : </tt><b>131.1.81.1:ffffff00 </a></b></pre></dl><dd><p class="Body"><a name="94962"> </a>When specifying the boot parameters in a boot string, the same Internet address specification looks as follows:</p><dl class="margin"><dd><pre class="Code2"><b><a name="86811">e=131.1.7.81:ffffff00 b=131.1.81.1:ffffff00 </a></b></pre></dl></dl></dl><a name="foot"><hr></a><p class="FootnoteNumberMarker">1: <span class="Footnote"><a name="86542"> </a>Internally, <b class="routine"><i class="routine">hostShow</i></b><b>( )</b> uses the resolver library to access DNS to get the information it needs to respond to a query. </span><p class="FootnoteNumberMarker">2: <span class="Footnote"><a name="86618"> </a>This assumes that the VxWorks image is configured with network show routines. The relevant configuration macro is <b class="symbol_UC">INCLUDE_NET_SHOW</b>.</span><p class="FootnoteNumberMarker">3: <span class="Footnote"><a name="86635"> </a>These routines manage static routing entries. These entries are not updated, modified, or deleted by the dynamic routing protocols (RIP or OSPF). They remain active until you explicitly delete them. </span><p class="FootnoteNumberMarker">4: <span class="Footnote"><a name="86713"> </a>This function is not built into the Tornado shell. The relevant configuration macro is <b class="symbol_UC">INCLUDE_NET_SHOW</b>. </span><p class="FootnoteNumberMarker">5: <span class="Footnote"><a name="86746"> </a>The <b class="symbol_UC">IPTOS</b> constants are defined in <b class="file">netinet/ip.h</b>. </span><p class="FootnoteNumberMarker">6: <span class="Footnote"><a name="86756"> </a>The <b class="symbol_UC">M2_ipRouteProto</b> constants are defined in <b class="file">h/m2Lib.h</b>. </span><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="c-tcpip.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-tcpip.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-tcpip2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-tcpip4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 4.0.11 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -