Main Page | Directories | File List | Globals

ip_core.c

Go to the documentation of this file.
00001 /*
00002  * kernel_net/layer_3/ip/ip_core.c
00003  *
00004  * Copyright (c) 2003-2005 Lukasz Dembinski <dembol@nasa.com.pl>
00005  * All Rights Reserved
00006  * 
00007  * Date:        2005/06
00008  * Author:      Lukasz Dembinski
00009  * Info:        ip_core.c core file
00010  * Contact:     mailto: <dembol@nasa.com.pl>
00011  *
00012  */
00013 
00014 #include <agnix/agnix.h>
00015 #include <agnix/adi/adi.h>
00016 #include <agnix/memory.h>
00017 #include <agnix/net/net.h>
00018 #include <agnix/list.h>
00019 #include <agnix/console.h>
00020 
00021 #define MOD_NAME        "NET: "
00022 
00023 int ip_recv(struct frb_s *frb);
00024 int ip_debug = 0;
00025 
00026 struct net_layer_2_pack ip_pack = {
00027     .pack_type          = 0x0008,
00028     .receiver           = ip_recv,
00029 };
00030 
00031 static struct ip_stats_s ip_stats;
00032 
00033 int ip_ioctl_set_ifaddr(struct adi_netdev_s *netdev, struct net_addr_s *addr)
00034 {
00035     memcpy(&netdev->if_layer_3.if_addr, addr, sizeof(struct net_addr_s));
00036 
00037     return 0;
00038 }
00039 
00040 int ip_ioctl_set_debug(int enable)
00041 {
00042     ip_debug = enable;
00043     
00044     return 0;
00045 }
00046 
00047 int ip_ioctl_get_debug(void)
00048 {
00049     return ip_debug;
00050 }
00051 
00052 int ip_print_stats(void)
00053 {
00054     printf("\n");
00055     printf("Total IP packets:     %d\n", ip_stats.total_packets);
00056     printf("Bad checksum packets: %d\n", ip_stats.bad_checksum_packets);
00057     
00058     return 0;
00059 }
00060 
00061 int ip_recv(struct frb_s *frb)
00062 {
00063     struct ip_hdr_s *iphdr = (struct ip_hdr_s *)frb_data(frb);
00064     u16 checksum;
00065     u8 *saddr_ptr = (u8 *)&iphdr->saddr;
00066     u8 *daddr_ptr = (u8 *)&iphdr->daddr;
00067 
00068     if (ip_debug) {
00069         printf("Packet IP recv %d.%d.%d.%d -> %d.%d.%d.%d\n", 
00070         saddr_ptr[0], saddr_ptr[1], saddr_ptr[2], saddr_ptr[3], 
00071         daddr_ptr[0], daddr_ptr[1], daddr_ptr[2], daddr_ptr[3]);
00072     }
00073 
00074     ip_stats.total_packets++;
00075 
00076     checksum = ip_checksum(iphdr);
00077 
00078     if (ip_checksum(iphdr) != 0) {
00079         printk("Packet IP bad checksum\n");
00080         ip_stats.bad_checksum_packets++;
00081     }
00082 
00083     return 0;
00084 }
00085 
00086 int net_layer_3_ip_init(void)
00087 {
00088     printk(", IPv4");
00089 
00090     net_layer_2_add_pack(&ip_pack);
00091     
00092     return 0;
00093 }
Dokumentacje wygenerowano programem Doxygen 1.4.2 dla projektu Agnix