mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
eth: process function
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
#define _ETH_H
|
#define _ETH_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <kernel/net.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t destination[6];
|
uint8_t destination[6];
|
||||||
@@ -12,4 +13,6 @@ typedef struct {
|
|||||||
#define ETH_PROTO_IP 0x0800
|
#define ETH_PROTO_IP 0x0800
|
||||||
#define ETH_PROTO_ARP 0x0806
|
#define ETH_PROTO_ARP 0x0806
|
||||||
|
|
||||||
|
void eth_process(netdev_t *netdev, void *buffer);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <kernel/eth.h>
|
#include <hashtable.h>
|
||||||
|
#include <mutex.h>
|
||||||
|
#include <event.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *address;
|
void *address;
|
||||||
@@ -19,22 +22,11 @@ typedef struct {
|
|||||||
typedef struct netdev_t {
|
typedef struct netdev_t {
|
||||||
mac_t mac;
|
mac_t mac;
|
||||||
size_t mtu;
|
size_t mtu;
|
||||||
|
hashtable_t arpcache;
|
||||||
int (*allocdesc)(size_t requestedsize, netdesc_t *desc);
|
int (*allocdesc)(size_t requestedsize, netdesc_t *desc);
|
||||||
int (*sendpacket)(struct netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto);
|
int (*sendpacket)(struct netdev_t *_internal, netdesc_t desc, mac_t targetmac, int proto);
|
||||||
} netdev_t;
|
} netdev_t;
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint16_t hwtype;
|
|
||||||
uint16_t protocoltype;
|
|
||||||
uint8_t hwlen;
|
|
||||||
uint8_t ptlen;
|
|
||||||
uint16_t opcode;
|
|
||||||
uint8_t srchw[6];
|
|
||||||
uint8_t srcpt[4];
|
|
||||||
uint8_t dsthw[6];
|
|
||||||
uint8_t dstpt[4];
|
|
||||||
} __attribute__((packed)) arpframe_t;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t version_length;
|
uint8_t version_length;
|
||||||
uint8_t servicetype_ecn;
|
uint8_t servicetype_ecn;
|
||||||
@@ -55,10 +47,20 @@ typedef struct {
|
|||||||
uint16_t checksum;
|
uint16_t checksum;
|
||||||
} __attribute__((packed)) udpframe_t;
|
} __attribute__((packed)) udpframe_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t port;
|
||||||
|
uint32_t addr;
|
||||||
|
} ipv4addr_t;
|
||||||
|
|
||||||
#define NET_BROADCAST_MAC (mac_t){.address = {0xff,0xff,0xff,0xff,0xff,0xff}}
|
#define NET_BROADCAST_MAC (mac_t){.address = {0xff,0xff,0xff,0xff,0xff,0xff}}
|
||||||
|
|
||||||
|
#define MAC_EQUAL(m1,m2) (memcmp(m1, m2, sizeof(mac_t)) == 0)
|
||||||
|
|
||||||
#define IPV4_PROTO_UDP 0x11
|
#define IPV4_PROTO_UDP 0x11
|
||||||
|
|
||||||
|
void arp_init();
|
||||||
|
void udp_init();
|
||||||
|
void arp_process(netdev_t *netdev, void *buffer);
|
||||||
int udp_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
int udp_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
||||||
int udp_sendpacket(netdev_t *netdev, netdesc_t desc, uint32_t ip, uint16_t srcport, uint16_t dstport);
|
int udp_sendpacket(netdev_t *netdev, netdesc_t desc, uint32_t ip, uint16_t srcport, uint16_t dstport);
|
||||||
int ipv4_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
int ipv4_allocdesc(netdev_t *netdev, size_t requestedsize, netdesc_t *desc);
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#include <kernel/net.h>
|
||||||
|
#include <kernel/eth.h>
|
||||||
|
#include <logging.h>
|
||||||
|
|
||||||
|
// runs on dpc context, called by the individual driver dpcs on a receive.
|
||||||
|
void eth_process(netdev_t *netdev, void *buffer) {
|
||||||
|
ethframe_t *frame = buffer;
|
||||||
|
|
||||||
|
mac_t dst, src;
|
||||||
|
memcpy(&dst, &frame->destination, sizeof(mac_t));
|
||||||
|
memcpy(&src, &frame->source, sizeof(mac_t));
|
||||||
|
|
||||||
|
mac_t broadcast = NET_BROADCAST_MAC;
|
||||||
|
// check if packet is for our machine or a broadcast. if neither, do nothing
|
||||||
|
if (!(MAC_EQUAL(&dst, &netdev->mac) || MAC_EQUAL(&dst, &broadcast)))
|
||||||
|
return;
|
||||||
|
|
||||||
|
printf("our machine!\n");
|
||||||
|
|
||||||
|
void *nextbuff = (void *)((uintptr_t)buffer + sizeof(ethframe_t));
|
||||||
|
|
||||||
|
switch (be_to_cpu_w(frame->type)) {
|
||||||
|
case ETH_PROTO_IP:
|
||||||
|
break;
|
||||||
|
case ETH_PROTO_ARP:
|
||||||
|
arp_process(netdev, nextbuff);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <kernel/net.h>
|
#include <kernel/net.h>
|
||||||
|
#include <kernel/eth.h>
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user