<commit_before>/**
 * @file arp.c
 *
 * @brief This module implements the Address Resolution Protocol ARP (RFC 826),
 * which is used to convert IP addresses into a low-level hardware address.
 * @date 11.03.2009
 * @author <NAME>
 */
#include <string.h>
#include <common.h>
#include <in.h>
#include <kernel/module.h>
#include <kernel/timers.h>
#include <net/skbuff.h>
#include <net/netdevice.h>
#include <net/net.h>
#include <net/inetdevice.h>
#include <net/etherdevice.h>
#include <net/net_pack_manager.h>
#include <net/arp.h>
#include <net/ip.h>

/* RFC1122 Status:
 *  2.3.2.1 (ARP Cache Validation):
 *    MUST provide mechanism to flush stale cache entries
 *    SHOULD be able to configure cache timeout
 *    MUST throttle ARP retransmits
 *  2.3.2.2 (ARP Packet Queue):
 *    SHOULD save at least one packet from each "conversation" with an
 *      unresolved IP address.
 */

arp_table_t arp_tables[ARP_CACHE_SIZE];

#define ARP_TABLE_SIZE array_len(arp_tables)

#define ARP_TIMER_ID 12

static struct packet_type arp_packet_type = {
        .type = ETH_P_ARP,
        .func = arp_rcv,
};

static LIST_HEAD(arp_q);

/*
 * Check if there are entries that are too old and remove them.
 */
static void arp_check_expire(uint32_t id) {
	int i;
	close_timer(ARP_TIMER_ID);
	for (i = 0; i < ARP_CACHE_SIZE; ++i) {
		arp_tables[i].ctime += ARP_CHECK_INTERVAL;
		if( arp_tables[i].state == 1 &&
		    arp_tables[i].ctime >= ARP_TIMEOUT) {
			arp_tables[i].state = 0;
		}
	}
	set_timer(ARP_TIMER_ID, ARP_CHECK_INTERVAL, arp_check_expire);
}

/* Queue an IP packet, while waiting for the ARP reply packet. */
void arp_queue(sk_buff_t *skb) {
	skb->tries = ARP_MAX_TRIES;
	list_add((struct list_head *)skb, &arp_q);
}

/* This will try to retransmit everything on the queue. */
static void arp_send_q(void) {
	struct list_head *skb_h;
	struct sk_buff *skb;
	net_device_t *dev;
	const struct net_device_ops *ops;
	net_device_stats_t *stats;

	list_for_each(skb_h, (struct list_head *)&arp_q) {
		skb = (struct sk_buff *)skb_h;
		dev = skb->dev;<commit_msg>[No commit log message]<commit_after>/**
 * @file arp.c
 *
 * @brief This module implements the Address Resolution Protocol ARP (RFC 826),
 * which is used to convert IP addresses into a low-level hardware address.
 * @date 11.03.2009
 * @author <NAME>
 */
#include <string.h>
#include <common.h>
#include <in.h>
#include <kernel/module.h>
#include <kernel/timers.h>
#include <net/skbuff.h>
#include <net/netdevice.h>
#include <net/net.h>
#include <net/inetdevice.h>
#include <net/etherdevice.h>
#include <net/net_pack_manager.h>
#include <net/arp.h>
#include <net/ip.h>

/* RFC1122 Status:
 *  2.3.2.1 (ARP Cache Validation):
 *    MUST provide mechanism to flush stale cache entries
 *    SHOULD be able to configure cache timeout
 *    MUST throttle ARP retransmits
 *  2.3.2.2 (ARP Packet Queue):
 *    SHOULD save at least one packet from each "conversation" with an
 *      unresolved IP address.
 */

arp_table_t arp_tables[ARP_CACHE_SIZE];

#define ARP_TABLE_SIZE array_len(arp_tables)

#define ARP_TIMER_ID 12

static struct packet_type arp_packet_type = {
        .type = ETH_P_ARP,
        .func = arp_rcv,
};

static LIST_HEAD(arp_q);

/*
 * Check if there are entries that are too old and remove them.
 */
static void arp_check_expire(uint32_t id) {
	int i;
	close_timer(ARP_TIMER_ID);
	for (i = 0; i < ARP_CACHE_SIZE; ++i) {
		//FIXME:
		//arp_tables[i].ctime += ARP_CHECK_INTERVAL;
		if( arp_tables[i].state == 1 &&
		    arp_tables[i].ctime >= ARP_TIMEOUT) {
			arp_tables[i].state = 0;
		}
	}
	set_timer(ARP_TIMER_ID, ARP_CHECK_INTERVAL, arp_check_expire);
}

/* Queue an IP packet, while waiting for the ARP reply packet. */
void arp_queue(sk_buff_t *skb) {
	skb->tries = ARP_MAX_TRIES;
	list_add((struct list_head *)skb, &arp_q);
}

/* This will try to retransmit everything on the queue. */
static void arp_send_q(void) {
	struct list_head *skb_h;
	struct sk_buff *skb;
	net_device_t *dev;
	const struct net_device_ops *ops;
	net_device_stats_t *stats;

	list_for_each(skb_h, (struct list_head *)&arp_q) {
		skb = (struct sk_buff *)skb_h;
		dev = skb->dev;
{'fraction_non_alphanumeric': 0.12327440058125454, 'fraction_numerical': 0.01453136352627755, 'mean_word_length': 4.006060606060606, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4182650', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1577, 'n_words': 423}