net: return TAPState from net_tap_init()
net_tap_fd_init() already returns TAPState, so this is a sensible cleanup in its own right. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
		
							parent
							
								
									1f7babf6d5
								
							
						
					
					
						commit
						4a77b25e2a
					
				
							
								
								
									
										23
									
								
								net.c
								
								
								
								
							
							
						
						
									
										23
									
								
								net.c
								
								
								
								
							| 
						 | 
				
			
			@ -1429,7 +1429,7 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
 | 
			
		|||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int net_tap_init(VLANState *vlan, const char *model,
 | 
			
		||||
static TAPState *net_tap_init(VLANState *vlan, const char *model,
 | 
			
		||||
                              const char *name, const char *ifname1,
 | 
			
		||||
                              const char *setup_script, const char *down_script)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -1443,13 +1443,13 @@ static int net_tap_init(VLANState *vlan, const char *model,
 | 
			
		|||
        ifname[0] = '\0';
 | 
			
		||||
    TFR(fd = tap_open(ifname, sizeof(ifname)));
 | 
			
		||||
    if (fd < 0)
 | 
			
		||||
        return -1;
 | 
			
		||||
        return NULL;
 | 
			
		||||
 | 
			
		||||
    if (!setup_script || !strcmp(setup_script, "no"))
 | 
			
		||||
        setup_script = "";
 | 
			
		||||
    if (setup_script[0] != '\0') {
 | 
			
		||||
	if (launch_script(setup_script, ifname, fd))
 | 
			
		||||
	    return -1;
 | 
			
		||||
    if (setup_script[0] != '\0' &&
 | 
			
		||||
        launch_script(setup_script, ifname, fd)) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    s = net_tap_fd_init(vlan, model, name, fd);
 | 
			
		||||
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
 | 
			
		||||
| 
						 | 
				
			
			@ -1459,7 +1459,7 @@ static int net_tap_init(VLANState *vlan, const char *model,
 | 
			
		|||
        snprintf(s->down_script, sizeof(s->down_script), "%s", down_script);
 | 
			
		||||
        snprintf(s->down_script_arg, sizeof(s->down_script_arg), "%s", ifname);
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* !_WIN32 */
 | 
			
		||||
| 
						 | 
				
			
			@ -2294,6 +2294,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
 | 
			
		|||
    if (!strcmp(device, "tap")) {
 | 
			
		||||
        char ifname[64], chkbuf[64];
 | 
			
		||||
        char setup_script[1024], down_script[1024];
 | 
			
		||||
        TAPState *s;
 | 
			
		||||
        int fd;
 | 
			
		||||
        vlan->nb_host_devs++;
 | 
			
		||||
        if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2304,8 +2305,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
 | 
			
		|||
            }
 | 
			
		||||
            fd = strtol(buf, NULL, 0);
 | 
			
		||||
            fcntl(fd, F_SETFL, O_NONBLOCK);
 | 
			
		||||
            net_tap_fd_init(vlan, device, name, fd);
 | 
			
		||||
            ret = 0;
 | 
			
		||||
            s = net_tap_fd_init(vlan, device, name, fd);
 | 
			
		||||
        } else {
 | 
			
		||||
            static const char * const tap_params[] = {
 | 
			
		||||
                "vlan", "name", "ifname", "script", "downscript", NULL
 | 
			
		||||
| 
						 | 
				
			
			@ -2324,7 +2324,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p)
 | 
			
		|||
            if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
 | 
			
		||||
                pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
 | 
			
		||||
            }
 | 
			
		||||
            ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
 | 
			
		||||
            s = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
 | 
			
		||||
        }
 | 
			
		||||
        if (s != NULL) {
 | 
			
		||||
            ret = 0;
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = -1;
 | 
			
		||||
        }
 | 
			
		||||
    } else
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue