Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: sbin/natd/natd.c
- ===================================================================
- --- sbin/natd/natd.c (revision 218960)
- +++ sbin/natd/natd.c (working copy)
- @@ -45,6 +45,8 @@
- #include <syslog.h>
- #include <unistd.h>
- +#include <pthread.h>
- +
- #include "natd.h"
- struct instance {
- @@ -132,13 +134,20 @@
- static void DoGlobal (int fd);
- static int CheckIpfwRulenum(unsigned int rnum);
- +static void* InfoThread(void*);
- +static void* InfoThreadStart(void*);
- +static int infoSocket;
- +
- +
- /*
- * Globals.
- */
- -static int verbose;
- -static int background;
- -static int running;
- +static pthread_t info_thread;
- +
- +static int verbose;
- +static int background;
- +static int running;
- static int logFacility;
- static int dynamicMode;
- @@ -149,6 +158,7 @@
- static int globalPort;
- static int divertGlobal;
- static int exitDelay;
- +static int shouldExit;
- int main (int argc, char** argv)
- @@ -366,6 +376,8 @@
- LibAliasSetAddress (mla, mip->aliasAddr);
- }
- + pthread_create(&info_thread, NULL, InfoThreadStart, NULL);
- +
- while (running) {
- mip = LIST_FIRST(&root); /* XXX: simon */
- @@ -989,8 +1001,12 @@
- * shutdown existing connections when system
- * is shut down.
- */
- + void *ret;
- siginterrupt(SIGALRM, 1);
- signal (SIGALRM, Shutdown);
- + shouldExit=1;
- + close(infoSocket);
- + pthread_join(info_thread, &ret);
- ualarm(exitDelay*1000, 1000);
- }
- @@ -2015,3 +2031,74 @@
- return 0;
- }
- +
- +static void*
- +InfoThreadStart(void* p)
- +{
- + struct sockaddr_in s_addr;
- + int sz=1;
- +
- + if((infoSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
- + return NULL;
- +
- + memset((char *) &s_addr, 0, sizeof(s_addr));
- +
- + s_addr.sin_family = AF_INET;
- + s_addr.sin_addr.s_addr = htonl(INADDR_ANY);
- + s_addr.sin_port = htons(666);
- +
- + setsockopt( infoSocket, SOL_SOCKET, SO_REUSEADDR, &sz, sizeof(int) );
- +
- + if(bind(infoSocket, (struct sockaddr *) &s_addr, sizeof(s_addr)) < 0)
- + return NULL;
- +
- + listen(infoSocket, 1);
- +
- + return InfoThread((void*)&infoSocket);
- +}
- +
- +static void*
- +InfoThread(void* p)
- +{
- + int s,s2;
- + struct sockaddr_in s2_addr;
- + int sz=1;
- + char buf[256];
- +
- + s = *(int*)p;
- +
- + sz = sizeof( struct sockaddr_in );
- +
- + for(;;){
- + s2 = accept(s, (struct sockaddr *) &s2_addr, &sz);
- + struct instance *tip;
- + LIST_FOREACH(tip, &root, list) {
- + sprintf(buf, "if:%s inport:%d outport:%d inoutport:%d\n",
- + tip->ifName, tip->inPort, tip->outPort, tip->inOutPort);
- +
- + write(s2,buf,strlen(buf)+1);
- +
- + sprintf(buf,"---\n");
- + write(s2,buf,strlen(buf)+1);
- +
- + ShowOutInfo(s2,tip->la);
- +
- + sprintf(buf,"---\n");
- + write(s2,buf,strlen(buf)+1);
- +
- + ShowInInfo(s2,tip->la);
- +
- + sprintf(buf,"---\n");
- + write(s2,buf,strlen(buf)+1);
- +
- + }
- +
- + sprintf(buf,"This is natd. Fuck you! :-)\n");
- + write(s2, buf, strlen(buf)+1);
- + close(s2);
- + if(shouldExit) return NULL;
- + }
- + close(s);
- + pthread_exit(&sz);
- + return NULL;
- +}
- Index: sbin/natd/Makefile
- ===================================================================
- --- sbin/natd/Makefile (revision 218960)
- +++ sbin/natd/Makefile (working copy)
- @@ -3,8 +3,9 @@
- PROG = natd
- SRCS = natd.c icmp.c
- WARNS?= 3
- -LDADD = -lalias
- +LDADD = -lalias -lpthread
- DPADD = ${LIBALIAS}
- MAN = natd.8
- +CFLAGS+= -I/usr/src/sys/netinet/libalias/
- .include <bsd.prog.mk>
- Index: sys/netinet/libalias/alias.h
- ===================================================================
- --- sys/netinet/libalias/alias.h (revision 218960)
- +++ sys/netinet/libalias/alias.h (working copy)
- @@ -42,6 +42,7 @@
- #include <netinet/in_systm.h>
- #include <netinet/in.h>
- #include <netinet/ip.h>
- +#include <sys/queue.h>
- #define LIBALIAS_BUF_SIZE 128
- #ifdef _KERNEL
- @@ -138,6 +139,11 @@
- /* Mbuf helper function. */
- struct mbuf *m_megapullup(struct mbuf *, int);
- +/* Alias info function and structures */
- +
- +void ShowOutInfo(int, struct libalias *);
- +void ShowInInfo(int, struct libalias *);
- +
- /*
- * Mode flags and other constants.
- */
- Index: sys/netinet/libalias/alias_db.c
- ===================================================================
- --- sys/netinet/libalias/alias_db.c (revision 218960)
- +++ sys/netinet/libalias/alias_db.c (working copy)
- @@ -161,6 +161,7 @@
- #include <sys/socket.h>
- #include <netinet/tcp.h>
- +#include <netdb.h>
- #ifdef _KERNEL
- #include <netinet/libalias/alias.h>
- @@ -1784,7 +1785,7 @@
- SetAckModified(), GetAckModified()
- GetDeltaAckIn(), GetDeltaSeqOut(), AddSeq()
- SetProtocolFlags(), GetProtocolFlags()
- - SetDestCallId()
- + SetDestCallId(), GetProto()
- */
- @@ -2158,7 +2159,14 @@
- la->deleteAllLinks = 0;
- }
- +int
- +GetProto(struct alias_link *lnk)
- +{
- + return (lnk->link_type);
- +}
- +
- +
- /* Miscellaneous Functions
- HouseKeeping()
- @@ -2934,3 +2942,85 @@
- return(redir); /* address redirect */
- }
- }
- +
- +void
- +ShowOutInfo(int socket, struct libalias *la) {
- + struct alias_link *lnk;
- + char buf[1024];
- + char _original_addr[20]="", _dest_addr[20]="", _alias_addr[20]="", _proxy_addr[20]="";
- + char original_addr[30]="", dest_addr[30]="", alias_addr[30]="", proxy_addr[30]="";
- + struct protoent *proto;
- + int i;
- + sprintf(buf,"Out table\n");
- + write(socket, buf, strlen(buf));
- + for(i=0; i<LINK_TABLE_OUT_SIZE; i++){
- + LIST_FOREACH(lnk, &la->linkTableOut[i], list_out){
- +
- + inet_ntoa_r(GetOriginalAddress(lnk), _original_addr, 20);
- + inet_ntoa_r(GetDestAddress(lnk), _dest_addr, 20);
- + inet_ntoa_r(GetAliasAddress(lnk), _alias_addr, 20);
- + inet_ntoa_r(GetProxyAddress(lnk), _proxy_addr, 20);
- +
- + snprintf(original_addr, 30, "%s:%d", _original_addr, ntohs(GetOriginalPort(lnk)));
- + snprintf(dest_addr, 30, "%s:%d", _dest_addr, ntohs(GetDestPort(lnk)));
- + snprintf(alias_addr, 30, "%s:%d", _alias_addr, ntohs(GetAliasPort(lnk)));
- + snprintf(proxy_addr, 30, "%s:%d", _proxy_addr, ntohs(GetProxyPort(lnk)));
- +
- + proto = getprotobynumber(GetProto(lnk));
- + snprintf(buf, 1024, "%25s %25s %25s %25s ",
- + original_addr,
- + dest_addr,
- + alias_addr,
- + proxy_addr
- + );
- + write(socket, buf, strlen(buf));
- + if(proto){
- + snprintf(buf, 1024, "%s\n", proto->p_name);
- + }else{
- + snprintf(buf, 1024, "%d\n", GetProto(lnk));
- + }
- + write(socket, buf, strlen(buf));
- + }
- + }
- +}
- +
- +void
- +ShowInInfo(int socket, struct libalias *la) {
- + struct alias_link *lnk;
- + char buf[1024];
- + char _original_addr[20]="", _dest_addr[20]="", _alias_addr[20]="", _proxy_addr[20]="";
- + char original_addr[30]="", dest_addr[30]="", alias_addr[30]="", proxy_addr[30]="";
- + struct protoent *proto;
- + int i;
- + sprintf(buf, "In table\n");
- + write(socket, buf, strlen(buf));
- + for(i=0; i<LINK_TABLE_IN_SIZE; i++){
- + LIST_FOREACH(lnk, &la->linkTableIn[i], list_in){
- +
- + inet_ntoa_r(GetOriginalAddress(lnk), _original_addr, 20);
- + inet_ntoa_r(GetDestAddress(lnk), _dest_addr, 20);
- + inet_ntoa_r(GetAliasAddress(lnk), _alias_addr, 20);
- + inet_ntoa_r(GetProxyAddress(lnk), _proxy_addr, 20);
- +
- + snprintf(original_addr, 30, "%s:%d", _original_addr, ntohs(GetOriginalPort(lnk)));
- + snprintf(dest_addr, 30, "%s:%d", _dest_addr, ntohs(GetDestPort(lnk)));
- + snprintf(alias_addr, 30, "%s:%d", _alias_addr, ntohs(GetAliasPort(lnk)));
- + snprintf(proxy_addr, 30, "%s:%d", _proxy_addr, ntohs(GetProxyPort(lnk)));
- +
- + proto = getprotobynumber(GetProto(lnk));
- + snprintf(buf, 1024, "%25s %25s %25s %25s ",
- + original_addr,
- + dest_addr,
- + alias_addr,
- + proxy_addr
- + );
- + write(socket, buf, strlen(buf));
- + if(proto){
- + snprintf(buf, 1024, "%s\n", proto->p_name);
- + }else{
- + snprintf(buf, 1024, "%d\n", GetProto(lnk));
- + }
- + write(socket, buf, strlen(buf));
- + }
- + }
- +}
- Index: sys/netinet/libalias/alias_local.h
- ===================================================================
- --- sys/netinet/libalias/alias_local.h (revision 218960)
- +++ sys/netinet/libalias/alias_local.h (working copy)
- @@ -341,6 +341,7 @@
- void SetProtocolFlags(struct alias_link *_lnk, int _pflags);
- int GetProtocolFlags(struct alias_link *_lnk);
- void SetDestCallId(struct alias_link *_lnk, u_int16_t _cid);
- +int GetProto(struct alias_link *_lnk);
- #ifndef NO_FW_PUNCH
- void PunchFWHole(struct alias_link *_lnk);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement