mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2025-01-02 18:56:32 +00:00
1b75d91002
Add arg to SATARep to specify drive types to show. Add checks in AHCIPortInit to verify port signatures, add helper method to get signatures from port.
312 lines
25 KiB
HTML
Executable file
312 lines
25 KiB
HTML
Executable file
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
|
|
<meta name="generator" content="ZealOS V0.13">
|
|
<style type="text/css">
|
|
body {background-color:#fef1f0;}
|
|
.cF0{color:#000000;background-color:#fef1f0;}
|
|
.cF1{color:#0148a4;background-color:#fef1f0;}
|
|
.cF2{color:#3b7901;background-color:#fef1f0;}
|
|
.cF3{color:#057c7e;background-color:#fef1f0;}
|
|
.cF4{color:#bb2020;background-color:#fef1f0;}
|
|
.cF5{color:#9e42ae;background-color:#fef1f0;}
|
|
.cF6{color:#b57901;background-color:#fef1f0;}
|
|
.cF7{color:#b2b6af;background-color:#fef1f0;}
|
|
.cF8{color:#555753;background-color:#fef1f0;}
|
|
.cF9{color:#678fbb;background-color:#fef1f0;}
|
|
.cFA{color:#82bc49;background-color:#fef1f0;}
|
|
.cFB{color:#0097a2;background-color:#fef1f0;}
|
|
.cFC{color:#e26a6a;background-color:#fef1f0;}
|
|
.cFD{color:#c671bc;background-color:#fef1f0;}
|
|
.cFE{color:#c7ab00;background-color:#fef1f0;}
|
|
.cFF{color:#fef1f0;background-color:#fef1f0;}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<pre style="font-family:monospace;font-size:12pt">
|
|
<a name="l1"></a><span class=cF0>#</span><span class=cF1>define</span><span class=cF0> IPV4_ERR_ADDR_INVALID -</span><span class=cFE>200001</span><span class=cF0>
|
|
<a name="l2"></a>#</span><span class=cF1>define</span><span class=cF0> IPV4_ERR_HOST_UNREACHABLE -</span><span class=cFE>200002</span><span class=cF0>
|
|
<a name="l3"></a>
|
|
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> IPV4_TTL </span><span class=cFE>64</span><span class=cF0>
|
|
<a name="l5"></a>
|
|
<a name="l6"></a></span><span class=cF2>//Look up IP Protocol Numbers online to see many more.</span><span class=cF0>
|
|
<a name="l7"></a>#</span><span class=cF1>define</span><span class=cF0> IP_PROTOCOL_ICMP </span><span class=cFE>0x01</span><span class=cF0>
|
|
<a name="l8"></a>#</span><span class=cF1>define</span><span class=cF0> IP_PROTOCOL_TCP </span><span class=cFE>0x06</span><span class=cF0>
|
|
<a name="l9"></a>#</span><span class=cF1>define</span><span class=cF0> IP_PROTOCOL_UDP </span><span class=cFE>0x11</span><span class=cF0>
|
|
<a name="l10"></a>
|
|
<a name="l11"></a></span><span class=cF1>class</span><span class=cF0> CIPV4Packet
|
|
<a name="l12"></a>{
|
|
<a name="l13"></a> CEthernetFrame *ethernet_frame;
|
|
<a name="l14"></a>
|
|
<a name="l15"></a> </span><span class=cF9>U32</span><span class=cF0> source_ip_address;
|
|
<a name="l16"></a> </span><span class=cF9>U32</span><span class=cF0> destination_ip_address;
|
|
<a name="l17"></a>
|
|
<a name="l18"></a> </span><span class=cF1>U8</span><span class=cF0> protocol;
|
|
<a name="l19"></a> </span><span class=cF1>U8</span><span class=cF0> padding[</span><span class=cFE>7</span><span class=cF0>];
|
|
<a name="l20"></a>
|
|
<a name="l21"></a> </span><span class=cF1>U8</span><span class=cF0> *data;
|
|
<a name="l22"></a> </span><span class=cF9>I64</span><span class=cF0> length;
|
|
<a name="l23"></a>};
|
|
<a name="l24"></a>
|
|
<a name="l25"></a></span><span class=cF1>class</span><span class=cF0> CIPV4Header
|
|
<a name="l26"></a>{ </span><span class=cF2>// note: U4's in some U8s.</span><span class=cF0>
|
|
<a name="l27"></a> </span><span class=cF1>U8</span><span class=cF0> version_ihl; </span><span class=cF2>// Version for IPV4 is 4. IHL=Internet Header Length</span><span class=cF0>
|
|
<a name="l28"></a> </span><span class=cF1>U8</span><span class=cF0> dscp_ecn; </span><span class=cF2>// DSCP=Differentiated Services Code Point. ECN=Explicit Congestion Notification</span><span class=cF0>
|
|
<a name="l29"></a>
|
|
<a name="l30"></a> </span><span class=cF9>U16</span><span class=cF0> total_length; </span><span class=cF2>// min 20B max 65535</span><span class=cF0>
|
|
<a name="l31"></a> </span><span class=cF9>U16</span><span class=cF0> identification;
|
|
<a name="l32"></a> </span><span class=cF9>U16</span><span class=cF0> flags_fragment_offset; </span><span class=cF2>// flags first(?) 3 bits. fragment offset min 0 max 65528</span><span class=cF0>
|
|
<a name="l33"></a> </span><span class=cF2>// flag: bit 0: reserved must be 0. bit 1: don't fragment. bit 2: more fragments</span><span class=cF0>
|
|
<a name="l34"></a>
|
|
<a name="l35"></a> </span><span class=cF1>U8</span><span class=cF0> time_to_live; </span><span class=cF2>// specified in seconds, wikipedia says nowadays serves as a hop count</span><span class=cF0>
|
|
<a name="l36"></a> </span><span class=cF1>U8</span><span class=cF0> protocol;
|
|
<a name="l37"></a>
|
|
<a name="l38"></a> </span><span class=cF9>U16</span><span class=cF0> header_checksum;
|
|
<a name="l39"></a>
|
|
<a name="l40"></a> </span><span class=cF9>U32</span><span class=cF0> source_ip_address;
|
|
<a name="l41"></a> </span><span class=cF9>U32</span><span class=cF0> destination_ip_address;
|
|
<a name="l42"></a>};
|
|
<a name="l43"></a>
|
|
<a name="l44"></a></span><span class=cF1>class</span><span class=cF0> CIPV4Globals
|
|
<a name="l45"></a>{ </span><span class=cF2>// _be indicates Big Endian</span><span class=cF0>
|
|
<a name="l46"></a> </span><span class=cF9>U32</span><span class=cF0> local_ip;
|
|
<a name="l47"></a> </span><span class=cF9>U32</span><span class=cF0> local_ip_be;
|
|
<a name="l48"></a>
|
|
<a name="l49"></a> </span><span class=cF9>U32</span><span class=cF0> ipv4_router_address;
|
|
<a name="l50"></a> </span><span class=cF9>U32</span><span class=cF0> ipv4_subnet_mask;
|
|
<a name="l51"></a>
|
|
<a name="l52"></a>} ipv4_globals;
|
|
<a name="l53"></a>
|
|
<a name="l54"></a></span><span class=cF1>U0</span><span class=cF0> IPV4GlobalsInit()
|
|
<a name="l55"></a>{
|
|
<a name="l56"></a> ipv4_globals.local_ip = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l57"></a> ipv4_globals.local_ip_be = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l58"></a> ipv4_globals.ipv4_router_address = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l59"></a> ipv4_globals.ipv4_subnet_mask = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l60"></a>};
|
|
<a name="l61"></a>
|
|
<a name="l62"></a></span><span class=cF2>// For now, trusting Shrine's implement</span><span class=cF0>
|
|
<a name="l63"></a></span><span class=cF2>// of checksum. Shrine links back to</span><span class=cF0>
|
|
<a name="l64"></a></span><span class=cF2>// http://stackoverflow.com/q/26774761/2524350</span><span class=cF0>
|
|
<a name="l65"></a>
|
|
<a name="l66"></a></span><span class=cF9>U16</span><span class=cF0> IPV4Checksum(</span><span class=cF1>U8</span><span class=cF0> *header, </span><span class=cF9>I64</span><span class=cF0> length)
|
|
<a name="l67"></a>{ </span><span class=cF2>//todo. make names clearer, and better comments.</span><span class=cF0>
|
|
<a name="l68"></a> </span><span class=cF9>I64</span><span class=cF0> nleft = length;
|
|
<a name="l69"></a> </span><span class=cF9>U16</span><span class=cF0> *w = header;
|
|
<a name="l70"></a> </span><span class=cF9>I64</span><span class=cF0> sum = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l71"></a>
|
|
<a name="l72"></a> </span><span class=cF1>while</span><span class=cF0> (nleft > </span><span class=cFE>1</span><span class=cF0>)
|
|
<a name="l73"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l74"></a> sum += *w++;
|
|
<a name="l75"></a> nleft -= </span><span class=cFE>2</span><span class=cF0>;
|
|
<a name="l76"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l77"></a>
|
|
<a name="l78"></a> </span><span class=cF2>// "mop up an odd byte, if necessary"</span><span class=cF0>
|
|
<a name="l79"></a> </span><span class=cF1>if</span><span class=cF0> (nleft == </span><span class=cFE>1</span><span class=cF0>)
|
|
<a name="l80"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l81"></a> sum += *w & </span><span class=cFE>0x00FF</span><span class=cF0>;
|
|
<a name="l82"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l83"></a>
|
|
<a name="l84"></a> </span><span class=cF2>// "add back carry outs from top 16 bits to low 16 bits"</span><span class=cF0>
|
|
<a name="l85"></a> sum = sum >> </span><span class=cFE>16</span><span class=cF0> + sum & </span><span class=cFE>0xFFFF</span><span class=cF0>; </span><span class=cF2>// "add hi 16 to low 16"</span><span class=cF0>
|
|
<a name="l86"></a> sum += sum >> </span><span class=cFE>16</span><span class=cF0>; </span><span class=cF2>// add carry</span><span class=cF0>
|
|
<a name="l87"></a> </span><span class=cF1>return</span><span class=cF0> ~sum & </span><span class=cFE>0xFFFF</span><span class=cF0>;
|
|
<a name="l88"></a>
|
|
<a name="l89"></a>}
|
|
<a name="l90"></a>
|
|
<a name="l91"></a></span><span class=cF9>I64</span><span class=cF0> IPV4AddressMACGet(</span><span class=cF9>U32</span><span class=cF0> ip_address, </span><span class=cF1>U8</span><span class=cF0> **mac_out)
|
|
<a name="l92"></a>{
|
|
<a name="l93"></a> CARPHash *entry;
|
|
<a name="l94"></a> </span><span class=cF9>I64</span><span class=cF0> retries;
|
|
<a name="l95"></a> </span><span class=cF9>I64</span><span class=cF0> attempt;
|
|
<a name="l96"></a>
|
|
<a name="l97"></a> </span><span class=cF1>if</span><span class=cF0> (ip_address == </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l98"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l99"></a> NetErr(</span><span class=cF6>"GET MAC FOR IP: Failed. Address = 0"</span><span class=cF0>);
|
|
<a name="l100"></a> </span><span class=cF1>return</span><span class=cF0> IPV4_ERR_ADDR_INVALID;
|
|
<a name="l101"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l102"></a> </span><span class=cF1>if</span><span class=cF0> (ip_address == </span><span class=cFE>0xFFFFFFFF</span><span class=cF0>)
|
|
<a name="l103"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l104"></a> NetLog(</span><span class=cF6>"GET MAC FOR IP: Returning ethernet broadcast"</span><span class=cF0>);
|
|
<a name="l105"></a> *mac_out = ethernet_globals.ethernet_broadcast;
|
|
<a name="l106"></a>
|
|
<a name="l107"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l108"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l109"></a>
|
|
<a name="l110"></a> </span><span class=cF2>// "outside this subnet; needs routing"</span><span class=cF0>
|
|
<a name="l111"></a> </span><span class=cF1>if</span><span class=cF0> (ip_address & ipv4_globals.ipv4_subnet_mask != ipv4_globals.local_ip & ipv4_globals.ipv4_subnet_mask)
|
|
<a name="l112"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l113"></a> NetWarn(</span><span class=cF6>"GET MAC FOR IP: TODO: Doing IPV4AddressMACGet recursion, could infinite loop and overflow stack."</span><span class=cF0>);
|
|
<a name="l114"></a> </span><span class=cF1>return</span><span class=cF0> IPV4AddressMACGet(ipv4_globals.ipv4_router_address, mac_out);
|
|
<a name="l115"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l116"></a> </span><span class=cF1>else</span><span class=cF0> </span><span class=cF2>// "local network"</span><span class=cF0>
|
|
<a name="l117"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l118"></a> NetLog(</span><span class=cF6>"GET MAC FOR IP: Attempting ARP Find by IP for address: %0X."</span><span class=cF0>, ip_address);
|
|
<a name="l119"></a> entry = ARPCacheFind(ip_address);
|
|
<a name="l120"></a>
|
|
<a name="l121"></a> </span><span class=cF1>if</span><span class=cF0> (entry)
|
|
<a name="l122"></a> {
|
|
<a name="l123"></a> *mac_out = entry->mac_address;
|
|
<a name="l124"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l125"></a> }
|
|
<a name="l126"></a> </span><span class=cF2>//else, not in cache, need to request it</span><span class=cF0>
|
|
<a name="l127"></a>
|
|
<a name="l128"></a> </span><span class=cF2>// "Up to 4 retries, 500 ms each"</span><span class=cF0>
|
|
<a name="l129"></a> retries = </span><span class=cFE>4</span><span class=cF0>;
|
|
<a name="l130"></a> </span><span class=cF1>while</span><span class=cF0> (retries)
|
|
<a name="l131"></a> {
|
|
<a name="l132"></a> ARPSend(ARP_REQUEST,
|
|
<a name="l133"></a> ethernet_globals.ethernet_broadcast,
|
|
<a name="l134"></a> EthernetMACGet,
|
|
<a name="l135"></a> ipv4_globals.local_ip_be,
|
|
<a name="l136"></a> ethernet_globals.ethernet_null,
|
|
<a name="l137"></a> </span><span class=cF5>EndianU32</span><span class=cF7>(</span><span class=cF0>ip_address</span><span class=cF7>)</span><span class=cF0>);
|
|
<a name="l138"></a>
|
|
<a name="l139"></a> attempt = </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l140"></a> </span><span class=cF1>for</span><span class=cF0> (attempt = </span><span class=cFE>0</span><span class=cF0>; attempt < </span><span class=cFE>50</span><span class=cF0>; attempt++)
|
|
<a name="l141"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l142"></a> </span><span class=cF5>Sleep</span><span class=cF0>(</span><span class=cFE>10</span><span class=cF0>);
|
|
<a name="l143"></a> entry = ARPCacheFind(ip_address);
|
|
<a name="l144"></a> </span><span class=cF1>if</span><span class=cF0> (entry)
|
|
<a name="l145"></a> </span><span class=cF1>break</span><span class=cF0>;
|
|
<a name="l146"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l147"></a>
|
|
<a name="l148"></a> </span><span class=cF1>if</span><span class=cF0> (entry)
|
|
<a name="l149"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l150"></a> *mac_out = entry->mac_address;
|
|
<a name="l151"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cFE>0</span><span class=cF0>;
|
|
<a name="l152"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l153"></a>
|
|
<a name="l154"></a> retries--;
|
|
<a name="l155"></a> }
|
|
<a name="l156"></a>
|
|
<a name="l157"></a> </span><span class=cF2>//Shrine does some in_addr mess to log error</span><span class=cF0>
|
|
<a name="l158"></a> NetErr(</span><span class=cF6>"GET MAC FOR IP: Failed to resolve address %d"</span><span class=cF0>, ip_address);
|
|
<a name="l159"></a> </span><span class=cF1>return</span><span class=cF0> IPV4_ERR_HOST_UNREACHABLE;
|
|
<a name="l160"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l161"></a>}
|
|
<a name="l162"></a>
|
|
<a name="l163"></a></span><span class=cF9>I64</span><span class=cF0> IPV4PacketAllocate(</span><span class=cF1>U8</span><span class=cF0> **frame_out,
|
|
<a name="l164"></a> </span><span class=cF1>U8</span><span class=cF0> protocol,
|
|
<a name="l165"></a> </span><span class=cF9>U32</span><span class=cF0> source_ip_address,
|
|
<a name="l166"></a> </span><span class=cF9>U32</span><span class=cF0> destination_ip_address,
|
|
<a name="l167"></a> </span><span class=cF9>I64</span><span class=cF0> length)
|
|
<a name="l168"></a>{
|
|
<a name="l169"></a> </span><span class=cF1>U8</span><span class=cF0> *ipv4_frame;
|
|
<a name="l170"></a> </span><span class=cF1>U8</span><span class=cF0> *destination_mac_address;
|
|
<a name="l171"></a> </span><span class=cF9>I64</span><span class=cF0> error;
|
|
<a name="l172"></a> </span><span class=cF9>I64</span><span class=cF0> de_index;
|
|
<a name="l173"></a> </span><span class=cF9>I64</span><span class=cF0> internet_header_length;
|
|
<a name="l174"></a> CIPV4Header *header;
|
|
<a name="l175"></a>
|
|
<a name="l176"></a> error = IPV4AddressMACGet(destination_ip_address, &destination_mac_address);
|
|
<a name="l177"></a>
|
|
<a name="l178"></a> </span><span class=cF1>if</span><span class=cF0> (error < </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l179"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l180"></a> NetLog(</span><span class=cF6>"IPV4 PACKET ALLOCATE: Failed to get MAC for destination."</span><span class=cF0>);
|
|
<a name="l181"></a> </span><span class=cF1>return</span><span class=cF0> error;
|
|
<a name="l182"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l183"></a>
|
|
<a name="l184"></a> de_index = EthernetFrameAllocate(&ipv4_frame,
|
|
<a name="l185"></a> EthernetMACGet,
|
|
<a name="l186"></a> destination_mac_address,
|
|
<a name="l187"></a> ETHERTYPE_IPV4,
|
|
<a name="l188"></a> </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF0>CIPV4Header</span><span class=cF7>)</span><span class=cF0> + length);
|
|
<a name="l189"></a> </span><span class=cF1>if</span><span class=cF0> (de_index < </span><span class=cFE>0</span><span class=cF0>)
|
|
<a name="l190"></a> </span><span class=cF7>{</span><span class=cF0>
|
|
<a name="l191"></a> NetLog(</span><span class=cF6>"IPV4 PACKET ALLOCATE: Ethernet Frame Allocate failed."</span><span class=cF0>);
|
|
<a name="l192"></a> </span><span class=cF1>return</span><span class=cF0> de_index;
|
|
<a name="l193"></a> </span><span class=cF7>}</span><span class=cF0>
|
|
<a name="l194"></a>
|
|
<a name="l195"></a> internet_header_length = </span><span class=cFE>5</span><span class=cF0>;</span><span class=cF2>// ... why. need a #define</span><span class=cF0>
|
|
<a name="l196"></a>
|
|
<a name="l197"></a> header = ipv4_frame;
|
|
<a name="l198"></a>
|
|
<a name="l199"></a> header->version_ihl = internet_header_length | </span><span class=cFE>4</span><span class=cF0> << </span><span class=cFE>4</span><span class=cF0>;</span><span class=cF2>// ? TODO: needs #define</span><span class=cF0>
|
|
<a name="l200"></a> header->dscp_ecn = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// a clear define of what this actually means would be good</span><span class=cF0>
|
|
<a name="l201"></a> header->total_length = </span><span class=cF5>EndianU16</span><span class=cF0>(internet_header_length * </span><span class=cFE>4</span><span class=cF0> + length); </span><span class=cF2>//...why?</span><span class=cF0>
|
|
<a name="l202"></a> header->identification = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// define would be clearer</span><span class=cF0>
|
|
<a name="l203"></a> header->flags_fragment_offset = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// define would be clearer</span><span class=cF0>
|
|
<a name="l204"></a> header->time_to_live = IPV4_TTL;
|
|
<a name="l205"></a> header->protocol = protocol;
|
|
<a name="l206"></a> header->header_checksum = </span><span class=cFE>0</span><span class=cF0>; </span><span class=cF2>// why is 0 ok?</span><span class=cF0>
|
|
<a name="l207"></a> header->source_ip_address = </span><span class=cF5>EndianU32</span><span class=cF0>(source_ip_address);
|
|
<a name="l208"></a> header->destination_ip_address = </span><span class=cF5>EndianU32</span><span class=cF0>(destination_ip_address);
|
|
<a name="l209"></a> header->header_checksum = IPV4Checksum(header, internet_header_length * </span><span class=cFE>4</span><span class=cF0>);</span><span class=cF2>//why the 4's...</span><span class=cF0>
|
|
<a name="l210"></a>
|
|
<a name="l211"></a> *frame_out = ipv4_frame + </span><span class=cF1>sizeof</span><span class=cF0>(CIPV4Header);
|
|
<a name="l212"></a> </span><span class=cF1>return</span><span class=cF0> de_index;
|
|
<a name="l213"></a>}
|
|
<a name="l214"></a>
|
|
<a name="l215"></a></span><span class=cF1>U0</span><span class=cF0> IPV4PacketFinish(</span><span class=cF9>I64</span><span class=cF0> de_index) </span><span class=cF2>//alias for EthernetFrameFinish</span><span class=cF0>
|
|
<a name="l216"></a>{
|
|
<a name="l217"></a> EthernetFrameFinish(de_index);
|
|
<a name="l218"></a>}
|
|
<a name="l219"></a>
|
|
<a name="l220"></a></span><span class=cF9>U32</span><span class=cF0> IPV4AddressGet()
|
|
<a name="l221"></a>{
|
|
<a name="l222"></a> </span><span class=cF1>return</span><span class=cF0> ipv4_globals.local_ip;
|
|
<a name="l223"></a>}
|
|
<a name="l224"></a>
|
|
<a name="l225"></a></span><span class=cF1>U0</span><span class=cF0> IPV4AddressSet(</span><span class=cF9>U32</span><span class=cF0> ip_address)
|
|
<a name="l226"></a>{
|
|
<a name="l227"></a> ipv4_globals.local_ip = ip_address;
|
|
<a name="l228"></a> ipv4_globals.local_ip_be = </span><span class=cF5>EndianU32</span><span class=cF0>(ip_address);
|
|
<a name="l229"></a>
|
|
<a name="l230"></a> ARPLocalIPV4Set(ip_address);
|
|
<a name="l231"></a>
|
|
<a name="l232"></a>}
|
|
<a name="l233"></a>
|
|
<a name="l234"></a></span><span class=cF1>U0</span><span class=cF0> IPV4SubnetSet(</span><span class=cF9>U32</span><span class=cF0> router_address, </span><span class=cF9>U32</span><span class=cF0> subnet_mask)
|
|
<a name="l235"></a>{
|
|
<a name="l236"></a> ipv4_globals.ipv4_router_address = router_address;
|
|
<a name="l237"></a> ipv4_globals.ipv4_subnet_mask = subnet_mask;
|
|
<a name="l238"></a>}
|
|
<a name="l239"></a>
|
|
<a name="l240"></a></span><span class=cF2>//I64</span><span class=cF0>
|
|
<a name="l241"></a></span><span class=cF1>U0</span><span class=cF0> IPV4PacketParse(CIPV4Packet *packet_out, CEthernetFrame *ethernet_frame)
|
|
<a name="l242"></a>{
|
|
<a name="l243"></a> </span><span class=cF2>//...if ethertype not ipv4 error?</span><span class=cF0>
|
|
<a name="l244"></a>
|
|
<a name="l245"></a> </span><span class=cF2>// TODO: Check ethernet_frame length ! ... we need to know what's appropriate</span><span class=cF0>
|
|
<a name="l246"></a>
|
|
<a name="l247"></a> CIPV4Header *header = ethernet_frame->data;
|
|
<a name="l248"></a> </span><span class=cF9>I64</span><span class=cF0> header_length = (header->version_ihl & </span><span class=cFE>0x0F</span><span class=cF0>) * </span><span class=cFE>4</span><span class=cF0>;</span><span class=cF2>//this Has to go. at least abstract or something..</span><span class=cF0>
|
|
<a name="l249"></a> </span><span class=cF9>U16</span><span class=cF0> total_length = </span><span class=cF5>EndianU16</span><span class=cF0>(header->total_length);
|
|
<a name="l250"></a>
|
|
<a name="l251"></a> packet_out->ethernet_frame = ethernet_frame;
|
|
<a name="l252"></a> packet_out->source_ip_address = </span><span class=cF5>EndianU32</span><span class=cF0>(header->source_ip_address);
|
|
<a name="l253"></a> packet_out->destination_ip_address = </span><span class=cF5>EndianU32</span><span class=cF0>(header->destination_ip_address);
|
|
<a name="l254"></a> packet_out->protocol = header->protocol;
|
|
<a name="l255"></a> packet_out->data = ethernet_frame->data + header_length;
|
|
<a name="l256"></a> packet_out->length = total_length - header_length;
|
|
<a name="l257"></a>
|
|
<a name="l258"></a></span><span class=cF2>//</span><span class=cF0> </span><span class=cF2>return 0;</span><span class=cF0>
|
|
<a name="l259"></a>}
|
|
<a name="l260"></a>
|
|
<a name="l261"></a></span><span class=cF1>U0</span><span class=cF0> IPV4Rep()
|
|
<a name="l262"></a>{
|
|
<a name="l263"></a> </span><span class=cF6>"$LTBLUE$IPV4 Report:$FG$\n\n"</span><span class=cF0>;
|
|
<a name="l264"></a>
|
|
<a name="l265"></a> </span><span class=cF6>"Local IPV4: %d.%d.%d.%d\n"</span><span class=cF0>,
|
|
<a name="l266"></a> ipv4_globals.local_ip.u8[</span><span class=cFE>3</span><span class=cF0>],
|
|
<a name="l267"></a> ipv4_globals.local_ip.u8[</span><span class=cFE>2</span><span class=cF0>],
|
|
<a name="l268"></a> ipv4_globals.local_ip.u8[</span><span class=cFE>1</span><span class=cF0>],
|
|
<a name="l269"></a> ipv4_globals.local_ip.u8[</span><span class=cFE>0</span><span class=cF0>];
|
|
<a name="l270"></a> </span><span class=cF6>"Router IPV4: %d.%d.%d.%d\n"</span><span class=cF0>,
|
|
<a name="l271"></a> ipv4_globals.ipv4_router_address.u8[</span><span class=cFE>3</span><span class=cF0>],
|
|
<a name="l272"></a> ipv4_globals.ipv4_router_address.u8[</span><span class=cFE>2</span><span class=cF0>],
|
|
<a name="l273"></a> ipv4_globals.ipv4_router_address.u8[</span><span class=cFE>1</span><span class=cF0>],
|
|
<a name="l274"></a> ipv4_globals.ipv4_router_address.u8[</span><span class=cFE>0</span><span class=cF0>];
|
|
<a name="l275"></a> </span><span class=cF6>"Subnet IPV4: %d.%d.%d.%d\n"</span><span class=cF0>,
|
|
<a name="l276"></a> ipv4_globals.ipv4_subnet_mask.u8[</span><span class=cFE>3</span><span class=cF0>],
|
|
<a name="l277"></a> ipv4_globals.ipv4_subnet_mask.u8[</span><span class=cFE>2</span><span class=cF0>],
|
|
<a name="l278"></a> ipv4_globals.ipv4_subnet_mask.u8[</span><span class=cFE>1</span><span class=cF0>],
|
|
<a name="l279"></a> ipv4_globals.ipv4_subnet_mask.u8[</span><span class=cFE>0</span><span class=cF0>];
|
|
<a name="l280"></a> </span><span class=cF6>"\n"</span><span class=cF0>;
|
|
<a name="l281"></a>}
|
|
<a name="l282"></a>
|
|
<a name="l283"></a></span><span class=cF2>// IPV4 handler moved to NetHandlerTask file.</span><span class=cF0>
|
|
<a name="l284"></a>IPV4GlobalsInit;</span></pre></body>
|
|
</html>
|