Beispiel #1
0
int skickabrev(void) {
        int pers,editret;
        char *adr;
        if(!(adr=strchr(argument,'@'))) {
                if((pers=parsenamn(argument))==-1) {
                        puttekn("\r\n\nFinns ingen som heter så eller har det numret\r\n\n",-1);
                        return(0);
                } else if(pers==-3) {
                        puttekn("\r\n\nSkriv: Brev <användare>\r\n\n",-1);
                        return(0);
                }
                nu_skrivs=BREV;
        } else {
                nu_skrivs=BREV_FIDO;
                *adr='\0';
                adr++;
                if(!getzone(adr) || !getnet(adr)) {
                        puttekn("\n\n\rSkriv: Brev <användare>@<zon>:<nät>/<nod>[.<point>]\n\r",-1);
                        return(0);
                }
        }
        if(nu_skrivs==BREV) editret=initbrevheader(pers);
        else if(nu_skrivs==BREV_FIDO) return(fido_brev(argument,adr,NULL));
        else return(0);
        if(editret==1) return(1);
        if(editret==2) return(0);
        if((editret=edittext(NULL))==1) return(1);
        if(!editret) sparabrev();
        return(0);
}
CNet *CRBox::getnet (char *signame)
{
  string  name;


  name = signame;

  return (getnet(name));
}
Beispiel #3
0
int fido_brev(char *tillpers,char *adr,struct Mote *motpek) {
        int length=0,x=0,editret,chrs;
        struct FidoDomain *fd;
        struct FidoText *komft,ft;
        struct MinNode *first, *last;
        char *foo,tmpfrom[100],fullpath[100],filnamn[20],subject[80],msgid[50],tkn;
        if(!(Servermem->inne[nodnr].grupper & Servermem->fidodata.mailgroups) &&
                Servermem->inne[nodnr].status < Servermem->fidodata.mailstatus) {
                puttekn("\n\n\rDu har ingen rätt att skicka FidoNet NetMail.\n\r",-1);
                return(0);
        }
        Servermem->action[nodnr] = SKRIVER;
        Servermem->varmote[nodnr] = -1;
        memset(&ft,0,sizeof(struct FidoText));
        if(!tillpers) { /* Det handlar om en kommentar */
                if(motpek) { /* Det är en personlig kommentar */
                        strcpy(fullpath,motpek->dir);
                        sprintf(filnamn,"%d.msg",senast_text_nr - motpek->renumber_offset);
                        AddPart(fullpath,filnamn,99);
                        komft = ReadFidoTextTags(fullpath,RFT_HeaderOnly,TRUE,TAG_DONE);
                        if(!komft) {
                                puttekn("\n\n\rTexten finns inte.\n\r",-1);
                                return(0);
                        }
                        strcpy(ft.touser,komft->fromuser);
                        ft.tozone = komft->fromzone;
                        ft.tonet = komft->fromnet;
                        ft.tonode = komft->fromnode;
                        ft.topoint = komft->frompoint;
                        strcpy(subject,komft->subject);
                        strcpy(msgid,komft->msgid);
                        FreeFidoText(komft);
                } else { /* Det är en kommentar av ett brev */
                        strcpy(tmpfrom,brevread.from);
                        foo=strchr(tmpfrom,'(');
                        if(!foo) {
                                puttekn("\n\n\rDen kommenterade texten saknar adress!\n\r",-1);
                                return(0);
                        }
                        *(foo-1)='\0';
                        foo++;
                        strcpy(ft.touser,tmpfrom);
                        ft.tozone=getzone(foo);
                        ft.tonet=getnet(foo);
                        ft.tonode=getnode(foo);
                        ft.topoint=getpoint(foo);
                        strcpy(subject,brevread.subject);
                        strcpy(msgid,brevread.messageid);

                }
        } else { /* Det är ett helt nytt brev */
                strcpy(ft.touser,tillpers);
                sprattgok(ft.touser);
                ft.tozone=getzone(adr);
                ft.tonet=getnet(adr);
                ft.tonode=getnode(adr);
                ft.topoint=getpoint(adr);
        }
        fd = getfidodomain(0,ft.tozone);
        if(!fd) {
                puttekn("\n\n\rDu kan inte skriva brev till den zonen.\n\r",-1);
                return(0);
        }
        if(!tillpers && !motpek) {
                foo = strchr(brevread.to,'(')+1;
                ft.fromzone = getzone(foo);
                ft.fromnet = getnet(foo);
                ft.fromnode = getnode(foo);
                ft.frompoint = getpoint(foo);
        } else {
                ft.fromzone = fd->zone;
                ft.fromnet = fd->net;
                ft.fromnode = fd->node;
                ft.frompoint = fd->point;
        }
        ft.attribut = FIDOT_PRIVATE | FIDOT_LOCAL;
        makefidousername(ft.fromuser,inloggad);
        makefidodate(ft.date);
        sprintf(outbuffer,"\r\n\nMöte: %s\r\n",Servermem->cfg.brevnamn);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Fido-nätbrev,  %s\n\r",ft.date);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Avsändare: %s (%d:%d/%d.%d)\r\n",ft.fromuser,ft.fromzone,ft.fromnet,ft.fromnode,ft.frompoint);
        puttekn(outbuffer,-1);
        sprintf(outbuffer,"Mottagare: %s (%d:%d/%d.%d)\n\r",ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
        puttekn(outbuffer,-1);
        puttekn("Ärende: ",-1);
        if(!tillpers) {
                if(!strncmp(subject,"Re:",3)) strcpy(ft.subject,subject);
                else sprintf(ft.subject,"Re: %s",subject);
                puttekn(ft.subject,-1);
        } else {
                if(getstring(EKO,40,NULL)) return(1);
                if(!inmat[0]) {
                        eka('\n');
                        return(0);
                }
                strcpy(ft.subject,inmat);
        }
        puttekn("\r\n",-1);
        if(Servermem->inne[nodnr].flaggor & STRECKRAD) {
                length=strlen(ft.subject);
                for(x=0;x<length+8;x++) outbuffer[x]='-';
                outbuffer[x]=0;
                puttekn(outbuffer,-1);
                puttekn("\r\n\n",-1);
        } else puttekn("\n",-1);
        crashmail = FALSE;
        editret = edittext(NULL);
        if(editret==1) return(1);
        if(editret==2) return(0);
        if(crashmail) ft.attribut |= FIDOT_CRASH;
        Servermem->inne[nodnr].skrivit++;
        Servermem->info.skrivna++;
        Statstr.write++;
        puttekn("\n\n\rTill vilken teckenuppsättning ska brevet konverteras?\r\n\n",-1);
        puttekn("1: ISO Latin 8-bitars tecken (Default)\n\r",-1);
        puttekn("2: IBM PC 8-bitars tecken\r\n",-1);
        puttekn("3: Macintosh 8-bitars tecken\r\n",-1);
        puttekn("4: Svenska 7-bitars tecken\r\n\n",-1);
        puttekn("Val: ",-1);
        for(;;) {
                tkn=gettekn();
                if(tkn==13 || tkn==10) tkn='1';
                if(tkn >= '1' && tkn <= '4') break;
        }
        sprintf(outbuffer,"%c\r\n\n",tkn);
        puttekn(outbuffer,-1);
        switch(tkn) {
                case '1' : chrs=CHRS_LATIN1; break;
                case '2' : chrs=CHRS_CP437; break;
                case '3' : chrs=CHRS_MAC; break;
                case '4' : chrs=CHRS_SIS7; break;
        }
        NewList((struct List *)&ft.text);
        first =  edit_list.mlh_Head;
        last = edit_list.mlh_TailPred;
        ft.text.mlh_Head = first;
        ft.text.mlh_TailPred = last;
        last->mln_Succ = (struct MinNode *)&ft.text.mlh_Tail;
        first->mln_Pred = (struct MinNode *)&ft.text;
        if(tillpers) x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                                      WFT_Domain,fd->domain,
                                                      WFT_CharSet,chrs,
                                                      TAG_DONE);
        else x = WriteFidoTextTags(&ft,WFT_MailDir,Servermem->fidodata.matrixdir,
                                            WFT_Domain,fd->domain,
                                            WFT_Reply,msgid,
                                            WFT_CharSet,chrs,
                                            TAG_DONE);
        sprintf(outbuffer,"Brevet fick nummer %d\r\n\n",x);
        puttekn(outbuffer,-1);
        if(Servermem->cfg.logmask & LOG_BREV) {
                strcpy(tmpfrom,getusername(inloggad));
                sprintf(outbuffer,"%s skickar brev %d till %s (%d:%d/%d.%d)",tmpfrom,x,ft.touser,ft.tozone,ft.tonet,ft.tonode,ft.topoint);
                logevent(outbuffer);
        }
        puttekn("Vill du ha en kopia av brevet i din egen brevlåda? ",-1);
        if(jaellernej('j','n',2)) savefidocopy(&ft,inloggad);
        while(first=(struct MinNode *)RemHead((struct List *)&ft.text)) FreeMem(first,sizeof(struct EditLine));
        NewList((struct List *)&edit_list);
        return(0);
}
Beispiel #4
0
void  CRBox::mbkload (MBK::CFig *mbkfig
                     , int z
                     , int zup
                     , int rtype
                     , bool halfpitch
                     , bool xhalfpitch
                     , bool yhalfpitch
                     , bool rotate
                     , set<string>* subNetList )
{
    MBK::MIns::iterator   itIns, endInstances, endOrphans;
  MBK::MLosig::iterator   endSig;
  MBK::MLosig::iterator   sig;
                   long   mX, mY, mZ, x, y, zz, xadjust, yadjust, yoffsetslice;
                   long   XRW1, YRW1, XRW2, YRW2;
                   bool   use_global;
                   long   northPad, southPad, eastPad, westPad;
                   long   xoffsettrack, yoffsettrack;
        MBK::chain_list  *pChain;
        MBK::locon_list  *pLocon;
        MBK::phcon_list  *pPhcon;
        MBK::losig_list  *pSig;
        MBK::phseg_list  *pSeg, flatSeg;
        MBK::phvia_list  *pVIA;
        MBK::phfig_list  *pModel;
            MBK::CXRect  *rect;
              MBK::CIns  *pIns;
                   CNet  *pNet;
                 string   sig_name, term_name, ins_name;
      CDRGrid::iterator   coord;
                  CNode  *node;


  cmess1 << "\n";
  cmess1 << "  o  Loading design into grid...\n";

  ischip       = false;
  fig          = mbkfig;
  endInstances = fig->instances.end ();
  endOrphans   = fig->orphans.end   ();
  endSig       = fig->lofig.signals.end ();

  northPad     = 0;
  southPad     = 0;
  westPad      = 0;
  eastPad      = 0;
  xoffsettrack = 0;
  yoffsettrack = 0;

  // Half pitch offset.
  if ( halfpitch ) {
    xoffsettrack = D::X_GRID / 2;
    yoffsettrack = D::Y_GRID / 2;
  }
  else if ( xhalfpitch ) {
    xoffsettrack = D::X_GRID / 2;
  }
  else if ( yhalfpitch ) {
    yoffsettrack = D::Y_GRID / 2;
  }

  // Search for pads.
  for (itIns = fig->instances.begin(); itIns != endInstances; itIns++) {
    pModel = itIns->second->getmodel ();

    if ( MBK::IsPxLib(pModel) ) {
      switch ( itIns->second->phins->TRANSF ) {
        case NOSYM:
          ischip = true;
          if ( northPad == 0 ) {
            cmess2 << "     o  North pad found.\n";
            northPad = pModel->YAB2 - pModel->YAB1 - MBK::SCALE(15);
          }
          break;
        case SYM_Y:
          ischip = true;
          if ( southPad == 0 ) {
            cmess2 << "     o  South pad found.\n";
            southPad = pModel->YAB2 - pModel->YAB1 - MBK::SCALE(15);
          }
          break;
        case ROT_P:
          ischip = true;
          if ( eastPad == 0 ) {
            cmess2 << "     o  East pad found.\n";
            eastPad = pModel->YAB2 - pModel->YAB1 - MBK::SCALE(15);
          }
          break;
        case SY_RP:
          ischip = true;
          if ( westPad == 0 ) {
            cmess2 << "     o  West pad found.\n";
            westPad = pModel->YAB2 - pModel->YAB1 - MBK::SCALE(15);
          }
          break;
        default:
          cerr << hwarn ("")
               << "  Pad " << itIns->second->phins->INSNAME
               << " have an invalid orientation.\n";
          break;
      }
    }
  }


  //southPad = northPad = westPad = eastPad = MBK::SCALE(50);
  //westPad = MBK::SCALE(100);


  // Default Routing Widow size : the AB.
  XRW1 = fig->XAB1 () + westPad;
  YRW1 = fig->YAB1 () + southPad;
  XRW2 = fig->XAB2 () - eastPad;
  YRW2 = fig->YAB2 () - northPad;

  // Find the a seed cell (one either from sxlib or dp_sxlib to
  // track adjust the grid).
  for (itIns = fig->instances.begin(); ; itIns++) {
    if (itIns == endInstances) {
      xadjust      = xoffsettrack;
      yadjust      = yoffsettrack;
      yoffsetslice = 0;
      cout << hwarn ("")
           << "  Unable to found a seed cell (i.e. belonging to either\n"
           << "  sxlib or dp_sxlib) grid could be misplaced.\n";
      break;
    }

    pModel = itIns->second->getmodel ();

    if ( !MBK::IsPxLib(pModel) ) {
      cmess2 << "     o  Using seed cell \"" << itIns->first
             << "\" (model \"" << pModel->NAME << "\").\n";
      xadjust      = abs((itIns->second->phins->XINS - XRW1) % D::X_GRID ) + xoffsettrack;
      yadjust      = abs((itIns->second->phins->YINS - YRW1) % D::Y_GRID ) + yoffsettrack;
      yoffsetslice = abs((itIns->second->phins->YINS - YRW1) % D::Y_SLICE) + YRW1;

      break;
    }
  }
  
  xoffsetgrid = XRW1 + xadjust;
  yoffsetgrid = YRW1 + yadjust;

  cmess2 << "     o  Grid offset : ("
         << MBK::UNSCALE(xoffsetgrid) << ","
         << MBK::UNSCALE(yoffsetgrid) << ")"
         << " [adjust ("
         << MBK::UNSCALE(xadjust) << ","
         << MBK::UNSCALE(yadjust) << ")]\n";

  // Compute the routing grid size.
  mX = (XRW2 - XRW1) / D::X_GRID + ((xadjust==0)?1:0);
  mY = (YRW2 - YRW1) / D::Y_GRID + ((yadjust==0)?1:0);
  mZ = z;


  // Is the design a complete chip.
  if (ischip)
    cmess2 << "     o  Design have pads, treated as a complete chip.\n";


  // Selecting the whether to use global routing.
  use_global = (mX + mY) > (2 * D::GLOBAL_HP);
  if (rtype == D::ROUTING_CHOOSE) {
    if (use_global) {
      cmess2 << "     o  Big design, global routing enabled.\n";
      rglobal = true;

      if (z < 5) {
        cmess2 << "        - Forcing 4 routing layers.\n";
        mZ = 5;
      }
    } else {
      cmess2 << "     o  Small design, global routing disabled.\n";
      rglobal = false;
    }
  } else {
    if (rtype == D::ROUTING_GLOBAL) {
      rglobal = true;
      if (!use_global) {
        cout << hwarn ("")
             << "  You have enabled global routing on a small design,\n"
             << "  this will waste upper routing layers.\n";
      }
    }
    if (rtype == D::ROUTING_LOCAL ) {
      rglobal = false;
      if (use_global) {
        cout << hwarn ("")
             << "  You have disabled global routing on a big design,\n"
             << "  this will slow down the routing.\n";
      }
    }
  }


  cmess2 << "     o  Allocating grid size ["
         << mX << "," << mY << "," << mZ << "].\n";

  float  mXf      = mX;
  float  mYf      = mY;
  float  mZf      = mZ;
  float  overflow = INT_MAX;

  if ( mXf * mYf * mZf >= overflow ) {
    cerr << herr("")
         << "  Internal routing grid capacity exceeded :\n"
         << "  More than " << INT_MAX << "nodes (INT_MAX).\n";
    throw except_done();
  }

  // Allocating the routing grid.
  drgrid = new CDRGrid (xoffsetgrid, yoffsetgrid, mX, mY, mZ, zup);


  rect = new MBK::CXRect (drgrid);


  cmess2 << "     o  Loading external terminals.\n";

  // Browse layout for terminals.
  for (pPhcon = fig->phfig.fig->PHCON; pPhcon != NULL; pPhcon = pPhcon->NEXT) {
    if (fig->lofig.signals.find(pPhcon->NAME) == endSig) {
      cerr << hwarn ("")
           << "  The terminal \"" << pPhcon->NAME << "\" at ("
           << MBK::UNSCALE (pPhcon->XCON) << ","
           << MBK::UNSCALE (pPhcon->YCON) << ") layer "
           << MBK::layer2a (pPhcon->LAYER) << "\n"
           << "  do not not belong to any logical signal : ignored.\n";

      continue;
    }

    pNet = getnet (pPhcon->NAME);

    term_name  = "external.";
    term_name += pPhcon->NAME;

    flatSeg.X1    = pPhcon->XCON;
    flatSeg.Y1    = pPhcon->YCON;
    flatSeg.X2    = pPhcon->XCON;
    flatSeg.Y2    = pPhcon->YCON;
    flatSeg.WIDTH = MBK::env.layer2width (pPhcon->LAYER);
    flatSeg.LAYER = pPhcon->LAYER;
    flatSeg.NAME  = pPhcon->NAME;

    rect->setSeg  (flatSeg);

    if ( rect->isInGrid() ) {
      pNet->newaccess ( term_name
                      , rect->grid
                      , MBK::env.layer2z (pPhcon->LAYER)
                      );
    } else {
      cerr << hwarn ("")
           << "  The terminal \"" << pPhcon->NAME << "\" at ("
           << MBK::UNSCALE (pPhcon->XCON) << ","
           << MBK::UNSCALE (pPhcon->YCON) << ") layer "
           << MBK::layer2a (pPhcon->LAYER) << "\n"
           << "  is outside the routing grid : ignored.\n";
    }

  }


  cmess2 << "     o  Finding obstacles.\n";


  // Browse father for obstacles (powers are obstacles) and already
  // routed or partially routed signals.
  for (pSeg = fig->phfig.fig->PHSEG; pSeg != NULL; pSeg = pSeg->NEXT) {
    // There must not be obstacle in the father!
    if (MBK::isobs (pSeg->LAYER)) {
      cerr << hwarn ("")
           << "  An obstacle has been found at design top level, ignored.\n";

      continue;
    }

    // Power grid.
    if (MBK::ISVDD (pSeg->NAME) || MBK::ISVSS (pSeg->NAME)) {
      if (pSeg->LAYER != MBK::CALU1) {
        rect->setSeg (*pSeg);
        
        //cerr << "+ Top power obstacle\n" << rect;

        if ( rect->isInGrid() )
          drgrid->nodes->obstacle (rect->grid, MBK::env.layer2z (pSeg->LAYER));
      }

      continue;
    }

    // Unnamed signals : ignored.
    if (pSeg->NAME == NULL) {
      cerr << hwarn ("")
           << "  An unnamed segment has been found at design top level, ignored.\n";

      continue;
    }

    // Partially routed signals.
    sig = fig->lofig.signals.find(pSeg->NAME);
    if ( sig == endSig) {
      cerr << hwarn ("")
           << "  The segment \"" << pSeg->NAME << "\" at ("
           << MBK::UNSCALE (pSeg->X1) << ","
           << MBK::UNSCALE (pSeg->Y1) << ") ("
           << MBK::UNSCALE (pSeg->X2) << ","
           << MBK::UNSCALE (pSeg->Y2) << ") layer "
           << MBK::layer2a (pSeg->LAYER) << "\n"
           << "  do not not belong to any logical signal : ignored.";

      continue;
    }

    pNet = getnet (getsigname(sig->second));
    if ( !pNet->fixed ) {
      cmess2 << "     o  Signal " << pNet->name << " is assumed to be routed.\n";
      pNet->fixed = true;
    }

    rect->setSeg  (*pSeg);

    if ( rect->isInGrid() ) {
      //pNet->newaccess ( pSeg->NAME
      //                , rect->grid
      //                , MBK::env.layer2z (pSeg->LAYER)
      //                );
      //cerr << "+ Net obstacle\n" << rect;
      drgrid->nodes->obstacle (rect->grid, MBK::env.layer2z (pSeg->LAYER));
    } else {
      cerr << hwarn ("")
           << "  The segment \"" << pSeg->NAME << "\" at ("
           << MBK::UNSCALE (pSeg->X1) << ","
           << MBK::UNSCALE (pSeg->Y1) << ") ("
           << MBK::UNSCALE (pSeg->X2) << ","
           << MBK::UNSCALE (pSeg->Y2) << ") layer "
           << MBK::layer2a (pSeg->LAYER) << "\n"
           << "  is outside the routing grid : ignored.";
    }
  }


  // Browse for obstacle VIAs.
  for (pVIA = fig->phfig.fig->PHVIA; pVIA != NULL; pVIA = pVIA->NEXT) {
    // Only power VIAs must be obstacles.
    if ( (! MBK::ISVDD (pVIA->NAME)) && (! MBK::ISVSS (pVIA->NAME))) {
      pNet = getnet (pVIA->NAME);
      if ( pNet && !pNet->fixed ) continue;
    }

    for (x = 0; x < 2; x++) {
      switch (x) {
        case 0: flatSeg.LAYER = MBK::topVIALayer    (pVIA->TYPE); break;
        case 1: flatSeg.LAYER = MBK::bottomVIALayer (pVIA->TYPE); break;
      }

      if (flatSeg.LAYER == MBK::CALU1) continue;

      long  xVIAshrink = 0;
      if (pVIA->DX) { xVIAshrink = (pVIA->DX - MBK::SCALE(3)) / 2; }
      flatSeg.X1    = pVIA->XVIA - xVIAshrink;
      flatSeg.X2    = pVIA->XVIA + xVIAshrink;
      flatSeg.Y1    = pVIA->YVIA;
      flatSeg.Y2    = pVIA->YVIA;
      flatSeg.WIDTH = pVIA->DY;

      rect->setSeg (flatSeg);

      //cerr << "+ Top VIA obstacle ("
      //     << MBK::UNSCALE(pVIA->XVIA) << ","
      //     << MBK::UNSCALE(pVIA->YVIA) << ") "
      //     << MBK::layer2a(flatSeg.LAYER) << endl;
      //cerr << rect;

      if ( rect->isInGrid() )
        drgrid->nodes->obstacle (rect->grid, MBK::env.layer2z (flatSeg.LAYER));
    }
  }


  // Browse instances & orphans for obstacles.
  for (itIns = fig->instances.begin(); ; itIns++) {
    if (itIns == endInstances) itIns = fig->orphans.begin ();
    if (itIns == endOrphans  ) break;

    pModel = itIns->second->getmodel ();

    cdebug << "+          - \"" << itIns->first
           << "\" (model \"" << pModel->NAME << "\").\n";


    // Find the obstacles in the current instance :
    // 1. - TALUx segments.
    // 2. - Power Terminals (vdd & vss), in CALUx layers & not CALU1.
    for (pSeg = pModel->PHSEG; pSeg != NULL; pSeg = pSeg->NEXT) {
      if (   MBK::isobs (pSeg->LAYER)
          || ((   MBK::ISVDD (pSeg->NAME)
               || MBK::ISVSS (pSeg->NAME)) && MBK::isCALU (pSeg->LAYER)
                                           && (pSeg->LAYER != MBK::CALU1))) {
        itIns->second->flatseg (flatSeg, *pSeg);
        rect->setSeg (flatSeg);

        //cerr << "+ Instance obstacle (" << flatSeg.X1 << "," << flatSeg.Y1 << ")"
        //     << MBK::layer2a(flatSeg.LAYER) << endl;

        if ( rect->isInGrid() )
          drgrid->nodes->obstacle (rect->grid, MBK::env.layer2z (pSeg->LAYER));

        if ( !MBK::ISVDD (pSeg->NAME) && !MBK::ISVSS (pSeg->NAME) )
          fig->addphseg ( flatSeg, true, ischip );
      }
    }
  }


  cmess2 << "     o  Loading nets into grid.\n";

  // Process the signals.
  for (pSig = fig->LOSIG (); pSig != NULL; pSig = pSig->NEXT) {
    sig_name = MBK::getsigname (pSig);

    cdebug << "+          - Signal \"" << sig_name << "\".\n";

    // Do not process power nets.
    // Temporary disabled.
    //if (   (MBK::ISVDD ((char*)sig_name.c_str ()) != 0)
    //    || (MBK::ISVSS ((char*)sig_name.c_str ()) != 0)) continue;

    // In the case of external terminals, override the signal name by
    // the terminal name.
    pChain = (MBK::chain_list*)(MBK::getptype (pSig->USER, LOFIGCHAIN)->DATA);
    for (; pChain != NULL; pChain = pChain->NEXT) {
      pLocon = (MBK::locon_list *)(pChain->DATA);

      if (pLocon->TYPE == EXTERNAL) {
        sig_name = pLocon->NAME;
        break;;
      }
    }

    pNet = getnet (sig_name);

    // Process each terminal of the signal.
    pChain = (MBK::chain_list*)(MBK::getptype (pSig->USER, LOFIGCHAIN)->DATA);

    for (; pChain != NULL; pChain = pChain->NEXT) {
      pLocon = (MBK::locon_list *)(pChain->DATA);

      if (pLocon->TYPE == EXTERNAL) {
        pNet->external = true;

        continue;
      }

      ins_name  = ((MBK::loins_list*)(pLocon->ROOT))->INSNAME;
      pIns      = fig->instances[ins_name];

      term_name = ins_name + "." + pLocon->NAME;
      cdebug << "+             I.T : " << term_name << " " << pIns->model->NAME << ".\n";

      // Find physical segments / CA of the terminal.
      for (pSeg = pIns->model->PHSEG; pSeg != NULL; pSeg = pSeg->NEXT) {
        if (!MBK::isCALU (pSeg->LAYER)) continue;
        if (pLocon->NAME != pSeg->NAME) continue;

        pIns->flatseg (flatSeg, *pSeg);
        rect->setSeg  (flatSeg);

        if ( MBK::IsPxLib(pIns->model) &&
             ( (pLocon->NAME == MBK::namealloc("pad" )) ||
               (pLocon->NAME == MBK::namealloc("vddi")) || 
               (pLocon->NAME == MBK::namealloc("vssi")) || 
               (pLocon->NAME == MBK::namealloc("vdde")) || 
               (pLocon->NAME == MBK::namealloc("vsse")) ) ) {
          flatSeg.NAME = (char*)sig_name.c_str();
          fig->addphseg (flatSeg,true,false);
          continue;
        }

        if (   (MBK::ISVDD ((char*)sig_name.c_str ()) != 0)
            || (MBK::ISVSS ((char*)sig_name.c_str ()) != 0)) continue;

        if (rect->isInGrid()) {
          if ( pNet->fixed ) {
            drgrid->nodes->obstacle (rect->grid, MBK::env.layer2z (pSeg->LAYER));
          } else {
            pNet->newaccess ( term_name
                            , rect->grid
                            , MBK::env.layer2z (pSeg->LAYER)
                            );
          }
        } else {
          //if ( MBK::IsPxLib(pModel) ) {
          //  flatSeg.NAME = (char*)sig_name.c_str();
          //  fig->addphseg (flatSeg,true,false);
          //} else {
            cerr << hwarn ("")
                 << "  The connector segment \"" << pSeg->NAME << "\" at ("
                 << MBK::UNSCALE (pSeg->X1) << ","
                 << MBK::UNSCALE (pSeg->Y1) << ") ("
                 << MBK::UNSCALE (pSeg->X2) << ","
                 << MBK::UNSCALE (pSeg->Y2) << ") layer "
                 << MBK::layer2a (pSeg->LAYER) << "\n"
                 << "  is outside of the grid : ignored.";
          }
        //}
      }
    } // End of "pChain" (terminal) loop.

    // Reorder terminals (nearest).
    pNet->order     ();
    pNet->lockalone (rglobal);
    
    cdebug << "+            " << pNet->bb << ".\n";
  } // End of "pSig" (signal) loop.

  // Restrict routed nets to the subNetList.
  if ( subNetList ) {
    for ( MNet::iterator it=nets.begin() ; it != nets.end() ; it++ ) {
      if ( subNetList->find(it->first) != subNetList->end() ) {
        cmess2 << "     o  Restricting nets to route.\n";
        cmess2 << "        - \"" << it->first << "\".\n";
      } else
        it->second->fixed = true;
    }
  }


  // Allocate the net scheduler.
  cmess2 << "     o  Allocating the net scheduler.\n";
  netsched  = new CASimple (&nets, drgrid);


  // Rebuild the power grid from the instances.
  if ( !ischip ) {
    cmess2 << "     o  Reading power grid.\n";
    powers[MBK::CALU1] = new MBK::CPowers ( fig
                                          , xadjust - xoffsettrack
                                          , yoffsetslice
                                          , C_HORIZONTAL
                                          , MBK::ALU1
                                          , D::WIDTH_VDD
                                          );
  }


  // Forbid the use of the edges of the routing box (only allow
  // peripheral terminals).
  coord = drgrid->origin;

  // Left & Right vertical edges.
  if ( xadjust == 0 ) {
    for (x = 0; x < mX; x += mX - 1) {
      for (y = 0; y < mY; y++) {
        for (zz = 1; zz < mZ; zz++) {
          node = &( coord.set(x,y,zz).node() );
          
          if ( !node->terminal() ) node->data.obstacle = true;
        }
      }
    }
  }

  // Bottom & top horizontal edges.
  if ( yadjust == 0 ) {
    for (y = 0; y < mY; y += mY - 1) {
      for (x = 0; x < mX; x++) {
        for (zz = 1; zz < mZ; zz++) {
          node = &( coord.set(x,y,zz).node() );
          
          if ( !node->terminal() ) node->data.obstacle = true;
        }
      }
    }
  }

  // On routing level above zupper (ALU4), use only half of the tracks.
  for (zz = zup; zz < mZ; zz++) {
    switch ((zz+rotate) % 2) {
      case 0:
        // Vertical tracks.
        for (x = 2; x < mX; x += 2) {
          for (y = 1; y < mY - 1; y++) {
            node = &( coord.set(x,y,zz).node() );

            if ( !node->terminal() ) node->data.obstacle = true;
          }
        }
        break;
      case 1:
        // Horizontal tracks.
        for (y = 2; y < mY; y += 2) {
          for (x = 1; x < mX; x++) {
            node = &( coord.set(x,y,zz).node() );
            if ( !node->terminal() ) node->data.obstacle = true;
          }
        }
        break;
    }
  }


  // This flag ensure that a figure has been successfully loaded.
  loaded = true;


  delete rect;
}
Beispiel #5
0
/*
 * Parse a set of parameters for an interface.
 * returns NULL or error message
 */
