#milkymist IRC log for Thursday, 2011-05-26

wpwrak(albatart) sounds like a very cool squat ;)01:53
wpwraka bit posh, though01:54
kristianpaulgn8 :-)04:58
scrtsis udp checksum is calculated in minimac or it is left all 0 ?10:17
Fallenouit's calculated by rtems10:17
Fallenouminimac does not compute anything AFAIK10:17
Fallenounot even Ethernet Checksum10:18
scrtshmm, where can I find a reference how the checksum is calculated?10:19
Fallenouyou mean in theory ?10:22
FallenouI thing udp checksum is the same as tcp checksum10:23
Fallenouit's the 1 complement (on 16 bits) of the sum of the 1 complement of bytes of header + payload10:24
Fallenouand you have a pseudo header to add to that10:24
Fallenoubased upon the IP header (ip addr source, dest etc)10:25
Fallenouthis may give you an hint http://www.netfor2.com/udpsum.htm not sure if it is correct but that's the idea10:25
scrtshm, so I take two bytes, make that ones complement, take another two bytes, make them ones complement and do a sum?10:30
scrtse.g. here is a good packet: http://i54.tinypic.com/14o7pzn.jpg10:32
scrtsI should take ones_compl(0xAD68)=0x5297 and ones_compl(0x298B)=0xD674 then 0x5297+0xD674.. then all the bytes added in such way..?10:34
kristianpaulmorning :-)11:02
Fallenouscrts: UDP checksum computation is optional for IPv4. If a checksum is not used it should be set to the value zero.11:15
FallenouI quote from wikipedia11:15
FallenouI quote the RFC11:15
FallenouChecksum is the 16-bit one's complement of the one's complement sum of a pseudo header of information from the IP header, the UDP header, and the data, padded with zero octets at the end (if necessary) to make a multiple of two octets.[4]11:15
scrtsI know, however UDP checksum is a part of IP header checksum, so if I compute this in hardware, I could do less job in software11:16
Fallenouwell it seems you could just set the checksum as 011:16
Fallenoubut computing it in hardware seems feasible11:17
Fallenouscrts: I guess it just means you add all the 16 bits words together using "normal arithmetic" (what they call one's complement arithmetic)12:01
Fallenouand then eventually you do the NOT logical operation on the result12:02
Fallenoulike ~result;12:02
scrtshm, that all 16 bit words are what? source port, dest port, source addr, dest addr,  all the payload, length etc?12:03
Fallenoupseudo header, followed by udp header, followed by udp payload12:03
Fallenouand padded with 0x00 if the number of bytes is not a multiple of two12:04
Fallenou(because you need to be able to sum 16 bits words)12:04
scrtswell yes, in my case the payload is 18 bytes, so no padding required12:04
Fallenouanyway the padding is then dropped after checksum computation12:04
Fallenouit's not sent over the wire12:04
Fallenou(or whatever physical medium you use)12:04
Fallenouone other thing, during checksum computation, set the udp checksum as 012:05
scrtswell I am still failing to calculate that checksum from the packet example12:05
FallenouI had this problem but with tcp a few days ago12:06
Fallenoubut I didn't sort everything out yet12:06
Fallenouscrts: I'm not sure about the endianness12:07
Fallenouabout the summing of 16 bits words12:07
Fallenouif you have aa bb cc dd , not sure if you have to do aa bb + cc dd or  bb aa + dd cc12:07
scrtsI am not sure too, trying all the possible variants :))12:07
Fallenouyep I guess that's the only solution :p12:07
Fallenoubut I think you should do aa bb + cc dd12:08
Fallenoubut that's what the processor is not doing i think12:08
Fallenouif it's normal x86 processor12:08
Fallenousince it's little endian12:08
Fallenouso you may do htons(ntohs(word[i]) + ntohs(word[i+1]))12:09
Fallenouor something like that12:09
Fallenouwell more something like sum += ntohs(word[i])12:10
Fallenouand then ~sum; and then write htons(sum)12:11
scrtswhat does ntohs()?12:18
scrtsI think I understood the calculation12:18
scrtswait a minute, I am checking myself with another packet12:19
Fallenountohs = network to host (for short type, i.e 16 bits)12:19
Fallenounetwork is big endian12:19
Fallenountohs implementation depends on your arch endianness for example12:20
Fallenouso I guess it's some kind of a dummy byte swap for x8612:20
Fallenoufor example in userspace when you bind a socket to a port, you do port = htons(80)12:20
Fallenoufor port 8012:20
Fallenouin order to put 0x0080 in the memory, and not 0x800012:21
scrtsyep, my calculations now are correct12:23
scrtswant to know?12:23
Fallenouyep sure :)12:25
Fallenouis it C code ?12:25
Fallenouif you can pastebin12:25
scrtsno, I did everything by hand12:25
scrtstake a look at the screenshot I gave before12:26
scrtsso You sum up the data as it is, but in 16 bit order: 06BA+02E6+E9AA...=3CBD012:26
scrtssum the source address and destination address in the same way: 3CBD0+2E49+385A+C0A8+003112:27
Fallenouyep that's what I would have done12:27
Fallenoubut in C you have to beware of endianness12:27
scrtsplus protocol +001112:27
Fallenoubut yes12:27
scrtsplus 2X (!!!) length12:27
scrtsthe everything xor FFFF12:28
scrts= checksum12:28
scrtsnow the problem is, how many clock cycles that would take..12:28
Fallenouyou can easily parallelize the summation12:29
Fallenouusing several summers in parallel12:29
Fallenouusing like "pyramids" of summers12:29
scrtsit is12:29
scrtshowever one clock cycle will be eaten by carry transfer :\12:29
scrtshm, I wonder if it is possible to solve this..12:29
Fallenouwell to add two 16 bits words, you need more than 1 clock cycle ?12:30
Fallenouoh and btw, why 2 times the length ? :o :o12:30
FallenouI've read that nowhere12:30
scrtsthe udp header includes UDP length12:31
scrtsand the pseudo ip header includes the length12:31
scrtssomehow those two "merged" into one in my brain lol12:32
Fallenouoh yes12:32
FallenouI took that into account12:32
Fallenoubut not like this :p12:32
Fallenouok ok12:32
scrtsok now o12:32
Fallenougood luck12:35
Fallenouand thanks for asking the question12:35
Fallenouit made the problem more clear to me too :)12:35
--- Fri May 27 201100:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!