Ejemplo n.º 1
0
void
vhost_if_add(struct vr_interface *vif)
{
    int i;
    struct net_device *dev = (struct net_device *)vif->vif_os;
    struct vhost_priv *vp = netdev_priv(dev);

    vp->vp_vifp = vif;
    if (vif->vif_type == VIF_TYPE_HOST) {
        if (vif->vif_bridge) {
            /*
             * if there already was an association, need to remove that
             */
            if ((vp->vp_phys_dev) &&
                    (vp->vp_phys_dev !=
                     ((struct net_device *)vif->vif_bridge->vif_os))) {
                vhost_del_tap_phys(vp->vp_phys_dev);
            }

            vp->vp_phys_dev =
                (struct net_device *)vif->vif_bridge->vif_os;
            strncpy(vp->vp_phys_name, vp->vp_phys_dev->name,
                    sizeof(vp->vp_phys_name));

            if (vp->vp_phys_dev->type != ARPHRD_ETHER) {
                dev->flags |= IFF_NOARP;
            } else {
                dev->flags &= ~IFF_NOARP;
            }

            if (vp->vp_db_index >= 0)
                return;

            /* ...may be a bitmap? */
            for (i = 0; i < VHOST_MAX_INTERFACES; i++)
                if (!vhost_priv_db[i])
                    break;

            if (i < VHOST_MAX_INTERFACES) {
                vp->vp_db_index = i;
                vhost_priv_db[i] = vp;
            } else {
                vr_printf("%s not added to vhost database. ",
                        vp->vp_dev->name);
                vr_printf("Cross connect will not work\n"); 
            }
        }
    }

    return;
}
Ejemplo n.º 2
0
static void
vr_flow_entry_set_hold(struct vrouter *router, struct vr_flow_entry *flow_e)
{
    unsigned int cpu;
    uint64_t act_count;
    struct vr_flow_table_info *infop = router->vr_flow_table_info;

    cpu = vr_get_cpu();
    if (cpu >= vr_num_cpus) {
        vr_printf("vrouter: Set HOLD failed (cpu %u num_cpus %u)\n",
                cpu, vr_num_cpus);
        return;
    }

    flow_e->fe_action = VR_FLOW_ACTION_HOLD;

    if (infop->vfti_hold_count[cpu] + 1 < infop->vfti_hold_count[cpu]) {
        (void)__sync_add_and_fetch(&infop->vfti_oflows, 1);
        act_count = infop->vfti_action_count;
        if (act_count > infop->vfti_hold_count[cpu]) {
           (void)__sync_sub_and_fetch(&infop->vfti_action_count,
                    infop->vfti_hold_count[cpu]);
            infop->vfti_hold_count[cpu] = 0;
        } else {
            infop->vfti_hold_count[cpu] -= act_count;
            (void)__sync_sub_and_fetch(&infop->vfti_action_count,
                    act_count);
        }
    }

    infop->vfti_hold_count[cpu]++;

    return;
}
Ejemplo n.º 3
0
static void
pr_errorcount(int level)
{
   char fmt[128];

   snprintf(fmt, sizeof(fmt), "%%d %s\n", _clic_ngettext("error", "errors", clic_errorcount));

   vr_printf(level, fmt, clic_errorcount);
}
Ejemplo n.º 4
0
static void
vr_fc_map_add(vr_fc_map_req *req)
{
    int ret = 0;
    unsigned int i;

    struct vrouter *router = vrouter_get(req->fmr_rid);
    struct vr_forwarding_class *fc_p;

    if (!req->fmr_id || !req->fmr_id_size ||
            !req->fmr_dscp || !req->fmr_dscp_size ||
            !req->fmr_mpls_qos || !req->fmr_mpls_qos_size ||
            !req->fmr_dotonep || !req->fmr_dotonep_size ||
            !req->fmr_queue_id || !req->fmr_queue_id_size) {
        ret = -EINVAL;
        goto generate_response;
    }

    for (i = 0; i < req->fmr_id_size; i++) {
        fc_p = vr_fc_map_get_fc(router, req->fmr_id[i]);
        if (!fc_p) {
            ret = -EINVAL;
            goto generate_response;
        }

        fc_p->vfc_id = req->fmr_id[i];
        fc_p->vfc_dscp = req->fmr_dscp[i];
        fc_p->vfc_mpls_qos = req->fmr_mpls_qos[i];
        fc_p->vfc_dotonep_qos = req->fmr_dotonep[i];
        fc_p->vfc_queue_id = req->fmr_queue_id[i];
        fc_p->vfc_valid = 1;
    }

    ret = vr_offload_fc_map_add(req);
    if (ret) {
        vr_printf("offload FC map not supported - not configuring\n");
        for (i = 0; i < req->fmr_id_size; i++) {
            fc_p = vr_fc_map_get_fc(router, req->fmr_id[i]);
            if (fc_p)
                memset(fc_p, 0, sizeof(*fc_p));
        }
    }

generate_response:
    vr_send_response(ret);
    return;
}
Ejemplo n.º 5
0
int
main(int argc, char **argv)
{
   int /*ch, */ i, ii, ret, err_flag = 0;

   clock_t beg, end, Beg, End;

   int files = 0;

   struct tms ts;

   char buf[256];

   char *e;

   prgname = strrchr(argv[0], '/');

   if (prgname)
      prgname++;
   else
      prgname = argv[0];

   e = getenv("CLIP_HOSTCS");
   if (e && *e)
   {
      sourceCharset = targetCharset = strdup(e);
   }
   else if (!e)
   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    sourceCharset = targetCharset = strdup(buf);
	 }
      }
   }

   {
      e = getenv("CLIP_LANG");
      if (e == NULL)
	 e = getenv("LANG");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_MESSAGES");
      if (!e || !*e || !strcmp(e, "C"))
	 e = getenv("LC_ALL");
      if (e && *e)
      {
	 char *s = strrchr(e, '.');

	 if (s)
	 {
	    snprintf(buf, sizeof(buf), "%s", s + 1);
	    for (s = buf; *s; s++)
	       *s = tolower(*s);
	    out_charset = strdup(buf);
	 }
      }
   }

   {
      char *locale;

      locale = getenv("CLIP_LANG");
      if (!locale || !*locale)
	 locale = getenv("LANG");
      /*if (locale && *locale &&
         strcasecmp(locale, "C") && strcasecmp(locale, "POSIX")) */
      /*
         setlocale(LC_ALL, locale);
       */
   }

   if (!sourceCharset)
      sourceCharset = targetCharset = strdup("c");

   getEnvironment();

   init_Coll(&includePaths, NULL, NULL);
   init_Coll(&lib_dirs, NULL, NULL);
   init_Coll(&arglibs, NULL, NULL);

