| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include "lwip/opt.h" |
| 25 |
#ifdef LWSLIRP |
| 26 |
|
| 27 |
#include <fcntl.h> |
| 28 |
#include <stdlib.h> |
| 29 |
#include <stdio.h> |
| 30 |
#include <string.h> |
| 31 |
#include <unistd.h> |
| 32 |
#include <sys/types.h> |
| 33 |
#include <sys/uio.h> |
| 34 |
#include <sys/socket.h> |
| 35 |
|
| 36 |
#include "lwip/debug.h" |
| 37 |
|
| 38 |
#include "lwip/def.h" |
| 39 |
#include "lwip/ip.h" |
| 40 |
#include "lwip/mem.h" |
| 41 |
#include "lwip/pbuf.h" |
| 42 |
#include "lwip/sys.h" |
| 43 |
|
| 44 |
#include "netif/etharp.h" |
| 45 |
|
| 46 |
#ifdef IPv6_AUTO_CONFIGURATION |
| 47 |
#include "lwip/ip_autoconf.h" |
| 48 |
#endif |
| 49 |
|
| 50 |
#if LWIP_NL |
| 51 |
#include "lwip/arphdr.h" |
| 52 |
#endif |
| 53 |
|
| 54 |
#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) |
| 55 |
#include "netif/tcpdump.h" |
| 56 |
#endif |
| 57 |
|
| 58 |
#include <sys/ioctl.h> |
| 59 |
#include <sys/un.h> |
| 60 |
#include <stdint.h> |
| 61 |
#include <libgen.h> |
| 62 |
#include <sys/poll.h> |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
#ifndef SLIRPIF_DEBUG |
| 67 |
#define SLIRPIF_DEBUG DBG_OFF |
| 68 |
#endif |
| 69 |
|
| 70 |
#define IFNAME0 's' |
| 71 |
#define IFNAME1 'l' |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
static const struct eth_addr ethbroadcast = { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} }; |
| 76 |
|
| 77 |
struct slirpif { |
| 78 |
|
| 79 |
char *path; |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
static err_t slirpif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr); |
| 84 |
|
| 85 |
|
| 86 |
static err_t slirpif_ctl(struct netif *netif, int request, void *arg) |
| 87 |
{ |
| 88 |
struct slirpif *slirpif = netif->state; |
| 89 |
|
| 90 |
if (slirpif) { |
| 91 |
switch (request) { |
| 92 |
case NETIFCTL_CLEANUP: |
| 93 |
if (slirpif->path) |
| 94 |
mem_free(slirpif->path); |
| 95 |
mem_free(slirpif); |
| 96 |
break; |
| 97 |
case NETIFCTL_SLIRPSOCK_DGRAM: |
| 98 |
return socket(AF_INET6, SOCK_DGRAM, 0); |
| 99 |
|
| 100 |
case NETIFCTL_SLIRPSOCK_STREAM: |
| 101 |
return socket(AF_INET6, SOCK_STREAM, 0); |
| 102 |
|
| 103 |
} |
| 104 |
return ERR_OK; |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
static err_t slirpif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) |
| 109 |
{ |
| 110 |
struct pbuf *r, *q; |
| 111 |
char *ptr; |
| 112 |
LWIP_DEBUGF(SLIRPIF_DEBUG, ("%s: start\n",__func__)); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
if (! (netif->flags & NETIF_FLAG_UP)) { |
| 121 |
return ERR_OK; |
| 122 |
} |
| 123 |
|
| 124 |
r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); |
| 125 |
if (r != NULL) { |
| 126 |
ptr = r->payload; |
| 127 |
|
| 128 |
for(q = p; q != NULL; q = q->next) { |
| 129 |
memcpy(ptr, q->payload, q->len); |
| 130 |
ptr += q->len; |
| 131 |
} |
| 132 |
netif->input( r, netif ); |
| 133 |
|
| 134 |
return ERR_OK; |
| 135 |
} |
| 136 |
|
| 137 |
return ERR_MEM; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
err_t slirpif_init(struct netif * netif) |
| 151 |
{ |
| 152 |
struct slirpif *slirpif; |
| 153 |
|
| 154 |
slirpif = mem_malloc(sizeof(struct slirpif)); |
| 155 |
memset(slirpif, 0, sizeof(struct slirpif)); |
| 156 |
if (!slirpif) |
| 157 |
return ERR_MEM; |
| 158 |
|
| 159 |
netif->state = slirpif; |
| 160 |
netif->name[0] = IFNAME0; |
| 161 |
netif->name[1] = IFNAME1; |
| 162 |
netif->link_type = NETIF_SLIRPIF; |
| 163 |
netif->num=netif_next_num(netif,NETIF_SLIRPIF); |
| 164 |
netif->output = slirpif_output; |
| 165 |
netif->netifctl = slirpif_ctl; |
| 166 |
netif->mtu = 65535; |
| 167 |
|
| 168 |
netif->hwaddr_len = 6; |
| 169 |
netif->flags |= NETIF_FLAG_BROADCAST; |
| 170 |
#if LWIP_NL |
| 171 |
netif->type = ARPHRD_ETHER; |
| 172 |
#endif |
| 173 |
|
| 174 |
return ERR_OK; |
| 175 |
} |
| 176 |
#endif |
| 177 |
|