const char *
parse_parms(char *line,
    boolean_t safe)			/* 1=from secure file */
{
#define	PARS(str) (strcasecmp(tgt, str) == 0)
#define	PARSEQ(str) (strncasecmp(tgt, str"=", sizeof (str)) == 0)
/*
 * This macro checks for conflicting configurations options
 * For eg  one can set either the IS_NO_SOL_OUT flag bit or the IS_SOL_OUT flag
 * bit, but not both.
 */
#define	CKF(g, b) {if (0 != (parm.parm_int_state & ((g) & ~(b)))) break; \
	parm.parm_int_state |= (b); }
	struct parm parm;
	struct intnet *intnetp;
	struct r1net *r1netp;
	struct tgate *tg;
	uint32_t addr, mask;
	char delim, *val0 = 0, *tgt, *val, *p;
	const char *msg;
	char buf[PARMS_MAXLINELEN], buf2[PARMS_MAXLINELEN];
	int i;


	/* "subnet=x.y.z.u/mask[,metric]" must be alone on the line */
	if (strncasecmp(line, "subnet=", sizeof ("subnet=") - 1) == 0 &&
	    *(val = &line[sizeof ("subnet=") -1 ]) != '\0') {
		if (0 > parse_quote(&val, ",", &delim, buf, sizeof (buf)))
			return (bad_str(line));
		intnetp = rtmalloc(sizeof (*intnetp),
		    "parse_parms subnet");
		intnetp->intnet_metric = 1;
		if (delim == ',') {
			intnetp->intnet_metric = (int)strtol(val+1, &p, 0);
			if (*p != '\0' || intnetp->intnet_metric <= 0 ||
			    val+1 == p ||
			    intnetp->intnet_metric >= HOPCNT_INFINITY) {
				free(intnetp);
				return (bad_str(line));
			}
		}
		if (!getnet(buf, &intnetp->intnet_addr,
		    &intnetp->intnet_mask) ||
		    intnetp->intnet_mask == HOST_MASK ||
		    intnetp->intnet_addr == RIP_DEFAULT) {
			free(intnetp);
			return (bad_str(line));
		}
		intnetp->intnet_addr = htonl(intnetp->intnet_addr);
		intnetp->intnet_next = intnets;
		intnets = intnetp;
		return (NULL);
	}

	/*
	 * "ripv1_mask=x.y.z.u/mask1,mask2" must be alone on the line.
	 * This requires that x.y.z.u/mask1 be considered a subnet of
	 * x.y.z.u/mask2, as if x.y.z.u/mask2 were a class-full network.
	 */
	if (!strncasecmp(line, "ripv1_mask=", sizeof ("ripv1_mask=") - 1) &&
	    *(val = &line[sizeof ("ripv1_mask=")-1]) != '\0') {
		if (0 > parse_quote(&val, ",", &delim, buf, sizeof (buf)) ||
		    delim == '\0')
			return (bad_str(line));
		if ((i = (int)strtol(val+1, &p, 0)) <= 0 || i > 32 ||
		    *p != '\0')
			return (bad_str(line));
		r1netp = rtmalloc(sizeof (*r1netp), "parse_parms ripv1_mask");
		r1netp->r1net_mask = HOST_MASK << (32-i);
		if (!getnet(buf, &r1netp->r1net_net, &r1netp->r1net_match) ||
		    r1netp->r1net_net == RIP_DEFAULT ||
		    r1netp->r1net_mask > r1netp->r1net_match) {
			free(r1netp);
			return (bad_str(line));
		}
		r1netp->r1net_next = r1nets;
		r1nets = r1netp;
		return (NULL);
	}

	(void) memset(&parm, 0, sizeof (parm));
	/*
	 * Support of the following for Solaris backward compatibility
	 * norip <ifname>
	 * noripin <ifname>
	 * noripout <ifname>
	 */
	if (strncasecmp("norip", line, 5) == 0) {
		char cmd[64], ifname[64];
		int n;

		n = sscanf(line, "%63s %63s\n", cmd, ifname);
		if (n != 2) {
			/* Not enough parameters */
			return (bad_str(line));
		}

		/*
		 * Get the interface name and turn on the appropriate
		 * interface flags
		 */
		(void) strlcpy(parm.parm_name, ifname, sizeof (parm.parm_name));
		if (strcasecmp("norip", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP;
		} else if (strcasecmp("noripin", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP_IN;
		} else if (strcasecmp("noripout", cmd) == 0) {
			parm.parm_int_state |= IS_NO_RIP_OUT;
		} else {
			/* Bad command */
			return (bad_str(line));
		}
		/*
		 * Look for duplication, and if new,
		 * link to the rest of the parm entries.
		 */
		return (insert_parm(&parm));
	}

	for (;;) {
		tgt = line + strspn(line, " ,\n\r");
		if (*tgt == '\0' || *tgt == '#')
			break;
		line = tgt+strcspn(tgt, "= #,\n\r");
		delim = *line;
		if (delim == '=') {
			val0 = ++line;
			if (0 > parse_quote(&line, " #,", &delim,
			    buf, sizeof (buf)))
				return (bad_str(tgt));
		}
		if (delim != '\0') {
			for (;;) {
				*line = '\0';
				if (delim == '#')
					break;
				++line;
				if (!isspace(delim) ||
				    ((delim = *line), !isspace(delim)))
					break;
			}
		}

		if (PARSEQ("if")) {
			if (parm.parm_name[0] != '\0' ||
			    strlen(buf) > IF_NAME_LEN)
				return (bad_str(tgt));
			(void) strlcpy(parm.parm_name, buf,
			    sizeof (parm.parm_name));

		} else if (PARSEQ("addr")) {
			/*
			 * This is a bad idea, because the address based
			 * sets of parameters cannot be checked for
			 * consistency with the interface name parameters.
			 * The parm_net stuff is needed to allow several
			 * -F settings.
			 */
			if (!getnet(val0, &addr, &mask) ||
			    parm.parm_name[0] != '\0')
				return (bad_str(tgt));
			parm.parm_net = addr;
			parm.parm_mask = mask;
			parm.parm_name[0] = '\n';

		} else if (PARSEQ("passwd")) {
			/*
			 * since cleartext passwords are so weak allow
			 * them anywhere
			 */
			msg = get_passwd(tgt, val0, &parm, RIP_AUTH_PW, 1);
			if (msg) {
				*val0 = '\0';
				return (bad_str(msg));
			}

		} else if (PARSEQ("md5_passwd")) {
			msg = get_passwd(tgt, val0, &parm, RIP_AUTH_MD5, safe);
			if (msg) {
				*val0 = '\0';
				return (bad_str(msg));
			}

		} else if (PARS("no_ag")) {
			parm.parm_int_state |= (IS_NO_AG | IS_NO_SUPER_AG);

		} else if (PARS("no_host")) {
			parm.parm_int_state |= IS_NO_HOST;

		} else if (PARS("no_super_ag")) {
			parm.parm_int_state |= IS_NO_SUPER_AG;

		} else if (PARS("no_ripv1_in")) {
			parm.parm_int_state |= IS_NO_RIPV1_IN;

		} else if (PARS("no_ripv2_in")) {
			parm.parm_int_state |= IS_NO_RIPV2_IN;

		} else if (PARS("ripv2_out")) {
			if (parm.parm_int_state & IS_NO_RIPV2_OUT)
				return (bad_str(tgt));
			parm.parm_int_state |= IS_NO_RIPV1_OUT;

		} else if (PARS("ripv2")) {
			if ((parm.parm_int_state & IS_NO_RIPV2_OUT) ||
			    (parm.parm_int_state & IS_NO_RIPV2_IN))
				return (bad_str(tgt));
			parm.parm_int_state |= (IS_NO_RIPV1_IN
			    | IS_NO_RIPV1_OUT);

		} else if (PARS("no_rip")) {
			CKF(IS_PM_RDISC, IS_NO_RIP);

		} else if (PARS("no_rip_mcast")) {
			parm.parm_int_state |= IS_NO_RIP_MCAST;

		} else if (PARS("no_rdisc")) {
			CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC);

		} else if (PARS("no_solicit")) {
			CKF(GROUP_IS_SOL_OUT, IS_NO_SOL_OUT);

		} else if (PARS("send_solicit")) {
			CKF(GROUP_IS_SOL_OUT, IS_SOL_OUT);

		} else if (PARS("no_rdisc_adv")) {
			CKF(GROUP_IS_ADV_OUT, IS_NO_ADV_OUT);

		} else if (PARS("rdisc_adv")) {
			CKF(GROUP_IS_ADV_OUT, IS_ADV_OUT);

		} else if (PARS("bcast_rdisc")) {
			parm.parm_int_state |= IS_BCAST_RDISC;

		} else if (PARS("passive")) {
			CKF((GROUP_IS_SOL_OUT|GROUP_IS_ADV_OUT), IS_NO_RDISC);
			parm.parm_int_state |= IS_NO_RIP | IS_PASSIVE;

		} else if (PARSEQ("rdisc_pref")) {
			if (parm.parm_rdisc_pref != 0 ||
			    (parm.parm_rdisc_pref = (int)strtol(buf, &p, 0),
			    *p != '\0') || (buf == p))
				return (bad_str(tgt));

		} else if (PARS("pm_rdisc")) {
			if (IS_RIP_OUT_OFF(parm.parm_int_state))
				return (bad_str(tgt));
			parm.parm_int_state |= IS_PM_RDISC;

		} else if (PARSEQ("rdisc_interval")) {
			if (parm.parm_rdisc_int != 0 ||
			    (parm.parm_rdisc_int = (int)strtoul(buf, &p, 0),
				*p != '\0') || (buf == p) ||
			    parm.parm_rdisc_int < MIN_MAXADVERTISEINTERVAL ||
			    parm.parm_rdisc_int > MAX_MAXADVERTISEINTERVAL)
				return (bad_str(tgt));

		} else if (PARSEQ("fake_default")) {
			if (parm.parm_d_metric != 0 ||
			    IS_RIP_OUT_OFF(parm.parm_int_state) ||
			    (parm.parm_d_metric = (int)strtoul(buf, &p, 0),
				*p != '\0') || (buf == p) ||
			    parm.parm_d_metric > HOPCNT_INFINITY-1)
				return (bad_str(tgt));

		} else if (PARSEQ("trust_gateway")) {
			/* look for trust_gateway=x.y.z|net/mask|...) */
			p = buf;
			if (0 > parse_quote(&p, "|", &delim, buf2,
			    sizeof (buf2)) || !gethost(buf2, &addr))
				return (bad_str(tgt));
			tg = rtmalloc(sizeof (*tg),
			    "parse_parms trust_gateway");
			(void) memset(tg, 0, sizeof (*tg));
			tg->tgate_addr = addr;
			i = 0;
			/* The default is to trust all routes. */
			while (delim == '|') {
				p++;
				if (i >= MAX_TGATE_NETS ||
				    0 > parse_quote(&p, "|", &delim, buf2,
					sizeof (buf2)) ||
				    !getnet(buf2, &tg->tgate_nets[i].net,
					&tg->tgate_nets[i].mask) ||
				    tg->tgate_nets[i].net == RIP_DEFAULT ||
				    tg->tgate_nets[i].mask == 0) {
					free(tg);
					return (bad_str(tgt));
				}
				i++;
			}
			tg->tgate_next = tgates;
			tgates = tg;
			parm.parm_int_state |= IS_DISTRUST;

		} else if (PARS("redirect_ok")) {
			parm.parm_int_state |= IS_REDIRECT_OK;

		} else if (PARSEQ("rip_neighbor")) {
			if (parm.parm_name[0] == '\0' ||
			    gethost(buf, &parm.parm_ripout_addr) != 1)
				return (bad_str(tgt));

		} else {
			return (bad_str(tgt));	/* error */
		}
	}

	return (insert_parm(&parm));
#undef PARS
#undef PARSEQ
#undef CKF
}
Beispiel #6
0
/*
 * Read a list of gateways from /etc/gateways and add them to our tables.
 *
 * This file contains a list of "remote" gateways.  That is usually
 * a gateway which we cannot immediately determine if it is present or
 * not as we can do for those provided by directly connected hardware.
 *
 * If a gateway is marked "passive" in the file, then we assume it
 * does not understand RIP and assume it is always present.  Those
 * not marked passive are treated as if they were directly connected
 * and assumed to be broken if they do not send us advertisements.
 * All remote interfaces are added to our list, and those not marked
 * passive are sent routing updates.
 *
 * A passive interface can also be local, hardware interface exempt
 * from RIP.
 */
void
gwkludge(void)
{
#define	STR2(x)	#x
#define	STR(x)	STR2(x)

#define	NETHOST_LEN	4
#define	DNAME_LEN	MAXHOSTNAMELEN
#define	GNAME_LEN	MAXHOSTNAMELEN
#define	QUAL_LEN	8

	FILE *fp;
	char *p, *lptr;
	const char *cp;
	char lbuf[PARMS_MAXLINELEN], net_host[NETHOST_LEN + 1];
	char dname[MAXHOSTNAMELEN + 1];
	char gname[MAXHOSTNAMELEN + 1], qual[QUAL_LEN +1];
	struct interface *ifp;
	uint32_t dst, netmask, gate;
	int n;
	uint32_t lnum;
	struct stat sb;
	uint32_t state, metric;
	boolean_t default_dst;


	fp = fopen(PATH_GATEWAYS, "r");
	if (fp == NULL)
		return;

	if (0 > fstat(fileno(fp), &sb)) {
		msglog("fstat() failed: %s for  "PATH_GATEWAYS,
		    rip_strerror(errno));
		(void) fclose(fp);
		return;
	}

	for (lnum = 1; ; lnum++) {
		if (NULL == fgets(lbuf, sizeof (lbuf), fp))
			break;

		/* Eliminate the /n character at the end of the lbuf */
		if (strlen(lbuf) > 0)
			lbuf[strlen(lbuf) - 1] = '\0';

		/* Move lptr to the first non-space character */
		for (lptr = lbuf; isspace(*lptr); lptr++)
			;

		if (*lptr == '#' || *lptr == '\0')
			continue;

		/* Move p to the end of the line */
		p = lptr + strlen(lptr) - 1;

		/* Skip all trailing spaces except escaped space */
		while (p > lptr && (isspace(*p) && *(p-1) != '\\'))
			p--;

		/* truncate the line to remove trailing spaces */
		*++p = '\0';

		/* notice newfangled parameter lines */
		if (strncasecmp("net", lptr, 3) != 0 &&
		    strncasecmp("host", lptr, 4) != 0) {
			cp = parse_parms(lptr, (sb.st_uid == 0 &&
			    !(sb.st_mode&(S_IRWXG|S_IRWXO))));
			if (cp != 0)
				msglog("%s in line %u of "PATH_GATEWAYS,
				    cp, lnum);
			continue;
		}

		/*
		 * Processes lines of the follwoing format:
		 * net|host <name>[/mask] gateway <Gname> metric <value>
		 * passive|active|extern
		 */
		qual[0] = '\0';
		n = sscanf(lptr, "%"STR(NETHOST_LEN)"s %"STR(DNAME_LEN)
		    "[^ \t] gateway %"STR(GNAME_LEN)"[^ / \t] metric %u %"
		    STR(QUAL_LEN)"s\n", net_host, dname, gname, &metric, qual);
		if (n != 4 && n != 5) {
			msglog("bad "PATH_GATEWAYS" entry \"%s\"; %d values",
			    lptr, n);
			continue;
		}
		if (metric >= HOPCNT_INFINITY) {
			msglog("bad metric in "PATH_GATEWAYS" entry \"%s\"",
			    lptr);
			continue;
		}
		default_dst = _B_FALSE;
		if (strcasecmp(net_host, "host") == 0) {
			if (!gethost(dname, &dst)) {
				msglog("bad host \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"", dname, lptr);
				continue;
			}
			netmask = HOST_MASK;
		} else if (strcasecmp(net_host, "net") == 0) {
			if (!getnet(dname, &dst, &netmask)) {
				msglog("bad net \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"", dname, lptr);
				continue;
			}
			default_dst = (dst == RIP_DEFAULT);
			dst = htonl(dst); /* make network # into IP address */
		} else {
			msglog("bad \"%s\" in "PATH_GATEWAYS
			    " entry \"%s\"", net_host, lptr);
			continue;
		}

		if (!gethost(gname, &gate)) {
			msglog("bad gateway \"%s\" in "PATH_GATEWAYS
			    " entry \"%s\"", gname, lptr);
			continue;
		}

		if (strcasecmp(qual, "passive") == 0) {
			/*
			 * Passive entries are not placed in our tables,
			 * only the kernel's, so we don't copy all of the
			 * external routing information within a net.
			 * Internal machines should use the default
			 * route to a suitable gateway (like us).
			 */
			state = IS_REMOTE | IS_PASSIVE;
			if (metric == 0)
				metric = 1;

		} else if (strcasecmp(qual, "external") == 0) {
			/*
			 * External entries are handled by other means
			 * such as EGP, and are placed only in the daemon
			 * tables to prevent overriding them with something
			 * else.
			 */
			(void) strlcpy(qual, "external", sizeof (qual));
			state = IS_REMOTE | IS_PASSIVE | IS_EXTERNAL;
			if (metric == 0)
				metric = 1;

		} else if (strcasecmp(qual, "active") == 0 ||
		    qual[0] == '\0') {

			if (default_dst) {
				msglog("bad net \"%s\" in "PATH_GATEWAYS
				    " entry \"%s\"-- cannot be default",
				    dname, lptr);
				continue;
			}

			if (metric != 0) {
				/*
				 * Entries that are neither "passive" nor
				 * "external" are "remote" and must behave
				 * like physical interfaces.  If they are not
				 * heard from regularly, they are deleted.
				 */
				state = IS_REMOTE;
			} else {
				/*
				 * "remote" entries with a metric of 0
				 * are aliases for our own interfaces
				 */
				state = IS_REMOTE | IS_PASSIVE | IS_ALIAS;
			}

		} else {
			msglog("bad "PATH_GATEWAYS" entry \"%s\";"
			    " unknown type %s", lptr, qual);
			continue;
		}

		if (0 != (state & (IS_PASSIVE | IS_REMOTE)))
			state |= IS_NO_RDISC;
		if (state & IS_PASSIVE)
			state |= IS_NO_RIP;


		if (default_dst) {
			addroutefordefault(dst, gate, netmask, metric,
			    ((state & IS_EXTERNAL)? RTS_EXTERNAL : 0));
			continue;
		}

		ifp = check_dup(NULL, gate, dst, netmask, 0, _B_FALSE);
		if (ifp != NULL) {
			msglog("duplicate "PATH_GATEWAYS" entry \"%s\"", lptr);
			continue;
		}

		ifp = rtmalloc(sizeof (*ifp), "gwkludge()");
		(void) memset(ifp, 0, sizeof (*ifp));

		ifp->int_state = state;
		if (netmask == HOST_MASK)
			ifp->int_if_flags = IFF_POINTOPOINT | IFF_UP;
		else
			ifp->int_if_flags = IFF_UP;
		ifp->int_act_time = NEVER;
		ifp->int_addr = gate;
		ifp->int_dstaddr = dst;
		ifp->int_mask = netmask;
		ifp->int_ripv1_mask = netmask;
		ifp->int_std_mask = std_mask(gate);
		ifp->int_net = ntohl(dst);
		ifp->int_std_net = ifp->int_net & ifp->int_std_mask;
		ifp->int_std_addr = htonl(ifp->int_std_net);
		ifp->int_metric = metric;
		if (!(state & IS_EXTERNAL) &&
		    ifp->int_mask != ifp->int_std_mask)
			ifp->int_state |= IS_SUBNET;
		(void) snprintf(ifp->int_name, sizeof (ifp->int_name),
		    "remote(%s)", gname);

		if_link(ifp, 0);
	}

	(void) fclose(fp);

	/*
	 * After all of the parameter lines have been read,
	 * apply them to any remote interfaces.
	 */
	for (ifp = ifnet; NULL != ifp; ifp = ifp->int_next) {
		get_parms(ifp);

		tot_interfaces++;
		if (!IS_RIP_OFF(ifp->int_state))
			rip_interfaces++;
		if (!IS_RIP_OUT_OFF(ifp->int_state))
			ripout_interfaces++;

		trace_if("Add", ifp);
	}

}
Beispiel #7
0
void imcsplay(int argc, char **argv) {
    setlinebuf(stdout);
    if (argc < 5 || argc > 7)
	usage();
    char mecolor = '?';
    int megame = 0;
    switch(argv[2][0]) {
    case 'O':
	switch(argv[2][1]) {
	case 'W':
	case 'B':
	case '?':
	    mecolor = argv[2][1];
	    break;
	default:
	    usage();
	}
	break;
    case 'A': {
	char ch = argv[2][1];
	if (isdigit(ch)) {
	    megame = atoi(&argv[2][1]);
	} else if (ch == 'W' || ch == 'B') {
	    mecolor = ch;
	    megame = atoi(&argv[2][2]);
	} else {
	    usage();
	}
	if (megame <= 0)
	    usage();
	break;
    }
    default:
	usage();
    }
    char *meuser = argv[3];
    char *mepassword = argv[4];
    char *host = "imcs.svcs.cs.pdx.edu";
    if (argc > 5)
	host = argv[5];
    int port = 3589;
    if (argc > 6) {
	port = atoi(argv[6]);
	if (port <= 0)
	    usage();
    }
    FILE *nf = netopen(host, port);
    setlinebuf(nf);
    startlog();
    char *greeting = expectcmd(nf, 1, 100, 0);
    (void) strtok(greeting, " ");
    char *pgm = strtok(0, " ");
    assert(!strcmp(pgm, "imcs"));
    char *version = strtok(0, " \r\n");
    if(strcmp(version, "2.5")) {
	fprintf(stderr, "got unexpected imcs version %s\n", version);
	exit(1);
    }
    sendcmd(nf, "me %s %s", meuser, mepassword);
    (void) expectcmd(nf, 1, 201, 0);
    if (megame != 0) {
	if (mecolor == '?')
	    sendcmd(nf, "accept %d", megame);
	else
	    sendcmd(nf, "accept %d %c", megame, mecolor);
	(void) expectcmd(nf, 1, 105, 106, 0);
    } else {
	if (mecolor == '?')
	    sendcmd(nf, "offer");
	else
	    sendcmd(nf, "offer %c", mecolor);
	(void) expectcmd(nf, 1, 103, 0);
	logmsg("waiting for opponent");
	(void) expectcmd(nf, 1, 105, 106, 0);
	logmsg("opponent found");
    }
    struct state s = s0;
    s.cureval = eval(&s);
    if (nttable > 0)
	s.curzhash = zhash(&s);
    while (1) {
	int ch = fgetc(nf);
	int r = ungetc(ch, nf);
	assert(r != EOF);
	if (isdigit(ch)) {
	    s = readstate(nf, 1);
	    s.cureval = eval(&s);
	    if (nttable > 0)
		s.curzhash = zhash(&s);
	    continue;
	}
	switch (ch) {
	case '?': {
	    char *r = getnet(nf, "?");
	    char *q = strtok(r, " ");
	    assert(!strcmp(q, "?"));
	    char *tl = strtok(0, " ");
	    char *tr = strtok(0, " ");
	    assert(tl && tr);
	    int t = readtimems(tl);
	    t = 95 * t / (100 * ((81 - s.ply) / 2));
	    struct move m = idnegamax(&s, t, 0);
	    logmsg("value %d at time %d depth %d for %s\n\n",
		   v0, t, d0, movestr(&m));
	    move(&s, &m, 0);
	    sendcmd(nf, "%s", movestr(&m));
	    printstate(&s, 1);
	    if (ponder)
		(void) idnegamax(&s, 0, nf);
	    continue;
	}
	case '!':
	    assert(fgetc(nf) == '!');
	    int ch;
	    do
		ch = fgetc(nf);
	    while (isspace(ch));
	    ungetc(ch, nf);
	    struct move m = getmove(nf, &s);
	    move(&s, &m, 0);
	    continue;
	case '=':
	    (void) getnet(nf, "=");
	    break;
	case 'X':
	    (void) getnet(nf, "X");
	    break;
	default:
	    (void) getnet(nf, "...");
	    continue;
	}
	break;
    }
    fclose(nf);
}
Beispiel #8
0
static struct filter *
parse_filter(gnc_t gnc, void *closure)
{
    int c;
    char *token;
    struct filter *filter;

    filter = calloc(1, sizeof(struct filter));
    if(filter == NULL)
        goto error;
    filter->plen_le = 128;

    c = gnc(closure);
    if(c < -1)
        goto error;

    while(c >= 0 && c != '\n') {
        c = skip_whitespace(c, gnc, closure);
        if(c == '\n' || c == '#') {
            c = skip_to_eol(c, gnc, closure);
            break;
        }
        c = getword(c, &token, gnc, closure);
        if(c < -1)
            goto error;

        if(strcmp(token, "ip") == 0) {
            c = getnet(c, &filter->prefix, &filter->plen, &filter->af,
                       gnc, closure);
            if(c < -1)
                goto error;
        } else if(strcmp(token, "eq") == 0) {
            int p;
            c = getint(c, &p, gnc, closure);
            if(c < -1)
                goto error;
            filter->plen_ge = MAX(filter->plen_ge, p);
            filter->plen_le = MIN(filter->plen_le, p);
        } else if(strcmp(token, "le") == 0) {
            int p;
            c = getint(c, &p, gnc, closure);
            if(c < -1)
                goto error;
            filter->plen_le = MIN(filter->plen_le, p);
        } else if(strcmp(token, "ge") == 0) {
            int p;
            c = getint(c, &p, gnc, closure);
            if(c < -1)
                goto error;
            filter->plen_ge = MAX(filter->plen_ge, p);
        } else if(strcmp(token, "neigh") == 0) {
            unsigned char *neigh;
            c = getip(c, &neigh, NULL, gnc, closure);
            if(c < -1)
                goto error;
            filter->neigh = neigh;
        } else if(strcmp(token, "id") == 0) {
            unsigned char *id;
            c = getid(c, &id, gnc, closure);
            if(c < -1)
                goto error;
            filter->id = id;
        } else if(strcmp(token, "proto") == 0) {
            int proto;
            c = getint(c, &proto, gnc, closure);
            if(c < -1)
                goto error;
            filter->proto = proto;
        } else if(strcmp(token, "local") == 0) {
            filter->proto = RTPROT_BABEL_LOCAL;
        } else if(strcmp(token, "if") == 0) {
            char *interface;
            c = getstring(c, &interface, gnc, closure);
            if(c < -1)
                goto error;
            filter->ifname = interface;
            filter->ifindex = if_nametoindex(interface);
        } else if(strcmp(token, "allow") == 0) {
            filter->result = 0;
        } else if(strcmp(token, "deny") == 0) {
            filter->result = INFINITY;
        } else if(strcmp(token, "metric") == 0) {
            int metric;
            c = getint(c, &metric, gnc, closure);
            if(c < -1) goto error;
            if(metric <= 0 || metric > INFINITY)
                goto error;
            filter->result = metric;
        } else {
            goto error;
        }
        free(token);
    }
    if(filter->af == 0) {
        if(filter->plen_le < 128 || filter->plen_ge > 0)
            filter->af = AF_INET6;
    } else if(filter->af == AF_INET) {
        filter->plen_le += 96;
        filter->plen_ge += 96;
    }
    return filter;

 error:
    free(filter);
    return NULL;
}
Beispiel #9
0
//------------------------------------------------------------------------
// rwhod - Periodically clean cache and (optionally) send rwho packets
//------------------------------------------------------------------------
PROCESS
rwhod(void)
{
	int i, j;
	struct rwent *rwptr;
	struct rwent *myptr;
	struct rwhopac *rpacptr;
	struct rw_who *rwwptr;
	struct epacket *packet;
	IPaddr mynet;
	long now;
	int len;
	int ps;

	// Initialize rwho information

	Rwho.rwnent = 1;
	Rwho.rwsend = TRUE;
	getutime(&Rwho.rwbtime);
	myptr = &Rwho.rwcache[0];
	getname(myptr->rwmach, RMACLEN);
	myptr->rwboot = myptr->rwlast = myptr->rwslast = Rwho.rwbtime;
	for (i = 0; i < 3; i++)
		myptr->rwload[i] = 0L;
	myptr->rwusers = 1;

	getnet(mynet);
	for (; TRUE; sleep(RWDELAY)) {
		getutime(&now);
		myptr->rwlast = myptr->rwslast = now;
		ps = disable();
		for (i = 0; i < Rwho.rwnent; i++) {
			rwptr = &Rwho.rwcache[i];
			if (now - rwptr->rwlast > RWMAXDT) {
				Rwho.rwnent--;
				for (j = i--; j < Rwho.rwnent; j++)
					Rwho.rwcache[j] =
					    Rwho.rwcache[j + 1];
			}
		}
		restore(ps);
		if (!Rwho.rwsend)
			continue;
		packet = (struct epacket *)getbuf(Net.netpool);
		rpacptr = (struct rwhopac *)
		    ((struct udp *)
		     (((struct ip *)packet->ep_data)->i_data))->u_data;
		rpacptr->rw_vers = RWVERSION;
		rpacptr->rw_type = RWSTATUS;
		rpacptr->rw_sndtim = hl2net(now);
		rpacptr->rw_rtim = 0L;
		getname(rpacptr->rw_host, sizeof(rpacptr->rw_host));
		for (j = 0; j < RWNLOAD; j++)
			rpacptr->rw_load[j] = 0L;
		rpacptr->rw_btim = hl2net(Rwho.rwbtime);
		len = RWMINP;
		if (marked(Shl.shmark) && Shl.shused) {
			rwwptr = &rpacptr->rw_rww[0];
			strlcpy(rwwptr->rw_tty, "Console", RWNLEN);
			strncpy(rwwptr->rw_nam, Shl.shuser, RWNLEN);
			rwwptr->rw_ton = hl2net(Shl.shlogon);
			rwwptr->rw_idle = hl2net(now - Shl.shlast);
			len += sizeof(struct rw_who);
		}
		udpsend(mynet, URWHO, URWHO, packet, len);
	}
}
Beispiel #10
0
int
main(int argc, char *argv[])
{
#define	MAX_RCVBUF 127*1024
#define	MIN_RCVBUF  4*1024

	int ch, bsize, soc;
	char *p, *tmp_ptr, *options, *value, delim;
	const char *result;
	in_addr_t netaddr, netmask;
	int on;

	(void) setlocale(LC_ALL, "");
#if	!defined(TEXT_DOMAIN)   /* Should be defined by cc -D */
#define	TEXT_DOMAIN	"SYS_TEXT"
#endif	/* ! TEXT_DOMAIN */

	(void) textdomain(TEXT_DOMAIN);

	OMSG.rip_nets[0].n_dst = RIP_DEFAULT;
	OMSG.rip_nets[0].n_family = RIP_AF_UNSPEC;
	OMSG.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY);

	if ((pgmname = argv[0]) == NULL)
		pgmname = "rtquery";
	while ((ch = getopt(argc, argv, "np1w:r:t:a:")) != -1)
		switch (ch) {
		case 'n':
			not_trace = _B_TRUE;
			nflag = _B_TRUE;
			break;

		case 'p':
			not_trace = _B_TRUE;
			pflag = _B_TRUE;
			break;

		case '1':
			ripv2 = _B_FALSE;
			break;

		case 'w':
			not_trace = _B_TRUE;
			wtime = (int)strtoul(optarg, &p, 0);
			if (*p != '\0' || wtime <= 0 || p == optarg)
				usage();
			break;

		case 'r':
			not_trace = _B_TRUE;
			if (rflag)
				usage();
			rflag = getnet(optarg, &netaddr, &netmask);
			if (rflag) {
				OMSG.rip_nets[0].n_dst = htonl(netaddr);
				OMSG.rip_nets[0].n_family = RIP_AF_INET;
				OMSG.rip_nets[0].n_mask = htonl(netmask);
			} else {
				struct hostent *hp = gethostbyname(optarg);
				if (hp == NULL) {
					(void) fprintf(stderr, "%s: %s: %s\n",
					    pgmname, optarg,
					    hstrerror(h_errno));
					exit(EXIT_FAILURE);
				}
				(void) memcpy(&OMSG.rip_nets[0].n_dst,
				    hp->h_addr,
				    sizeof (OMSG.rip_nets[0].n_dst));
				OMSG.rip_nets[0].n_family = RIP_AF_INET;
				OMSG.rip_nets[0].n_mask = INADDR_BROADCAST;
				rflag = _B_TRUE;
			}
			break;

		case 't':
			trace = _B_TRUE;
			options = optarg;
			while (*options != '\0') {
				/* messy complications to make -W -Wall happy */
				static char on_str[] = "on";
				static char more_str[] = "more";
				static char off_str[] = "off";
				static char dump_str[] = "dump";
				static char *traceopts[] = {
#define	TRACE_ON	0
					on_str,
#define	TRACE_MORE	1
					more_str,
#define	TRACE_OFF	2
					off_str,
#define	TRACE_DUMP	3
					dump_str,
					0
				};
				result = "";
				switch (getsubopt(&options, traceopts,
				    &value)) {
				case TRACE_ON:
					OMSG.rip_cmd = RIPCMD_TRACEON;
					if (value == NULL ||
					    strlen(value) > MAXPATHLEN)
					    usage();
					result = value;
					break;
				case TRACE_MORE:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEON;
					break;
				case TRACE_OFF:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEOFF;
					break;
				case TRACE_DUMP:
					if (value != NULL)
					    usage();
					OMSG.rip_cmd = RIPCMD_TRACEON;
					result = "dump/../table";
					break;
				default:
					usage();
				}
				(void) strlcpy((char *)OMSG.rip_tracefile,
				    result, MAXPATHLEN);
				omsg_len += strlen(result) -
				    sizeof (OMSG.ripun);
			}
			break;

		case 'a':
			not_trace = _B_TRUE;
			p = strchr(optarg, '=');
			if (p == NULL)
				usage();
			*p++ = '\0';
			if (0 == strcasecmp("passwd", optarg))
				auth_type = RIP_AUTH_PW;
			else if (0 == strcasecmp("md5_passwd", optarg))
				auth_type = RIP_AUTH_MD5;
			else
				usage();
			if (0 > parse_quote(&p, "|", &delim,
			    passwd, sizeof (passwd)))
				usage();
			if (auth_type == RIP_AUTH_MD5 &&
			    delim == '|') {
				tmp_ptr = p+1;
				keyid = strtoul(p+1, &p, 0);
				if (keyid > 255 || *p != '\0' ||
				    p == tmp_ptr)
					usage();
			} else if (delim != '\0') {
				usage();
			}
			break;

		default:
			usage();
	}
	argv += optind;
	argc -= optind;
	if (not_trace && trace)
		usage();
	if (argc == 0) {
		argc = 1;
		argv = default_argv;
	}

	soc = socket(PF_INET, SOCK_DGRAM, 0);
	if (soc < 0) {
		perror("rtquery: socket");
		exit(EXIT_FAILURE);
	}

	on = 1;
	if (setsockopt(soc, IPPROTO_IP, IP_RECVIF, &on, sizeof (on)))
		perror("rtquery: setsockopt IP_RECVIF");

	/* be prepared to receive a lot of routes */
	for (bsize = MAX_RCVBUF; ; bsize -= 1024) {
		if (setsockopt(soc, SOL_SOCKET, SO_RCVBUF,
		    &bsize, sizeof (bsize)) == 0)
			break;
		if (bsize <= MIN_RCVBUF) {
			perror("rtquery: setsockopt SO_RCVBUF");
			break;
		}
	}

	if (trace)
		trace_loop(argv, soc);
	else
		query_loop(argv, argc, soc);
	/* NOTREACHED */
	return (0);
}
CRBox::CRBox (int rtype, bool debug)
{
  int     X, Y, Z;
  CNet   *pNet;
  CTerm  *pTerm;
  //CCoord  coord;


  cdebug << "ENTERING: CRBox::CRBox ()\n";
  X = 10 ; //10;
  Y = 15 ; //15;
  Z = 3;


  // Creating routing matrix.
  cdebug << "  Routing matrix size := (10, 15, 5)\n";

  drgrid = new CDRGrid (0, 0, X, Y, Z, 4);


  // Adding signal "sig_one".
  cdebug << "  Creating net \"sig_one\".\n";
  pNet = getnet ("sig_one");


  // Adding terminal "i0" of "sig_one".
  cdebug << "    Adding terminal \"i0\".\n";
  cdebug << "      Adding CA \"(0,0,0)\".\n";
  pNet->newaccess ("i0", 0, 0, 0);
  //cdebug << "      Adding CA \"(0,0,1)\".\n";
  //nets["sig_one"]->newaccess ("i0", 0, 0, 1);
  //cdebug << "      Adding CA \"(0,1,1)\".\n";
  //nets["sig_one"]->newaccess ("i0", 0, 1, 1);


  // Adding terminal "i1" of "sig_one".
  cdebug << "    Adding terminal \"i1\".\n";
  cdebug << "      Adding CA \"(9,0,0)\".\n";
  pNet->newaccess ("i1", 9, 0, 0);


  // Adding terminal "o" of "sig_one".
  cdebug << "    Adding terminal \"o\".\n";
  //cdebug << "      Adding CA \"(5,10,0)\".\n";
  //nets["sig_one"]->newaccess ("o", 5, 10, 0);

  //cdebug << "      Adding CA \"(7,12,0)\".\n";
  //nets["sig_one"]->newaccess ("o", 7, 12, 0);


  // Adding signal "sig_two".
  //cdebug << "  Creating net \"sig_two\".\n";
  //nets["sig_two"] = new CNet ("sig_two");


  // Adding terminal "i0" of "sig_two".
  //cdebug << "    Adding terminal \"i0\".\n";
  //cdebug << "      Adding CA \"(4,1,0)\".\n";
  //nets["sig_two"]->newaccess ("i0", 4, 1, 0);


  // Adding terminal "o" of "sig_two".
  //cdebug << "    Adding terminal \"o\".\n";
  //cdebug << "      Adding CA \"(4,11,0)\".\n";
  //nets["sig_two"]->newaccess ("o", 4, 11, 0);


  //{
  //  int j;

  //  for (j = 0; j < Y; j++) {
  //    (*::grid)[coord.set (160, j, 1)]->data.pri = 128;
  //    (*::grid)[coord.set (160, j, 2)]->data.pri = 128;
  //  } 
  //}
  // Putting obstacles.
  //(*::grid)[coord.set (5, 5, 2)]->data.pri = 128;
  //(*::grid)[coord.set (6, 5, 2)]->data.pri = 128;
  //(*::grid)[coord.set (7, 5, 2)]->data.pri = 128;
  //(*::grid)[coord.set (8, 5, 2)]->data.pri = 128;
  //(*::grid)[coord.set (9, 5, 2)]->data.pri = 128;


  netsched  = new CASimple (&nets, drgrid);

  cdebug << "EXITING: CRBox::CRBox ()\n";
}