4 namespace eval excentis {
13 namespace eval ByteBlower {
17 package require excentis_basic
44 proc LinkLayer.AutoComplete { frameContent bbPort } {
49 x.Print.Debug "LinkLayer.AutoComplete: OLD Frame Content: {${frameContent}}"
55 set frameSize [
llength $frameContent ]
57 if { $frameSize < $l3HeaderOffset} {
58 error "LinkLayer.AutoComplete: Frame too small"
63 set l2UlProtocol "0x[
string range $frameContentString [
expr 2 * $l2TypeOffset ] [
expr 2 * ( $l2TypeOffset + 2 ) - 1 ] ]"
69 set l3Data [
string range $frameContentString [
expr 2 * $l3HeaderOffset ] end ]
72 switch -- [
string tolower $l2UlProtocol ] {
75 if { $frameSize < $l3HeaderOffset + 20 } {
76 # --- Incomplete IPv4 Header
77 x.Print.Debug stderr "Incomplete IPv4 Header."
80 set l3Length "0x[
string range $l3Data 4 7 ]"
81 incr payloadLength $l3Length
85 set dstIpStr [
string range $l3Data 32 39 ]
88 x.Print.Debug "Destination IPv4 address: ${dstIp}."
90 set l3 [ $bbPort Layer3.IPv4.Get ]
91 x.Print.Debug "Processing L3 Protocol is ${l3} ([
if { [
llength $l3 ] } { lindex [ $l3 Info -implements ] 0 } else { lindex "n/a" 0 } ])."
96 # --- Unable to resolve these kinds of IP addresses
97 x.Print.Debug stderr "IpAddress is ThisNetwork / Multicast / Broadcast."
98 } elseif { [
llength $l3 ] < 1 } {
99 # --- Port is not Layer3 IPv4 configured
100 x.Print.Debug stderr "Port is not Layer3 configured."
103 x.Print.Debug stderr "Netmask is not 'host' netmask and IpAddress is broadcast for netmask."
105 set resolveAddress $dstIp
106 set l3 [ $bbPort Layer3.IPv4.Get ]
117 if { $frameSize < $l3HeaderOffset + 20 } {
118 # --- Incomplete IPv6 Header
120 set ipv6PayloadLength "0x[
string range $l3Data 8 11 ]"
121 incr payloadLength [
expr 40 + $ipv6PayloadLength ]
122 unset ipv6PayloadLength
124 set dstIpStr [
string range $l3Data 48 79 ]
128 set resolveAddress $dstIp
129 set l3 [ $bbPort Layer3.IPv6.Get ]
140 error "LinkLayer.AutoComplete: Auto-completion of VLAN 802.1Q Frame is not supported."
144 # --- PPPoE Discovery/Session TAG
145 error "LinkLayer.AutoComplete: Auto-completion of PPPoE Frame is not supported."
150 error "LinkLayer.AutoComplete: Auto-completion of VLAN QinQ Frame is not supported."
153 # --- Skipping Mac address resolution
154 # If we have e.g. a VLAN tag in the packet already
155 # do we have to resolve including the VLAN tag also?
156 # FIXME: We should fix this to the correct size, using the VLAN's upper layer payload size
157 #incr payloadLength [
expr $frameSize - $l3HeaderOffset ]
158 error "LinkLayer.AutoComplete: Auto-completion of Ethernet Frame (EtherType ${l2UlProtocol}) is not supported."
165 set extraHeaderSize 0
176 set pppoeClients [ $bbPort Layer2_5.PPPoE.Get ]
177 for {
set i [
expr [
llength $pppoeClients ] - 1 ]} { $i >= 0} {
incr i -1} {
178 set pppoeClient [
lindex $pppoeClients $i ]
179 x.Print.Debug "Processing PPPoE Protocol ${pppoeClient} ([
lindex [ $pppoeClient Info -implements ] 0 ])."
185 [ $pppoeClient SessionId.Get ] \
192 set l2UlProtocol 0x8864
195 incr extraHeaderSize 8
199 unset pppoeSessionHeader
203 set vlans [ $bbPort Layer2_5.Vlan.Get ]
204 for {
set i [
expr [
llength $vlans ] - 1 ]} { $i >= 0} {
incr i -1} {
205 set vlanProtocol [
lindex $vlans $i ]
206 x.Print.Debug "Processing VLAN Protocol ${vlanProtocol} ([
lindex [ $vlanProtocol Info -implements ] 0 ])."
211 [ $vlanProtocol ID.Get ] \
212 [ $vlanProtocol Priority.Get ] \
213 [ $vlanProtocol DropEligible.Get ] \
214 [ $vlanProtocol Protocol.ID.Get ] ]
223 set extraHeader "${vlanExtraHeader}${extraHeader}"
227 set l2UlProtocol [ $vlanProtocol Protocol.ID.Get ]
230 unset vlanExtraHeader
237 if { ![ string equal $extraHeader "" ]} {
239 set newFrameContentString [
string range $frameContentString 0 [
expr ( 2 * $l2TypeOffset ) - 1 ] ]
243 append newFrameContentString $extraHeader
244 append newFrameContentString [
string range $frameContentString [
expr ( 2 * $l3HeaderOffset ) ] end ]
245 incr frameSize $extraHeaderSize
248 set newFrameContentString $frameContentString
252 unset extraHeaderSize
257 if { ![ string equal $resolveAddress "" ]} {
260 set destinationMac [ $l3 Resolve $resolveAddress ]
281 set l2 [ $bbPort Layer2.EthII.Get ]
283 set sourceMac [ $l2 Mac.Get ]
290 return ${newFrameContentString}