📄 rtap_cmds.c
字号:
Label( OP_se ), SetLit( RAPI_RSTYLE_SE, 1), Not_EOL( NULL, 2), Action( Aresv_fin, NULL, OK), IsNot( OP_filter, "Missing filter spec", ERR), Action( Afilter, NULL, 1), Is( OP_filter, NULL, -1), InFile( OP_flowspec, ".rsvp.profile", 2), IsNot( OP_flowspec, "Missing flowspec", ERR), Action( Aflowspec, NULL, -7), Label( OP_tspec ), /* Tspec * '[' 't' <r> <b> <p> <m> [<M>] ']' */ Not_Char("[", NO), Not_String("t", 2), SetLit(QOS_TSPEC, 2), Print("Unknown service", ERR), Not_Integer("Missing r: TB depth", ERR), Not_Integer("Missing b: TB rate", ERR), Not_Integer("Missing p: Peak rate", ERR), Not_Integer("Missing m: Min policed size", ERR), Not_Integer(NULL, 1), Char("]", 2), Print("Missing ]", ERR), Action(Atspec, NULL, OK), Label( OP_flowspec ), /* '[' 'cl' <r> <b> <p> <m> [<M>] ']' * '[' 'g' <R> <S> <r> <b> <p> <m> [<M>] ']' */ Not_Char("[", NO), Not_String("g", 2), SetLit(QOS_GUARANTEED, 4), Not_String("cl", 2), SetLit(QOS_CNTR_LOAD, 4), Print("Unknown service", ERR), Not_Integer("Missing R: Rate", ERR), Not_Integer("Missing S: Slack", ERR), Not_Integer("Missing r: TB depth", ERR), Not_Integer("Missing b: TB rate", ERR), Not_Integer("Missing p: Peak rate", ERR), Not_Integer("Missing m: Min policed size", ERR), Not_Integer(NULL, 1), Char("]", OK), Print("Missing ]", ERR), Label( OP_filter ), /* host [ / port ] */ Not_Host(NULL, NO), WhSp( NULL, OK), Char("/", 2), Print("Bad dest port", ERR), Not_Integer(NULL, -1), Go( OK), Label( OP_adspec ), Char("(", 2), Action(Aadspec, NULL, NO), /* Record null Adspec */ SetLit(GENERAL_INFO, 1), /* General info section */ Is(OP_breakbit, NULL, 1), /* Scan Break bit -- */ /* Also initializes adspec area */ /* Have to recurse now to keep value stack consistent. This is * quite confusing... I need to think of a better way to handle * the value stack. */ Is(OP_genparm, NULL, 1), /* Scan general parms */ Not_Char(")", 2), /* ) => done */ Action(Aadspec, NULL, OK), Char(",", 1), /* Ignore comma */ /* scan for service-specific fragments, if any. */ Is(OP_Gadspec, "", -3), Is(OP_CLadspec,"", -4), /* General info parms MUST be in order; however, suffix strings * are optional. */ Label( OP_genparm ), SetLit(IS_WKP_HOP_CNT, 1), Not_Integer("Missing # hops", ERR), Action(Aadspec_p, NULL, 1), String("hop", 1), SetLit(IS_WKP_PATH_BW, 1), Not_Integer("Missing BW", ERR), Action(Aadspec_p, NULL, 1), String("B/s", 1), SetLit(IS_WKP_MIN_LATENCY, 1), Not_Integer("Missing min lat", ERR), Action(Aadspec_p, NULL, 1), String("usec", 1), SetLit(IS_WKP_COMPOSED_MTU, 1), Not_Integer("Missing MTU", ERR), Action(Aadspec_p, NULL, 1), String("B", OK), Go( OK), Label( OP_hops ), SetLit(IS_WKP_HOP_CNT, 1), Not_Integer(NULL, NO), Not_String("hop", NO), Action(Aadspec_p, NULL, OK), Label( OP_BW ), SetLit(IS_WKP_PATH_BW, 1), Not_Integer(NULL, NO), Not_String("BW", NO), Action(Aadspec_p, NULL, OK), Label( OP_minlat ), SetLit(IS_WKP_MIN_LATENCY, 1), Not_Integer(NULL, NO), Not_String("us", NO), Action(Aadspec_p, NULL, OK), Label( OP_MTU ), SetLit(IS_WKP_COMPOSED_MTU, 1), Not_Integer(NULL, NO), Not_String("mtu", NO), Action(Aadspec_p, NULL, OK), Label( OP_breakbit ), SetLit(0, 1), /* Type = Break bit */ String("br!", 2), SetLit(0, 2), /* Value = break bit */ SetLit(1, 1), Action(Aadspec_p, NULL, OK), Label( OP_Gadspec ), Not_String("G=", NO), Not_String("{", NO), SetLit(GUARANTEED_SERV, 1), Is(OP_breakbit, NULL, 1), /* Break bit -- */ Is(OP_Gadparms, NULL, 1), String("}", OK), Is(OP_hops, NULL, -1), Is(OP_BW, NULL, -2), Is(OP_minlat, NULL, -3), Is(OP_MTU, NULL, -4), Print("Bad Guar override parm", ERR), Label( OP_Gadparms ), SetLit(GUAR_ADSPARM_C, 1), Not_Integer("Missing G parm1", ERR), Not_Integer("Missing G parm2", ERR), Not_Integer("Missing G parm3", ERR), Not_Integer("Missing G parm4", ERR), Action(Aadspec_p, NULL, OK), Label( OP_CLadspec ), Not_String("CL=", NO), Not_String("{", NO), SetLit(CONTROLLED_LOAD_SERV, 1), Is(OP_breakbit, NULL, 1), /* Break bit -- */ String("}", OK), Is(OP_hops, NULL, -1), Is(OP_BW, NULL, -2), Is(OP_minlat, NULL, -3), Is(OP_MTU, NULL, -4), Print("Bad CL override parm", ERR), Label( 0 ) };/* XXX TEMPORARY! */void mallocmap(){}intPm_Action(int op, int vi, int parm) { int i, sid, rc; u_char flags;#ifdef DATA double F_intvl; long I_intvl;#endif#ifdef ISI_TEST void mallocmap();#endif#ifdef RTAP char *cp; u_char u_ch;#endif switch (op) { case Ahelp: for (i = 0; i < OP_NULL; i++) printf("%s", cmd_table[i].cmd_help); case Aotherhelp: printf(Other_help); break; case Abug: Pm_debug = !Pm_debug; break; case Asession: /* val stack: * gpi?1|0 intserv?1:0 proto desthost [destport] */ flags = 0; if (val0) { flags = RAPI_GPI_SESSION; Mode[T] |= GPI_MODE; } if (val1) flags |= RAPI_USE_INTSERV; protid[T] = val2; get_sockaddr(3, (struct sockaddr *) &dest[T]); if (Sid[T] != NULL_SID) { printf("close first\n"); break; } sid = rapi_session((struct sockaddr *)&dest[T], protid[T], flags, (rapi_event_rtn_t) asynch_handler, 0, &rc); if (sid == NULL_SID) print_errno("rsvp_session()", rc); else { Sid[T] = sid; rtap_fd = rapi_getfd(sid); printf("T%d: rapi_session => sid= %d, fd= %d\n", T, sid, rtap_fd); }#ifdef DATA send_data_bytes = recv_data_bytes = 0; send_data_msgs = recv_data_msgs = 0;#endif break;#ifdef DATA case Adata: if (Pm_vi > 0) { F_intvl = atof(val0); I_intvl = (long) rint(1e6/F_intvl); timeout.tv_sec = I_intvl/1000000; timeout.tv_usec = I_intvl%1000000; if (Pm_vi > 1) data_size = val1; else data_size = DEFAULTDATA_SIZE; } gettimeofday(&nexttime, NULL); tvadd(&nexttime, &timeout); break;#endif /* DATA */ case Arecv: if (Sid[T] == NULL_SID) { printf("Must issue dest cmd first\n"); break; } memset(&rcvr[T], 0, sizeof(struct SOCKADDR)); if (Pm_vi > 0) { Append_Val(0); /* No port */ get_sockaddr(vi, (struct sockaddr *) &rcvr[T]); } if (udpsock[T] < 0) udpsock[T] = Get_Socket((struct sockaddr *) &dest[T]); Set_Recv((struct sockaddr *) &dest[T], (struct sockaddr *) &rcvr[T]); break; case Attl: if (Pm_vi > 0) ttl[T] = val0;#ifdef DATA if (( Mode & S_MODE ) && data_size > 0) Set_Send(&dest[T], &src[T], ttl[T]);#endif break; case Aunsupported: printf("Not supported\n"); break; case Asender: /* Sender: value stack is: * [ <1> <host> <port> | <0> <empty> <port> ] */ if (Sid[T] == NULL_SID) { printf("Must issue dest cmd first\n"); break; } if (Pm_vi) { /* There are parameters ... not just empty sender. * */ if (!Pm_val[vi]) { /* No host; supply INADDR_ANY of * same type as dest address. */ Set_INADDR_ANY(&Pm_addrs[vi+1], (struct sockaddr *) &dest[T]); } if (Mode[T] & GPI_MODE) { memset(&src[T], 0, sizeof(struct SOCKADDR)); init_Area((area_t **)&snd_template[T], sizeof(rapi_filter_t)); get_GPIfilter(vi+1, &snd_template[T], sizeof(rapi_filter_t)); } else { /* Normal case... */ free_Area(&snd_template[T]); get_sockaddr(vi+1, (struct sockaddr *) &src[T]); } } /* * Make rapi_sender call to RSVP API */ rc = rapi_sender(Sid[T], 0, (Pm_vi>0)? (struct sockaddr *)&src[T]: NULL, Area_Data((rapi_filter_t *), snd_template[T]), Area_Data((rapi_tspec_t *), snd_tspec[T]), Area_Data((rapi_adspec_t *), snd_adspec[T]), NULL, /* Policy */ ttl[T]); if (rc) print_errno("rsvp_sender()", rc); else printf("rapi_sender() OK\n"); Mode[T] |= S_MODE; break; case Atspec: init_Area((area_t **)&snd_tspec[T], sizeof(rapi_tspec_t)); get_tspec(vi, &snd_tspec[T], sizeof(rapi_tspec_t)); Pm_vi = vi; /* Pop off value stack */ break; case Aadspec_p: /* Adspec parm: * !Value stack is offset by 1; it contains: * (Service#) |> (parm#) (value) * except: * (GUARANTEED) |> (GUAR_ADSPARM_C) (p1) (p2) (p3) (p4) */ set_adspec_p(vi-1, Pm_val[vi-1], Pm_val[vi], 1); Pm_vi -= 2; break; case Aadspec: /* Completed Adspec * */ if (vi < Pm_vi) { Adspec.len = sizeof(Adspec); Adspec.form = RAPI_ADSTYPE_Simplified; init_Area((area_t **)&snd_adspec[T], sizeof(rapi_adspec_t)); Cat_Area(snd_adspec[T], (rapi_hdr_t *) &Adspec); } else if (snd_adspec[T]) { free (snd_adspec[T]); snd_adspec[T] = NULL; } break; case Aclose: if (Sid[T] == NULL_SID) { printf("Already closed\n"); break; } rc = rapi_release(Sid[T]); if (rc) print_errno("rapi_release()", rc); printf("T%d: rapi_release(): sid= %d, fd= %d\n", T, Sid[T], rtap_fd); Sid[T] = NULL_SID; Mode[T] = NO_MODE; if (udpsock[T] >= 0) close(udpsock[T]); /* close data socket */ udpsock[T] = -1; break; case Aconfirm: resv_flags[T] = RAPI_REQ_CONFIRM; break; case Asynch: rc = rapi_dispatch(); if (rc) print_errno("rapi_dispatch()", rc); case Amemory:#if defined(ISI_TEST) && defined(SunOS) mallocmap();#else printf("Not supported.\n");#endif break; case Ahexmsg: /* To send arbitrary RSVP message, use: * hexmsg <type> <host> <vif> x<hex string> * * The first 8 bytes of <hex string> will be * replaced by an RSVP common header. Blanks in * <hex string> will be ignored. * * If the packet is larger than 100 bytes or for * convenience, can split into multiple lines, ended * with the line show above; e.g., * hexmsg x<hex string1> * hexmsg x<hex string2> * ... * hexmsg <type> <host> [vif] x<last hex string> * * or: * hexmsg x<hex string1> * ... * hexmsg x<last hex string> * hexmsg <type> <host> [vif] * * Val stack: [<msg type #> <target host> <vif|-1>] */#ifdef RTAP if (packet_size >= MAX_PACKET) { printf("Hex msg too large\n"); break; } u_ch = i = 0; for (cp = Pm_cp; *cp; cp++) { if (isxdigit(*cp)) {#define tohex(c) (isdigit(c)?c-'0':tolower(c)-'a'+10) u_ch = (u_ch<<4)|tohex(*cp); if (++i == 2) { packet_buff[packet_size++] = u_ch; i = u_ch = 0; } } else if ((*cp == ' '||*cp == '#') &&(i)) { printf("Bad hex @ +%d\n", cp-Pm_cp-1); break; } if (*cp == '#') break; } /* Only last line of multi-line message specifies host, * and therefore has Pm_vi > 0. */ if (Pm_vi == 0) break; rtap_hexmsg(val0, val2, &Pm_addrs[1], packet_buff, packet_size); packet_size = 0;#else printf("Unsupported by remote rtap\n");#endif break; case Asleep: rtap_sleep((Pm_vi > 0)? val0:0); break; case Astatus: print_status(); break; case Aquit: if (Sid[T] != NULL_SID) { rc = rapi_release(Sid[T]); if (rc) print_errno("rapi_release()", rc); printf("Closed sid= %d, fd= %d\n", Sid[T], rtap_fd); } if (udpsock[T] >= 0) close(udpsock[T]); /* close data socket */#ifdef RTAP dump_rsvp_stats();#endif exit(0); case Afilter: if (Mode[T] & GPI_MODE) get_GPIfilter(1+vi, &Filter_specs[T], sizeof(rapi_filter_t));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -