NSIS-ka
A free C++ implementation of NSIS protocols

Changeset 4192


Ignore:
Timestamp:
Aug 2, 2009, 10:47:09 PM (8 years ago)
Author:
bless
Message:
  • removed get_local_if() functions
  • moved readnl to protlib
  • updates due to new addresslist.h in protlib
Location:
ntlp/branches/20081127-merge-mobility-mk3
Files:
2 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • ntlp/branches/20081127-merge-mobility-mk3/include/apiwrapper.h

    r3701 r4192  
    4141#include "goettingen_api.h"
    4242
     43#include "addresslist.h"
    4344
    4445// Constants of Goettingen's GIST API
  • ntlp/branches/20081127-merge-mobility-mk3/include/mri.h

    r4147 r4192  
    6969        /// returns the destination address of the signaling packet depending on the MRI
    7070        virtual appladdress* determine_dest_address() const = 0;
    71 
    72         /// returns the appropriate local outgoing interface for the flow
    73         virtual uint16 get_local_if() const = 0;
    7471   
    7572        /// returns the IP Version
  • ntlp/branches/20081127-merge-mobility-mk3/include/mri_est.h

    r4147 r4192  
    113113
    114114        virtual appladdress* determine_dest_address() const { return new appladdress(dest_signaling_addr,prot_udp,GIST_default_port); }
    115 
    116         // Returns the appropriate local outgoing interface for the flow
    117         virtual uint16 get_local_if() const { return mri_pc.get_local_if(); }
    118115   
    119116        // Returns the IP Version
  • ntlp/branches/20081127-merge-mobility-mk3/include/mri_le.h

    r4147 r4192  
    7878
    7979        virtual appladdress* determine_dest_address() const;
    80         virtual uint16 get_local_if() const;
    8180        virtual void invertDirection();
    8281
  • ntlp/branches/20081127-merge-mobility-mk3/include/mri_pc.h

    r4147 r4192  
    9494
    9595        virtual appladdress* determine_dest_address() const;
    96         virtual uint16 get_local_if() const;
    9796
    9897
  • ntlp/branches/20081127-merge-mobility-mk3/include/ntlp_starter.h

    r4147 r4192  
    3535#include "threads.h"
    3636#include "address.h"
     37#include "addresslist.h"
    3738#include "flowinfo.h"
    3839
  • ntlp/branches/20081127-merge-mobility-mk3/src/ntlp_proto.h

    r4147 r4192  
    4242#include "threadsafe_db.h"
    4343#include "logfile.h"
     44
     45#include "addresslist.h"
    4446
    4547#ifndef NSIS_OMNETPP_SIM
  • ntlp/branches/20081127-merge-mobility-mk3/src/ntlp_statemodule_api.cpp

    r4188 r4192  
    3939
    4040#include "gist_conf.h"
     41#include "rfc5014_hack.h"
    4142
    4243namespace ntlp {
     
    892893      peer->set_rao(param.rt.get_rao(r_key->nslpid));
    893894      DLog(param.name, "Set RAO value to the one of the NSLP (we know it for sure)");
    894            
    895       uint16 outgoinginterface = mymri->get_local_if();
    896            
    897       if (!outgoinginterface)
    898       {
    899         DLog(param.name, "Lookup of outgoing interface failed (this would certainly also affect the flow's routing). TP modules may use any interface.");
    900       }
    901       else
    902       {
    903         peer->set_if_index(outgoinginterface);
    904         DLog(param.name, "Set request for outgoing interface index " << outgoinginterface << " for GIST Query");
    905       }
    906 
    907895
    908896      // send it to signaling
  • ntlp/branches/20081127-merge-mobility-mk3/src/ntlp_statemodule_main.cpp

    r4185 r4192  
    5151#endif
    5252
     53#include "rfc5014_hack.h"
     54
    5355#include <sstream>
    5456#include <list>
  • ntlp/branches/20081127-merge-mobility-mk3/src/ntlp_statemodule_responder.cpp

    r4147 r4192  
    4444#include "authorized_peer_db.h"
    4545
     46#include "rfc5014_hack.h"
     47
    4648#include "gist_conf.h"
    4749
  • ntlp/branches/20081127-merge-mobility-mk3/src/pdu/mri_le.cpp

    r4147 r4192  
    310310
    311311
    312 
    313 
    314 //virtual function which allows each MRI subtype to return a local interface address
    315 uint16
    316 mri_looseend::get_local_if() const
    317 {
    318 
    319     // a local IF number of '0' will cause the Framework not to try to bind to a specific interface - unnecessary here!
    320      return 0;
    321    
    322 }
    323 
    324 
    325 
    326 
    327 //virtual function inverting direction flag, Responder nodes stores MRI with inverted direction
     312// virtual function inverting direction flag, Responder nodes stores MRI with inverted direction
    328313void mri_looseend::invertDirection() {
    329314
  • ntlp/branches/20081127-merge-mobility-mk3/src/pdu/mri_pc.cpp

    r4147 r4192  
    3131#include <iomanip>
    3232#include <string>
    33 #include <cerrno>
    34 
    35 #ifndef NSIS_OMNETPP_SIM
    36 // this will NOT be included in the OMNeT++ simulation, but otherwise
    37   #include <net/if.h>
    38   #include <linux/types.h> // in case that this one is not included in netlink.h
    39   #include <linux/netlink.h>
    40   #include <linux/rtnetlink.h>
    41 #endif // end ifndef NSIS_OMNETPP_SIM
    4233
    4334#include "logfile.h"
    4435#include "mri_pc.h"
    45 
    46 #include "readnl.h"
    4736
    4837using namespace ntlp;
     
    611600
    612601
    613 #ifndef NSIS_OMNETPP_SIM
    614 
    615 /**
    616  * Returns the interface number the kernel would use for this MRI.
    617  *
    618  * This depends on the Direction flag (upstream/downstream).
    619  *
    620  * TODO: Review and cleanup necessary.
    621  */
    622 uint16
    623 mri_pathcoupled::get_local_if() const
    624 {
    625     //#######################################################################
    626     //
    627     // Query the kernel via RTNetlink socket with RTM_GET_ROUTE
    628     //
    629     // currently, this fails for IPv4, no idea as to why
    630     //
    631     //#######################################################################
    632 
    633     // Buffer for error messages, used by the strerror_r() calls below.
    634     char msg_buf[1024];
    635 
    636     // We must decide whether IPv4 or IPv6 is used
    637     bool ipv6 = destaddress.is_ipv6();
    638 
    639 
    640     // 2 sockaddr_in6?
    641     struct in6_addr dstaddr, srcaddr;
    642     struct in_addr dstaddr4, srcaddr4;
    643    
    644     // Netlink Message header plus RTNetlink Message Header plus 1024byte data
    645     struct {
    646         struct nlmsghdr n;
    647         struct rtmsg r;
    648         char data[1024];
    649     } req;
    650 
    651     // Struct rtattr
    652     struct rtattr *attr;
    653     struct rtattr *attr2;
    654 
    655    
    656     // int outgoinginterface
    657     uint16 outgoinginterface = 0;
    658 
    659    
    660     // enable this routine here
    661     if (true) {
    662 
    663         // OPEN a RTNETLINK SOCKET
    664        
    665         int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    666         if (sock < 0) {
    667             strerror_r(errno, msg_buf, sizeof msg_buf);
    668             ERRCLog("mri_pathcoupled::get_local_if()",
    669                         "error opening Netlink socket: " << msg_buf);
    670         }       
    671 
    672         // if IPv6
    673 
    674         if (ipv6) {
    675 
    676             if (flags & Direction) {
    677                 sourceaddress.get_ip(dstaddr);
    678                 destaddress.get_ip(srcaddr);
    679             } else {
    680                 destaddress.get_ip(dstaddr);
    681                 sourceaddress.get_ip(srcaddr);
    682             }           
    683 
    684             memset(&req, 0, sizeof(req));
    685             req.n.nlmsg_len =
    686                 NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))) +
    687                 RTA_LENGTH(sizeof(dstaddr)) + RTA_LENGTH(sizeof(srcaddr));
    688             req.n.nlmsg_flags = NLM_F_REQUEST;
    689             req.n.nlmsg_type = RTM_GETROUTE;
    690             req.r.rtm_family = AF_INET6;
    691             req.r.rtm_dst_len = 128;
    692             req.r.rtm_src_len = 128;
    693 
    694             attr = (rtattr*) (((char *) &req) + NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))));
    695             attr->rta_type = RTA_DST;
    696             attr->rta_len = RTA_LENGTH(sizeof(dstaddr));
    697 
    698             memcpy(RTA_DATA(attr), &dstaddr, sizeof(dstaddr));
    699 
    700 
    701             attr2 = (rtattr*) (((char*) &req) + NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))) + attr->rta_len);
    702             attr2->rta_type = RTA_SRC;
    703             attr2->rta_len = RTA_LENGTH(sizeof(srcaddr));
    704 
    705 
    706             memcpy(RTA_DATA(attr2), &srcaddr, sizeof(srcaddr));
    707 
    708 
    709             // Send to Kernel
    710 
    711              /*Send the message*/
    712 
    713             if (send(sock, &req, req.n.nlmsg_len, 0) < 0) {
    714                 strerror_r(errno, msg_buf, sizeof msg_buf);
    715                 ERRCLog("mri_pathcoupled::get_local_if()",
    716                         "error sending Netlink message: " << msg_buf);
    717                 close(sock);
    718             }
    719 
    720             char* returnbuf = new char[NL_BUFSIZE];
    721 
    722             int read = readnl(sock, returnbuf);
    723 
    724             if (read < 0) return 0;
    725 
    726             nlmsghdr* nlhdrp = (struct nlmsghdr *)returnbuf;
    727 
    728             rtmsg* rtmsg = (struct rtmsg*)NLMSG_DATA(nlhdrp);
    729            
    730 
    731             // Iterate through data area serachin
    732 
    733             rtattr* attrp = RTM_RTA(rtmsg);
    734             uint32 attrlen = RTM_PAYLOAD(nlhdrp);
    735 
    736             for( ; RTA_OK(attrp, attrlen); attrp = RTA_NEXT(attrp, attrlen) ){
    737 
    738                
    739                 if ((attrp->rta_type) == RTA_OIF) {
    740                    
    741                     char* ifname= new char[IF_NAMESIZE];
    742                     if_indextoname(*(int *)RTA_DATA(attrp), ifname);
    743 
    744                     Log(EVENT_LOG, LOG_NORMAL, "mri_pathcoupled",  "Kernel decided the outgoing interface index should be " << *(int *)RTA_DATA(attrp) << ", interface Name " << ifname);
    745                
    746                     outgoinginterface=*(int *)RTA_DATA(attrp);
    747                     delete ifname;
    748                 }
    749 
    750 
    751             }
    752 
    753 
    754 
    755 
    756         } //end if IPv6
    757         else
    758         {
    759 
    760 
    761             //cout << "IPv4 used, query for IPv4" << endl;
    762 
    763 
    764             if (flags & Direction) {
    765 
    766             sourceaddress.get_ip(dstaddr4);
    767             destaddress.get_ip(srcaddr4);
    768 
    769             } else {
    770 
    771             destaddress.get_ip(dstaddr4);
    772             sourceaddress.get_ip(srcaddr4);
    773 
    774             }
    775 
    776             //cout << "Got socket addresses from data structures" << endl;
    777            
    778             memset(&req, 0, sizeof(req));
    779             req.n.nlmsg_len =
    780                 NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))) +
    781                 RTA_LENGTH(sizeof(dstaddr4)) + RTA_LENGTH(sizeof(srcaddr4));
    782             req.n.nlmsg_flags = NLM_F_REQUEST;
    783             req.n.nlmsg_type = RTM_GETROUTE;
    784             req.r.rtm_family = AF_INET;
    785             req.r.rtm_dst_len = 12;
    786             req.r.rtm_src_len = 12;
    787 
    788             attr = (rtattr*) (((char *) &req) + NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))));
    789             attr->rta_type = RTA_DST;
    790             attr->rta_len = RTA_LENGTH(sizeof(dstaddr4));
    791 
    792             memcpy(RTA_DATA(attr), &dstaddr4, sizeof(dstaddr4));
    793 
    794             attr2 = (rtattr*) (((char*) &req) + NLMSG_ALIGN(NLMSG_LENGTH(sizeof(req.r))) + RTA_LENGTH(sizeof(dstaddr4)));
    795             attr2->rta_type = RTA_SRC;
    796             attr2->rta_len = RTA_LENGTH(sizeof(srcaddr4));
    797 
    798 
    799             memcpy(RTA_DATA(attr2), &srcaddr4, sizeof(srcaddr4));
    800 
    801 
    802             // Send to Kernel
    803 
    804             if (send(sock, &req, req.n.nlmsg_len, 0) < 0) {
    805                 strerror_r(errno, msg_buf, sizeof msg_buf);
    806                 ERRCLog("mri_pathcoupled::get_local_if()",
    807                         "error sending Netlink message: " << msg_buf);
    808                 close(sock);
    809             }
    810 
    811             char* returnbuf = new char[NL_BUFSIZE];
    812 
    813             int read = readnl(sock, returnbuf);
    814 
    815             if (read <0 ) return 0;
    816 
    817             nlmsghdr* nlhdrp = (struct nlmsghdr *)returnbuf;
    818 
    819             rtmsg* rtmsg = (struct rtmsg*)NLMSG_DATA(nlhdrp);
    820            
    821             // Iterate through data area serachin
    822             rtattr* attrp = RTM_RTA(rtmsg);
    823             uint32 attrlen = RTM_PAYLOAD(nlhdrp);
    824 
    825             for( ; RTA_OK(attrp, attrlen); attrp = RTA_NEXT(attrp, attrlen) ){
    826 
    827                 if ((attrp->rta_type) == RTA_OIF) {
    828                    
    829                     char* ifname= new char[IF_NAMESIZE];
    830                     if_indextoname(*(int *)RTA_DATA(attrp), ifname);
    831 
    832                     Log(EVENT_LOG, LOG_NORMAL, "mri_pathcoupled",  "Linux Kernel decided the outgoing interface index should be " << *(int *)RTA_DATA(attrp) << ", interface Name " << ifname);
    833                
    834                     outgoinginterface=*(int *)RTA_DATA(attrp);
    835                     delete ifname;
    836                 }
    837 
    838 
    839             }
    840 
    841             if (returnbuf) delete returnbuf;
    842             close(sock);
    843 
    844             if (!outgoinginterface) {
    845                
    846                 Log(EVENT_LOG, LOG_NORMAL, "mri_pathcoupled", "Linux Kernel was unable to provide a outgoing interface for this flow, taking default route.");
    847 
    848             }
    849         }
    850     }
    851    
    852     return outgoinginterface;
    853 }
    854 
    855 #else
    856 // this is only included in the OMNeT++ Simulation
    857 uint16
    858 mri_pathcoupled::get_local_if() const
    859 {
    860   return 0; // not really relevant yet
    861 }
    862 
    863 #endif // ifndef NSIS_OMNETPP_SIM
    864 
    865602
    866603// Invert direction flag; responder nodes stores MRI with inverted direction
  • ntlp/branches/20081127-merge-mobility-mk3/src/signalingmodule_ntlp.cpp

    r4181 r4192  
    5151#include "logfile.h"
    5252#include "ntlp_proto.h"
     53#include "rfc5014_hack.h"
    5354
    5455#ifndef NSIS_OMNETPP_SIM
     
    12961297    char* returnbuf = new char[NL_BUFSIZE];
    12971298       
    1298     readnl(sock, returnbuf);
     1299    protlib::util::readnl(sock, returnbuf);
    12991300       
    13001301    nlmsghdr* nlhdrp = reinterpret_cast<struct nlmsghdr *>(returnbuf);
     
    13771378    char* returnbuf = new char[NL_BUFSIZE];
    13781379       
    1379     readnl(sock, returnbuf);
     1380    protlib::util::readnl(sock, returnbuf);
    13801381       
    13811382    nlmsghdr* nlhdrp = reinterpret_cast<struct nlmsghdr *>(returnbuf);
Note: See TracChangeset for help on using the changeset viewer.