[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] [PATCH 1/3] tcpip: Kommandozeilenparameter fuer Default-IP



+ tcpip: Kommandozeilenparameter ip=a.b.c.d fuer Default-IP. Die vom Treiber
  uebergebene IP wird ab sofort ignoriert.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 src/modules/tcpip/arp.c          |    6 +++---
 src/modules/tcpip/include/main.h |    9 ++++++---
 src/modules/tcpip/ip.c           |    2 +-
 src/modules/tcpip/lostio_if.c    |    4 ++--
 src/modules/tcpip/main.c         |    8 +++++++-
 src/modules/tcpip/tcp.c          |    2 +-
 src/modules/tcpip/tcp_server.c   |    2 +-
 7 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/modules/tcpip/arp.c b/src/modules/tcpip/arp.c
index e2b7609..b2b6236 100644
--- a/src/modules/tcpip/arp.c
+++ b/src/modules/tcpip/arp.c
@@ -76,7 +76,7 @@ static void arp_send_request(struct device *device,
     arp->source_mac = device->dev.mac;
     arp->dest_mac = eth->dest;
 
-    arp->source_ip = device->dev.ip;
+    arp->source_ip = device->ip;
     arp->dest_ip = ip;
 
     ethernet_send_packet(device,
@@ -107,7 +107,7 @@ void arp_send_response(struct device* device, struct arp* request)
     arp->source_mac = eth->src;
     arp->dest_mac = eth->dest;
 
-    arp->source_ip = device->dev.ip;
+    arp->source_ip = device->ip;
     arp->dest_ip = request->source_ip;
 
     ethernet_send_packet(device,
@@ -173,7 +173,7 @@ void arp_receive(struct device *device, void* packet, size_t size)
     }
     else if (arp->command == ARP_CMD_REQUEST)
     {
-        if (arp->dest_ip == device->dev.ip) {
+        if (arp->dest_ip == device->ip) {
             arp_send_response(device, arp);
         }
     }
diff --git a/src/modules/tcpip/include/main.h b/src/modules/tcpip/include/main.h
index caebd31..9340469 100644
--- a/src/modules/tcpip/include/main.h
+++ b/src/modules/tcpip/include/main.h
@@ -37,11 +37,13 @@
 #define _MAIN_H_
 
 #include <collections.h>
-#include "network.h"
+#include <network.h>
+#include <stdint.h>
 
 struct module_options {
-    dword   gateway;
-    dword   nameserver;
+    uint32_t    gateway;
+    uint32_t    nameserver;
+    uint32_t    ip;
 };
 
 struct driver
@@ -55,6 +57,7 @@ struct device
 {
     struct net_device dev;
     struct driver *driver;
+    uint32_t ip;
 };
 
 extern struct module_options options;
diff --git a/src/modules/tcpip/ip.c b/src/modules/tcpip/ip.c
index 67c60b1..8a1b975 100644
--- a/src/modules/tcpip/ip.c
+++ b/src/modules/tcpip/ip.c
@@ -120,7 +120,7 @@ static bool ip_send_packet_direct(struct device* device, uint32_t dest_ip,
     struct eth_packet_header* eth;
 
     // Source-IP im Header eintagen und Pruefsumme berechnen
-    header->source_ip = device->dev.ip;
+    header->source_ip = device->ip;
     ip_update_checksum(header);
 
 
diff --git a/src/modules/tcpip/lostio_if.c b/src/modules/tcpip/lostio_if.c
index a3b0f1c..b79ebf8 100644
--- a/src/modules/tcpip/lostio_if.c
+++ b/src/modules/tcpip/lostio_if.c
@@ -357,7 +357,7 @@ size_t lostio_netconfig_read(lostio_filehandle_t *handle, void *buf, size_t bloc
     char *data = NULL;
     // <treibername>/<devicenummer>/ip
     if (handle->node->size == 1)
-        data = ip_to_string(device->dev.ip);
+        data = ip_to_string(device->ip);
     // <treibername>/<devicenummer>/mac
     else if (handle->node->size == 2)
         data = mac_to_string(device->dev.mac);
@@ -385,7 +385,7 @@ size_t lostio_netconfig_write(lostio_filehandle_t *handle, size_t blocksize, siz
     struct device *device = (struct device *) handle->node->data;
     if (handle->node->size == 1)
     {
-        device->dev.ip = string_to_ip(data);
+        device->ip = string_to_ip(data);
         return blocksize * count;
     }
     else if (handle->node->size == 2)
diff --git a/src/modules/tcpip/main.c b/src/modules/tcpip/main.c
index 5618482..1a99014 100644
--- a/src/modules/tcpip/main.c
+++ b/src/modules/tcpip/main.c
@@ -55,7 +55,8 @@ static list_t *net_drivers;
 
 struct module_options options = {
     .gateway = 0x0202000a,
-    .nameserver = 0xdede43d0
+    .nameserver = 0xdede43d0,
+    .ip = 0x0e02000a,
 };
 
 void init_routing(struct device *device);
@@ -157,6 +158,7 @@ void rpc_register_driver(pid_t pid, dword cid, size_t data_size, void* data)
     struct device *device = malloc(sizeof(struct device));
     memcpy(device, data, sizeof(struct net_device));
     device->driver = driver;
+    device->ip = options.ip;
     list_push(driver->devices, device);
 
     // VFS Ordner und Dateien für das Device erstellen
@@ -218,6 +220,10 @@ void process_parameter(struct module_options* options, char* param)
         dword nameserver = string_to_ip(&param[3]);        
         printf("Nameserver: %08x\n", nameserver);
         options->nameserver = nameserver;
+    } else if (strncmp(param, "ip=", 3) == 0) {
+        uint32_t ip = string_to_ip(&param[3]);
+        printf("IP-Adresse: %08x\n", ip);
+        options->ip = ip;
     } else {
         printf("Unbekannter Parameter %s\n", param);
     }
diff --git a/src/modules/tcpip/tcp.c b/src/modules/tcpip/tcp.c
index 30d39ae..79febba 100644
--- a/src/modules/tcpip/tcp.c
+++ b/src/modules/tcpip/tcp.c
@@ -196,7 +196,7 @@ struct tcp_connection* tcp_open_connection(dword ip, word port)
 
     conn->dest_ip = ip;
     conn->dest_port = port;
-    conn->source_ip = route->device->dev.ip;
+    conn->source_ip = route->device->ip;
     conn->source_port = tcp_get_free_port();
     conn->window = 0;
     conn->ack = 0;
diff --git a/src/modules/tcpip/tcp_server.c b/src/modules/tcpip/tcp_server.c
index 16b0a72..28ce98d 100644
--- a/src/modules/tcpip/tcp_server.c
+++ b/src/modules/tcpip/tcp_server.c
@@ -242,7 +242,7 @@ int tcp_incoming_connection(uint32_t remote_ip,
 
     conn->dest_ip = remote_ip;
     conn->dest_port = remote_port;
-    conn->source_ip = route->device->dev.ip;
+    conn->source_ip = route->device->ip;
     conn->source_port = local_port;
     conn->window = 0x1000;
     conn->ack = big_endian_dword(header->seq) + 1;
-- 
1.5.6.5