Changeset 902 in MondoRescue for branches/stable/mindi-busybox/networking


Ignore:
Timestamp:
Oct 25, 2006, 12:41:23 AM (17 years ago)
Author:
Bruno Cornec
Message:

mindi-busybox now uses busybox 1.2.2 (Thanks Rob for that last update and good lucck for your future projects).

Location:
branches/stable/mindi-busybox/networking
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mindi-busybox/networking/dnsd.c

    r821 r902  
    2929#define LOCK_FILE       "/var/run/dnsd.lock"
    3030#define LOG_FILE        "/var/log/dnsd.log"
     31
     32#define is_daemon()  (flags&16)
     33#define is_verbose() (flags&32)
     34//#define DEBUG
     35
    3136
    3237enum {
     
    224229{
    225230    int i;
    226     struct dns_entry *d=dnsentry;
    227 
    228     do {
     231    struct dns_entry *d = dnsentry;
     232
     233    if(d) do {
    229234#ifdef DEBUG
    230         char *p,*q;
    231         q = (char *)&(qs[1]);
    232         p = &(d->name[1]);
    233         fprintf(stderr, "\ntest: %d <%s> <%s> %d", strlen(p), p, q, strlen(q));
    234 #endif
    235         if (type == REQ_A) { /* search by host name */
     235        if(qs && d) {
     236            char *p,*q;
     237            q = (char *)&(qs[1]);
     238            p = &(d->name[1]);
     239            fprintf(stderr, "\n%s: %d/%d p:%s q:%s %d",
     240                __FUNCTION__, strlen(p), (int)(d->name[0]),
     241                p, q, strlen(q));
     242        }
     243#endif
     244        if (type == REQ_A) {            /* search by host name */
    236245            for(i = 1; i <= (int)(d->name[0]); i++)
    237246                if(tolower(qs[i]) != d->name[i])
    238                     continue;
     247                    break;
     248            if(i > (int)(d->name[0])) {
    239249#ifdef DEBUG
    240             fprintf(stderr, " OK");
    241 #endif
    242             strcpy((char *)as, d->ip);
     250                fprintf(stderr, " OK");
     251#endif
     252                strcpy((char *)as, d->ip);
    243253#ifdef DEBUG
    244             fprintf(stderr, " %s ", as);
    245 #endif
    246                     return 0;
    247                 }
    248         else if (type == REQ_PTR) { /* search by IP-address */
     254                fprintf(stderr, " as:%s\n", as);
     255#endif
     256                return 0;
     257            }
     258        } else
     259        if (type == REQ_PTR) {          /* search by IP-address */
    249260            if (!strncmp((char*)&d->rip[1], (char*)&qs[1], strlen(d->rip)-1)) {
    250261                strcpy((char *)as, d->name);
     
    282293
    283294    from = (void *)&head[1];    //  start of query string
    284     next = answb = from + strlen((char *)&head[1]) + 1 + sizeof(struct dns_prop);   // where to append answer block
     295    next = answb = from + strlen((char *)from) + 1 + sizeof(struct dns_prop);   // where to append answer block
    285296
    286297    outr.rlen = 0;          // may change later
     
    306317
    307318    // We have a standard query
    308 
    309     log_message(LOG_FILE, (char *)head);
    310     lookup_result = table_lookup(type, answstr, (uint8_t*)(&head[1]));
     319    log_message(LOG_FILE, (char *)from);
     320    lookup_result = table_lookup(type, answstr, (uint8_t*)from);
    311321    if (lookup_result != 0) {
    312322        outr.flags = 3 | 0x0400;    //name do not exist and auth
     
    342352    next += outr.rlen;
    343353
    344       empty_packet:
    345 
     354empty_packet:
    346355    flags = ntohs(head->flags);
    347356    // clear rcode and RA, set responsebit and our new flags
     
    365374}
    366375
    367 #define is_daemon()  (flags&16)
    368 #define is_verbose() (flags&32)
    369 //#define DEBUG 1
    370376
    371377int dnsd_main(int argc, char **argv)
     
    438444                     (void *)&fromlen);
    439445            if(is_verbose())
    440                 fprintf(stderr, "\n--- Got UDP  ");
    441             log_message(LOG_FILE, "\n--- Got UDP  ");
     446                fprintf(stderr, "\n--- Got UDP size=%d ", r);
     447            log_message(LOG_FILE, "\n--- Got UDP ");
    442448
    443449            if (r < 12 || r > 512) {
  • branches/stable/mindi-busybox/networking/httpd.c

    r821 r902  
    864864  struct sockaddr_in lsocket;
    865865  int fd;
     866  int on = 1;
    866867
    867868  /* create the socket right now */
     
    874875  /* tell the OS it's OK to reuse a previous address even though */
    875876  /* it may still be in a close down state.  Allows bind to succeed. */
    876   int on = 1;
    877877#ifdef SO_REUSEPORT
    878878  setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) ;
  • branches/stable/mindi-busybox/networking/ping6.c

    r821 r902  
    211211    pkt->icmp6_code = 0;
    212212    pkt->icmp6_cksum = 0;
    213     pkt->icmp6_seq = ntransmitted++;
     213    pkt->icmp6_seq = SWAP_BE16(ntransmitted++);
    214214    pkt->icmp6_id = myid;
    215215    CLR(pkt->icmp6_seq % MAX_DUP_CHK);
  • branches/stable/mindi-busybox/networking/traceroute.c

    r821 r902  
    10041004        port = (u_short)str2val(port_str, "port", 1, (1 << 16) - 1);
    10051005    if(nprobes_str)
    1006         nprobes = str2val(optarg, "nprobes", 1, -1);
     1006        nprobes = str2val(nprobes_str, "nprobes", 1, -1);
    10071007    if(source) {
    10081008        /*
  • branches/stable/mindi-busybox/networking/zcip.c

    r821 r902  
    1515 */
    1616
    17 // #define      DEBUG
     17//#define DEBUG
    1818
    1919// TODO:
     
    4343struct arp_packet {
    4444    struct ether_header hdr;
    45     // FIXME this part is netinet/if_ether.h "struct ether_arp"
    46     struct arphdr arp;
    47     struct ether_addr source_addr;
    48     struct in_addr source_ip;
    49     struct ether_addr target_addr;
    50     struct in_addr target_ip;
     45    struct ether_arp arp;
    5146} ATTRIBUTE_PACKED;
    5247
     
    6863};
    6964
    70 static const struct in_addr null_ip = { 0 };
    71 static const struct ether_addr null_addr = { {0, 0, 0, 0, 0, 0} };
    72 
    73 static int verbose = 0;
     65/* States during the configuration process. */
     66enum {
     67    PROBE = 0,
     68    RATE_LIMIT_PROBE,
     69    ANNOUNCE,
     70    MONITOR,
     71    DEFEND
     72};
     73
     74/* Implicitly zero-initialized */
     75static const struct in_addr null_ip;
     76static const struct ether_addr null_addr;
     77static int verbose;
    7478
    7579#define DBG(fmt,args...) \
     
    100104{
    101105    struct arp_packet p;
     106    memset(&p, 0, sizeof(p));
    102107
    103108    // ether header
     
    107112
    108113    // arp request
    109     p.arp.ar_hrd = htons(ARPHRD_ETHER);
    110     p.arp.ar_pro = htons(ETHERTYPE_IP);
    111     p.arp.ar_hln = ETH_ALEN;
    112     p.arp.ar_pln = 4;
    113     p.arp.ar_op = htons(op);
    114     memcpy(&p.source_addr, source_addr, ETH_ALEN);
    115     memcpy(&p.source_ip, &source_ip, sizeof (p.source_ip));
    116     memcpy(&p.target_addr, target_addr, ETH_ALEN);
    117     memcpy(&p.target_ip, &target_ip, sizeof (p.target_ip));
     114    p.arp.arp_hrd = htons(ARPHRD_ETHER);
     115    p.arp.arp_pro = htons(ETHERTYPE_IP);
     116    p.arp.arp_hln = ETH_ALEN;
     117    p.arp.arp_pln = 4;
     118    p.arp.arp_op = htons(op);
     119    memcpy(&p.arp.arp_sha, source_addr, ETH_ALEN);
     120    memcpy(&p.arp.arp_spa, &source_ip, sizeof (p.arp.arp_spa));
     121    memcpy(&p.arp.arp_tha, target_addr, ETH_ALEN);
     122    memcpy(&p.arp.arp_tpa, &target_ip, sizeof (p.arp.arp_tpa));
    118123
    119124    // send it
     
    196201    int ready = 0;
    197202    suseconds_t timeout = 0;    // milliseconds
    198     time_t defend = 0;
    199203    unsigned conflicts = 0;
    200204    unsigned nprobes = 0;
    201205    unsigned nclaims = 0;
    202206    int t;
     207    int state = PROBE;
    203208
    204209    // parse commandline: prog [options] ifname script
     
    307312        fds[0].revents = 0;
    308313
     314        int source_ip_conflict = 0;
     315        int target_ip_conflict = 0;
     316
    309317        // poll, being ready to adjust current timeout
    310318        if (!timeout) {
     
    314322            // ones we'd care about.
    315323        }
     324        // set tv1 to the point in time when we timeout
    316325        gettimeofday(&tv1, NULL);
    317326        tv1.tv_usec += (timeout % 1000) * 1000;
     
    326335        switch (poll(fds, 1, timeout)) {
    327336
    328         // timeouts trigger protocol transitions
     337        // timeout
    329338        case 0:
    330             // probes
    331             if (nprobes < PROBE_NUM) {
    332                 nprobes++;
    333                 VDBG("probe/%d %s@%s\n",
    334                         nprobes, intf, inet_ntoa(ip));
    335                 (void)arp(fd, &saddr, ARPOP_REQUEST,
    336                         &addr, null_ip,
    337                         &null_addr, ip);
     339            VDBG("state = %d\n", state);
     340            switch (state) {
     341            case PROBE:
     342                // timeouts in the PROBE state means no conflicting ARP packets
     343                // have been received, so we can progress through the states
    338344                if (nprobes < PROBE_NUM) {
     345                    nprobes++;
     346                    VDBG("probe/%d %s@%s\n",
     347                            nprobes, intf, inet_ntoa(ip));
     348                    (void)arp(fd, &saddr, ARPOP_REQUEST,
     349                            &addr, null_ip,
     350                            &null_addr, ip);
    339351                    timeout = PROBE_MIN * 1000;
    340352                    timeout += ms_rdelay(PROBE_MAX
    341353                            - PROBE_MIN);
    342                 } else
    343                     timeout = ANNOUNCE_WAIT * 1000;
    344             }
    345             // then announcements
    346             else if (nclaims < ANNOUNCE_NUM) {
    347                 nclaims++;
     354                }
     355                else {
     356                    // Switch to announce state.
     357                    state = ANNOUNCE;
     358                    nclaims = 0;
     359                    VDBG("announce/%d %s@%s\n",
     360                            nclaims, intf, inet_ntoa(ip));
     361                    (void)arp(fd, &saddr, ARPOP_REQUEST,
     362                            &addr, ip,
     363                            &addr, ip);
     364                    timeout = ANNOUNCE_INTERVAL * 1000;
     365                }
     366                break;
     367            case RATE_LIMIT_PROBE:
     368                // timeouts in the RATE_LIMIT_PROBE state means no conflicting ARP packets
     369                // have been received, so we can move immediately to the announce state
     370                state = ANNOUNCE;
     371                nclaims = 0;
    348372                VDBG("announce/%d %s@%s\n",
    349373                        nclaims, intf, inet_ntoa(ip));
     
    351375                        &addr, ip,
    352376                        &addr, ip);
     377                timeout = ANNOUNCE_INTERVAL * 1000;
     378                break;
     379            case ANNOUNCE:
     380                // timeouts in the ANNOUNCE state means no conflicting ARP packets
     381                // have been received, so we can progress through the states
    353382                if (nclaims < ANNOUNCE_NUM) {
     383                    nclaims++;
     384                    VDBG("announce/%d %s@%s\n",
     385                            nclaims, intf, inet_ntoa(ip));
     386                    (void)arp(fd, &saddr, ARPOP_REQUEST,
     387                            &addr, ip,
     388                            &addr, ip);
    354389                    timeout = ANNOUNCE_INTERVAL * 1000;
    355                 } else {
     390                }
     391                else {
     392                    // Switch to monitor state.
     393                    state = MONITOR;
    356394                    // link is ok to use earlier
     395                    // FIXME update filters
    357396                    run(script, "config", intf, &ip);
    358397                    ready = 1;
    359398                    conflicts = 0;
    360                     timeout = -1;
     399                    timeout = -1; // Never timeout in the monitor state.
    361400
    362401                    // NOTE:  all other exit paths
     
    364403                    if (quit)
    365404                        return EXIT_SUCCESS;
    366                     // FIXME update filters
    367                 }
    368             }
    369             break;
    370 
     405                }
     406                break;
     407            case DEFEND:
     408                // We won!  No ARP replies, so just go back to monitor.
     409                state = MONITOR;
     410                timeout = -1;
     411                conflicts = 0;
     412                break;
     413            default:
     414                // Invalid, should never happen.  Restart the whole protocol.
     415                state = PROBE;
     416                pick(&ip);
     417                timeout = 0;
     418                nprobes = 0;
     419                nclaims = 0;
     420                break;
     421            } // switch (state)
     422            break; // case 0 (timeout)
    371423        // packets arriving
    372424        case 1:
    373             // maybe adjust timeout
     425            // We need to adjust the timeout in case we didn't receive
     426            // a conflicting packet.
    374427            if (timeout > 0) {
    375428                struct timeval tv2;
     
    377430                gettimeofday(&tv2, NULL);
    378431                if (timercmp(&tv1, &tv2, <)) {
     432                    // Current time is greater than the expected timeout time.
     433                    // Should never happen.
     434                    VDBG("missed an expected timeout\n");
    379435                    timeout = 0;
    380436                } else {
     437                    VDBG("adjusting timeout\n");
    381438                    timersub(&tv1, &tv2, &tv1);
    382439                    timeout = 1000 * tv1.tv_sec
     
    384441                }
    385442            }
     443
    386444            if ((fds[0].revents & POLLIN) == 0) {
    387445                if (fds[0].revents & POLLERR) {
     
    397455                continue;
    398456            }
     457
    399458            // read ARP packet
    400459            if (recv(fd, &p, sizeof (p), 0) < 0) {
     
    405464                continue;
    406465
    407             VDBG("%s recv arp type=%d, op=%d,\n",
     466#ifdef DEBUG
     467            {
     468                struct ether_addr * sha = (struct ether_addr *) p.arp.arp_sha;
     469                struct ether_addr * tha = (struct ether_addr *) p.arp.arp_tha;
     470                struct in_addr * spa = (struct in_addr *) p.arp.arp_spa;
     471                struct in_addr * tpa = (struct in_addr *) p.arp.arp_tpa;
     472                VDBG("%s recv arp type=%d, op=%d,\n",
    408473                    intf, ntohs(p.hdr.ether_type),
    409                     ntohs(p.arp.ar_op));
    410             VDBG("\tsource=%s %s\n",
    411                     ether_ntoa(&p.source_addr),
    412                     inet_ntoa(p.source_ip));
    413             VDBG("\ttarget=%s %s\n",
    414                     ether_ntoa(&p.target_addr),
    415                     inet_ntoa(p.target_ip));
    416             if (p.arp.ar_op != htons(ARPOP_REQUEST)
    417                     && p.arp.ar_op != htons(ARPOP_REPLY))
     474                    ntohs(p.arp.arp_op));
     475                VDBG("\tsource=%s %s\n",
     476                    ether_ntoa(sha),
     477                    inet_ntoa(*spa));
     478                VDBG("\ttarget=%s %s\n",
     479                    ether_ntoa(tha),
     480                    inet_ntoa(*tpa));
     481            }
     482#endif
     483            if (p.arp.arp_op != htons(ARPOP_REQUEST)
     484                    && p.arp.arp_op != htons(ARPOP_REPLY))
    418485                continue;
    419486
    420             // some cases are always conflicts
    421             if ((p.source_ip.s_addr == ip.s_addr)
    422                     && (memcmp(&addr, &p.source_addr,
    423                             ETH_ALEN) != 0)) {
    424 collision:
    425                 VDBG("%s ARP conflict from %s\n", intf,
    426                         ether_ntoa(&p.source_addr));
    427                 if (ready) {
    428                     time_t now = time(0);
    429 
    430                     if ((defend + DEFEND_INTERVAL)
    431                             < now) {
    432                         defend = now;
    433                         (void)arp(fd, &saddr,
    434                                 ARPOP_REQUEST,
    435                                 &addr, ip,
    436                                 &addr, ip);
    437                         VDBG("%s defend\n", intf);
    438                         timeout = -1;
    439                         continue;
     487            if (memcmp(p.arp.arp_spa, &ip.s_addr, sizeof(struct in_addr)) == 0 &&
     488                memcmp(&addr, &p.arp.arp_sha, ETH_ALEN) != 0) {
     489                source_ip_conflict = 1;
     490            }
     491            if (memcmp(p.arp.arp_tpa, &ip.s_addr, sizeof(struct in_addr)) == 0 &&
     492                p.arp.arp_op == htons(ARPOP_REQUEST) &&
     493                memcmp(&addr, &p.arp.arp_tha, ETH_ALEN) != 0) {
     494                target_ip_conflict = 1;
     495            }
     496
     497            VDBG("state = %d, source ip conflict = %d, target ip conflict = %d\n",
     498                state, source_ip_conflict, target_ip_conflict);
     499            switch (state) {
     500            case PROBE:
     501            case ANNOUNCE:
     502                // When probing or announcing, check for source IP conflicts
     503                // and other hosts doing ARP probes (target IP conflicts).
     504                if (source_ip_conflict || target_ip_conflict) {
     505                    conflicts++;
     506                    if (conflicts >= MAX_CONFLICTS) {
     507                        VDBG("%s ratelimit\n", intf);
     508                        timeout = RATE_LIMIT_INTERVAL * 1000;
     509                        state = RATE_LIMIT_PROBE;
    440510                    }
    441                     defend = now;
     511
     512                    // restart the whole protocol
     513                    pick(&ip);
     514                    timeout = 0;
     515                    nprobes = 0;
     516                    nclaims = 0;
     517                }
     518                break;
     519            case MONITOR:
     520                // If a conflict, we try to defend with a single ARP probe.
     521                if (source_ip_conflict) {
     522                    VDBG("monitor conflict -- defending\n");
     523                    state = DEFEND;
     524                    timeout = DEFEND_INTERVAL * 1000;
     525                    (void)arp(fd, &saddr,
     526                            ARPOP_REQUEST,
     527                            &addr, ip,
     528                            &addr, ip);
     529                }
     530                break;
     531            case DEFEND:
     532                // Well, we tried.  Start over (on conflict).
     533                if (source_ip_conflict) {
     534                    state = PROBE;
     535                    VDBG("defend conflict -- starting over\n");
    442536                    ready = 0;
    443537                    run(script, "deconfig", intf, &ip);
    444                     // FIXME rm filters: setsockopt(fd,
    445                     // SO_DETACH_FILTER, ...)
    446                 }
    447                 conflicts++;
    448                 if (conflicts >= MAX_CONFLICTS) {
    449                     VDBG("%s ratelimit\n", intf);
    450                     sleep(RATE_LIMIT_INTERVAL);
    451                 }
    452                 // restart the whole protocol
     538
     539                    // restart the whole protocol
     540                    pick(&ip);
     541                    timeout = 0;
     542                    nprobes = 0;
     543                    nclaims = 0;
     544                }
     545                break;
     546            default:
     547                // Invalid, should never happen.  Restart the whole protocol.
     548                VDBG("invalid state -- starting over\n");
     549                state = PROBE;
    453550                pick(&ip);
    454551                timeout = 0;
    455552                nprobes = 0;
    456553                nclaims = 0;
    457             }
    458             // two hosts probing one address is a collision too
    459             else if (p.target_ip.s_addr == ip.s_addr
    460                     && nclaims == 0
    461                     && p.arp.ar_op == htons(ARPOP_REQUEST)
    462                     && memcmp(&addr, &p.target_addr,
    463                             ETH_ALEN) != 0) {
    464                 goto collision;
    465             }
    466             break;
    467 
     554                break;
     555            } // switch state
     556
     557            break; // case 1 (packets arriving)
    468558        default:
    469559            why = "poll";
    470560            goto bad;
    471         }
     561        } // switch poll
    472562    }
    473563bad:
Note: See TracChangeset for help on using the changeset viewer.