Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/networking/udhcp/static_leases.c

    r1765 r2725  
    11/* vi: set sw=4 ts=4: */
    22/*
    3  * static_leases.c -- Couple of functions to assist with storing and
    4  * retrieving data for static leases
     3 * Storing and retrieving data for static leases
    54 *
    65 * Wade Berrier <wberrier@myrealbox.com> September 2004
    76 *
     7 * Licensed under GPLv2, see file LICENSE in this source tree.
    88 */
    9 
    109#include "common.h"
    1110#include "dhcpd.h"
    1211
     12/* Takes the address of the pointer to the static_leases linked list,
     13 * address to a 6 byte mac address,
     14 * 4 byte IP address */
     15void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp,
     16        uint8_t *mac,
     17        uint32_t nip)
     18{
     19    struct static_lease *st_lease;
    1320
    14 /* Takes the address of the pointer to the static_leases linked list,
    15  *   Address to a 6 byte mac address
    16  *   Address to a 4 byte ip address */
    17 int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
     21    /* Find the tail of the list */
     22    while ((st_lease = *st_lease_pp) != NULL) {
     23        st_lease_pp = &st_lease->next;
     24    }
     25
     26    /* Add new node */
     27    *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease));
     28    memcpy(st_lease->mac, mac, 6);
     29    st_lease->nip = nip;
     30    /*st_lease->next = NULL;*/
     31}
     32
     33/* Find static lease IP by mac */
     34uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac)
     35{
     36    while (st_lease) {
     37        if (memcmp(st_lease->mac, mac, 6) == 0)
     38            return st_lease->nip;
     39        st_lease = st_lease->next;
     40    }
     41
     42    return 0;
     43}
     44
     45/* Check to see if an IP is reserved as a static IP */
     46int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip)
     47{
     48    while (st_lease) {
     49        if (st_lease->nip == nip)
     50            return 1;
     51        st_lease = st_lease->next;
     52    }
     53
     54    return 0;
     55}
     56
     57#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
     58/* Print out static leases just to check what's going on */
     59/* Takes the address of the pointer to the static_leases linked list */
     60void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp)
    1861{
    1962    struct static_lease *cur;
    20     struct static_lease *new_static_lease;
    2163
    22     /* Build new node */
    23     new_static_lease = xmalloc(sizeof(struct static_lease));
    24     new_static_lease->mac = mac;
    25     new_static_lease->ip = ip;
    26     new_static_lease->next = NULL;
     64    if (dhcp_verbose < 2)
     65        return;
    2766
    28     /* If it's the first node to be added... */
    29     if (*lease_struct == NULL) {
    30         *lease_struct = new_static_lease;
    31     } else {
    32         cur = *lease_struct;
    33         while (cur->next) {
    34             cur = cur->next;
    35         }
    36 
    37         cur->next = new_static_lease;
    38     }
    39 
    40     return 1;
    41 }
    42 
    43 /* Check to see if a mac has an associated static lease */
    44 uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
    45 {
    46     uint32_t return_ip;
    47     struct static_lease *cur = lease_struct;
    48     uint8_t *mac = arg;
    49 
    50     return_ip = 0;
    51 
     67    cur = *st_lease_pp;
    5268    while (cur) {
    53         /* If the client has the correct mac  */
    54         if (memcmp(cur->mac, mac, 6) == 0) {
    55             return_ip = *(cur->ip);
    56         }
    57 
    58         cur = cur->next;
    59     }
    60 
    61     return return_ip;
    62 }
    63 
    64 /* Check to see if an ip is reserved as a static ip */
    65 uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
    66 {
    67     struct static_lease *cur = lease_struct;
    68 
    69     uint32_t return_val = 0;
    70 
    71     while (cur) {
    72         /* If the client has the correct ip  */
    73         if (*cur->ip == ip)
    74             return_val = 1;
    75 
    76         cur = cur->next;
    77     }
    78 
    79     return return_val;
    80 }
    81 
    82 #if ENABLE_FEATURE_UDHCP_DEBUG
    83 /* Print out static leases just to check what's going on */
    84 /* Takes the address of the pointer to the static_leases linked list */
    85 void printStaticLeases(struct static_lease **arg)
    86 {
    87     /* Get a pointer to the linked list */
    88     struct static_lease *cur = *arg;
    89 
    90     while (cur) {
    91         /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
    92         printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
    93         /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
    94         printf("PrintStaticLeases: Lease ip Value: %x\n", *(cur->ip));
    95 
     69        bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
     70            cur->mac[0], cur->mac[1], cur->mac[2],
     71            cur->mac[3], cur->mac[4], cur->mac[5],
     72            cur->nip
     73        );
    9674        cur = cur->next;
    9775    }
Note: See TracChangeset for help on using the changeset viewer.