1 /* Author: Domen Puncer Kugler <domen@cba.si>. License: WTFPL, see file LICENSE */
3 #include <net/ethernet.h>
8 //#define ip_print_array print_array
9 #define ip_print_array(tag, buf, size)
12 static LIST_DECLARE_INIT(ip_handler_list
);
15 static int ip_handle(u8
*buf
, unsigned len
)
17 struct ip_packet
*ip
= (struct ip_packet
*)buf
;
19 ip_print_array("IP RX", buf
, sizeof(*ip
));
20 if (len
<= sizeof(*ip
))
25 if (ip
->vihl
!= 0x45) /* IPv4, 20B header */
29 list_for_each(&ip_handler_list
, it
) {
30 struct ip_handler
*han
= list_entry(it
, struct ip_handler
, list
);
32 if (ip
->protocol
== han
->protocol
)
33 return han
->handler(ip
->payload
, len
);
41 static struct eth_handler eth_handler_ip
= {
42 .list
= LIST_INIT(eth_handler_ip
.list
),
43 .ethertype
= ETHERTYPE_IP
,
49 return eth_register_handler(ð_handler_ip
);
52 int ip_register_handler(struct ip_handler
*han
)
54 list_add_tail(&ip_handler_list
, &han
->list
);