#if 1
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIB_DIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   init_Coll(&predefines, NULL, NULL);
   init_Coll(&poName, NULL, NULL);
   init_Coll(&paName, NULL, NULL);
   init_Coll(&include_files, NULL, NULL);

   snprintf(buf, sizeof(buf), "__CLIP__=\"%s\"", CLIP_VERSION);
   append_Coll(&predefines, strdup(buf));

   init_module();

   {
      char buf[256], *s;

      s = getenv("HOME");
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

   }

   getrc(".cliprc");

   {
      char buf[256], *s;

      DIR *dp;

      s = CLIPROOT;
      if (s && *s)
      {
	 snprintf(buf, sizeof(buf), "%s/.cliprc", s);
	 getrc(buf);
      }

      snprintf(buf, sizeof(buf), "%s/cliprc", CLIPROOT);
      dp = opendir(buf);
      if (dp)
      {
	 struct dirent *ep;

	 struct stat st;

	 Coll files;

	 int i;

	 init_Coll(&files, free, strcmp);
	 while ((ep = readdir(dp)))
	 {
	    snprintf(buf, sizeof(buf), "%s/cliprc/%s", CLIPROOT, ep->d_name);
	    if (stat(buf, &st))
	       continue;
	    if (!S_ISREG(st.st_mode))
	       continue;
	    if (access(buf, R_OK))
	       continue;
	    insert_Coll(&files, strdup(buf));
	 }
	 closedir(dp);

	 for (i = 0; i < files.count_of_Coll; i++)
	 {
		 char *name = (char *) files.items_of_Coll[i];

	    getrc(name);
	 }

	 destroy_Coll(&files);
      }
   }

   argc--;
   argv++;
   get_opt(argc, argv);

   argc -= optind;
   argv += optind;

   if (err_flag)
      return 1;

