Run indent on files.

This commit is contained in:
Manoel Rebelo Abranches 2011-06-07 21:59:53 -03:00
parent 423a1849ef
commit 4700d08bb4
8 changed files with 307 additions and 288 deletions

View file

@ -9,8 +9,8 @@
static struct arp_entry arp_table[10];
static grub_int8_t new_table_entry = -1;
static
void arp_init_table(void)
static void
arp_init_table (void)
{
grub_memset (arp_table, 0, sizeof (arp_table));
new_table_entry = 0;
@ -103,20 +103,21 @@ grub_net_arp_receive (struct grub_net_buff *nb)
grub_net_network_level_address_t hwaddress;
struct grub_net_network_level_interface *inf;
sender_hardware_address = (grub_uint8_t *) arp_header + sizeof(*arp_header);
sender_hardware_address =
(grub_uint8_t *) arp_header + sizeof (*arp_header);
sender_protocol_address = sender_hardware_address + arp_header->hln;
target_hardware_address = sender_protocol_address + arp_header->pln;
target_protocol_address = target_hardware_address + arp_header->hln;
grub_memcpy (&hwaddress.ipv4, sender_protocol_address, 4);
/* Check if the sender is in the cache table */
/* Check if the sender is in the cache table. */
entry = arp_find_entry (&hwaddress);
/* Update sender hardware address */
/* Update sender hardware address. */
if (entry)
grub_memcpy (entry->ll_address.mac, sender_hardware_address, 6);
else
{
/* Add sender to cache table */
/* Add sender to cache table. */
if (new_table_entry == -1)
arp_init_table ();
entry = &(arp_table[new_table_entry]);
@ -136,10 +137,12 @@ grub_net_arp_receive (struct grub_net_buff *nb)
{
grub_net_link_level_address_t aux;
/* Swap hardware fields */
grub_memcpy (target_hardware_address, sender_hardware_address, arp_header->hln);
grub_memcpy (target_hardware_address, sender_hardware_address,
arp_header->hln);
grub_memcpy (sender_hardware_address, inf->hwaddress.mac, 6);
grub_memcpy (aux.mac, sender_protocol_address, 6);
grub_memcpy (sender_protocol_address, target_protocol_address, arp_header->pln);
grub_memcpy (sender_protocol_address, target_protocol_address,
arp_header->pln);
grub_memcpy (target_protocol_address, aux.mac, arp_header->pln);
/* Change operation to REPLY and send packet */
arp_header->op = grub_be_to_cpu16 (ARP_REPLY);

View file

@ -84,6 +84,3 @@ GRUB_MOD_FINI(emunet)
grub_net_card_unregister (&emucard);
}
}

View file

@ -12,9 +12,12 @@ card_open (struct grub_net_card *dev)
{
int status;
struct grub_ofnetcard_data *data = dev->data;
char path[grub_strlen(data->path) + grub_strlen(":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1];
char path[grub_strlen (data->path) +
grub_strlen (":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512") + 1];
/* The full string will prevent a bootp packet to be sent. Just put some valid ip in there. */
grub_snprintf(path,sizeof(path),"%s%s",data->path,":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512");
grub_snprintf (path, sizeof (path), "%s%s", data->path,
":speed=auto,duplex=auto,1.1.1.1,dummy,1.1.1.1,1.1.1.1,5,5,1.1.1.1,512");
status = grub_ieee1275_open (path, &(data->handle));
if (status)
@ -111,8 +114,7 @@ grub_getbootp_real ( void )
bootp_response = grub_malloc (size);
if (grub_ieee1275_get_property (grub_ieee1275_chosen,
bootp_response_properties[i].name,
bootp_response ,
size, 0) < 0)
bootp_response, size, 0) < 0)
return NULL;
grub_memcpy (packet, bootp_response + bootp_response_properties[i].offset, sizeof (*packet));
@ -120,8 +122,8 @@ grub_getbootp_real ( void )
return packet;
}
static
void grub_ofnet_findcards (void)
static void
grub_ofnet_findcards (void)
{
struct grub_net_card *card;
grub_ieee1275_phandle_t devhandle;
@ -135,16 +137,19 @@ void grub_ofnet_findcards (void)
{
card = grub_malloc (sizeof (struct grub_net_card));
struct grub_ofnetcard_data *ofdata = grub_malloc (sizeof (struct grub_ofnetcard_data));
struct grub_ofnetcard_data *ofdata =
grub_malloc (sizeof (struct grub_ofnetcard_data));
ofdata->path = grub_strdup (alias->path);
grub_ieee1275_finddevice (ofdata->path, &devhandle);
if (grub_ieee1275_get_integer_property
(devhandle, "max-frame-size", &(ofdata->mtu), sizeof (ofdata->mtu), 0))
(devhandle, "max-frame-size", &(ofdata->mtu),
sizeof (ofdata->mtu), 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mtu size.");
if (grub_ieee1275_get_property (devhandle, "mac-address", &(lla.mac), 6, 0))
if (grub_ieee1275_get_property
(devhandle, "mac-address", &(lla.mac), 6, 0))
return grub_error (GRUB_ERR_IO, "Couldn't retrieve mac address.");
lla.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
@ -153,7 +158,7 @@ void grub_ofnet_findcards (void)
card->driver = NULL;
card->data = ofdata;
card->flags = 0;
card->name = grub_xasprintf("eth%d",i++); // grub_strdup (alias->name);
card->name = grub_xasprintf ("eth%d", i++);
grub_net_card_register (card);
return 0;
}
@ -164,8 +169,8 @@ void grub_ofnet_findcards (void)
grub_ieee1275_devices_iterate (search_net_devices);
}
static
void grub_ofnet_probecards (void)
static void
grub_ofnet_probecards (void)
{
struct grub_net_card *card;
struct grub_net_card_driver *driver;
@ -183,11 +188,13 @@ void grub_ofnet_probecards (void)
if (driver->init (card) == GRUB_ERR_NONE)
{
card->driver = driver;
if (bootp_pckt && grub_memcmp(bootp_pckt->chaddr,card->default_address.mac,6) == 0)
if (bootp_pckt
&& grub_memcmp (bootp_pckt->chaddr, card->default_address.mac, 6) == 0)
{
addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
addr.ipv4 = bootp_pckt->yiaddr;
grub_net_add_addr ("bootp_cli_addr", card, addr, card->default_address, 0);
grub_net_add_addr ("bootp_cli_addr", card, addr,
card->default_address, 0);
FOR_NET_NETWORK_LEVEL_INTERFACES (inter)
if (grub_strcmp (inter->name, "bootp_cli_addr") == 0)
break;
@ -221,6 +228,3 @@ GRUB_MOD_FINI (ofnet)
grub_net_card_driver_unregister (&ofdriver);
grub_getbootp = NULL;
}

View file

@ -51,13 +51,13 @@ grub_net_recv_ethernet_packet (struct grub_net_buff *nb)
}
}
/* ARP packet */
/* ARP packet. */
if (type == GRUB_NET_ETHERTYPE_ARP)
{
grub_net_arp_receive (nb);
grub_netbuff_free (nb);
}
/* IP packet */
/* IP packet. */
if (type == GRUB_NET_ETHERTYPE_IP)
grub_net_recv_ip_packets (nb);

View file

@ -56,6 +56,7 @@ grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
return err;
return send_ethernet_packet (inf, nb, ll_target_addr, GRUB_NET_ETHERTYPE_IP);
}
/*
static int
ip_filter (struct grub_net_buff *nb)

View file

@ -22,7 +22,8 @@
#include <grub/net/netbuff.h>
grub_err_t grub_netbuff_put (struct grub_net_buff *nb ,grub_size_t len)
grub_err_t
grub_netbuff_put (struct grub_net_buff *nb, grub_size_t len)
{
nb->tail += len;
if (nb->tail > nb->end)
@ -30,40 +31,49 @@ grub_err_t grub_netbuff_put (struct grub_net_buff *nb ,grub_size_t len)
return GRUB_ERR_NONE;
}
grub_err_t grub_netbuff_unput (struct grub_net_buff *nb ,grub_size_t len)
grub_err_t
grub_netbuff_unput (struct grub_net_buff *nb, grub_size_t len)
{
nb->tail -= len;
if (nb->tail < nb->head)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "unput out of the packet range.");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"unput out of the packet range.");
return GRUB_ERR_NONE;
}
grub_err_t grub_netbuff_push (struct grub_net_buff *nb ,grub_size_t len)
grub_err_t
grub_netbuff_push (struct grub_net_buff *nb, grub_size_t len)
{
nb->data -= len;
if (nb->data < nb->head)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "push out of the packet range.");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"push out of the packet range.");
return GRUB_ERR_NONE;
}
grub_err_t grub_netbuff_pull (struct grub_net_buff *nb ,grub_size_t len)
grub_err_t
grub_netbuff_pull (struct grub_net_buff *nb, grub_size_t len)
{
nb->data += len;
if (nb->data > nb->end)
return grub_error (GRUB_ERR_OUT_OF_RANGE, "pull out of the packet range.");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"pull out of the packet range.");
return GRUB_ERR_NONE;
}
grub_err_t grub_netbuff_reserve (struct grub_net_buff *nb ,grub_size_t len)
grub_err_t
grub_netbuff_reserve (struct grub_net_buff *nb, grub_size_t len)
{
nb->data += len;
nb->tail += len;
if ((nb->tail > nb->end) || (nb->data > nb->end))
return grub_error (GRUB_ERR_OUT_OF_RANGE, "reserve out of the packet range.");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"reserve out of the packet range.");
return GRUB_ERR_NONE;
}
struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len )
struct grub_net_buff *
grub_netbuff_alloc (grub_size_t len)
{
struct grub_net_buff *nb;
void *data;
@ -81,14 +91,15 @@ struct grub_net_buff *grub_netbuff_alloc ( grub_size_t len )
return nb;
}
grub_err_t grub_netbuff_free (struct grub_net_buff *nb)
grub_err_t
grub_netbuff_free (struct grub_net_buff *nb)
{
grub_free (nb->head);
return 0;
}
grub_err_t grub_netbuff_clear (struct grub_net_buff *nb)
grub_err_t
grub_netbuff_clear (struct grub_net_buff *nb)
{
nb->data = nb->tail = nb->head;
return 0;

View file

@ -130,7 +130,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
grub_netbuff_clear (nb);
break;
case TFTP_DATA:
grub_netbuff_pull (nb,sizeof (tftph->opcode) + sizeof (tftph->u.data.block));
grub_netbuff_pull (nb, sizeof (tftph->opcode) +
sizeof (tftph->u.data.block));
if (grub_be_to_cpu16 (tftph->u.data.block) == data->block + 1)
{
@ -153,7 +154,8 @@ tftp_receive (grub_net_socket_t sock, struct grub_net_buff *nb)
}
grub_netbuff_clear (&nb_ack);
grub_netbuff_reserve (&nb_ack, 128);
grub_netbuff_push (&nb_ack,sizeof (tftph->opcode) + sizeof (tftph->u.ack.block));
grub_netbuff_push (&nb_ack, sizeof (tftph->opcode)
+ sizeof (tftph->u.ack.block));
tftph = (struct tftphdr *) nb_ack.data;
tftph->opcode = grub_cpu_to_be16 (TFTP_ACK);

View file

@ -5,7 +5,8 @@
#include <grub/time.h>
grub_err_t
grub_net_send_udp_packet (const grub_net_socket_t socket , struct grub_net_buff *nb)
grub_net_send_udp_packet (const grub_net_socket_t socket,
struct grub_net_buff *nb)
{
struct udphdr *udph;