/* WARNING: Globals starting with '_' overlap smaller symbols at the same address */

undefined4 vconfig_main(int param_1,int param_2)

{
  size_t sVar1;
  int iVar2;
  int *piVar3;
  char *pcVar4;
  int iVar5;
  int iVar6;
  FILE *pFVar7;
  char *pcVar8;
  char *pcVar9;
  code *pcVar10;
  undefined4 local_58;
  char acStack_54 [24];
  int local_3c;
  undefined2 local_24;
  
  memset(&local_58,0,0x38)   //possible issue identified - semgrep
  if (2 < param_1 - 3U) {
    fprintf(_stdout,"Expecting argc to be 3-5, inclusive.  Was: %d\n",param_1);
LAB_00406b9c:
    pcVar10 = fprintf;
    pcVar8 = (char *)_stdout;
    pFVar7 = (FILE *)PTR_s_Usage__add__interface_name___vla_0041ca1c;
LAB_00406ba8:
    (*pcVar10)(pcVar8,pFVar7);
    iVar6 = 1;
LAB_00406bc0:
                    /* WARNING: Subroutine does not return */
    exit(iVar6);
  }
  pcVar9 = *(char **)(param_2 + 4);
  iVar6 = strcasecmp(pcVar9,"set_name_type");
  pcVar8 = *(char **)(param_2 + 8);
  if (iVar6 == 0) {
    iVar6 = strcasecmp(pcVar8,"VLAN_PLUS_VID");
    iVar5 = 0;
    if (iVar6 != 0) {
      iVar6 = strcasecmp(pcVar8,"VLAN_PLUS_VID_NO_PAD");
      iVar5 = 2;
      if (iVar6 != 0) {
        iVar6 = strcasecmp(pcVar8,"DEV_PLUS_VID");
        iVar5 = 1;
        if (iVar6 != 0) {
          iVar6 = strcasecmp(pcVar8,"DEV_PLUS_VID_NO_PAD");
          iVar5 = 3;
          if (iVar6 != 0) {
            fputs("Invalid name type.\n",_stderr);
            goto LAB_00406b9c;
          }
        }
      }
    }
    pcVar8 = (char *)0x0;
    local_3c = iVar5;
  }
  else {
    sVar1 = strlen(pcVar8);
    if (0xf < sVar1) {
      pcVar10 = fputs;
      pcVar8 = "ERROR:  if_name must be 15 characters or less.\n";
      pFVar7 = _stderr;
      goto LAB_00406ba8;
    }
    strcpy(acStack_54,pcVar8)   //possible issue identified - semgrep
  }
  if (param_1 == 4) {
    iVar6 = atoi(*(char **)(param_2 + 0xc));
    local_3c = iVar6;
  }
  else {
    iVar6 = 0;
    if (param_1 == 5) {
      iVar5 = atoi(*(char **)(param_2 + 0xc));
      iVar2 = atoi(*(char **)(param_2 + 0x10));
      local_24 = (undefined2)iVar2;
      local_3c = iVar5;
    }
  }
  iVar5 = open("/proc/net/vlan/config",0)   //possible issue identified - semgrep
  if (iVar5 < 0) {
    fputs("WARNING:  Could not open /proc/net/vlan/config.  Maybe you need to load the 8021q module, or maybe you are not using PROCFS??\n"
          ,_stderr);
  }
  else {
    close(iVar5);
  }
  iVar5 = socket(2,2,0);
  if (iVar5 < 0) {
    fputs("FATAL:  Couldn\'t open a socket..go figure!\n",_stderr);
    iVar6 = 2;
    goto LAB_00406bc0;
  }
  iVar2 = strcasecmp(pcVar9,"add");
  if (iVar2 == 0) {
    local_58 = 0;
    iVar5 = ioctl(iVar5,0x8983,&local_58);
    pFVar7 = _stderr;
    if (iVar5 < 0) {
      piVar3 = __errno_location();
      pcVar9 = strerror(*piVar3);
      fprintf(pFVar7,"ERROR: trying to add VLAN #%u to IF -:%s:-  error: %s\n",iVar6,pcVar8,pcVar9);
      return 0;
    }
    fprintf(_stdout,"Added VLAN with VID == %u to IF -:%s:-\n",iVar6,pcVar8);
    if (iVar6 != 1) {
      return 0;
    }
    pcVar8 = 
    "WARNING:  VLAN 1 does not work with many switches,\nconsider another number if you have problems.\n"
    ;
LAB_00407158:
    fputs(pcVar8,_stdout);
  }
  else {
    iVar6 = strcasecmp(pcVar9,"rem");
    if (iVar6 == 0) {
      local_58 = 1;
      iVar6 = ioctl(iVar5,0x8983,&local_58);
      pFVar7 = _stderr;
      if (-1 < iVar6) {
        pcVar9 = "Removed VLAN -:%s:-\n";
        pFVar7 = _stdout;
LAB_00407138:
        fprintf(pFVar7,pcVar9,pcVar8);
        return 0;
      }
      piVar3 = __errno_location();
      pcVar4 = strerror(*piVar3);
      pcVar9 = "ERROR: trying to remove VLAN -:%s:- error: %s\n";
    }
    else {
      iVar6 = strcasecmp(pcVar9,"set_egress_map");
      pcVar4 = pcVar8;
      if (iVar6 == 0) {
        local_58 = 3;
        iVar6 = ioctl(iVar5,0x8983,&local_58);
        pFVar7 = _stderr;
        if (iVar6 < 0) {
          piVar3 = __errno_location();
          pcVar4 = strerror(*piVar3);
          pcVar9 = "ERROR: trying to set egress map on device -:%s:- error: %s\n";
        }
        else {
          pcVar9 = "Set egress mapping on device -:%s:- Should be visible in /proc/net/vlan/%s\n";
          pFVar7 = _stdout;
        }
      }
      else {
        iVar6 = strcasecmp(pcVar9,"set_ingress_map");
        if (iVar6 == 0) {
          local_58 = 2;
          iVar6 = ioctl(iVar5,0x8983,&local_58);
          pFVar7 = _stderr;
          if (iVar6 < 0) {
            piVar3 = __errno_location();
            pcVar4 = strerror(*piVar3);
            pcVar9 = "ERROR: trying to set ingress map on device -:%s:- error: %s\n";
          }
          else {
            pcVar9 = "Set ingress mapping on device -:%s:- Should be visible in /proc/net/vlan/%s\n"
            ;
            pFVar7 = _stdout;
          }
        }
        else {
          iVar6 = strcasecmp(pcVar9,"set_flag");
          if (iVar6 != 0) {
            iVar6 = strcasecmp(pcVar9,"set_name_type");
            if (iVar6 != 0) {
              fprintf(_stderr,"Unknown command -:%s:-\n",pcVar9);
              fprintf(_stdout,PTR_s_Usage__add__interface_name___vla_0041ca1c)   //possible issue identified - semgrep
              iVar6 = 5;
              goto LAB_00406bc0;
            }
            local_58 = 6;
            iVar6 = ioctl(iVar5,0x8983,&local_58);
            pFVar7 = _stderr;
            if (iVar6 < 0) {
              piVar3 = __errno_location();
              pcVar8 = strerror(*piVar3);
              pcVar9 = "ERROR: trying to set name type for VLAN subsystem, error: %s\n";
              goto LAB_00407138;
            }
            pcVar8 = 
            "Set name-type for VLAN subsystem. Should be visible in /proc/net/vlan/config\n";
            goto LAB_00407158;
          }
          local_58 = 7;
          iVar6 = ioctl(iVar5,0x8983,&local_58);
          pFVar7 = _stderr;
          if (iVar6 < 0) {
            piVar3 = __errno_location();
            pcVar4 = strerror(*piVar3);
            pcVar9 = "ERROR: trying to set flag on device -:%s:- error: %s\n";
          }
          else {
            pcVar9 = "Set flag on device -:%s:- Should be visible in /proc/net/vlan/%s\n";
            pFVar7 = _stdout;
          }
        }
      }
    }
    fprintf(pFVar7,pcVar9,pcVar8,pcVar4);
  }
  return 0;
}