9
0
Fork 0

net: add a context to the packet handler

This is not yet used, but with this the different network
commands can get rid of their global data.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2011-04-10 19:09:21 +02:00
parent dcf5df122f
commit c75ab78763
8 changed files with 27 additions and 22 deletions

View File

@ -363,7 +363,7 @@ static inline int is_valid_ether_addr(const u8 *addr)
return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
}
typedef void rx_handler_f(char *packet, unsigned int len);
typedef void rx_handler_f(void *ctx, char *packet, unsigned int len);
void eth_set_current(struct eth_device *eth);
struct eth_device *eth_get_current(void);
@ -388,6 +388,7 @@ struct net_connection {
struct list_head list;
rx_handler_f *handler;
int proto;
void *priv;
};
static inline char *net_alloc_packet(void)
@ -396,9 +397,10 @@ static inline char *net_alloc_packet(void)
}
struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
rx_handler_f *handler);
rx_handler_f *handler, void *ctx);
struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler);
struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler,
void *ctx);
void net_unregister(struct net_connection *con);

View File

@ -381,7 +381,7 @@ static void dhcp_send_request_packet(struct bootp *bp_offer)
/*
* Handle DHCP received packets.
*/
static void dhcp_handler(char *packet, unsigned int len)
static void dhcp_handler(void *ctx, char *packet, unsigned int len)
{
char *pkt = net_eth_to_udp_payload(packet);
struct udphdr *udp = net_eth_to_udphdr(packet);
@ -439,7 +439,7 @@ static int do_dhcp(struct command *cmdtp, int argc, char *argv[])
{
int ret;
dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler);
dhcp_con = net_udp_new(0xffffffff, PORT_BOOTPS, dhcp_handler, NULL);
if (IS_ERR(dhcp_con)) {
ret = PTR_ERR(dhcp_con);
goto out;

View File

@ -116,7 +116,7 @@ static int dns_send(char *name)
return ret;
}
static void dns_handler(char *packet, unsigned len)
static void dns_handler(void *ctx, char *packet, unsigned len)
{
struct header *header;
unsigned char *p, *e, *s;
@ -211,7 +211,7 @@ IPaddr_t resolv(char *host)
debug("resolving host %s via nameserver %s\n", host, getenv("nameserver"));
dns_con = net_udp_new(ip, DNS_PORT, dns_handler);
dns_con = net_udp_new(ip, DNS_PORT, dns_handler, NULL);
if (IS_ERR(dns_con))
return PTR_ERR(dns_con);
dns_timer_start = get_time_ns();

View File

@ -343,7 +343,8 @@ void net_set_gateway(IPaddr_t gw)
static LIST_HEAD(connection_list);
static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler,
void *ctx)
{
struct eth_device *edev = eth_get_current();
struct net_connection *con;
@ -366,6 +367,7 @@ static struct net_connection *net_new(IPaddr_t dest, rx_handler_f *handler)
con = xzalloc(sizeof(*con));
con->packet = xmemalign(32, PKTSIZE);
con->priv = ctx;
memset(con->packet, 0, PKTSIZE);
con->et = (struct ethernet *)con->packet;
@ -402,9 +404,9 @@ out:
}
struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
rx_handler_f *handler)
rx_handler_f *handler, void *ctx)
{
struct net_connection *con = net_new(dest, handler);
struct net_connection *con = net_new(dest, handler, ctx);
if (IS_ERR(con))
return con;
@ -417,9 +419,10 @@ struct net_connection *net_udp_new(IPaddr_t dest, uint16_t dport,
return con;
}
struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler)
struct net_connection *net_icmp_new(IPaddr_t dest, rx_handler_f *handler,
void *ctx)
{
struct net_connection *con = net_new(dest, handler);
struct net_connection *con = net_new(dest, handler, ctx);
if (IS_ERR(con))
return con;
@ -564,7 +567,7 @@ static int net_handle_udp(unsigned char *pkt, int len)
port = ntohs(udp->uh_dport);
list_for_each_entry(con, &connection_list, list) {
if (con->proto == IPPROTO_UDP && port == ntohs(con->udp->uh_sport)) {
con->handler(pkt, len);
con->handler(con->priv, pkt, len);
return 0;
}
}
@ -579,7 +582,7 @@ static int net_handle_icmp(unsigned char *pkt, int len)
list_for_each_entry(con, &connection_list, list) {
if (con->proto == IPPROTO_ICMP) {
con->handler(pkt, len);
con->handler(con->priv, pkt, len);
return 0;
}
}

View File

@ -50,7 +50,7 @@ struct nc_priv {
static struct nc_priv *g_priv;
static void nc_handler(char *pkt, unsigned len)
static void nc_handler(void *ctx, char *pkt, unsigned len)
{
struct nc_priv *priv = g_priv;
unsigned char *packet = net_eth_to_udp_payload(pkt);
@ -65,7 +65,7 @@ static int nc_init(void)
if (priv->con)
net_unregister(priv->con);
priv->con = net_udp_new(priv->ip, priv->port, nc_handler);
priv->con = net_udp_new(priv->ip, priv->port, nc_handler, NULL);
if (IS_ERR(priv->con)) {
int ret = PTR_ERR(priv->con);
priv->con = NULL;

View File

@ -562,7 +562,7 @@ static int nfs_read_reply(unsigned char *pkt, unsigned len)
Interfaces of barebox
**************************************************************************/
static void nfs_handler(char *packet, unsigned len)
static void nfs_handler(void *ctx, char *packet, unsigned len)
{
char *pkt = net_eth_to_udp_payload(packet);
int ret;
@ -689,7 +689,7 @@ static int do_nfs(struct command *cmdtp, int argc, char *argv[])
return 1;
}
nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler);
nfs_con = net_udp_new(net_get_serverip(), 0, nfs_handler, NULL);
if (IS_ERR(nfs_con)) {
nfs_err = PTR_ERR(nfs_con);
goto err_udp;

View File

@ -40,7 +40,7 @@ static int ping_send(void)
return net_icmp_send(ping_con, 9);
}
static void ping_handler(char *pkt, unsigned len)
static void ping_handler(void *ctx, char *pkt, unsigned len)
{
IPaddr_t tmp;
struct iphdr *ip = net_eth_to_iphdr(pkt);
@ -66,7 +66,7 @@ static int do_ping(struct command *cmdtp, int argc, char *argv[])
return 1;
}
ping_con = net_icmp_new(net_ping_ip, ping_handler);
ping_con = net_icmp_new(net_ping_ip, ping_handler, NULL);
if (IS_ERR(ping_con)) {
ret = PTR_ERR(ping_con);
goto out;

View File

@ -141,7 +141,7 @@ static int tftp_send(void)
return ret;
}
static void tftp_handler(char *packet, unsigned len)
static void tftp_handler(void *ctx, char *packet, unsigned len)
{
uint16_t proto;
uint16_t *s;
@ -314,7 +314,7 @@ static int do_tftpb(struct command *cmdtp, int argc, char *argv[])
return 1;
}
tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler);
tftp_con = net_udp_new(net_get_serverip(), TFTP_PORT, tftp_handler, NULL);
if (IS_ERR(tftp_con)) {
tftp_err = PTR_ERR(tftp_con);
goto out_close;