Exemple #1
0
void
rib_arp_delete(int ifindex, struct in_addr *dst_addr, char *ll_addr) {
  arp_delete(ifindex, dst_addr, ll_addr);
}
Exemple #2
0
static int _tftpd_open(tftp_info_t *info,char *hostname,char *filename,int mode)
{
    ebuf_t *buf = NULL;
    uint16_t type;
    int res;
    int retries;
    char ch = 0;
#ifdef RESCUE_MODE
	uint8_t asuslink[13] = "ASUSSPACELINK";
	uint8_t maclink[13]="snxxxxxxxxxxx";
	unsigned char tftpmask[4] = { 0xff, 0xff, 0xff, 0x00 };
	int i;
	char tftpnull;
	uint8_t ipaddr[4] = { 0xc0, 0xa8, 0x01, 0x0c };
	uint8_t hwaddr[6] = { 0x00, 0xe0, 0x18, 0x00, 0x3e, 0xc4 };
#endif

    /*
     * Open a UDP socket
     */    

    info->tftp_socket = udp_socket(UDP_PROTO_TFTP);
    info->tftp_lastblock = 0;
    info->tftp_error = 0;
    info->tftp_filemode = mode;

    /*
     * Listen for requests
     */

    res = udp_bind(info->tftp_socket,UDP_PROTO_TFTP);
    if (res < 0) return res;

    res = CFE_ERR_TIMEOUT;

    for (retries = 0; retries < tftp_max_retries; retries++) {
	while (console_status()) {
	    console_read(&ch,1);
	    if (ch == 3) break;
	}
	if (ch == 3) {
	    res = CFE_ERR_INTR;
	    break;
	}

	buf = udp_recv_with_timeout(info->tftp_socket,tftp_recv_timeout);
	if (buf == NULL) continue;

	/*
	 * Process the request
	 */

	ebuf_get_u16_be(buf,type);

	switch (type) {
	    case TFTP_OP_RRQ:
#ifdef RESCUE_MODE
                         udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
                         ackport = buf->eb_usrdata;
                         memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
                         info->tftp_blknum = 1;
                         info->tftp_blklen = 0;
                         for (i=0; i<13; i++) {
                                if (buf->eb_ptr[i] != asuslink[i])
                                                break;
                         }
                         if (i==13) {
                                tftpipfrom[0]=buf->eb_ptr[16];
                                tftpipfrom[1]=buf->eb_ptr[15];
                                tftpipfrom[2]=buf->eb_ptr[14];
                                tftpipfrom[3]=buf->eb_ptr[13];
                                tftpipto[0]=buf->eb_usrptr[0];
                                tftpipto[1]=buf->eb_usrptr[1];
                                tftpipto[2]=buf->eb_usrptr[2];
                                tftpipto[3]=buf->eb_usrptr[3];
                                        net_setparam(NET_IPADDR,tftpipfrom);
                                        net_setparam(NET_NETMASK,tftpmask);
                                        net_setparam(NET_GATEWAY,tftpipfrom);
                                        ui_myshowifconfig();
                                        net_setnetvars();
                                        for (i=0; i<4; i++)
                                                ipaddr[i]=tftpipto[i];
                                        for (i=0; i<6; i++)
                                                hwaddr[i]=buf->eb_data[6+i];
                                        buf = udp_alloc();
                                        if (!buf) {
                                                res = CFE_ERR_TIMEOUT;
                                                break;
                                        }
                                        ebuf_append_u16_be(buf, 3);
                                        ebuf_append_u16_be(buf, 1);
                                        ebuf_append_bytes(buf,&tftpnull, 0);
                                        arp_delete(ipaddr);
                                        arp_add(ipaddr,hwaddr);
                                        udp_send(info->tftp_socket, buf, tftpipto);
                                }
                                else {
                                        for (i=0; i<13; i++) {
                                                if (buf->eb_ptr[i] != maclink[i])
                                                        break;
                                        }
                                        if (i==13) {
                                                tftpipfrom[0]=buf->eb_ptr[16];
                                                tftpipfrom[1]=buf->eb_ptr[15];
                                                tftpipfrom[2]=buf->eb_ptr[14];
                                                tftpipfrom[3]=buf->eb_ptr[13];
                                                tftpipto[0]=buf->eb_usrptr[0];
                                                tftpipto[1]=buf->eb_usrptr[1];
                                                tftpipto[2]=buf->eb_usrptr[2];
                                                tftpipto[3]=buf->eb_usrptr[3];
                                                net_setparam(NET_IPADDR,tftpipfrom);
                                                net_setparam(NET_NETMASK,tftpmask);
                                                net_setparam(NET_GATEWAY,tftpipfrom);
                                                ui_myshowifconfig();
                                                net_setnetvars();
                                                for (i=0; i<4; i++)
                                                        ipaddr[i]=tftpipto[i];
                                                for (i=0; i<6; i++)
                                                        hwaddr[i]=buf->eb_data[6+i];
                                                buf = udp_alloc();
                                                if (!buf) {
                                                        res = CFE_ERR_TIMEOUT;
                                                break;
                                        }
                                        ebuf_append_u16_be(buf, 3);
                                        ebuf_append_u16_be(buf, 1);
                                        ebuf_append_bytes(buf,&tftpnull, 0);
                                        arp_delete(ipaddr);
                                        arp_add(ipaddr,hwaddr);
                                        udp_send(info->tftp_socket, buf, tftpipto);
                                }
                        }
                        res = CFE_ERR_TIMEOUT;
#else
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 1;
		info->tftp_blklen = 0;
		res = 0;
#endif
		break;

	    case TFTP_OP_WRQ:
		udp_connect(info->tftp_socket,(uint16_t) buf->eb_usrdata);
		memcpy(info->tftp_ipaddr,buf->eb_usrptr,IP_ADDR_LEN);
		info->tftp_blknum = 0;
		res = _tftp_readmore(info);
		break;

	    default:
		/* 
		 * we aren't expecting any of these messages
		 */
		res = CFE_ERR_PROTOCOLERR;
		break;
	}

	udp_free(buf);
	break;
    }

    if (res) {
	udp_close(info->tftp_socket);
	info->tftp_socket = -1;
    }

    return res;
}