1 / 37

14 장 . Out-of-Band Data

14 장 . Out-of-Band Data. System Software Lab. 이종호. 목차. Out-of-band data 의 정의 Out-of-band data 의 필요성 Socket and out-of-band data Variations in implementation Out-of-band data 사용 Urgent Pointer 의 이해 Receiving Out-of-band data inline Urgent mode pointer 의 제한점 Summary. 8. 7. 6. 5. 4.

kosey
Download Presentation

14 장 . Out-of-Band Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 14장. Out-of-Band Data System Software Lab. 이종호 한남대학교 컴퓨터공학과 컴퓨터 네트워크 실험실

  2. 목차 • Out-of-band data의 정의 • Out-of-band data의 필요성 • Socket and out-of-band data • Variations in implementation • Out-of-band data 사용 • Urgent Pointer의 이해 • Receiving Out-of-band data inline • Urgent mode pointer의 제한점 • Summary

  3. 8 7 6 5 4 3 2 U Out-of-band data 1 Out-of-band 데이터의 정의 • 정의 • 대역밖의 데이터 • 긴급한 데이터로서 일정한 순서를 가지지 않고 순차화 된 데이터보다 더 먼저 처리 되어야 할 필요가 있는 데이터를 일컫는다. 즉, TCP/IP 통신상에서 긴급한 데이터 • 예

  4. Out-of-band data의 필요성 • 필요성 • 보내진 데이터보다 먼저 처리되어야 할 이유가 있을 때 처리하는 방법 필요 • 서버에게 보내진 요청을 취소할 이유가 있을 때 처리하는 방법이 필요 • Out-of-band 데이터의 사용프로그램 • telnet • rlogin • ftp

  5. Socket 과 Out-of-band data • 소켓 과 Out-of-band data 관계 • TCP스트림 • 특징 • 완전한 순차적인 데이터 바이트를 보냄 • Out-of-band 데이터를 보낼 수 없음 • “Urgent” data 제공 • 해결책 • Urgent data의 개념으로 out-of-band 데이터로서 소켓API 사용 • 소켓과 out-of-band data • Out-of-band data를 사용하기 위해 소켓사용

  6. Variations in implementation • 긴급한 데이터 조작되어지는 방법 • RFC793 해석 • BSD 해석(Linux default) • 대부분의 실행은 BSD 소스코드에 근거 • 오늘날 공통적으로 사용 • 리눅스 시스템 사항 확인 및 설정 $ cat /proc/sys/net/ipv4/tcp_stdurg 0 $ 만약 위와 같이 0이 나온다면 BSD 해석으로 긴급한 데이터가 조작됨 만약 1 이 나온다면 RFC793 해석으로 긴급한 데이터가 조작됨

  7. Out-of-band data 사용(1) • writing out-of-band data • 송신하기 위한 함수 • Send()함수 • send()함수 이해 #include<sys/types.h> #include<sys/socket.h> Int send(int s, const void *msg, int len, unsigned int flags); ※해석 s : 데이터를 전송할 소켓번호 msg : 전송할 데이터가 저장된 버퍼 len : 버퍼의 크기 flags : 데이터가 보내어지는 방법에 영향 value: ① 0 : write()함수와 같은 역할 ②MSG_OOB : out-of-band data를 보냄. ③MSG_DONTROUTE : 프로토콜의 라우팅 조건을 전혀 무시하고 메시지가 보내어짐. (가장 빠른 경로가 아니라 가장 직선적인 경로를 통해 보내지는 것 의미) 반환값 : 정상적 처리 : 전송된 테이터 크기를 바이트단위로 리턴 error : -1값을 리턴

  8. Out-of-band data 사용(2) • reading out-of-band data • 수신하기 위한 함수 • recv()함수 • recv()함수 이해 #include<sys/types.h> #include<sys/socket.h> Int recv(int s, void *buf, int len, unsigned intflags); ※해석 s : 데이터를 수신할 소켓번호 msg : 수신할 데이터가 저장될 버퍼 len : 버퍼의 크기 flags : 데이터를 받을 수 있는 방법에 영향 value: ① 0 : write()함수와 같은 역할 ② MSG_OOB : out-of-band data만 받음 (정상적 데이터는 통과) ③ MSG_PEEK : 프로세스는 실제로 데이터를 받지않고도 데이터를 볼수 있음. ④ MSG_WAITALL : 완전한 양의 데이터를 얻을수 있을 때에만 recv 호출로부터 복귀 반환값 : 정상적 처리 : 수신된 테이터 크기를 바이트단위로 리턴 error : -1값을 리턴

  9. Out-of-band data 사용(3) • Out-of-band data 수신방법 • Out-of-band data 개별적 수신 • In-band data 와 혼합적으로 수신

  10. Out-of-band data 사용(4) • Understanding the signal SIGURG • Receiving process • Out-of-band data가 받아질 때 인지되기 위해 필요 • SIGURG signal • 소켓에 높은 대역폭의 자료가 이용 가능함. • 프로세스에게 네트워크 연결이 긴급하거나 대역을 벗어난(out-of-band) 데이터가 수신되었음을 알림. • SIGURG signal 사용위한 요구사항 • 소켓의 소유권 확립 • fcntl()함수 사용 • SIGURG 에 대한 signal handler 확립 • 프로그램이 SIGURG를 받기 위해 준비되어 있어야 함

  11. Out-of-band data 사용(5) • fcntl()함수 이해 #include<unistd.h> #include<fcntl.h> Int fcntl(int fd, int cmd, long arg); ※해석 fd : 파일기술자 또는 소켓(fcntl은 fd에 의해 식별되는 개방된 파일에 대해서 동작) cmd : 특정기능 선택 (cmd의 값을 헤더화일<fcntl.h>로 부터 고름) value : F_SETOWN : 소켓을 성공적으로 확립했을 때 0값을 리턴 arg : 설정을 위한값 (프로세스 식별번호) 반환값 : 정상적 처리 : 0 error : -1 예 : int fcntl(s, F_SETOWN, getpid());

  12. Out-of-band data 사용(6) • Supporting Subprograms • 예제 14.1 bindacpt.c • Socket() 함수 • 주소 종류, 스트림형 또는 데이터 그램형의 소켓의 타입 그리고 프로토콜을 지정하여 소켓을 생성 • 리턴값 • 성공 : 새로 만들어진 소켓번호 • 실패 : -1 • Bind() 함수 • 소켓번호 와 소켓주소 구조체를 연결 • 리턴값 • 성공 : 0 • 실패 : -1 • Listen() 함수 • 서버에서 스트림 소켓 s를 연결을 기다리는 상태로 만든다. Listen()을 호출하기 전에 소켓은 반드시 bind()되어 있어야 한다. 동시에 지정한 수만큼의 연결요청을 대기시켰다가 accept가 되는 대로 차례로 연결을 처리한다. • 리턴값 • 성공 : 0 • 실패 : -1

  13. Out-of-band data 사용(7) • Accept() 함수 • 서버에서 클라이언트의 연결요청을 수락하기 위하여 listen()을 호출 한 후에 호출되며, 성공시 새로운 소켓이 만들어진다. 새로 만들어지는 소켓은 소켓 s와 같은 속성을 가진다. Accept()가 성공적으로 수행된 후 소켓 s는 다시 listen 상태로 돌아간다. 즉, 새로운 accept()를 처리할 수 있게 된다. • 리턴값 • 성공 : 새로 만들어진 소켓번호 • 실패 : -1 • Mkaddr() 함수 • 주소를 생성하기 위한 함수 • 리턴값 • 성공: 0 • 에러 : -1 : 문자열의 호스트 부분의 이상, unknown host name -2: 포트 넘버 이상, 알려지지 않은 서비스 이름 • Bail() 함수 • 에러를 보고하고, 프로그램의 위험을 회피하기 위한 함수

  14. Out-of-band data 사용(8) • Bindaccept() 함수 • 소켓을 생성하고 주소를 결합하기 위한 함수 • create, bind, listen, accept 모두 조작 • Connect() 함수 • 소켓을 생성하고 원격서버에 연결하기 위한 함수로 스트림(TCP)으로 개설된 소켓번호를 상대방 호스트와 연결되도록 시도 • 리턴값 • 성공 : 0 • 실패 : -1

  15. 함수선언/초기화 데이터 수신 소켓생성 / 서버주소연결 Z값 z=-1 z=0 other 소유권 확립 에러 break 수신 데이터 출력 SIGURG 신호감지 소켓 종료 Out-of-band data 사용(9) • Receiving with the SIGURG signal • 예제 14.2 oobrecv.c • 순서도

  16. Out-of-band data 사용(10) • 소스분석 • 함수 선언 (line 15-37) • extern void bail(char *on_what); //에러발생시 에러보고 (line 15) • extern int bindAccept(char *addr); //소켓을 생성하고 주소를 결합 (line 16) • static int s=-1; //소켓 (line 18) • static void sigurg(int signo); //SIGURG signal handler (line 23-37) • 초기화 (line 41-42) • int z; //상태를 나타내기 위한 변수 (line 41) • char buf[256]; //수신데이터를 위한 버퍼 (line 42) int n; char buf[256]; n=recv(s,buf,sizeof buf,MSG_OOB); if(n<0) bail(“recv(2)”); Buf[n]=0; Printf(“URG ‘%s’ (%d)\n”, buf, n); Signal(SIGURG, sigurg);

  17. Out-of-band data 사용(11) • 소켓생성 및 서버 주소 연결 • S=BindAccept(arqc>=2 ? argv[1] : ”127.0.0.1:9011”); (line 52-54) • 소켓 소유권 확립 • Z=fcntl(s, F_SETOWN, getpid()); (line 59) • SIGURG 신호 감지 • Signal(SIGURG, sigurg); (line 66) • 데이터 수신 • Z=recv(s, buf, sizeof buf, 0); (line 69) • 수신데이터 출력 • Printf(“rcv ‘%s’ (%d)\n”, buf, z);(line 76) • 소켓 종료 • Close(s); (line 80)

  18. Out-of-band data 사용(12) • Sending out-of-band data • 예제 14.3 oobsend.c • 순서도 함수선언/초기화 out-of-band 데이터 송신 소켓생성 / 상대방 과 연결 Sleep(1)함수 호출 in-band 데이터 송신 in-band 데이터 송신 sleep(1)함수호출 소켓 종료

  19. Out-of-band data 사용(13) • 소스분석 • 함수 선언 • extern void bail(char *on_what); //에러발생시 에러보고 (line 13) • extern int Connect(char *addr); //소켓을 생성하고 원격서버에 연결 (line 14) • Static void iband(ints, char *str) //in-band 데이터 송신 (line 19-28) • Static void oband(int s, char*str) //out-of-band 데이터 송신 (line 33-42) int z; Z=send(s,str,strlen(str),0); If(z==-1) bail(“send(2)”); Printf(“ib : ‘%s’ (%d)\n”,str, z); int z; Z=send(s,str,strlen(str),MSG_OOB); If(z==-1) bail(“send(2)”); Printf(“OOB : ‘%s’ (%d)\n”,str, z);

  20. Out-of-band data 사용(14) • 초기화 • int s =-1; //소켓 (line 46) • 소켓생성 및 상대방과 연결 • s=Connect(arqc>=2 ? Argv[1] : “127.0.0.1:9011”); (line 48-50) • in-band 데이터 송신 (line 52-59) • iband(s, “In the beginning”); • sleep(1);//프로세스를 1초동안 쉬게 함 • iband(s, “Linus begat Linux,”); • sleep(1);//프로세스를 1초동안 쉬게 함 • iband(s, “and the Penguins”); • sleep(1);//프로세스를 1초동안 쉬게 함 • out-of-band 데이터 송신 (line 61-62) • oband(s, “rejoiced”); • sleep(1); • in-band 데이터 송신 (line 64) • iband(s, “exceedingly.”); • 소켓종료 • close(s); (line 65)

  21. Out-of-band data 사용(15) • oobrecv and oobsend programs 실행 • 실행 $ ./oobrecv (default : local loopback address “127.0.0.1:9011”) $ ./oobsend

  22. Out-of-band data 사용(16) • 결과-BSD해석 $ ./oobsend ib: ‘In the beginning’ (16) ib: ‘Linus begat Linux,’ (18) ib: ‘and the penguins’ (16) OOB ‘rejoiced’ (8) ib: ‘exceedingly.’ (12) $ ./oobrecv rcv ‘In the beginning’ (16) rcv ‘Linus begat Linux,’ (18) rcv ‘and the penguins’ (16) URG ‘d’(1) rcv ‘rejoice’ (7) rcv ‘exceedingly.’ (12)

  23. send (s, “rejoiced”, 8, MSG_00B) r e j o i c e d Offset=0 RFC793 Urgent pointer (offset=7) BSD(Linux) Urgent pointer (offset=8) Tcp_stdurg=1 Tcp_stdurg=0 Understanding the Urgent Pointer(1) • Understanding TCP Urgent Mode

  24. URG=1 Urgent Pointer=8 r e j o i c e d TCP header Packet Data Offset=0 BSD(Linux) Urgent pointer (offset=8) tcp_stdurg=0 Understanding the Urgent Pointer(2)

  25. Understanding the Urgent Pointer(3) • Urgent Mode When tcp_stdurg=1 • Urgent mode 가 종종 들어 올 때 그것에 반응하는 urgent-pointer는 읽혀지기 위해 urgent data없이 수신 • 패킷안에 포함되어 있는 마지막 바이트에서 urgent pointer가 발생되어질 때 뒤따라오고 있는 바이트는 수신되지 않을지도 모름 • No urgent data가 read되어질 수 있도록 errno값 EAGAIN 리턴(몇몇 유닉스장치 : EWOULDBLOCK)

  26. Receiving Out-of-Band data Inline(1) • in-band 데이터 와 out-of-band 데이터 혼합수신 • 소켓옵션 설정 int z; //status int s; //socket int oobinline=1; //true z=setsockopt(s, SOL_SOCKET, SO_OOBINLINE, &oobinline, sizeof oobinline); ※해석 s : 소켓번호 SOL_SOCKET : 프로토콜 레벨 지정(보통 SOL_SOCKET 지정) SO_OOBINLINE : 선택할 옵션 지정(OOB 데이터를 일반 데이터처럼 읽음) &oobinline : 지정된 옵션 값이 저장된 버퍼의 포인터(값이 1이면 선택, 0이면 취소) oobinline : 지정된 옵션 값이 저장된 버퍼의크기 반환값 : 정상적 처리 : 0 error : -1 ※주의 : recv()함수 호출시 MSG_OOB 설정할 필요없음. 만약 설정후 호출한다면 EINVAL 에러발생

  27. Receiving Out-of-Band data Inline(2) • Determining the Urgent Pointer • ioctl()함수 #include <sys/ioctl.h> … int z; //status int s; //socket int flag; //true when at mark z=ioctl(s,SIOCATMARK,&flag); if (z==-1) abort();/* 호출하는 프로그램이 비정상 종료하여 코어를 덤프 하도록 SIGABRT 시그널을 보냄 잘못되었을 때 프로세스가 현재 상태를 기록할 수 있도록 하기위해 */ if (flag !=0) puts(“At Mark”); else puts(“Not at mark.”);

  28. 소켓 옵션 설정 함수선언/초기화 소켓생성 / 서버주소 연결 Socketmark 출력 데이터 수신 소켓 소유권 확립 에러 break 수신데이터 출력 SIGURG 감지 소켓 종료 Receiving Out-of-Band data Inline(3) • Using Out-of-Band data Inline • 예제 14.4 oobinline.c • 순서도 Z=-1 Z=0

  29. Receiving Out-of-Band data Inline(4) • 소스분석 • 함수 선언 • extern void bail(char *on_what); //에러발생시 에러보고 (line 16) • extern int BindAccept(char *addr); //소켓을 생성하고 주소결합 (line 17) • Static void sigurg(int signo) //SIGURG signal handler (line 22-27) • Static int sockatmark(int s) // 소켓표시 (line 33-42) write(1,”[SIGURG]\n”,9); signal(SIGURG,sigurg); int z; int flag; z=ioctl(s,SIOCATMARK,&flag); if(z==-1) return –1; return flag ? 1 : 0;

  30. Receiving Out-of-Band data Inline(5) • 초기화 (line 46-49) • int z; //상태표시 • int s; //소켓 • int oobinline=1; //OOB inline • char buf[256]; • 소켓생성 및 서버주소연결 • s=BindAccept(argc>=2 ? Argv[1] : “127.0.0.1:9011”); (line 59-61) • 소켓 소유권 확립 • Z=fcntl(s, F_SETOWN, getpid()); (line 66) • SIGURG 감지 • Signal(SIGURG,sigurg); (line 73) • 소켓옵션 설정 (line 78-82) • Z=setsockopt(s, SOL_SOCKET, SO_OOBINLINE,&oobinline,sizeof oobinline); • Sockatmark 출력 • Printf(“\n[%s]\n”, Socketmark(s) ? “AT MARK” : “No Mark”); (line 87-90) • 데이터 수신 • z=recv(s, buf, sizeof buf, 0) (line 92) • 수신데이터 출력 • Printf(“rcv ‘%s’ (%d)\n”, buf, z); (line 99-100) • 소켓종료 • close(s); (line 103)

  31. Receiving Out-of-Band data Inline(6) • 실행 $ ./oobsend $ ./oobinline

  32. Receiving Out-of-Band data Inline(7) • 실행 결과-BSD $ ./oobsend ib: ‘In the beginning’ (16) ib: ‘Linux begat Linux,’ (18) ib: ‘and the penguins’ (16) OOB ‘rejoiced’ (8) ib: ‘exceedingly.’ (12) $ $ ./oobinline [No Mark] rcv ‘In the beginning’ (16) [No Mark] rcv ‘Linux begat Linux,’ (18) [No Mark] rcv ‘and the penguins’ (16) [No Mark] [SIGURG] rcv ‘rejoice’ (7) [AT Mark] rcv ‘d’ (1) [No Mark] rcv ‘exceedingly.’ (12) [No Mark] $

  33. Limitations of the Urgent Mode Pointer(1) • 제한점 • TCP 프로토콜 • out-of-band 데이터의 한 바이트로 제공되어짐 • TCP의 urgent 모드를 사용하여 수행되어지기 때문 • TCP urgent mode 와 TCP urgent pointer • Urgent data의 경계를 표시할 수 없음 • 실험 • oobsend.c 프로그램 수정 • sleep()함수 제거 • oband(s,”very”) 함수 추가

  34. Limitations of the Urgent Mode Pointer(2) • oobsend.c 수정 int main(int argc, char **argv){ int s=-1; s=connect(argc >=2 ? argv[1] : “127.0.0.1:9011”); iband(s,”In the beginning”); iband(s,”Linus begat Linux,”); iband(s,”and the Penguins”); oband(s,”rejoiced”); oband(s,”very”); iband(s,”exceedingly.”); close(s); return 0; }

  35. Limitations of the Urgent Mode Pointer(3) • 실행 결과-BSD $ ./oobsend ib: ‘In the beginning’ (16) ib: ‘Linus begat Linux,’ (18) ib: ‘and the penguins’ (16) OOB ‘rejoiced’ (8) OOB ‘very’ (4) ib: ‘exceedingly.’ (12) $ $ ./oobinline [No Mark] Rcv ‘In the beginning’ (16) [No Mark] Rcv ‘Linus begat Linux,’ (18) [No Mark] [SIGURG] Rcv ‘and the penguinsrejoicedver’ (27) [At Mark] Rcv ‘yexceedingly.’ (13) [No Mark] $

  36. Limitations of the Urgent Mode Pointer(4) • Processing out-of-band data with select(2) • select() 함수 호출 • select()함수가 호출되는 동안을 제외하고 out-of-band 데이터의 도착을 인식 • select()함수 방해 • A read event • A write event • An exception

  37. 요약

More Related