#if 0
   insert_Coll(&includePaths, ".");
   snprintf(buf, sizeof(buf), "%s/include", CLIPROOT);
   insert_Coll(&includePaths, strdup(buf));
#ifdef STD_LIBDIR
   snprintf(buf, sizeof(buf), STD_LIBDIR);
   insert_Coll(&lib_dirs, strdup(buf));
#endif
   snprintf(buf, sizeof(buf), "%s/lib", CLIPROOT);
   insert_Coll(&lib_dirs, strdup(buf));
#endif

   if (syntax_tree_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 1;
      compile_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      exec_flag = 0;
   }

   if (!write_obj_flag)
   {
      /*codegen_flag = 0; */
      compile_flag = 0;
   }
   if (preproc_flag)
   {
      write_obj_flag = 0;
      codegen_flag = 0;
      syntax_tree_flag = 0;
      compile_flag = 0;
      exec_flag = 0;
      pcode_flag = 0;
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pcode_flag)
   {
      pc_flag = 0;
      asm_flag = 0;
      shared_flag = 0;
   }

   if (pc_flag)
   {
      pcode_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 1;
      else
	 asm_flag = 0;
#endif
   }

   if (xpc_flag)
   {
      pcode_flag = 1;
      pc_flag = 1;
#ifdef USE_AS
      if (use_asm)
	 asm_flag = 0;
      else
	 asm_flag = 1;
#endif
   }

#if 0
   if (shared_flag && pcode_flag)
   {
      v_printf(0, "conflict between -s and -p flags\n");
      exit(1);
   }
