Changeset 43154f8625f76af133f75133b2517fd6565f6b35

Show
Ignore:
Timestamp:
07/29/10 23:34:53 (22 months ago)
Author:
Neutron Soutmun <neo.neutron@…>
Children:
3cbe0c2fb30e0b5337ba35e14fb6cafda374e7b9
Parents:
732bc1be8e814ff17f8d31268e1de28124d93aeb
git-committer:
Neutron Soutmun <neo.neutron@…> (07/29/10 23:34:53)
Message:

Add implementation of class-of-service

  • Add new implementation of class-of-service which respect to the RADIUS Attribute "WISPr-Billing-Class-Of-Service"
  • Remove the concept of vip users and use the class-of-service concept which more flexibility instead.
  • Update the firewall script which "--option ! xxx" is deprecated and should replaced by "! --option xxx".
  • Update the firewall script to support the serviceclass concept.
  • Update weblogin which should send the class-of-service name when RADIUS return this attribute back.
  • src/include has been removed (no needs).
Files:
6 added
3 removed
18 modified

Legend:

Unmodified
Added
Removed
  • configure.ac

    r91cc1f0 r43154f8  
    6262  tools/rahunas-firewall 
    6363  tools/rahunas-bandwidth 
    64   tools/rahunas-vipmap 
    6564  tools/rahunas-weblogin-config-update 
    6665  example/Makefile 
  • src/Makefile.am

    r91cc1f0 r43154f8  
    99  $(LIBGDA_CFLAGS) \ 
    1010  -I$(top_srcdir)/src/ \ 
    11   -I$(top_srcdir)/src/include/ \ 
    1211  -DRAHUNAS_VERSION=\"$(RAHUNAS_VERSION)\" \ 
    1312  -DPROGRAM=\"$(PROGRAM)\" \ 
     
    4544  rh-task-bandwidth.c \ 
    4645  rh-task-bandwidth.h \ 
     46  rh-task-serviceclass.c \ 
     47  rh-task-serviceclass.h \ 
    4748  rh-radius.h \ 
    4849  rh-config.c \ 
    49   rh-config.h 
     50  rh-config.h \ 
     51  rh-serviceclass.h \ 
     52  rh-serviceclass.c 
    5053 
    5154rahunasd_LDADD =  \ 
     
    5457  $(LIBGNET_LIBS) \ 
    5558  $(LIBGDA_LIBS) 
    56  
    57 noinst_HEADERS = \ 
    58   include/linux/netfilter_ipv4/ip_set.h \ 
    59   include/linux/netfilter_ipv4/ip_set_rahunas.h 
    60  
  • src/ipset/ip_set.h

    rb813a36 r43154f8  
    11#ifndef _IP_SET_H 
    22#define _IP_SET_H 
     3 
     4#include <inttypes.h> 
    35 
    46/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu> 
  • src/rahunasd.c

    r220ede9 r43154f8  
    2929struct main_server rh_main_server_instance = { 
    3030  .vserver_list = NULL, 
     31  .serviceclass_list = NULL, 
    3132  .task_list = NULL, 
    3233}; 
     
    177178  } 
    178179 
     180  /* Get serviceclass config, again */ 
     181  if (rh_main_server->main_config->serviceclass_conf_dir != NULL) { 
     182    get_serviceclass_config(rh_main_server->main_config->serviceclass_conf_dir, 
     183                            rh_main_server); 
     184  } else { 
     185    syslog(LOG_ERR, "The main configuration file is incompleted, lack of serviceclass_conf_dir\n"); 
     186    exit(EXIT_FAILURE); 
     187  } 
     188 
     189  walk_through_serviceclass(&serviceclass_reload, rh_main_server); 
     190  serviceclass_unused_cleanup(rh_main_server); 
     191 
    179192  walk_through_vserver(&vserver_reload, rh_main_server); 
    180193  vserver_unused_cleanup(rh_main_server); 
     
    284297  if (member->session_id && member->session_id != termstring) 
    285298    free(member->session_id); 
     299 
     300  if (member->serviceclass_name && member->serviceclass_name != termstring) 
     301    free(member->serviceclass_name); 
     302 
     303  if (member->mapping_ip && member->mapping_ip != termstring) 
     304    free(member->mapping_ip); 
    286305} 
    287306 
     
    299318  union rahunas_config rh_main_config = { 
    300319    .rh_main.conf_dir = NULL, 
     320    .rh_main.serviceclass_conf_dir = NULL, 
    301321    .rh_main.log_file = NULL, 
    302322    .rh_main.dhcp = NULL, 
    303323    .rh_main.polling_interval = POLLING, 
    304324    .rh_main.bandwidth_shape = BANDWIDTH_SHAPE, 
     325    .rh_main.serviceclass = 0, 
    305326  }; 
    306327 
     
    343364  } 
    344365 
     366  if (rh_main_server->main_config->serviceclass) { 
     367    /* Get serviceclass config */ 
     368    if (rh_main_server->main_config->serviceclass_conf_dir != NULL) { 
     369      get_serviceclass_config(rh_main_server->main_config->serviceclass_conf_dir, 
     370                              rh_main_server); 
     371    } else { 
     372      syslog(LOG_ERR, "The main configuration file is incompleted, lack of serviceclass_conf_dir\n"); 
     373      exit(EXIT_FAILURE); 
     374    } 
     375  } 
     376 
     377 
    345378  snprintf(version, sizeof (version), "Starting %s - Version %s", PROGRAM,  
    346379           RAHUNAS_VERSION); 
     
    349382  rh_task_register(rh_main_server); 
    350383  rh_task_startservice(rh_main_server); 
     384 
     385  if (rh_main_server->main_config->serviceclass) 
     386    walk_through_serviceclass(&serviceclass_init, rh_main_server); 
    351387 
    352388  walk_through_vserver(&rh_task_init, rh_main_server); 
  • src/rahunasd.h

    r91cc1f0 r43154f8  
    5959  long bandwidth_max_up; 
    6060  unsigned short bandwidth_slot_id; 
     61  char *serviceclass_name; 
     62  uint32_t serviceclass_slot_id; 
     63  char *mapping_ip; 
    6164  char *username; 
    6265  char *session_id; 
  • src/rh-config.c

    r91cc1f0 r43154f8  
    4545  if (strncmp(main_key, "main", 4) == 0) { 
    4646    cfg_type = MAIN; 
    47  
    48   } if (strncmp(main_key, "service_class", strlen ("service_class")) == 0) { 
     47  } else if (strncmp(main_key, "service_class", strlen ("service_class")) == 0) { 
    4948    cfg_type = SERVICECLASS; 
    5049  } else { 
     
    6059          free(config->rh_main.conf_dir); 
    6160        config->rh_main.conf_dir = strdup(value); 
     61      } else if (strncmp(sub_key, "serviceclass_conf_dir", 21) == 0) { 
     62        if (config->rh_main.serviceclass_conf_dir != NULL) 
     63          free(config->rh_main.serviceclass_conf_dir); 
     64        config->rh_main.serviceclass_conf_dir = strdup(value); 
    6265      } else if (strncmp(sub_key, "log_file", 8) == 0) { 
    6366        if (config->rh_main.log_file != NULL) 
     
    6871          free(config->rh_main.dhcp); 
    6972        config->rh_main.dhcp = strdup(value); 
     73      } else if (strncmp(sub_key, "serviceclass", 12) == 0) { 
     74        config->rh_main.serviceclass = strncmp(value, "yes", 3) == 0 ? 1 : 0; 
    7075      } else if (strncmp(sub_key, "bandwidth_shape", 15) == 0) { 
    71         if (strncmp(value, "yes", 3) == 0) 
    72           config->rh_main.bandwidth_shape = 1;  
    73         else 
    74           config->rh_main.bandwidth_shape = 0; 
     76        config->rh_main.bandwidth_shape = strncmp(value, "yes", 3) == 0 ? 1 : 0; 
    7577      } else if (strncmp(sub_key, "bittorrent_download_max", 23) == 0) { 
    7678        config->rh_main.bittorrent_download_max = atoi(value);  
     
    8385 
    8486    case SERVICECLASS: 
    85       if (strncmp (sub_key, "name", strlen("name")) == 0) { 
    86         if (config->rh_serviceclass.name != NULL) 
    87           free(config->rh_serviceclass.name); 
    88         config->rh_serviceclass.name = strdup(value); 
     87      if (strncmp (sub_key, "serviceclass_id", 
     88            strlen("serviceclass_id")) == 0) { 
     89        config->rh_serviceclass.serviceclass_id = atoi (value); 
     90      } else if (strncmp (sub_key, "serviceclass_name", strlen("serviceclass_name")) == 0) { 
     91        if (config->rh_serviceclass.serviceclass_name != NULL) 
     92          free(config->rh_serviceclass.serviceclass_name); 
     93        config->rh_serviceclass.serviceclass_name = strdup(value); 
    8994      } else if (strncmp (sub_key, "description", strlen("description")) == 0) { 
    9095        if (config->rh_serviceclass.description != NULL) 
     
    114119            else 
    115120              { 
    116                 // Start address should not be the network address 
    117                 config->rh_serviceclass.start_addr.s_addr += 1; 
    118121                DP ("service_class: %s - start ip = %s, size: %d", 
    119                     config->rh_serviceclass.name, 
     122                    config->rh_serviceclass.serviceclass_name, 
    120123                    inet_ntoa (config->rh_serviceclass.start_addr), 
    121124                    config->rh_serviceclass.network_size); 
     
    130133 
    131134        if (!valid) { 
    132           if (config->rh_serviceclass.name != NULL) { 
     135          if (config->rh_serviceclass.serviceclass_name != NULL) { 
    133136            syslog(LOG_ERR, "\"%s\" service_class config config error: " 
    134137                            "invalid network %s", 
    135                             config->rh_serviceclass.name, value); 
     138                            config->rh_serviceclass.serviceclass_name, value); 
    136139          } else { 
    137140            syslog(LOG_ERR, "unknown service_class config error: " 
     
    139142          } 
    140143        } 
    141       } else if (strncmp (sub_key, "fake_arpd", strlen("fake_arpd")) == 0) { 
    142         if (config->rh_serviceclass.fake_arpd != NULL) 
    143           free(config->rh_serviceclass.fake_arpd); 
    144         config->rh_serviceclass.fake_arpd = strdup(value); 
    145144      } else if (strncmp (sub_key, "fake_arpd_iface", 
    146145                 strlen("fake_arpd_iface")) == 0) { 
     
    148147          free(config->rh_serviceclass.fake_arpd_iface); 
    149148        config->rh_serviceclass.fake_arpd_iface = strdup(value); 
     149      } else if (strncmp (sub_key, "fake_arpd", strlen("fake_arpd")) == 0) { 
     150        if (config->rh_serviceclass.fake_arpd != NULL) 
     151          free(config->rh_serviceclass.fake_arpd); 
     152        config->rh_serviceclass.fake_arpd = strdup(value); 
    150153      } 
    151154      break; 
     
    374377} 
    375378 
     379int get_serviceclass_config(const char *conf_dir, struct main_server *server) 
     380{ 
     381  DIR *dp; 
     382  struct dirent *dirp; 
     383  void *data = NULL; 
     384  size_t len; 
     385  char conf_file[200]; 
     386 
     387  if ((dp = opendir(conf_dir)) == NULL) 
     388    return errno; 
     389 
     390  while ((dirp = readdir(dp)) != NULL) { 
     391    if (strstr(dirp->d_name, ".conf") == NULL) 
     392      continue; 
     393 
     394    memset(conf_file, 0, sizeof(conf_file)); 
     395 
     396    strncat(conf_file, conf_dir, sizeof(conf_file)); 
     397    strncat(conf_file, "/", 1); 
     398    strncat(conf_file, dirp->d_name, sizeof(conf_file)); 
     399 
     400    syslog(LOG_INFO, "Loading service class config file: %s", conf_file); 
     401 
     402    register_serviceclass(server, conf_file); 
     403  } 
     404 
     405  closedir(dp); 
     406  return 0; 
     407} 
    376408 
    377409int cleanup_vserver_config(struct rahunas_vserver_config *config) 
     
    416448int cleanup_serviceclass_config(struct rahunas_serviceclass_config *config) 
    417449{ 
    418   rh_free(&(config->name)); 
     450  rh_free(&(config->serviceclass_name)); 
    419451  rh_free(&(config->description)); 
    420452  rh_free(&(config->network)); 
     
    428460{ 
    429461  rh_free(&(config->conf_dir));   
     462  rh_free(&(config->serviceclass_conf_dir)); 
    430463  rh_free(&(config->log_file)); 
    431464  rh_free(&(config->dhcp)); 
  • src/rh-config.h

    r91cc1f0 r43154f8  
    99#include "../lcfg/lcfg_static.h" 
    1010#include "rh-server.h" 
     11#include "rh-serviceclass.h" 
    1112 
    1213#define DEFAULT_LOG RAHUNAS_LOG_DIR "rahunas.log" 
     
    3536struct rahunas_main_config { 
    3637  char *conf_dir; 
     38  char *serviceclass_conf_dir; 
    3739  char *log_file; 
    3840  char *dhcp; 
     41  int  serviceclass; 
    3942  int  bandwidth_shape; 
    4043  int  bittorrent_download_max; 
    4144  int  bittorrent_upload_max; 
    4245  int  polling_interval; 
    43   int  service_class_enabled; 
    4446}; 
    4547 
     
    8587 
    8688struct rahunas_serviceclass_config { 
    87   char *name; 
     89  char *serviceclass_name; 
     90  int  serviceclass_id; 
     91  int  init_flag; 
    8892  char *description; 
    8993  char *network; 
     
    114118}; 
    115119 
     120enum serviceclass_config_init_flag { 
     121  SC_NONE, 
     122  SC_INIT, 
     123  SC_RELOAD, 
     124  SC_RESET, 
     125  SC_DONE 
     126}; 
     127 
    116128extern GList *interfaces_list; 
    117129 
     
    119131int get_value(const char *cfg_file, const char *key, void **data, size_t *len); 
    120132int get_vservers_config(const char *conf_dir, struct main_server *server); 
     133int get_serviceclass_config(const char *conf_dir, struct main_server *server); 
    121134int cleanup_vserver_config(struct rahunas_vserver_config *config); 
    122135int cleanup_serviceclass_config(struct rahunas_serviceclass_config *config); 
  • src/rh-ipset.c

    r220ede9 r43154f8  
    1010#include <unistd.h> 
    1111#include <syslog.h> 
     12#include <ipset/ip_set_rahunas_ipiphash.h> 
    1213#include "rh-ipset.h" 
    1314#include "rh-utils.h" 
     
    297298} 
    298299 
     300int set_ipiphash_adtip(struct set *rahunas_set, const char *ip, 
     301                       const char *ip1, unsigned op) 
     302{ 
     303  ip_set_ip_t _ip; 
     304  ip_set_ip_t _ip1; 
     305  parse_ip(ip, &_ip); 
     306  parse_ip(ip1, &_ip1); 
     307 
     308  return set_adtip_nb(rahunas_set, &_ip, &_ip1, op); 
     309} 
     310 
     311int set_ipiphash_adtip_nb(struct set *rahunas_set, ip_set_ip_t *ip, 
     312                          ip_set_ip_t *ip1, unsigned op) 
     313{ 
     314  struct ip_set_req_adt *req_adt = NULL; 
     315  struct ip_set_req_rahunas_ipiphash req; 
     316 
     317  size_t size; 
     318  void *data; 
     319  int res = 0; 
     320 
     321  check_protocolversion (); 
     322 
     323  if (rahunas_set == NULL) 
     324    return -1; 
     325 
     326  size = ALIGNED(sizeof(struct ip_set_req_adt)) + sizeof(struct ip_set_req_rahunas_ipiphash); 
     327  data = rh_malloc(size); 
     328 
     329  memcpy(&req.ip, ip, sizeof(ip_set_ip_t)); 
     330  memcpy(&req.ip1, ip1, sizeof(ip_set_ip_t)); 
     331 
     332  req_adt = (struct ip_set_req_adt *) data; 
     333  req_adt->op = op; 
     334  req_adt->index = rahunas_set->index; 
     335  memcpy(data + ALIGNED(sizeof(struct ip_set_req_adt)), &req, 
     336           sizeof(struct ip_set_req_rahunas_ipiphash)); 
     337 
     338  if (kernel_sendto_handleerrno(op, data, size) == -1) 
     339    switch (op) { 
     340    case IP_SET_OP_ADD_IP: 
     341      DP("%s:%s is already in set", ip_tostring(ip), ip_tostring(ip1)); 
     342      res = RH_IS_IN_SET; 
     343      break; 
     344    case IP_SET_OP_DEL_IP: 
     345      DP("%s:%s is not in set", ip_tostring(ip), ip_tostring(ip1)); 
     346      res = RH_IS_NOT_IN_SET; 
     347      break; 
     348    case IP_SET_OP_TEST_IP: 
     349      DP("%s:%s is in set", ip_tostring(ip), ip_tostring(ip1)); 
     350      res = RH_IS_IN_SET; 
     351      break; 
     352    default: 
     353      break; 
     354    } 
     355  else 
     356    switch (op) { 
     357    case IP_SET_OP_TEST_IP: 
     358      DP("%s:%s is not in set", ip_tostring(ip), ip_tostring(ip1)); 
     359      res = RH_IS_NOT_IN_SET; 
     360      break; 
     361    default: 
     362      break; 
     363    } 
     364 
     365  rh_free(&data); 
     366 
     367  return res; 
     368} 
     369 
    299370void set_flush(const char *name) 
    300371{ 
  • src/rh-ipset.h

    r220ede9 r43154f8  
    8383 
    8484int set_adtip_nb(struct set *rahunas_set, ip_set_ip_t *adtip,  
    85                      unsigned char adtmac[ETH_ALEN], unsigned op); 
     85                 unsigned char adtmac[ETH_ALEN], unsigned op); 
     86 
     87int set_ipiphash_adtip(struct set *rahunas_set, const char *ip, 
     88                       const char *ip1, unsigned op); 
     89int set_ipiphash_adtip_nb(struct set *rahunas_set, ip_set_ip_t *ip, 
     90                          ip_set_ip_t *ip1, unsigned op); 
    8691 
    8792void set_flush(const char *name); 
  • src/rh-server.c

    r91cc1f0 r43154f8  
    176176  new_vserver->vserver_config = vserver_config; 
    177177 
     178  new_vserver->main_server = ms; 
    178179  new_vserver->vserver_config->init_flag = VS_INIT; 
    179180  ms->vserver_list = g_list_append(ms->vserver_list, new_vserver); 
  • src/rh-server.h

    r91cc1f0 r43154f8  
    1010#include "rh-config.h" 
    1111 
     12struct main_server { 
     13  struct rahunas_main_config *main_config; 
     14  GList *vserver_list; 
     15  GList *serviceclass_list; 
     16  GList *task_list; 
     17  int log_fd; 
     18  int polling_blocked; 
     19}; 
     20 
    1221struct vserver { 
    1322  struct rahunas_vserver_config *vserver_config; 
     
    1524  struct rahunas_map *v_map; 
    1625  struct set *v_set; 
    17 }; 
    18  
    19 struct main_server { 
    20   struct rahunas_main_config *main_config; 
    21   GList *vserver_list; 
    22   GList *task_list; 
    23   int log_fd; 
    24   int polling_blocked; 
     26  struct main_server *main_server; 
    2527}; 
    2628 
  • src/rh-task-dbset.c

    r515ff2d r43154f8  
    2626  long bandwidth_max_down; 
    2727  long bandwidth_max_up; 
     28  gchar *service_class; 
     29  uint32_t service_class_slot_id; 
    2830}; 
    2931 
     
    101103      } else if (strncmp("bandwidth_max_up", title, 18) == 0) { 
    102104        row->bandwidth_max_up = atol(str); 
     105      } else if (strncmp("service_class_slot_id", title, 
     106                         strlen("service_class_slot_id")) == 0) { 
     107          row->service_class_slot_id = atol(str); 
     108      } else if (strncmp("service_class", title, 
     109                         strlen("service_class")) == 0) { 
     110          row->service_class = g_strdup(str); 
    103111      } 
    104112    } 
     
    187195    g_free(row->ip); 
    188196    g_free(row->mac); 
     197    g_free(row->service_class); 
    189198  } 
    190199   
     
    235244    req.bandwidth_max_up = row->bandwidth_max_up; 
    236245 
     246    req.serviceclass_name = row->service_class; 
     247    req.serviceclass_slot_id = row->service_class_slot_id; 
     248 
    237249    rh_task_startsess(vs, &req); 
    238250  } 
     
    354366         "(session_id,vserver_id,username,ip,mac,session_start," 
    355367         "session_timeout,bandwidth_slot_id,bandwidth_max_down," 
    356          "bandwidth_max_up) " 
    357          "VALUES('%s','%d','%s','%s','%s',%s,%s,%u,%lu,%lu)", 
     368         "bandwidth_max_up,service_class,service_class_slot_id) " 
     369         "VALUES('%s','%d','%s','%s','%s',%s,%s,%u,%lu,%lu,'%s',%lu)", 
    358370         req->session_id,  
    359371         vs->vserver_config->vserver_id,  
     
    365377         member->bandwidth_slot_id,  
    366378         req->bandwidth_max_down, 
    367          req->bandwidth_max_up); 
     379         req->bandwidth_max_up, 
     380         member->serviceclass_name, 
     381         member->serviceclass_slot_id); 
    368382 
    369383  DP("SQL: %s", startsess_cmd); 
  • src/rh-task-memset.c

    r927d0c7 r43154f8  
    149149    free(member->session_id); 
    150150 
     151  if (member->serviceclass_name && member->serviceclass_name != termstring) 
     152    free(member->serviceclass_name); 
     153 
     154  if (member->mapping_ip && member->mapping_ip != termstring) 
     155    free(member->mapping_ip); 
     156 
    151157  member->username   = strdup(req->username); 
    152158  if (!member->username) 
     
    156162  if (!member->session_id) 
    157163    member->session_id = termstring; 
     164 
     165  member->serviceclass_name    = NULL; 
     166  member->serviceclass_slot_id = 0; 
     167  member->mapping_ip = termstring; 
    158168 
    159169  if (req->session_start == 0) { 
  • src/rh-task.c

    r91cc1f0 r43154f8  
    5555    rh_task_memset_reg(ms); 
    5656    rh_task_ipset_reg(ms); 
     57 
     58    if (ms->main_config->serviceclass) 
     59      rh_task_serviceclass_reg(ms); 
    5760 
    5861    if (ms->main_config->bandwidth_shape) 
  • src/rh-task.h

    r91cc1f0 r43154f8  
    2323  unsigned long bandwidth_max_down; 
    2424  unsigned long bandwidth_max_up; 
     25  const char *serviceclass_name; 
     26  uint32_t serviceclass_slot_id; 
    2527  unsigned short req_opt; 
    2628}; 
  • src/rh-xmlrpc-server.c

    r91cc1f0 r43154f8  
    3535  gchar *bandwidth_max_down = NULL; 
    3636  gchar *bandwidth_max_up = NULL; 
    37   gchar *service_class = NULL; 
     37  gchar *serviceclass_name = NULL; 
    3838  gchar *vserver_id = NULL; 
    3939  uint32_t id; 
     
    5353  bandwidth_max_down = rh_string_get_sep(param, "|", 6); 
    5454  bandwidth_max_up   = rh_string_get_sep(param, "|", 7); 
    55   service_class      = rh_string_get_sep(param, "|", 8); 
     55  serviceclass_name  = rh_string_get_sep(param, "|", 8); 
    5656  vserver_id         = rh_string_get_sep(param, "|", 9); 
    5757 
     
    111111    member = (struct rahunas_member *)member_node->data; 
    112112    *reply_string = g_strdup_printf("Greeting! Got: IP %s, User %s, ID %s, " 
    113                                     "VIP-IP %s", 
     113                                    "Service Class %s, Mapping %s", 
    114114                                    ip, member->username,  
    115                                     member->session_id, ""); 
     115                                    member->session_id, 
     116                                    member->serviceclass_name, 
     117                                    member->mapping_ip); 
    116118    goto cleanup; 
    117119  } 
     
    130132  g_free(bandwidth_max_down); 
    131133  g_free(bandwidth_max_up); 
    132   g_free(service_class); 
     134  g_free(serviceclass_name); 
    133135  g_free(vserver_id); 
    134136  return 0; 
  • tools/rahunas-firewall.in

    r51ab753 r43154f8  
    4040  file=$3 
    4141 
    42   cat $file | sed -e "0,/$section = {/ ! { /}/,/$section = {/ ! s/^/>>/ }" | grep "^>>" | sed -e "s/^>>//g" | grep -w "$key" | cut -d= -f2 | sed "s/^ *\(.*[^ ]\) *$/\1/" | sed 's/"//g' 
     42  cat $file | sed -e "0,/$section = {/ ! { /}/,/$section = {/ ! s/^/>>/ }" | grep "^>>" | sed -e "s/^>>//g" | grep -w "$key[ ]*=" | cut -d= -f2 | sed "s/^ *\(.*[^ ]\) *$/\1/" | sed 's/"//g' 
    4343} 
    4444 
     
    4949# Main 
    5050MAIN_CONF_DIR=`get_config_value main conf_dir $RAHUNAS_CONFIG` 
     51MAIN_SERVICECLASS=`get_config_value main serviceclass $RAHUNAS_CONFIG` 
    5152MAIN_BANDWIDTH_SHAPE=`get_config_value main bandwidth_shape $RAHUNAS_CONFIG` 
    5253MAIN_BITTORRENT_DOWNLOAD_MAX=`get_config_value main bittorrent_download_max $RAHUNAS_CONFIG` 
     
    7980  VSERVER_PORTS_INTERCEPT= 
    8081  SETNAME= 
    81   VIPMAP= 
    82   VIPMAP_FAKE_ARP= 
    8382fi 
    8483 
     
    101100CHAIN_NAT_POSTROUTING= 
    102101CHAIN_NAT_AUTHEN= 
    103 CHAIN_NAT_VIP_PREROUTING= 
    104 CHAIN_NAT_VIP_POSTROUTING= 
    105102CHAIN_P2P_DETECT= 
    106103CHAIN_P2P_RECHECK= 
     
    151148    VSERVER_PORTS_ALLOW=`get_config_value $SETNAME vserver_ports_allow $file` 
    152149    VSERVER_PORTS_INTERCEPT=`get_config_value $SETNAME vserver_ports_intercept $file` 
    153     VIPMAP=`get_config_value $SETNAME vipmap $file` 
    154     VIPMAP_NETWORK=`get_config_value $SETNAME vipmap_network $file` 
    155     VIPMAP_FAKE_ARP=`get_config_value $SETNAME vipmap_fake_arp $file` 
    156150  fi 
    157151  
     
    180174  CHAIN_NAT_POSTROUTING="${SETNAME}_nat_post" 
    181175  CHAIN_NAT_AUTHEN="${SETNAME}_nat_authen" 
    182   CHAIN_NAT_VIP_PREROUTING="${SETNAME}_nat_vip_pre" 
    183   CHAIN_NAT_VIP_POSTROUTING="${SETNAME}_nat_vip_post" 
    184176   
    185177  # P2P checking chains declaration 
     
    230222  $IPSET -N $SETNAME rahunas $ipset_opt $ipset_ignoremac  
    231223 
    232   if [ "$VIPMAP" = "yes" ]; then 
    233     $IPSET -N ${SETNAME}-vip rahunas $ipset_opt $ipset_ignoremac 
    234   fi 
    235  
    236224  if [ "$BITTORRENT" = "throttle" ]; then 
    237225    $IPSET -N $P2P_SET iphash 
     
    253241  $IPSET -F $SETNAME 
    254242  $IPSET -X $SETNAME 
    255  
    256   if [ "$VIPMAP" = "yes" ]; then 
    257     $IPSET -F ${SETNAME}-vip 
    258     $IPSET -X ${SETNAME}-vip 
    259   fi 
    260243 
    261244  if [ "$BITTORRENT" = "throttle" ]; then 
     
    374357      -j $CHAIN_NAT_POSTROUTING 
    375358  done 
    376 } 
     359 
     360 
     361} 
     362 
    377363 
    378364## 
     
    412398  $IPTABLES -t nat -F $CHAIN_NAT_AUTHEN 
    413399  $IPTABLES -t nat -X $CHAIN_NAT_AUTHEN 
    414  
    415   if [ "$VIPMAP" = "yes" ]; then 
    416     $IPTABLES -t nat -F $CHAIN_NAT_VIP_PREROUTING 
    417     $IPTABLES -t nat -X $CHAIN_NAT_VIP_PREROUTING 
    418  
    419     $IPTABLES -t nat -F $CHAIN_NAT_VIP_POSTROUTING 
    420     $IPTABLES -t nat -X $CHAIN_NAT_VIP_POSTROUTING 
    421   fi 
    422400 
    423401  if [ "$BITTORRENT" = "throttle" ]; then 
     
    448426  $IPTABLES -t nat -N $CHAIN_NAT_AUTHEN 
    449427 
    450   if [ "$VIPMAP" = "yes" ]; then 
    451     $IPTABLES -t nat -N $CHAIN_NAT_VIP_PREROUTING 
    452     $IPTABLES -t nat -N $CHAIN_NAT_VIP_POSTROUTING 
    453   fi 
    454  
    455428  if [ "$BITTORRENT" = "throttle" ]; then 
    456429    $IPTABLES -t mangle -N $CHAIN_P2P_CHECK 
     
    675648    fi 
    676649 
    677     if [ "$VIPMAP" = "yes" ]; then 
     650    if [ "$MAIN_SERVICECLASS" = "yes" ]; then 
    678651      $IPTABLES -t nat -A $CHAIN_NAT_PREROUTING \ 
    679         -m set --set ${SETNAME}-vip src -j $CHAIN_NAT_VIP_PREROUTING 
    680  
    681       $IPTABLES -t nat -A $CHAIN_NAT_VIP_PREROUTING -j ACCEPT 
     652        -m set --set rahunas_serviceclass src -j ACCEPT 
    682653    fi 
    683654 
     
    686657      then 
    687658        $IPTABLES -t nat -A $CHAIN_NAT_PREROUTING -p tcp --dport http \ 
    688           -d ! $VSERVER_IP \ 
     659          ! -d $VSERVER_IP \ 
    689660          -m connmark --mark 2/2 -j REDIRECT --to-ports $PROXY_PORT 
    690661      else 
    691662        $IPTABLES -t nat -A $CHAIN_NAT_PREROUTING -p tcp --dport http \ 
    692           -d ! $VSERVER_IP \ 
     663          ! -d $VSERVER_IP \ 
    693664          -m connmark --mark 2/2 \ 
    694665          -j DNAT --to-destination $PROXY_HOST:$PROXY_PORT 
     
    702673   
    703674  $IPTABLES -t nat -A $CHAIN_NAT_PREROUTING -p tcp -m multiport \ 
    704     --dports $VSERVER_PORTS_INTERCEPT -d ! $VSERVER_IP \ 
     675    --dports $VSERVER_PORTS_INTERCEPT ! -d $VSERVER_IP \ 
    705676    -m connmark ! --mark 2/2 \ 
    706677    -j $CHAIN_NAT_AUTHEN 
     
    712683  # MASQUERADE 
    713684  ## 
    714   if [ "$VIPMAP" = "yes" ]; then 
    715     $IPTABLES -t nat -A $CHAIN_NAT_POSTROUTING \ 
    716       -m set --set ${SETNAME}-vip src -j $CHAIN_NAT_VIP_POSTROUTING 
    717   fi 
    718  
    719685  if [ "$MASQUERADE" = "yes" ]; then 
    720686    $IPTABLES -t nat -A $CHAIN_NAT_POSTROUTING -j MASQUERADE 
     
    744710  $IPTABLES -t nat -A $CHAIN_NAT_PREROUTING -j RETURN 
    745711  $IPTABLES -t nat -A $CHAIN_NAT_POSTROUTING -j RETURN 
    746  
    747   if [ "$VIPMAP" = "yes" ]; then 
    748     $IPTABLES -t nat -A $CHAIN_NAT_VIP_PREROUTING -j RETURN 
    749     $IPTABLES -t nat -A $CHAIN_NAT_VIP_POSTROUTING -j RETURN 
    750  
    751     if [ "$VIPMAP_FAKE_ARP" = "yes" ]; then 
    752       for dev in $DEV_EXTERNAL_LIST; do 
    753         $FARPD -i $dev $VIPMAP_NETWORK 
    754       done 
    755     fi 
     712} 
     713 
     714## 
     715# Service class set 
     716## 
     717serviceclass_set () { 
     718  opt=$1 
     719  if [ "$opt" = "start" ]; then 
     720    $IPSET -N rahunas_serviceclass rahunas_ipiphash 
     721  elif [ "$opt" = "cleanup" ]; then 
     722    $IPSET -F rahunas_serviceclass 
     723    $IPSET -X rahunas_serviceclass 
     724  fi 
     725} 
     726 
     727## 
     728# Service class rules 
     729## 
     730serviceclass_rules () { 
     731  opt=$1 
     732  if [ "$opt" = "start" ]; then 
     733    action="-I" 
     734  elif [ "$opt" = "stop" ]; then 
     735    action="-D" 
     736  fi 
     737 
     738  if [ "$MAIN_SERVICECLASS" = "yes" -o "$opt" = "stop" ]; then 
     739    # RAW - Service class 
     740    $IPTABLES -t raw $action PREROUTING \ 
     741      -m set --set rahunas_serviceclass src \ 
     742      -j RAHURAWDNAT --bind-set rahunas_serviceclass 
     743 
     744    $IPTABLES -t rawpost $action POSTROUTING \ 
     745      -m set --set rahunas_serviceclass dst \ 
     746      -j RAHURAWSNAT --bind-set rahunas_serviceclass 
    756747  fi 
    757748} 
     
    790781  policy  
    791782 
     783  if [ "$MAIN_SERVICECLASS" = "yes" ]; then 
     784    serviceclass_set start 
     785    serviceclass_rules start 
     786  fi 
     787 
    792788  touch $RUN 
    793789} 
     
    795791stop () { 
    796792  test -f $RUN || return 0 
     793 
     794  serviceclass_rules stop 
     795  serviceclass_set cleanup 
    797796    
    798797  cleanup_policy 
  • weblogin/login.php

    r51ab753 r43154f8  
    4646$config = get_config_by_network($ip, $config_list); 
    4747$vserver_id = $config["VSERVER_ID"]; 
    48 $vip_user = 0; 
    4948 
    5049$forward = false; 
     
    103102    $racct->gen_session_id(); 
    104103 
    105     if ($config["VIPMAP"] == "yes" && 
    106           !empty ($rauth->attributes[$config["VIPMAP_ATTRIBUTE"]])) { 
    107       $vip_user = 1; 
    108     } 
    109  
    110  
    111104    try { 
    112105      $prepareData = array ( 
     
    118111        "Bandwidth-Max-Down" => $rauth->attributes['WISPr-Bandwidth-Max-Down'], 
    119112        "Bandwidth-Max-Up" => $rauth->attributes['WISPr-Bandwidth-Max-Up'], 
    120         "Vip_User" => $vip_user, 
     113        "Class-Of-Service" => $rauth->attributes['WISPr-Billing-Class-Of-Service'], 
    121114      ); 
    122115      $result = $xmlrpc->do_startsession($vserver_id, $prepareData); 
     
    125118        $forward = false; 
    126119      } else if (strstr($result, "Greeting")) { 
    127         $split = explode ("VIP-IP ", $result); 
     120        $split = explode ("Mapping ", $result); 
    128121        $called_station_id = $split[1]; 
    129122        if (!empty ($called_station_id))