{"id":347367,"date":"2023-03-27T21:00:18","date_gmt":"2023-03-27T21:00:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=347367"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=347367","title":{"rendered":"<span>\u041a\u043e\u0433\u0434\u0430 \u043e\u0434\u0438\u043d TCP-\u043f\u043e\u0440\u0442 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u0435\u043b\u0451\u043d<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u044b \u0437\u0430\u043c\u0435\u0447\u0430\u043b\u0438, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c? \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u0434\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432. \u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u2013 \u043d\u0430\u0448\u0430 \u043b\u044e\u0431\u0438\u043c\u0430\u044f: \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b Linux. <\/p>\n<h2>\u041a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 TCP-\u0441\u043e\u043a\u0435\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441?   <\/h2>\n<p>\u0415\u0441\u043b\u0438 \u044f \u043f\u0435\u0440\u0435\u0439\u0434\u0443 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435\u00a0<a href=\"https:\/\/blog.cloudflare.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/blog.cloudflare.com\/<\/a>, \u043c\u043e\u0439 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 TCP-\u0430\u0434\u0440\u0435\u0441\u0443, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c 104.16.132.229:443. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0439\u0434\u0451\u0442 \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 Linux, \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 TCP-\u043f\u043e\u0440\u0442, \u0441\u043a\u0430\u0436\u0435\u043c, 192.0.2.42:54321. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u044f \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u0448\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0430\u0439\u0442? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0435 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043f\u043e\u0440\u0442\u0430?<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0434\u0430\u0432\u0430\u0439\u0442\u0435\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Discovery_learning\" rel=\"noopener noreferrer nofollow\">\u0432\u044b\u044f\u0441\u043d\u0438\u043c \u0435\u0433\u043e \u043e\u043f\u044b\u0442\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c<\/a>. \u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u0432\u043e\u0441\u0435\u043c\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432-\u0437\u0430\u0434\u0430\u0447\u0435\u043a. \u041e\u0442\u0432\u0435\u0442\u0438\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445, \u0432\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0442\u0435\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u0447\u0442\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 TCP-\u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438 \u043f\u043e\u0434 Linux. \u0427\u0435\u0441\u0442\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u0435\u043c: \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0439\u0442\u0438 \u0443\u043c \u0437\u0430 \u0440\u0430\u0437\u0443\u043c.<\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0434\u0432\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7c5\/06b\/e1f\/7c506be1fb66ebf0791619248f2ef488.png\" width=\"881\" height=\"461\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7c5\/06b\/e1f\/7c506be1fb66ebf0791619248f2ef488.png\"\/><\/figure>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430 \u043d\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435 IP \u0438 \u043f\u043e\u0440\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438 \u043f\u043e\u0440\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0438\u043b\u0438, \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0442\u043e\u043b\u044c\u043a\u043e IP-\u0430\u0434\u0440\u0435\u0441.<\/p>\n<p>\u041e\u0442\u0432\u0435\u0447\u0430\u044f \u043d\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445:<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0442\u044c \u041e\u0421 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438\/\u0438\u043b\u0438 \u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u0441\u043e\u043a\u0435\u0442\u0430 \u0438\u043b\u0438 <\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 \u042f\u0432\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/bind.2.html\" rel=\"noopener noreferrer nofollow\">bind()<\/a>, \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f\u00a0(<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/connect.2.html\" rel=\"noopener noreferrer nofollow\">connect()<\/a>) \u043a \u0441\u043e\u043a\u0435\u0442\u0443; \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<a href=\"https:\/\/idea.popcount.org\/2014-04-03-bind-before-connect\/\" rel=\"noopener noreferrer nofollow\">bind-before-connect<\/a>.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 <code>bind()<\/code>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0442\u044c \u0432\u0441\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u0430\u0440\u044b (IP, \u043f\u043e\u0440\u0442). \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0431\u044b\u043b\u043e \u0431\u044b\u00a0<a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/networking\/ip-sysctl.html?#ip-variables\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/a>\u00a0\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u041e\u0421 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u043a\u0435\u0442\u0430\u043c: \u00a0<\/p>\n<pre><code>sysctl -w net.ipv4.ip_local_port_range='60000 60000'<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435-\u0437\u0430\u0433\u0430\u0434\u043a\u0435 \u0432\u0430\u0441 \u0436\u0434\u0451\u0442 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043d\u0430 Python. \u0412\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u2013 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u043e\u0433 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u043a\u043e\u0434 \u0443\u0441\u043f\u0435\u0448\u043d\u043e? \u0418\u043b\u0438 \u043d\u0435\u0442? \u0421\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c ChatGPT \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f ?.<\/p>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u0434\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c. \u0414\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \u043c\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u0435\u0451 \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cmake\">from os import system from socket import *  # \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b IP_BIND_ADDRESS_NO_PORT = 24  # \u0412 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0451\u043d \u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0442\u0438 \u0432\u0441\u0435\u0433\u043e *\u043e\u0434\u0438\u043d* \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 system(\"sysctl -w net.ipv4.ip_local_port_range='60000 60000'\")  # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u043a\u0435\u0442 \u043f\u043e *:1234. \u0418\u043c\u0435\u043d\u043d\u043e \u043a \u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f. ln = socket(AF_INET, SOCK_STREAM) ln.bind((\"\", 1234)) ln.listen(SOMAXCONN)<\/code><\/pre>\n<p>\u0418\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u044d\u0442\u0438\u0445 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u0430\u0447\u043d\u0451\u043c. \u041d\u0430 \u0441\u0442\u0430\u0440\u0442, \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u0430\u0440\u0448!   <\/p>\n<h2>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 #1: \u041a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d, \u043d\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f   <\/h2>\n<p>\u0412 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 #1 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443: 127.9.9.9:1234. \u042d\u0442\u0438 \u0441\u043e\u043a\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430?   <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">127.0.0.1<br \/>127.1.1.1<br \/>127.2.2.2<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">60_000<\/p>\n<\/td>\n<td>\n<p align=\"left\">127.9.9.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">1234<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #1   <\/h2>\n<p>\u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043a \u0440\u0430\u0437\u043d\u044b\u043c, \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u041e\u0421 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442. \u041f\u043e\u043c\u043d\u0438\u0442\u0435: \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u043e\u0432 \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0440\u0442 (60 000).   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.1.1.1', 0)) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.2.2.2', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_1.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #1<\/a>   <\/p>\n<pre><code class=\"cmake\">#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #1 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.2.2.2', 0)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.2.2.2', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #2   <\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u043a\u0430\u044f \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0437\u0430\u0433\u0430\u0434\u043a\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u041e\u0421 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0438 \u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430. \u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0437\u0430\u0433\u0430\u0434\u043a\u0435?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.2.2.2', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_2.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #2<\/a>.<\/p>\n<pre><code class=\"cmake\">#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #2 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.2.2.2', 0)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.2.2.2', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #3   <\/h2>\n<p>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u043e\u0447\u043d\u043e, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f. \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043e\u043a\u0435\u0442\u0443 \u0441 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e, \u0432\u0435\u0440\u043d\u043e?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.1.1.1', 0)) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_3.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #3<\/a>.  <\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #3 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234))  >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) Traceback (most recent call last):   ... OSError: [Errno 99] Cannot assign requested address  Outcome: FAILURE. Local port can't be shared.  Cleanup:  >>> p1, _ = ln.accept() >>> p1.close() # TIME-WAIT on server side  >>> s1.close() >>> s2.close()  Solution #3 -----------  Use `IP_BIND_ADDRESS_NO_PORT` socket option.  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared when using `IP_BIND_ADDRESS_NO_PORT` option.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 #2: \u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438 \u043f\u043e\u0440\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b, \u043d\u043e \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f   <\/h2>\n<p>\u0412 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 #2 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 IP \u0438 \u043e\u0434\u0438\u043d \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441, \u0430 \u043e\u0434\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 <code>127.0.0.1:60000<\/code>\u00a0\u0438 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u0430. \u0412\u0441\u0451 \u0442\u043e\u0442 \u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441: \u043c\u043e\u0433\u0443\u0442 \u043b\u0438 \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442? \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e: \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u043e\u0432 \u0443 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0432\u0435\u043d \u0435\u0434\u0438\u043d\u0438\u0446\u0435.   <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">127.0.0.1<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">60_000<\/p>\n<\/td>\n<td>\n<p align=\"left\">127.8.8.8<br \/>127.9.9.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">1234<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #4   <\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0430\u0437\u043e\u0432. \u041c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f\u00a0(connect()) \u043a \u0434\u0432\u0443\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u043c \u0430\u0434\u0440\u0435\u0441\u0430\u043c. \u042d\u0442\u043e \u0434\u043b\u044f \u0437\u0430\u0442\u0440\u0430\u0432\u043a\u0438 ?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_4.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #4<\/a>.<\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #4 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local (IP, port) is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #5   <\/h2>\n<p>\u0427\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f\u0432\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f\u00a0(<code>bind()<\/code>) \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c IP, \u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u041e\u0421 \u0441\u0430\u043c\u043e\u0439 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0440\u0442 \u2013 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0447\u0442\u043e-\u043b\u0438\u0431\u043e?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.0.0.1', 0)) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.0.0.1', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_5.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #5<\/a>.   <\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #5 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.0.0.1', 0)) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.0.0.1', 0)) Traceback (most recent call last):   ... OSError: [Errno 98] Address already in use >>>  Outcome: FAILURE. Local (IP, port) can't be shared.  Cleanup:  >>> p1, _ = ln.accept() >>> p1.close() # TIME-WAIT on server side >>> s1.close() >>> s2.close()  Solution #5 -----------  Use `IP_BIND_ADDRESS_NO_PORT` socket option.  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1) >>> s1.bind(('127.0.0.1', 0)) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.setsockopt(SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1) >>> s2.bind(('127.0.0.1', 0)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local (IP, port) is shared when using `IP_BIND_ADDRESS_NO_PORT`.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #6<\/h2>\n<p>\u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043c\u044b \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0436\u0435\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0438 \u043f\u043e\u0440\u0442. \u0418\u043d\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442.   <\/p>\n<pre><code>s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.0.0.1', 60_000)) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.0.0.1', 60_000)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_6.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #6<\/a>.<\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #6 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.0.0.1', 60_000)) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.0.0.1', 60_000)) Traceback (most recent call last):   ... OSError: [Errno 98] Address already in use >>>  Outcome: FAILURE. Local (IP, port) can't be shared.  Cleanup:  >>> p1, _ = ln.accept() >>> p1.close() # TIME-WAIT on server side >>> s1.close() >>> s2.close() >>>  Solution #6 -----------  Use `SO_REUSEADDR` socket option.  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s1.bind(('127.0.0.1', 60_000)) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s2.bind(('127.0.0.1', 60_000)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local (IP, port) is shared when using `SO_REUSEADDR`.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #7   <\/h2>\n<p>\u041d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043b\u0430\u0433\u0430\u043b\u0438, \u0447\u0442\u043e \u0441\u0442\u0440\u0430\u043d\u044c\u0448\u0435 \u0431\u044b\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u2013 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u044d\u0442\u0443 \u0441\u043c\u0435\u0441\u044c <a href=\"https:\/\/manpages.debian.org\/unstable\/manpages\/socket.7.en.html#SO_REUSEADDR\" rel=\"noopener noreferrer nofollow\">SO_REUSEADDR<\/a>.<\/p>\n<p>\u0421\u043f\u0435\u0440\u0432\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u041e\u0421, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u0432\u044b\u0434\u0435\u043b\u0438\u043b\u0430 \u0434\u043b\u044f \u043d\u0430\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441. \u0417\u0430\u0442\u0435\u043c<br \/> \u044f\u0432\u043d\u043e \u0441\u0432\u044f\u0436\u0435\u043c\u0441\u044f \u0441 \u0442\u0435\u043c \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0430\u0434\u0440\u0435\u0441\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u0437\u043d\u0430\u0435\u043c, \u041e\u0421 \u043e\u0431\u044f\u0437\u0430\u043d\u0430<br \/> \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u043e\u043c\u0443 \u0441\u043e\u043a\u0435\u0442\u0443. \u041c\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439<br \/> \u0430\u0434\u0440\u0435\u0441 \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432. \u042d\u0442\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043e?<\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s2.bind(('127.0.0.1', 60_000)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_7.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #7<\/a>.<\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #7 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s2.bind(('127.0.0.1', 60_000)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local (IP, port) is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #8   <\/h2>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u0438\u0448\u0435\u043d\u043a\u0430 \u043d\u0430 \u0442\u043e\u0440\u0442\u0435. \u042d\u0442\u0430 \u0437\u0430\u0433\u0430\u0434\u043a\u0430 \u2013 \u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043a \u0438 #7, \u043d\u043e \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u0417\u0434\u0440\u0430\u0432\u044b\u0439 \u0441\u043c\u044b\u0441\u043b \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u043c\u043d\u0435\u043d\u0438\u0439, \u0447\u0442\u043e \u043e\u0442\u0432\u0435\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0442\u043e\u0447\u043d\u043e \u043a\u0430\u043a \u0432 #7, \u043d\u043e \u0442\u0430\u043a \u043b\u0438 \u044d\u0442\u043e?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s1.bind(('127.0.0.1', 60_000)) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) s2.connect(('127.8.8.8', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_8.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #8<\/a>.  <\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #8 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s1.bind(('127.0.0.1', 60_000)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s2.connect(('127.8.8.8', 1234)) Traceback (most recent call last):   ... OSError: [Errno 99] Cannot assign requested address >>>  Outcome: FAILURE. Local (IP, port) can't be shared.  Cleanup:  >>> s1.close() >>> s2.close()  Solution #8 -----------  There is NONE.  \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<p><strong>\u0422\u0430\u0439\u043d\u0430\u044f \u0436\u0438\u0437\u043d\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e TCP-\u043f\u043e\u0440\u0442\u0430 \u2013 \u0432 \u0442\u0440\u0451\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f\u0445<\/strong> <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u0432\u0441\u0451 \u043f\u043e\u043d\u044f\u0442\u043d\u043e? \u041c\u044b \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u043c\u0441\u044f \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u0447\u0451\u0440\u043d\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430. \u041f\u043e\u0436\u0430\u043b\u0443\u0439, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u043a\u0430\u043a \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0447\u0435\u0440\u043d\u043e\u0433\u043e \u044f\u0449\u0438\u043a\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u0436\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u043a\u0443\u043b\u0438\u0441\u0430\u043c\u0438? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0443\u0434\u0430 \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c.<\/p>\n<p>Linux \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 TCP-<strong>\u043f\u043e\u0440\u0442\u044b<\/strong>\u00a0\u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/include\/net\/inet_hashtables.h#L166\" rel=\"noopener noreferrer nofollow\">bhash<\/a>. \u041d\u0435 \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0439\u0442\u0435 \u0435\u0451 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 <a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/include\/net\/inet_hashtables.h#L156\" rel=\"noopener noreferrer nofollow\">ehash<\/a>; \u0432 \u043d\u0435\u0439 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f <strong>\u0441\u043e\u043a\u0435\u0442\u044b<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u044b \u043a\u0430\u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435, \u0442\u0430\u043a \u0438 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/187\/a10\/905\/187a10905db61f3a33fd82d52bb30ebb.png\" width=\"1600\" height=\"585\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/187\/a10\/905\/187a10905db61f3a33fd82d52bb30ebb.png\"\/><\/figure>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0445\u0435\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u00ab\u043a\u043e\u0440\u0437\u0438\u043d \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438\u00bb (bind bucket). \u0412 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441\u043e\u043a\u0435\u0442\u044b, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u043e\u0434\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442. \u0422\u043e\u0447\u043d\u0435\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0441\u043e\u043a\u0435\u0442\u044b \u0433\u0440\u0443\u043f\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c:<\/p>\n<ul>\n<li>\n<p> \u0421\u0435\u0442\u0435\u0432\u043e\u0435 <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/network_namespaces.7.html\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d,<\/a>\u00a0\u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043e\u0442\u043d\u043e\u0441\u044f\u0442\u0441\u044f \u0438<\/p>\n<\/li>\n<li>\n<p> \u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e\u00a0<a href=\"https:\/\/docs.kernel.org\/networking\/vrf.html\" rel=\"noopener noreferrer nofollow\">VRF<\/a>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u044b, \u0438<\/p>\n<\/li>\n<li>\n<p> \u041d\u043e\u043c\u0435\u0440 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u043e \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0430\u044f \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u2014 \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u043e \u0441\u0435\u0442\u0435\u0432\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u0438\u043c\u0451\u043d, \u043d\u0438\u043a\u0430\u043a\u0438\u0445 VRF \u2013 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u043e\u043a\u0435\u0442\u044b \u0441\u0433\u0440\u0443\u043f\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043f\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u043f\u043e\u0440\u0442\u0430.<\/p>\n<p>\u041d\u0430\u0431\u043e\u0440 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0432 \u043a\u0430\u0436\u0434\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438, \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442, \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0432\u044f\u0437\u043d\u044b\u043c \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0434\u0430\u0442\u0435\u043b\u0435\u0439.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u0438\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u044f\u0434\u0440\u0443 \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0441\u043e\u043a\u0435\u0442\u0443, \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430<br \/> \u2013 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u043b\u0438 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442 \u0441 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u0441\u043e\u043a\u0435\u0442\u043e\u043c. \u0414\u0435\u043b\u043e \u0432<br \/> \u0442\u043e\u043c, \u0447\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043d\u043e\u043c\u0435\u0440 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430 \u043c\u043e\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043f\u0440\u0438 \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0438\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/include\/net\/inet_hashtables.h#L43\" rel=\"noopener noreferrer nofollow\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439<\/a>:<\/p>\n<pre><code>\/* \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u0441\u043b\u0435\u0434\u0443\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0434\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442   * \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438.  \u0412 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438:  *  *   1) \u0421\u043e\u043a\u0435\u0442\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438, \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442   *      \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u2013 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0442\u0435\u0441\u0442\u0443 2.  *   2) \u0415\u0441\u043b\u0438 \u0443 \u0432\u0441\u0435\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0435\u0441\u0442\u044c \u043d\u0430\u0431\u043e\u0440 sk->sk_reuse, \u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438  *      TCP_LISTEN, \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u0430.  *      \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u2013 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043a \u0442\u0435\u0441\u0442\u0443 3.  *   3) \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u043a\u0435\u0442\u044b \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0430\u0434\u0440\u0435\u0441\u043e\u043c inet_sk(sk)->rcv_saddr, \u0438  * \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0445 \u0441\u0440\u0435\u0434\u0438 \u043d\u0438\u0445 \u043d\u0435\u0442, \u0442\u043e \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u0430  *      \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u0442\u043e \u043f\u043e\u0440\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f.  *  * \u0417\u0434\u0435\u0441\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0442\u0435\u0441\u0442 #2.  \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0438\u043c \u0432\u0435\u0441\u044c \u0434\u0435\u043d\u044c \u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f FTP-\u0441\u0435\u0440\u0432\u0435\u0440.  * \u0427\u0442\u043e\u0431\u044b \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0441\u043b\u0443\u0447\u0430\u0439, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u0444\u043b\u0430\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u0442, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0439 \u043d\u0438\u0436\u0435.    * \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0441\u043e\u043a\u0435\u0442\u044b \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438, \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c:   * (newsk->sk_reuse &amp;&amp; (newsk->sk_state != TCP_LISTEN))  * \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u043a\u0435\u0442\u044b \u0438\u0437 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043f\u0440\u043e\u0439\u0434\u0443\u0442 \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442,   * \u0431\u0443\u0434\u0435\u0442 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0444\u043b\u0430\u0433\u043e\u0432\u044b\u0439 \u0431\u0438\u0442.  * ...  *\/<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u0438\u0437 \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f, \u044f\u0434\u0440\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043a\u043e\u0434 \u0432 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 \u043d\u0430 \u043e\u043f\u0442\u0438\u043c\u0438\u0441\u0442\u0438\u0447\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439: \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0430 \u043d\u0435\u0442. \u041f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u044b \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0445\u0441\u044f \u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u0440\u0437\u0438\u043d\u0435:   <\/p>\n<pre><code class=\"cmake\">struct inet_bind_bucket {         \/* ... *\/         signed char          fastreuse;         signed char          fastreuseport;         kuid_t               fastuid; #if IS_ENABLED(CONFIG_IPV6)         struct in6_addr      fast_v6_rcv_saddr; #endif         __be32               fast_rcv_saddr;         unsigned short       fast_sk_family;         bool                 fast_ipv6_only;         \/* ... *\/ };<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u043c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043e\u0432\u043e\u043a\u0443\u043f\u043d\u043e\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 &#8212;\u00a0fastreuse. \u041e\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 Linux \u0441\u043e \u0432\u0440\u0435\u043c\u0451\u043d \u043d\u044b\u043d\u0435 \u0434\u043e\u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 2.1.90pre1. \u041a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438, \u0438\u0441\u0445\u043e\u0434\u043d\u043e \u0432 \u0444\u043e\u0440\u043c\u0435 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/history\/history.git\/tree\/include\/net\/tcp.h?h=2.1.90pre1&amp;id=9d11a5176cc5b9609542b1bd5a827b8618efe681#n76\" rel=\"noopener noreferrer nofollow\">\u0444\u043b\u0430\u0433\u043e\u0432\u043e\u0433\u043e \u0431\u0438\u0442\u0430<\/a>, \u0430 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u043e\u043d \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u0432 \u043f\u043e\u043b\u0435, \u0440\u0430\u0437\u043c\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0430\u0439\u0442\u0430\u0445.<\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0448\u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0435\u0439 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u043e\u0437\u0436\u0435 \u0441 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/torvalds\/linux.git\/commit\/?id=da5e36308d9f7151845018369148201a5d28b46d\" rel=\"noopener noreferrer nofollow\">SO_REUSEPORT\u00a0\u0432 Linux 3.9<\/a>. \u0412\u0435\u0434\u044c \u043e\u043d\u0438 \u0438\u0433\u0440\u0430\u044e\u0442 \u0440\u043e\u043b\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0444\u043b\u0430\u0433\u00a0<a href=\"https:\/\/manpages.debian.org\/unstable\/manpages\/socket.7.en.html#SO_REUSEPORT\" rel=\"noopener noreferrer nofollow\">SO_REUSEPORT<\/a>. \u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0438\u0445 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c.<\/p>\n<p>\u0412\u0441\u044f\u043a\u0438\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u044f\u0434\u0440\u0443 Linux \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c \u0441\u043e\u043a\u0435\u0442 \u043a \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0438\u0441\u043a\u0430\u0442\u044c \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430. \u041d\u0430\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0436\u0438\u0437\u043d\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u0441\u043f\u0435\u043a\u0442: \u043f\u043e\u0438\u0441\u043a TCP-\u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0432 \u044f\u0434\u0440\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0434\u0432\u0443\u0445 \u0442\u043e\u0447\u043a\u0430\u0445 \u044f\u0434\u0440\u0430. \u041f\u043e\u0438\u0441\u043a \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0437\u0430\u0440\u0430\u043d\u0435\u0435, \u0432\u043e \u0432\u0440\u0435\u043c\u044f &#8212;\u00a0<code>at bind()<\/code> \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e, \u0432\u043e \u0432\u0440\u0435\u043c\u044f <code>at connect()<\/code>. \u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0437 \u044d\u0442\u0438\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u2013 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0431\u044b\u043b \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0439 \u0441\u043e\u043a\u0435\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/074\/6d9\/edb\/0746d9edbb974b39e75c687a1b97ca30.png\" width=\"711\" height=\"481\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/074\/6d9\/edb\/0746d9edbb974b39e75c687a1b97ca30.png\"\/><\/figure>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044f\u0441\u044c \u0432\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_connection_sock.c#L486\" rel=\"noopener noreferrer nofollow\">inet_csk_get_port<\/a>\u00a0\u0438\u043b\u0438\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_hashtables.c#L992\" rel=\"noopener noreferrer nofollow\">__inet_hash_connect<\/a>, \u043d\u0430\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u0445\u043e\u0434\u0438\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443 \u043a\u043e\u0440\u0437\u0438\u043d \u0432 bhash, \u043f\u043e\u0434\u044b\u0441\u043a\u0438\u0432\u0430\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u0441 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u043c \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u043f\u043e\u0440\u0442\u0430. \u0422\u0430\u043a\u0430\u044f \u043a\u043e\u0440\u0437\u0438\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u043b\u0438\u0431\u043e \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u0442\u044c. \u041d\u043e, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442, \u0435\u0451 \u043f\u043e\u043b\u0435 fastreuse \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0442\u0440\u0451\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439. \u042d\u0442\u043e\u00a0-1,\u00a00 \u0438\u043b\u0438\u00a0+1. \u0421\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u0435\u043d\u0438\u0435, \u0431\u0443\u0434\u0442\u043e Linux-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u043b\u044f\u043b\u0438\u0441\u044c <a href=\"https:\/\/en.wikipedia.org\/wiki\/Triplet_state\" rel=\"noopener noreferrer nofollow\">\u043a\u0432\u0430\u043d\u0442\u043e\u0432\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u043a\u043e\u0439<\/a>.<\/p>\n<p>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442\u0440\u0430\u0436\u0430\u0435\u0442 \u0434\u0432\u0430 \u0430\u0441\u043f\u0435\u043a\u0442\u0430 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438:<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 \u041a\u0430\u043a\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u044b \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0435?<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 \u041a\u043e\u0433\u0434\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430?<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f fastreuse \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0442 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u0441\u043b\u0443\u0447\u0430\u0435\u0432.<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0447\u0442\u043e \u043d\u0430\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e fastreuse \u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u0445 \u043a\u043e\u0440\u0437\u0438\u043d\u044b, \u0442\u043e \u0435\u0441\u0442\u044c, \u043e \u0441\u043e\u043a\u0435\u0442\u0430\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0439 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442?<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 fastreuse <\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0412 \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">-1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u043a\u0435\u0442\u044b, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0435 (<code>connect()<\/code>) \u0438\u0437 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u043e\u0433\u043e   \u043f\u043e\u0440\u0442\u0430<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">0<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u043a\u0435\u0442\u044b, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435   \u0431\u0435\u0437 <code>SO_REUSEADDR<\/code><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">+1<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0421\u043e\u043a\u0435\u0442\u044b, \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 <code>SO_REUSEADDR<\/code><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u042d\u0442\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0432\u0441\u044f, \u043d\u043e \u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u044f \u043f\u0440\u0430\u0432\u0434\u0430. \u0412\u0441\u043a\u043e\u0440\u0435 \u043c\u044b \u0434\u043e\u0431\u0435\u0440\u0451\u043c\u0441\u044f \u0434\u043e \u0441\u0443\u0442\u0438.<\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0436\u0435 \u0434\u0435\u043b\u043e \u0434\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0440\u0442\u043e\u0432, \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043c\u0435\u043d\u0435\u0435 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041c\u043e\u0436\u043d\u043e \u043b\u0438, \u2026 \u043a\u043e\u0433\u0434\u0430 \u2026<\/p>\n<\/td>\n<td>\n<p align=\"left\">fastreuse = -1<\/p>\n<\/td>\n<td>\n<p align=\"left\">fastreuse = 0<\/p>\n<\/td>\n<td>\n<p align=\"left\">fastreuse = +1<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f (bind()) \u0441 \u0442\u0435\u043c \u0436\u0435 \u0441\u0430\u043c\u044b\u043c \u043f\u043e\u0440\u0442\u043e\u043c (\u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u043c \u0438\u043b\u0438   \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c)<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0414\u0430,<\/strong>\u00a0\u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430,   \u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u2460<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2190\u00a0<a href=\"https:\/\/en.wiktionary.org\/wiki\/idem#Pronoun\" rel=\"noopener noreferrer nofollow\">idem<\/a><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2190 idem<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0421\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f (bind()) \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u043f\u043e\u0440\u0442\u043e\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 SO_REUSEADDR<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0414\u0430,<\/strong>\u00a0\u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430   \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u0418\u041b\u0418 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443\u044e\u0449\u0438\u0439 \u0441\u043e\u043a\u0435\u0442   \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 SO_REUSEADDR \u2460<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u2190 idem<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0434\u0430<\/strong>\u00a0\u2461<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f (connect()) \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u043e\u0433\u043e   \u043f\u043e\u0440\u0442\u0430 \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 (IP, \u043f\u043e\u0440\u0442\u0443)<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0414\u0430,<\/strong>\u00a0\u0442\u043e\u0433\u0434\u0430 \u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u0434\u0430,   \u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d \u2462<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u043d\u0435\u0442<\/strong>\u00a0\u2462<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u043d\u0435\u0442<\/strong>\u00a0\u2462<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u041f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f (connect()) \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u043e\u0433\u043e   \u043f\u043e\u0440\u0442\u0430 \u043a \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 (IP, \u043f\u043e\u0440\u0442\u0443)<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u0434\u0430<\/strong>\u00a0\u2462<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u043d\u0435\u0442<\/strong>\u00a0\u2462<\/p>\n<\/td>\n<td>\n<p align=\"left\"><strong>\u043d\u0435\u0442<\/strong>\u00a0\u2462<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u2460 \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_connection_sock.c#L214\" rel=\"noopener noreferrer nofollow\">inet_csk_bind_conflict()<\/a>, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u043e\u0439 \u0438\u0437\u00a0<code>inet_csk_get_port()<\/code>\u00a0(\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443) \u0438\u043b\u0438\u00a0<code>inet_csk_get_port()<\/code>\u00a0\u2192\u00a0<code>inet_csk_find_open_port()<\/code>\u00a0(\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043a \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u043e\u043c\u0443 \u043f\u043e\u0440\u0442\u0443).<\/p>\n<p>\u2461 \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443\u00a0<code>inet_csk_get_port()<\/code>\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_connection_sock.c#L531\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432<\/a>\u00a0\u0434\u043b\u044f\u00a0fastreuse == 1 buckets.<\/p>\n<p>\u2462 \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443\u00a0<code>inet_hash_connect()<\/code>\u00a0\u2192\u00a0<code>__inet_hash_connect()<\/code>\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_hashtables.c#L1062\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043a\u043e\u0440\u0437\u0438\u043d\u044b<\/a>\u00a0\u0441\u00a0fastreuse != -1.<\/p>\n<p>\u041f\u0440\u0438\u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u0432\u0441\u0451 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e, \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0432\u043f\u043e\u043b\u043d\u0435 \u0441\u0432\u043e\u0434\u0438\u043c\u0430 \u043a \u0434\u0432\u0443\u043c \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432\u0435\u0440\u043d\u044b\u043c\u0438 \u2013 \u0432 \u0442\u0430\u043a\u043e\u043c \u0432\u0438\u0434\u0435 \u043e\u043d\u0430 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435:<\/p>\n<ul>\n<li>\n<p><code>bind()<\/code> \u0438\u043b\u0438 \u0440\u0430\u043d\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c IP-\u0430\u0434\u0440\u0435\u0441\u043e\u043c \u0438 \u043a\u0430\u043a\u0438\u043c-\u043b\u0438\u0431\u043e \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432,<\/p>\n<\/li>\n<li>\n<p><code>connect()<\/code> \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u0435\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0443\u0434\u0430\u0447\u0435\u0439, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043a\u043e\u0440\u0437\u0438\u043d\u0430 TCP-\u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0434\u043b\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043a\u0440\u043e\u043c\u0435 fastreuse = -1,<\/p>\n<\/li>\n<li>\n<p><code>connect()<\/code>\u00a0\u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0443\u0441\u043f\u0435\u0445\u043e\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u043c\u0438 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438,<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u043a\u0435\u0442\u043d\u0430\u044f \u043e\u043f\u0446\u0438\u044f <code>SO_REUSEADDR<\/code>\u00a0\u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432, \u0435\u0441\u043b\u0438 \u044d\u0442\u0430 \u043e\u043f\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c\u0438 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438 (\u0438 \u043d\u0438 \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445 \u043d\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0441\u043b\u0443\u0448\u0430\u0442\u0435\u043b\u044f).<\/p>\n<\/li>\n<\/ul>\n<h2>\u042d\u0442\u043e \u0431\u0435\u0437\u0443\u043c\u0438\u0435. \u042f \u0432\u0430\u043c \u043d\u0435 \u0432\u0435\u0440\u044e   <\/h2>\n<p>\u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0432\u044b \u0438 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u043d\u044b. \u041f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0430\u00a0<a href=\"https:\/\/drgn.readthedocs.io\/en\/latest\/index.html\" rel=\"noopener noreferrer nofollow\">drgn<\/a> \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043f\u0440\u044f\u043c\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u044f\u0434\u0440\u0435:   <\/p>\n<pre><code class=\"python\">#!\/usr\/bin\/env drgn  \"\"\" dump_bhash.py - List all TCP bind buckets in the current netns.  Script is not aware of VRF. \"\"\"  import os  from drgn.helpers.linux.list import hlist_for_each, hlist_for_each_entry from drgn.helpers.linux.net import get_net_ns_by_fd from drgn.helpers.linux.pid import find_task   def dump_bind_bucket(head, net):     for tb in hlist_for_each_entry(\"struct inet_bind_bucket\", head, \"node\"):         # \u041f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043d\u0435 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0435\u0442\u0438         if tb.ib_net.net != net:             continue          port = tb.port.value_()         fastreuse = tb.fastreuse.value_()         owners_len = len(list(hlist_for_each(tb.owners)))          print(             \"{:8d}  {:{sign}9d}  {:7d}\".format(                 port,                 fastreuse,                 owners_len,                 sign=\"+\" if fastreuse != 0 else \" \",             )         )   def get_netns():     pid = os.getpid()     task = find_task(prog, pid)     with open(f\"\/proc\/{pid}\/ns\/net\") as f:         return get_net_ns_by_fd(task, f.fileno())   def main():     print(\"{:8}  {:9}  {:7}\".format(\"TCP-PORT\", \"FASTREUSE\", \"#OWNERS\"))      tcp_hashinfo = prog.object(\"tcp_hashinfo\")     net = get_netns()      # \u041f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u043b\u043e\u0442\u044b bhash      for i in range(0, tcp_hashinfo.bhash_size):         head = tcp_hashinfo.bhash[i].chain         # \u041f\u0435\u0440\u0435\u0431\u0440\u0430\u0442\u044c \u043a\u043e\u0440\u0437\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u0432 \u0441\u043b\u043e\u0442\u0435         dump_bind_bucket(head, net)   main()<\/code><\/pre>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u043f\u0440\u043e\u0431\u0443\u0435\u043c\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/dump_bhash.py\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u043e\u0442 \u0441\u043a\u0440\u0438\u043f\u0442<\/a>\u00a0\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c \u0432\u0435\u0449\u0438, \u043f\u043e\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 <em>\u0442\u0430\u0431\u043b\u0438\u0446\u0435 1<\/em>\u00a0\u043a\u0430\u043a \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u0435. \u0423\u0447\u0438\u0442\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0445 \u043d\u0438\u0436\u0435 \u0441\u0435\u0430\u043d\u0441\u043e\u0432\u044b\u0445 \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u043e\u0432 ipython &#8212;classic\u00a0\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u0439 \u0436\u0435 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0435\u043b\u0430\u043b\u0430\u0441\u044c \u0434\u043b\u044f \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u043d\u0430 \u0437\u0430\u0433\u0430\u0434\u043a\u0438. <\/p>\n<p>\u0414\u0432\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0445 \u0441\u043e\u043a\u0435\u0442\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 60 000:<\/p>\n<pre><code>>>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.connect(('127.1.1.1', 1234)) >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.2.2.2', 1234)) >>> !.\/dump_bhash.py TCP-PORT  FASTREUSE  #OWNERS     1234          0        3    60000         -1        2 >>><\/code><\/pre>\n<p>\u0414\u0432\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u043e\u0440\u0442 60 000:   <\/p>\n<pre><code>>>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s1.bind(('127.1.1.1', 60_000)) >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s2.bind(('127.1.1.1', 60_000)) >>> !.\/dump_bhash.py TCP-PORT  FASTREUSE  #OWNERS     1234          0        1    60000         +1        2 >>><\/code><\/pre>\n<p>\u0421\u043c\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0441 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u043e\u043f\u0446\u0438\u0435\u0439 REUSEADDR \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043f\u043e\u0440\u0442 60 000:   <\/p>\n<pre><code>>>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) >>> s1.bind(('127.1.1.1', 60_000)) >>> !.\/dump_bhash.py TCP-PORT  FASTREUSE  #OWNERS     1234          0        1    60000         +1        1 >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.2.2.2', 60_000)) >>> !.\/dump_bhash.py TCP-PORT  FASTREUSE  #OWNERS     1234          0        1    60000          0        2 >>><\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0430\u043a\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0442\u043e \u0434\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439\u0441\u044f \u0432 <em>\u0442\u0430\u0431\u043b\u0438\u0446\u0435 2<\/em>, \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0442 <a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/test_fastreuse.py\" rel=\"noopener noreferrer nofollow\">\u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432<\/a>.   <\/p>\n<p>\u041d\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435? \u041a\u043e\u0440\u0437\u0438\u043d\u0430 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u044f\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0448\u043b\u0430 \u0438\u0437 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f fastreuse \u0432 \u0434\u0440\u0443\u0433\u043e\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0443\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 <em>\u0442\u0430\u0431\u043b\u0438\u0446\u0435 1<\/em>. \u0418 \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u043b\u043d\u043e\u0439 \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043c\u044b \u0441\u0435\u0431\u0435 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c.<\/p>\n<p>\u041d\u0430\u043c \u0435\u0449\u0451 \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 fastreuse \u0443 \u043a\u043e\u0440\u0437\u0438\u043d\u044b. \u0417\u0434\u0435\u0441\u044c \u044f\u0432\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442.<\/p>\n<h2>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442<\/h2>\n<p>\u041a\u0430\u043a \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043c\u043e\u0433\u043b\u0438 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u043a\u043e\u0440\u0437\u0438\u043d\u0435 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 fastreuse. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u0432 \u043a\u043e\u0440\u0437\u0438\u043d\u0443 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u0440\u043e\u0432\u043e\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 fastreuse = 0, \u0435\u0441\u043b\u0438 \u043d\u0430\u043c \u0434\u043e\u0432\u0435\u0434\u0451\u0442\u0441\u044f \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u0442\u044c (<code>bind()<\/code>) \u0441\u043e\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439: <\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 \u043d\u0435 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u0443\u0435\u0442 \u0441 \u0443\u0436\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u043c\u0438\u0441\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u043c\u0438 \u0438<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 \u0443 \u043d\u0435\u0433\u043e \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u043e\u043f\u0446\u0438\u044f\u00a0SO_REUSEADDR.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/10a\/3cf\/d30\/10a3cfd30e892229cf2ea2f8af797c80.png\" width=\"731\" height=\"681\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/10a\/3cf\/d30\/10a3cfd30e892229cf2ea2f8af797c80.png\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e, \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u043a\u043e\u0434 \u0432\u00a0<a href=\"https:\/\/elixir.bootlin.com\/linux\/v6.2\/source\/net\/ipv4\/inet_connection_sock.c#L431\" rel=\"noopener noreferrer nofollow\">inet_csk_get_port \u2192 inet_csk_update_fastreuse<\/a>, \u043d\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e \u043d\u0435 \u043f\u043e\u0432\u0440\u0435\u0434\u0438\u043b\u043e \u0431\u044b \u043f\u043e\u0434\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043d\u044f\u043b\u0438, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 <a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/test_fastreuse_states.py\" rel=\"noopener noreferrer nofollow\">\u0435\u0449\u0451 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u0441\u0442\u043e\u0432<\/a>.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u043d\u0443\u044e \u043a\u0430\u0440\u0442\u0438\u043d\u0443, \u043d\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u2026 <\/p>\n<h2>\u0417\u0430\u0447\u0435\u043c \u0432\u044b \u043c\u043d\u0435 \u0432\u0441\u0451 \u044d\u0442\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435?   <\/h2>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430 \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432\u00a0<code>bind()<\/code>\u00a0\u043e\u0442\u043a\u043b\u043e\u043d\u0438\u0442 \u0432\u0430\u0448 \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0435\u0439\u00a0<code>EADDRINUSE<\/code>, \u0438\u043b\u0438\u00a0<code>connect()<\/code>\u00a0\u0443\u043f\u0440\u0451\u0442\u0441\u044f, \u0432\u044b\u0434\u0430\u0432 \u043e\u0448\u0438\u0431\u043a\u0443\u00a0<code>EADDRNOTAVAIL<\/code>\u00a0\u2013 \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u0437\u043d\u0430\u043b\u0438, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u0438\u043b\u0438, \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u043e\u0431\u043b\u0430\u0434\u0430\u043b\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u043c \u044d\u0442\u043e \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c. <\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0430\u043d\u0435\u0435 \u043c\u044b <a href=\"https:\/\/blog.cloudflare.com\/how-to-stop-running-out-of-ephemeral-ports-and-start-to-love-long-lived-connections\/\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043a\u043b\u0430\u043c\u0438\u0440\u043e\u0432\u0430\u043b\u0438, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e<\/a>\u00a0\u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043f\u043e\u0440\u0442\u043e\u0432. \u0422\u0430\u043a\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0441\u043e\u043f\u0440\u044f\u0436\u0435\u043d\u0430 \u0441 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u043e\u0439 \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u043e\u043f\u0446\u0438\u044f <code>SO_REUSEADDR<\/code>. \u0422\u043e\u0433\u0434\u0430 \u043c\u044b \u0435\u0449\u0451 \u043d\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u0432\u0430\u043b\u0438, \u0447\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/test_fastreuse.py#L300\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0440\u0442 \u043d\u0435 \u043f\u043e\u0434\u0434\u0430\u0451\u0442\u0441\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438\u00a0connect(). \u041f\u0440\u0438\u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u0433\u043e\u0434\u044b \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f.<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043c\u044b \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e\u043c Linux \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u0432 API \u044f\u0434\u0440\u0430<br \/> \u043d\u043e\u0432\u0443\u044e \u0441\u043e\u043a\u0435\u0442\u043d\u0443\u044e \u043e\u043f\u0446\u0438\u044e, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e\u00a0<a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/torvalds\/linux.git\/commit\/?id=91d0b78c5177\" rel=\"noopener noreferrer nofollow\">\u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d<br \/> \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u043e\u0432<\/a>. \u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043d\u043e\u0432\u0430\u044f \u043e\u043f\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u0433\u043e\u0442\u043e\u0432\u044f\u0449\u0435\u0439\u0441\u044f \u043a \u0432\u044b\u0445\u043e\u0434\u0443 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Linux 6.3. \u0418\u043c\u0435\u044f \u0442\u0430\u043a\u0443\u044e \u043e\u043f\u0446\u0438\u044e, \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u0438\u0431\u0435\u0433\u0430\u0442\u044c \u043a \u0443\u043b\u043e\u0432\u043a\u0430\u043c \u0441 <code>bind()<\/code>. \u041e\u043f\u044f\u0442\u044c \u0436\u0435, \u0442\u0430\u043a \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e <code>connect()<\/code>.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u044b\u0441\u043b\u0438<\/h2>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2013 \u0432 \u043a\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0434\u0432\u0430 TCP-\u0441\u043e\u043a\u0435\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441? \u2013 \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0431\u044b\u043b \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043f\u0443\u0442\u044c \u043a \u043e\u0442\u0432\u0435\u0442\u0443. \u042d\u0442\u043e\u0442 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0436\u0435\u043d, \u0447\u0442\u043e \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u0435\u0433\u043e \u043d\u0435 \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u044d\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442. \u0412 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0438\u0433\u043d\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u0447\u0443 <code>SO_REUSEPORT<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u043b\u0438 \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0432\u043b\u0435\u0447\u0435\u043d\u044b \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0435 TCP-\u0441\u043e\u043a\u0435\u0442\u044b.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u044b\u0432\u043e\u0434, \u0442\u043e \u0432\u043e\u0442 \u043e\u043d: \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u044f \u0441\u043e\u043a\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 bind(), \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0440\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u0432\u0430\u0440\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f. \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>bind()<\/code> \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u043e\u0447\u0435\u0442\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0432\u044b\u0431\u043e\u0440 \u0441 \u0441\u043e\u043a\u0435\u0442\u043d\u043e\u0439 \u043e\u043f\u0446\u0438\u0435\u0439 <code>IP_BIND_ADDRESS_NO_PORT<\/code>, \u0430 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0440\u0442\u043e\u0432 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044f\u0434\u0440\u0443. \u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u043f\u0440\u0435\u0434\u043d\u0430\u043c\u0435\u0440\u0435\u043d\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u0440\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 TCP-\u043f\u043e\u0440\u0442\u043e\u0432.<\/p>\n<p>\u041f\u0440\u0438\u0441\u043a\u043e\u0440\u0431\u043d\u043e, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0441\u043e\u0432\u0435\u0442 \u043d\u0435\u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u043a UDP, \u0433\u0434\u0435 <code>IP_BIND_ADDRESS_NO_PORT<\/code> \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041d\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u0434\u0440\u0443\u0433\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f. <\/p>\n<p>\u0414\u043e \u043d\u043e\u0432\u044b\u0445 \u0432\u0441\u0442\u0440\u0435\u0447 ?.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/725144\/\"> https:\/\/habr.com\/ru\/post\/725144\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u044b \u0437\u0430\u043c\u0435\u0447\u0430\u043b\u0438, \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0442 \u043a \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c? \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u043e\u0434\u0441\u0442\u0443\u043f\u0438\u0442\u044c\u0441\u044f \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432. \u041a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f \u2013 \u043d\u0430\u0448\u0430 \u043b\u044e\u0431\u0438\u043c\u0430\u044f: \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b Linux. <\/p>\n<h2>\u041a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 TCP-\u0441\u043e\u043a\u0435\u0442\u0430 \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441?   <\/h2>\n<p>\u0415\u0441\u043b\u0438 \u044f \u043f\u0435\u0440\u0435\u0439\u0434\u0443 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435\u00a0<a href=\"https:\/\/blog.cloudflare.com\/\" rel=\"noopener noreferrer nofollow\">https:\/\/blog.cloudflare.com\/<\/a>, \u043c\u043e\u0439 \u0431\u0440\u0430\u0443\u0437\u0435\u0440 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 TCP-\u0430\u0434\u0440\u0435\u0441\u0443, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c 104.16.132.229:443. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u0439\u0434\u0451\u0442 \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043e\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441 Linux, \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0439 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 TCP-\u043f\u043e\u0440\u0442, \u0441\u043a\u0430\u0436\u0435\u043c, 192.0.2.42:54321. \u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0451\u0442, \u0435\u0441\u043b\u0438 \u044f \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u0448\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0430\u0439\u0442? \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0435 TCP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043f\u043e\u0440\u0442\u0430?<\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0434\u0430\u0432\u0430\u0439\u0442\u0435\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Discovery_learning\" rel=\"noopener noreferrer nofollow\">\u0432\u044b\u044f\u0441\u043d\u0438\u043c \u0435\u0433\u043e \u043e\u043f\u044b\u0442\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c<\/a>. \u041c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0434\u043b\u044f \u0432\u0430\u0441 \u0432\u043e\u0441\u0435\u043c\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432-\u0437\u0430\u0434\u0430\u0447\u0435\u043a. \u041e\u0442\u0432\u0435\u0442\u0438\u0432 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445, \u0432\u044b \u043e\u0442\u043a\u0440\u043e\u0435\u0442\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u043e\u0434\u0438\u043d \u0438\u0437 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0442\u0435\u0445 \u043f\u0440\u0430\u0432\u0438\u043b, \u0447\u0442\u043e \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u0443\u044e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 TCP-\u0441\u043e\u043a\u0435\u0442\u0430\u043c\u0438 \u043f\u043e\u0434 Linux. \u0427\u0435\u0441\u0442\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u0435\u043c: \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0439\u0442\u0438 \u0443\u043c \u0437\u0430 \u0440\u0430\u0437\u0443\u043c.<\/p>\n<p>\u0412\u043e\u043f\u0440\u043e\u0441\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u0430 \u0434\u0432\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430 \u043d\u0430 \u043e\u0434\u043d\u0438 \u0438 \u0442\u0435 \u0436\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0435 IP \u0438 \u043f\u043e\u0440\u0442. \u041e\u0434\u043d\u0430\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>\u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438 \u043f\u043e\u0440\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u043d\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u0438\u043b\u0438, \u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u0442\u043e\u043b\u044c\u043a\u043e IP-\u0430\u0434\u0440\u0435\u0441.<\/p>\n<p>\u041e\u0442\u0432\u0435\u0447\u0430\u044f \u043d\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445:<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0 \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0442\u044c \u041e\u0421 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438\/\u0438\u043b\u0438 \u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u0441\u043e\u043a\u0435\u0442\u0430 \u0438\u043b\u0438 <\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0 \u042f\u0432\u043d\u043e \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/bind.2.html\" rel=\"noopener noreferrer nofollow\">bind()<\/a>, \u043f\u0440\u0435\u0436\u0434\u0435, \u0447\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f\u00a0(<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/connect.2.html\" rel=\"noopener noreferrer nofollow\">connect()<\/a>) \u043a \u0441\u043e\u043a\u0435\u0442\u0443; \u0442\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f\u00a0<a href=\"https:\/\/idea.popcount.org\/2014-04-03-bind-before-connect\/\" rel=\"noopener noreferrer nofollow\">bind-before-connect<\/a>.<\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u043d\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 <code>bind()<\/code>, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u0438\u0441\u0447\u0435\u0440\u043f\u0430\u0442\u044c \u0432\u0441\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u0442\u043e \u0435\u0441\u0442\u044c, \u043f\u0430\u0440\u044b (IP, \u043f\u043e\u0440\u0442). \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0431\u0430\u043d\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u043e\u0432, \u043d\u043e \u043f\u0440\u043e\u0449\u0435 \u0431\u044b\u043b\u043e \u0431\u044b\u00a0<a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/networking\/ip-sysctl.html?#ip-variables\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0434\u043a\u0440\u0443\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u044b<\/a>\u00a0\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u041e\u0421 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c \u0441\u043e\u043a\u0435\u0442\u0430\u043c: \u00a0<\/p>\n<pre><code>sysctl -w net.ipv4.ip_local_port_range='60000 60000'<\/code><\/pre>\n<p>\u0412 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u043e\u043f\u0440\u043e\u0441\u0435-\u0437\u0430\u0433\u0430\u0434\u043a\u0435 \u0432\u0430\u0441 \u0436\u0434\u0451\u0442 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u043b\u0438\u0441\u0442\u0438\u043d\u0433 \u043d\u0430 Python. \u0412\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u2013 \u0441\u043f\u0440\u043e\u0433\u043d\u043e\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a\u0430\u043a\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0438\u0442\u043e\u0433 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u043a\u043e\u0434 \u0443\u0441\u043f\u0435\u0448\u043d\u043e? \u0418\u043b\u0438 \u043d\u0435\u0442? \u0421\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c ChatGPT \u043d\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f ?.<\/p>\n<p>\u0412\u0441\u0435\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043a\u043e\u0434\u0430, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u043d\u0438\u0442\u044c. \u0414\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \u043c\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u043c \u0435\u0451 \u0438\u0437 \u043d\u0430\u0448\u0438\u0445 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code class=\"cmake\">from os import system from socket import *  # \u041d\u0435\u0434\u043e\u0441\u0442\u0430\u044e\u0449\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b IP_BIND_ADDRESS_NO_PORT = 24  # \u0412 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u0438\u043c\u0451\u043d \u043d\u0430\u0448\u0435\u0439 \u0441\u0435\u0442\u0438 \u0432\u0441\u0435\u0433\u043e *\u043e\u0434\u0438\u043d* \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 system(\"sysctl -w net.ipv4.ip_local_port_range='60000 60000'\")  # \u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0448\u0430\u044e\u0449\u0438\u0439 \u0441\u043e\u043a\u0435\u0442 \u043f\u043e *:1234. \u0418\u043c\u0435\u043d\u043d\u043e \u043a \u043d\u0435\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f. ln = socket(AF_INET, SOCK_STREAM) ln.bind((\"\", 1234)) ln.listen(SOMAXCONN)<\/code><\/pre>\n<p>\u0418\u0437\u0431\u0430\u0432\u0438\u0432\u0448\u0438\u0441\u044c \u043e\u0442 \u044d\u0442\u0438\u0445 \u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439, \u043d\u0430\u0447\u043d\u0451\u043c. \u041d\u0430 \u0441\u0442\u0430\u0440\u0442, \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043c\u0430\u0440\u0448!   <\/p>\n<h2>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 #1: \u041a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0443\u043d\u0438\u043a\u0430\u043b\u0435\u043d, \u043d\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442 \u043d\u0435 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f   <\/h2>\n<p>\u0412 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 #1 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043a \u043e\u0434\u043d\u043e\u043c\u0443 \u0438 \u0442\u043e\u043c\u0443 \u0436\u0435 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0430\u0434\u0440\u0435\u0441\u0443: 127.9.9.9:1234. \u042d\u0442\u0438 \u0441\u043e\u043a\u0435\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 IP-\u0430\u0434\u0440\u0435\u0441\u0430, \u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u0434\u043b\u044f \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0440\u0442\u0430?   <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">127.0.0.1<br \/>127.1.1.1<br \/>127.2.2.2<\/p>\n<\/td>\n<td data-colwidth=\"176\" width=\"176\">\n<p align=\"left\">60_000<\/p>\n<\/td>\n<td>\n<p align=\"left\">127.9.9.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">1234<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #1   <\/h2>\n<p>\u041d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b \u043f\u0440\u0438\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u043a \u0440\u0430\u0437\u043d\u044b\u043c, \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u043c \u041e\u0421 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442. \u041f\u043e\u043c\u043d\u0438\u0442\u0435: \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u043e\u0432 \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u043c\u0430\u0448\u0438\u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u043f\u043e\u0440\u0442 (60 000).   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.1.1.1', 0)) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.2.2.2', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_1.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #1<\/a>   <\/p>\n<pre><code class=\"cmake\">#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #1 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.2.2.2', 0)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.2.2.2', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #2   <\/h2>\n<p>\u0417\u0434\u0435\u0441\u044c \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0442\u0430\u043a\u0430\u044f \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0437\u0430\u0433\u0430\u0434\u043a\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u041e\u0421 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP-\u0430\u0434\u0440\u0435\u0441 \u0438 \u043f\u043e\u0440\u0442 \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430. \u041a\u0430\u043a \u0432\u044b \u0434\u0443\u043c\u0430\u0435\u0442\u0435, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0437\u0430\u0433\u0430\u0434\u043a\u0435?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.2.2.2', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_2.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #2<\/a>.<\/p>\n<pre><code class=\"cmake\">#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #2 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.2.2.2', 0)) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.2.2.2', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #3   <\/h2>\n<p>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 \u0441\u0444\u043e\u0440\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0442\u043e\u0447\u043d\u043e, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0430\u044f. \u041c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0438 \u043f\u043e\u0440\u044f\u0434\u043e\u043a. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u043e\u043a\u0435\u0442\u0443 \u0441 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u043b\u044f \u043d\u0430\u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u043f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0442\u0438 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e, \u0432\u0435\u0440\u043d\u043e?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.1.1.1', 0)) s1.connect(('127.9.9.9', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_3.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #3<\/a>.  <\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #3 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234))  >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) Traceback (most recent call last):   ... OSError: [Errno 99] Cannot assign requested address  Outcome: FAILURE. Local port can't be shared.  Cleanup:  >>> p1, _ = ln.accept() >>> p1.close() # TIME-WAIT on server side  >>> s1.close() >>> s2.close()  Solution #3 -----------  Use `IP_BIND_ADDRESS_NO_PORT` socket option.  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.setsockopt(SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1) >>> s1.bind(('127.1.1.1', 0)) >>> s1.connect(('127.9.9.9', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.1.1.1', 60000), ('127.9.9.9', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local port is shared when using `IP_BIND_ADDRESS_NO_PORT` option.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439 #2: \u043a\u043e\u0433\u0434\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP \u0438 \u043f\u043e\u0440\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b, \u043d\u043e \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f   <\/h2>\n<p>\u0412 \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u0438 #2 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0443. \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 IP \u0438 \u043e\u0434\u0438\u043d \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441, \u0430 \u043e\u0434\u0438\u043d \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u0430\u0434\u0440\u0435\u0441 <code>127.0.0.1:60000<\/code>\u00a0\u0438 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u0430. \u0412\u0441\u0451 \u0442\u043e\u0442 \u0436\u0435 \u0432\u043e\u043f\u0440\u043e\u0441: \u043c\u043e\u0433\u0443\u0442 \u043b\u0438 \u0434\u0432\u0430 \u0441\u043e\u043a\u0435\u0442\u0430 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442? \u041d\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u044e: \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d \u044d\u0444\u0435\u043c\u0435\u0440\u043d\u044b\u0445 \u043f\u043e\u0440\u0442\u043e\u0432 \u0443 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0440\u0430\u0432\u0435\u043d \u0435\u0434\u0438\u043d\u0438\u0446\u0435.   <\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td>\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">\u041b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 IP<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0423\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u0439 \u043f\u043e\u0440\u0442<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\">127.0.0.1<\/p>\n<\/td>\n<td data-colwidth=\"175\" width=\"175\">\n<p align=\"left\">60_000<\/p>\n<\/td>\n<td>\n<p align=\"left\">127.8.8.8<br \/>127.9.9.9<\/p>\n<\/td>\n<td>\n<p align=\"left\">1234<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #4   <\/h2>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0430\u0437\u043e\u0432. \u041c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f\u00a0(connect()) \u043a \u0434\u0432\u0443\u043c \u0440\u0430\u0437\u043d\u044b\u043c \u0443\u0434\u0430\u043b\u0451\u043d\u043d\u044b\u043c \u0430\u0434\u0440\u0435\u0441\u0430\u043c. \u042d\u0442\u043e \u0434\u043b\u044f \u0437\u0430\u0442\u0440\u0430\u0432\u043a\u0438 ?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_4.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #4<\/a>.<\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #4 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.connect(('127.9.9.9', 1234)) >>> s2.getsockname(), s2.getpeername() (('127.0.0.1', 60000), ('127.9.9.9', 1234)) >>>  Outcome: SUCCESS. Local (IP, port) is shared.  Cleanup:  >>> s1.close() >>> s2.close() \"\"\"  from quiz_common import run_doctest from socket import *  if __name__ == \"__main__\":     run_doctest(__name__)<\/code><\/pre>\n<h2>\u0417\u0430\u0433\u0430\u0434\u043a\u0430 #5   <\/h2>\n<p>\u0427\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f\u0432\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f\u00a0(<code>bind()<\/code>) \u0441 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c IP, \u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u041e\u0421 \u0441\u0430\u043c\u043e\u0439 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0440\u0442 \u2013 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f \u043b\u0438 \u043e\u0442 \u044d\u0442\u043e\u0433\u043e \u0447\u0442\u043e-\u043b\u0438\u0431\u043e?   <\/p>\n<pre><code class=\"cmake\">s1 = socket(AF_INET, SOCK_STREAM) s1.bind(('127.0.0.1', 0)) s1.connect(('127.8.8.8', 1234)) s1.getsockname(), s1.getpeername()  s2 = socket(AF_INET, SOCK_STREAM) s2.bind(('127.0.0.1', 0)) s2.connect(('127.9.9.9', 1234)) s2.getsockname(), s2.getpeername()<\/code><\/pre>\n<p>\u0410 \u0412\u041e\u0422\u00a0<a href=\"https:\/\/github.com\/cloudflare\/cloudflare-blog\/blob\/master\/2023-03-quantum-state-of-tcp-port\/quiz_5.py\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442 #5<\/a>.   <\/p>\n<pre><code>#!\/usr\/bin\/env -S unshare --user --map-root-user --net -- strace -e %net -- python  \"\"\" Quiz #5 -------  >>> s1 = socket(AF_INET, SOCK_STREAM) >>> s1.bind(('127.0.0.1', 0)) >>> s1.connect(('127.8.8.8', 1234)) >>> s1.getsockname(), s1.getpeername() (('127.0.0.1', 60000), ('127.8.8.8', 1234)) >>> >>> s2 = socket(AF_INET, SOCK_STREAM) >>> s2.bind(('127.0.0.1', 0)) Traceback (most recent call last):   ... OSError: [Errno 98] Address already in use >>>  Outcome: FAILURE. Local (IP, port) can't be shared.  Cleanup:  >>> p1, _ = ln.accept() >>> p1.close() #<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-347367","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=347367"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/347367\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=347367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=347367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=347367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}