#endif

   if (pcode_flag && c_flag)
   {
      v_printf(0, "conflict between -c and -p flags\n");
      exit(1);
   }

   /*if ( exec_flag && !main_flag && !shared_flag)
      {
      v_printf(0, "-e(xec) flag without -M(ain) or -s(hared) flags\n");
      exit(2);
      } */

   if (pcode_flag)
   {
      compile_flag = 0;
   }

   if (nomain_flag && main_flag)
   {
      v_printf(0, "conflict between -n and -m flags\n");
      exit(1);
   }

   if (!exec_flag && oname)
   {
      char *e;

      if (oname[0] == '/')
	 snprintf(buf, sizeof(buf), "%s", oname);
      else
	 snprintf(buf, sizeof(buf), "%s%s%s", outdir ? outdir : "", outdir ? "/" : "", oname);
      e = strrchr(buf, '/');
      if (e)
      {
	 *e = 0;
	 outdir = strdup(buf);
      }
   }

   if (!outdir)
      outdir = ".";

   if (outdir)
   {
      char cdir[256];

      getcwd(cdir, sizeof(cdir));

      if (!chdir(outdir))
      {
	 getcwd(buf, sizeof(buf));
	 outdir = strdup(buf);
	 chdir(cdir);
      }
      else
      {
	 yyerror("cannot change to output dir '%s': %s", outdir, strerror(errno));
	 exit(1);
      }
   }

   if (!preproc_flag)
   {
      v_printf(2, "set source charset to %s\n", sourceCharset);
      v_printf(2, "set target charset to %s\n", targetCharset);
   }

   init_lex();
   init_parser();

   if (argc < 1)
      ii = -1;
   else
      ii = 0;

   Beg = times(&ts);
   if (argc > 0)
   {
      for (i = 0; i < argc; i++)
      {
	 char *e;

	 e = argv[i];
	 if (e[0] == '-' && e[1] == 'L')
	 {
	    insert_Coll(&lib_dirs, strdup(e + 2));
	    continue;
	 }
	 e = strrchr(argv[i], '.');
	 if (!e)
	 {
	    e = argv[i];
	    if (e[0] == '-' && e[1] == 'l')
	       /*append_Coll(&arglibs, strdup(e+2)) */ ;
	    else
	       yyerror("unknown file type '' file '%s'", argv[i]);
	    continue;
	 }
	 else if (!strcasecmp(e, ".po"))
	    insert_Coll(&poName, strdup(argv[i]));
	 else if (!strcasecmp(e, ".pa"))
	    insert_Coll(&paName, strdup(argv[i]));
	 else if (strcasecmp(e, ".prg") && strcasecmp(e, ".c") && strcasecmp(e, ".cc") && strcasecmp(e, OBJSUF) && strcasecmp(e, SOBJSUF) && strcasecmp(e, ".a") && strcasecmp(e, ".lib"))
	 {
	    /*yywarning("unknown file type '%s' file '%s'", e, argv[i]); */
	    continue;
	 }
      }
   }

   for (; clic_errorcount == 0 && ii < argc; ii++)
   {
      ++files;
      if (ii < 0)
      {
	 v_printf(1, "no input files, so use stdin; -h will help\n");
	 fflush(stderr);
	 set_locale_name("stdin");
	 ret = clic_parse("stdin", stdin);
	 add_name("stdin");
      }
      else
      {
	 char *e;

	 e = strrchr(argv[ii], '.');
	 add_name(argv[ii]);

	 if (!e)
	    continue;
	 else if (!strcasecmp(e, ".c") || !strcasecmp(e, ".cc") || !strcasecmp(e, ".cpp"))
	 {
	    if (!preproc_flag)
	    {
	       v_printf(1, "process file '%s' ..", argv[ii]);
	       v_neednl = 1;
	    }

	    beg = times(&ts);
	    compile_CFile(argv[ii]);
	    end = times(&ts);

	    if (!preproc_flag)
	    {
	       v_neednl = 0;
	       if (clic_errorcount == 0)
		  v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	       else
		  pr_errorcount(1);
	    }
	    continue;
	 }
	 else if (strcasecmp(e, ".prg"))
	 {
	    continue;
	 }

	 if (ii > 0)
	    main_flag = 0;

	 if (!preproc_flag)
	 {
	    v_printf(1, "parsing file '%s' ..", argv[ii]);
	    v_neednl = 1;
	 }
	 beg = times(&ts);
	 set_locale_name(argv[ii]);
	 ret = clic_parse(argv[ii], 0);
	 end = times(&ts);

	 if (!preproc_flag)
	 {
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done (%d/%d %s, %d %s, %s)\n",
			clic_line, all_lines, _clic_ngettext("line", "lines", clic_line), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount), diff_clock(beg, end));
	    else
	       vr_printf(1, "%d %s, %d %s\n", clic_errorcount, _clic_ngettext("error", "errors", clic_errorcount), clic_warncount, _clic_ngettext("warning", "warnings", clic_warncount));
	 }
      }
      if (ret)
	 break;

      if (clic_errorcount == 0 && codegen_flag)
      {
	 v_printf(2, "codegen file '%s' ..", curFile->name_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 codegen_File(curFile);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(2, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(2);
      }
      if (clic_errorcount == 0 && syntax_tree_flag)
      {
	 print_File(curFile);
      }
      if (clic_errorcount == 0 && write_obj_flag)
      {
	 if (pcode_flag)
	 {
	    long len;

	    v_printf(1, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    write_OFile(curFile, &len);
	    write_names(curFile);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %ld %s ,%s\n", len, _clic_ngettext("byte", "bytes", len), diff_clock(beg, end));
	    else
	       pr_errorcount(1);
	 }
	 else
	 {
	    v_printf(2, "writing file '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    write_File(curFile);
	    write_names(curFile);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(2, ".. done\n");
	    else
	       pr_errorcount(2);
	 }
      }

      if (clic_errorcount == 0 && (compile_flag || pc_flag))
      {
	 if (ii)
	    main_flag = 0;
	 v_printf(1, "compile file '%s' ..", curFile->s_cname_of_File);
	 v_neednl = 1;
	 beg = times(&ts);
	 compile_File(curFile->cname_of_File);
	 end = times(&ts);
	 v_neednl = 0;
	 if (clic_errorcount == 0)
	    v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	 else
	    pr_errorcount(1);

	 if (clic_errorcount == 0 && shared_flag && !exec_flag)
	 {
	    v_printf(1, "make shared object '%s' ..", curFile->s_cname_of_File);
	    v_neednl = 1;
	    beg = times(&ts);
	    share_File(curFile->cname_of_File);
	    end = times(&ts);
	    v_neednl = 0;
	    if (clic_errorcount == 0)
	       v_printf(1, ".. done, %s\n", diff_clock(beg, end));
	    else
	       pr_errorcount(1);

	 }
      }

      if (ii < 0)
	 break;

      delete_File(curFile);
      curFile = NULL;
   }

   if (clic_errorcount == 0 && exec_flag)
   {
      char cmd[1024 * 8], *e;

      char cfuncname[256], ofuncname[256];

      char *libroot;

      int i;

      Coll ex, nm;

      init_Coll(&ex, free, strcasecmp);
      init_Coll(&nm, free, strcasecmp);
#ifdef STD_LIBDIR
      libroot = 0;
#else
      libroot = CLIPROOT;
#endif

      ++files;
#ifdef STD_LIBDIR
      if (eshared_flag || shared_flag)
      {
	 snprintf(cmd, sizeof(cmd), "-lclip");
	 add_name(cmd);
      }
      else
#endif
      {
	 e = (eshared_flag || shared_flag) ? CLIPSLIB : CLIPLIB;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, strlen(e));
	 add_name(cmd);
      }
      for (e = CLIPLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 lib_name(cmd, sizeof(cmd), libroot, "lib", e, l);
	 add_name(cmd);
	 e += l;
      }
      for (e = ADDLIBS; *e;)
      {
	 int l;

	 l = strspn(e, " \t");
	 e += l;
	 l = strcspn(e, " \t");
	 if (!l)
	    break;
	 memcpy(cmd, e, l);
	 cmd[l] = 0;
	 add_name(cmd);
	 e += l;
      }
      add_name(MATHLIB);
      add_name(DLLIB);

      /* generate _cfunctions */
      if (asm_flag)
	 sprintf(cfuncname, "%s_ref.s", oname);
      else
	 sprintf(cfuncname, "%s_ref.c", oname);
      sprintf(ofuncname, "%s_ref.o", oname);
      v_printf(1, "generate reference file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      write_Cfunc(cfuncname, onum, ovect, &ex, &nm);
      check_names(&ex, &nm);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
      if (clic_errorcount)
	 goto end;

      v_printf(1, "compile file '%s' ..", cfuncname);
      v_neednl = 1;
      beg = times(&ts);
      compile_File(cfuncname);
      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);

#ifdef USE_LD
      if (use_asm && (shared_flag || eshared_flag))
      {
	 int ll;

	 const char *ld_prg, *ld_end;

	 if (shared_flag || eshared_flag)
	 {
	    ld_prg = LD_PRG;
	    ld_end = LD_END;
	 }
	 else
	 {
	    ld_prg = LDS_PRG;
	    ld_end = LDS_END;
	 }

	 snprintf(cmd, sizeof(cmd), "%s", ld_prg);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 snprintf(e, sizeof(cmd) - ll, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s %s %s -o %s", optLevel ? COPT : "", genDebug ? CDBG : "", ofuncname, oname);
	 ll = strlen(cmd);
	 for (e = cmd + ll, i = 0; i < onum; ++i)
	 {
	    snprintf(e, sizeof(cmd) - ll, " %s", ovect[i]);
	    ll = strlen(cmd);
	    e = cmd + ll;
	 }
	 ll = strlen(cmd);
	 snprintf(cmd + ll, sizeof(cmd) - ll, " %s", ld_end);
      }
      else
#endif
      {
	 sprintf(cmd, "%s", CC);
	 for (e = cmd + strlen(cmd), i = 0; i < includePaths.count_of_Coll; ++i)
	 {
		 sprintf(e, " %s %s", INCLUDE_FLAG, (char *) includePaths.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 for (e = cmd + strlen(cmd), i = 0; i < lib_dirs.count_of_Coll; ++i)
	 {
		 sprintf(e, " -L%s", (char *) lib_dirs.items_of_Coll[i]);
	    e = cmd + strlen(cmd);
	 }

	 sprintf(cmd + strlen(cmd), " %s %s %s %s %s %s %s", optLevel ? COPT : "", genDebug ? CDBG : "", CFLAGS, ADDCFLAGS, ofuncname, OUT_FLAG, oname);
	 for (e = cmd + strlen(cmd), i = 0; i < onum; ++i)
	 {
	    sprintf(e, " %s", ovect[i]);
	    e = cmd + strlen(cmd);
	 }
      }

      v_printf(1, "make file '%s' ..", oname);
      v_neednl = 1;
      beg = times(&ts);
      v_printf(2, "%s\n", cmd);
      if (system(cmd))
	 yyerror("C level error in command: %s", cmd);
      else if (rmc_flag)
      {
	 unlink(cfuncname);
	 unlink(ofuncname);
      }

      end = times(&ts);
      v_neednl = 0;
      if (clic_errorcount == 0)
	 v_printf(1, ".. done, %s\n", diff_clock(beg, end));
      else
	 pr_errorcount(1);
   }

 end:
   End = times(&ts);

   resume_parser();
   resume_lex();
   resume_locale();

   if (!preproc_flag)
      v_printf(1, "clip: %d %s, %s\n", files, _clic_ngettext("file", "files", files), diff_clock(Beg, End));
   return clic_errorcount == 0 ? 0 : 1;
}
/* Default print function */
static int
print_ind(unsigned int index, void *data, void *udata)
{
    vr_printf("Index %d Data 0x%p\n", index, data);
    return 1;
}
Ejemplo n.º 7
0
static void
vr_qos_map_add(vr_qos_map_req *req)
{
    int ret = 0;
    bool need_set = false;
    unsigned int size, i;

    struct vrouter *router = vrouter_get(req->qmr_rid);
    struct vr_forwarding_class *fc_p, *fc_e;

    ret = vr_qos_map_request_validate(req);
    if (ret) {
        goto generate_response;
    }

    fc_p = vr_qos_map_get_fc(router, req->qmr_id);
    if (!fc_p) {
        size = vr_qos_map_entry_size * sizeof(struct vr_forwarding_class);
        fc_p = vr_zalloc(size, VR_QOS_MAP_OBJECT);
        if (!fc_p) {
            ret = -ENOMEM;
            goto generate_response;
        }
        need_set = true;
    }

    for (i = 0; i < req->qmr_dscp_size; i++) {
        if (req->qmr_dscp[i] >= VR_DSCP_QOS_ENTRIES)
            continue;

        fc_e = &fc_p[req->qmr_dscp[i]];
        fc_e->vfc_dscp = req->qmr_dscp[i];
        fc_e->vfc_id = req->qmr_dscp_fc_id[i];
        fc_e->vfc_valid = 1;
    }

    for (i = 0; i < req->qmr_mpls_qos_size; i++) {
        if (req->qmr_mpls_qos[i] >= VR_MPLS_QOS_ENTRIES)
            continue;

        fc_e = &fc_p[VR_DSCP_QOS_ENTRIES + req->qmr_mpls_qos[i]];
        fc_e->vfc_mpls_qos = req->qmr_mpls_qos[i];
        fc_e->vfc_id = req->qmr_mpls_qos_fc_id[i];
        fc_e->vfc_valid = 1;
    }

    for (i = 0; i < req->qmr_dotonep_size; i++) {
        if (req->qmr_dotonep[i] >= VR_DOTONEP_QOS_ENTRIES)
            continue;

        fc_e = &fc_p[VR_DSCP_QOS_ENTRIES + VR_MPLS_QOS_ENTRIES +
            req->qmr_dotonep[i]];
        fc_e->vfc_dotonep_qos = req->qmr_dotonep[i];
        fc_e->vfc_id = req->qmr_dotonep_fc_id[i];
        fc_e->vfc_valid = 1;
    }

    ret = vr_offload_qos_map_add(req);
    if (ret) {
        vr_printf("offload QoS map not supported - not configuring\n");
        vr_free(fc_p, VR_QOS_MAP_OBJECT);
        goto generate_response;
    }

    if (need_set) {
        vr_qos_map_set_fc(router, req->qmr_id, fc_p);
    }

generate_response:
    vr_send_response(ret);
    return;
}