MCPcopy Create free account
hub / github.com/apache/nuttx / sim_tapdev_init

Function sim_tapdev_init

arch/sim/src/sim/posix/sim_tapdev.c:190–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188 ****************************************************************************/
189
190void sim_tapdev_init(int devidx, void *priv,
191 void (*tx_done_intr_cb)(void *priv),
192 void (*rx_ready_intr_cb)(void *priv))
193{
194 struct ifreq ifr;
195 int tapdevfd;
196 int ret;
197 int sockfd;
198
199 /* Open the tap device */
200
201 tapdevfd = open(DEVTAP, O_RDWR, 0644);
202 if (tapdevfd < 0)
203 {
204 syslog(LOG_ERR, "TAPDEV: open failed: %d\n", -tapdevfd);
205 return;
206 }
207
208 /* Configure the tap device */
209
210 memset(&ifr, 0, sizeof(ifr));
211 ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
212 ret = ioctl(tapdevfd, TUNSETIFF, (unsigned long) &ifr);
213 if (ret < 0)
214 {
215 syslog(LOG_ERR, "TAPDEV: ioctl failed: %d\n", -ret);
216 close(tapdevfd);
217 return;
218 }
219
220 /* Save the tap device name */
221
222 strncpy(gdevname[devidx], ifr.ifr_name, IFNAMSIZ);
223
224 /* Get a socket with which to manipulate the tap device; the remaining
225 * ioctl calls unfortunately won't work on the tap device fd.
226 */
227
228 sockfd = socket(AF_INET, SOCK_DGRAM, 0);
229 if (sockfd < 0)
230 {
231 syslog(LOG_ERR, "TAPDEV: Can't open socket: %d\n", -sockfd);
232 close(tapdevfd);
233 return;
234 }
235
236#ifdef CONFIG_SIM_NET_BRIDGE
237 /* Assign the tap device to a bridge */
238
239 memset(&ifr, 0, sizeof(ifr));
240 strncpy(ifr.ifr_name, CONFIG_SIM_NET_BRIDGE_DEVICE, IFNAMSIZ);
241 ifr.ifr_ifindex = if_nametoindex(gdevname[devidx]);
242
243 ret = ioctl(sockfd, SIOCBRADDIF, &ifr);
244 if (ret < 0)
245 {
246 syslog(LOG_ERR, "TAPDEV: ioctl failed (can't add interface %s to "
247 "bridge %s): %d\n",

Callers

nothing calls this directly

Calls 10

openFunction · 0.85
ioctlFunction · 0.85
closeFunction · 0.85
if_nametoindexFunction · 0.85
sim_netdriver_setmtuFunction · 0.85
set_macaddrFunction · 0.85
syslogFunction · 0.50
memsetFunction · 0.50
strncpyFunction · 0.50
socketClass · 0.50

Tested by

no test coverage detected