OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [trunk/] [sw/] [dev/] [test_main/] [src/] [net/] [ip.c] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 kuzmi4
 
2
#include "xil_lib.h" 
3
#include "ip.h"
4
#include "icmp.h"
5
 
6
// net-if
7
net_if_t *ifp;
8
 
9
// ??
10
void eth_ip_init(net_if_t *ip_net_if)
11
{
12
    ifp = ip_net_if;
13
    // Final
14
}
15
// simple IP-parser: for {ICMP_PROT} only!!!
16
void eth_ip(char *iv_data)
17
{
18
 
19
    ip_hdr_t * pip; // the internet header
20
    u16 ffo; // IP hdr: {flags + fragment_offset}
21
 
22
    // 
23
    pip = ip_head(iv_data);
24
 
25
    // !check IP version
26
    if ( ((pip->ip_ver_ihl & 0xf0) >> 4) != IP_VER) {
27
        //printf("ip_rcv: bad version number\n");
28
        return;
29
    }
30
 
31
    // !check IP Header Checksum
32
 
33
    // !check our own IP addr / NET IF
34
    if (pip->ip_dest != ifp->ip_addr) {
35
        if (pip->ip_dest != 0xFFFFFFFF) { // broadcast for all nets
36
            //printf("ip_rcv: got pkt not for me; for %x\n", pip->ip_dest);
37
            return;
38
        }
39
    }
40
 
41
    // !check TTL
42
    if (pip->ip_time == 0) { // expired?
43
        //printf("ip_rcv: bad ttl\n");
44
        return;
45
    }
46
 
47
    // Test for fragment:
48
    ffo = htons(pip->ip_flgs_foff);
49
    if (ffo & IP_FLG_MASK){
50
        if ((ffo & IP_FLG_DF) == 0){
51
            //printf("ip_rcv: bad ip-frag\n");
52
            return;
53
        }
54
    }
55
 
56
    // !check IHL
57
    if ((pip->ip_ver_ihl & 0x0F) != IP_LEN) {
58
        //printf("ip_rcv: bad IHL\n");
59
        return;
60
    }
61
 
62
    //
63
    // pass pkt to upper layer
64
    switch(pip->ip_prot) {
65
        case ICMP_PROT : { // Internet Control Message Protocol type
66
            eth_icmp(iv_data);
67
            break;
68
        }
69
        default : { // unsupported type
70
            //printf("ip_rcv: ip_prot=%x\n", pip->ip_prot);
71
            break;
72
        }
73
    }
74
    // Final
75
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.