Subject | Hash | Author | Date (UTC) |
---|---|---|---|
First version | d2839681f34f4760ac29dab2c6fa3f52544ed5af | Catalin(ux) M. BOIE | 2022-10-21 12:26:32 |
gnutls working, more js stuff | cea2625f1129f2e6decb4947c18be31adedfe9e5 | Catalin(ux) M. BOIE | 2022-09-26 16:44:19 |
First add | d3b73b065b617424162195b5dfef2f0121adaa46 | Catalin(ux) M. BOIE | 2022-07-08 05:54:34 |
File agent/java/Tech.txt added (mode: 100644) (index 0000000..74b96fe) | |||
1 | Seems we can inject -javaagent parameter by setting env variable JAVA_TOOL_OPTIONS. | ||
2 | Seems it is checked by JNI_CreateJavaVM function. | ||
3 | |||
4 |
File agent/java/agent/.gitignore copied from file ingestd/.gitignore (similarity 100%) |
File agent/java/agent/META-INF/MANIFEST.MF added (mode: 100644) (index 0000000..3f492a7) | |||
1 | Agent-Class: MyInstrumentationAgent | ||
2 | Can-Redefine-Classes: true | ||
3 | Can-Retransform-Classes: true | ||
4 | Premain-Class: MyInstrumentationAgent | ||
5 | Boot-Class-Path: javassist.jar ninedogs.jar |
File agent/java/agent/Makefile added (mode: 100644) (index 0000000..fac3b4a) | |||
1 | |||
2 | CLASSES := AtmTransformer.class QueryTransformer.class MyInstrumentationAgent.class | ||
3 | JARS := javassist.jar ninedogs.jar | ||
4 | |||
5 | ninedogs-agent.jar: Makefile META-INF/MANIFEST.MF $(JARS) $(CLASSES) | ||
6 | jar --create --verbose --manifest META-INF/MANIFEST.MF \ | ||
7 | --file ninedogs-agent.jar $(JARS) $(CLASSES) | ||
8 | @sleep .3 | ||
9 | |||
10 | ninedogs.jar: Makefile META-INF/MANIFEST.MF ninedogs.class | ||
11 | jar --create --verbose \ | ||
12 | --main-class=ninedogs \ | ||
13 | --file ninedogs.jar ninedogs.class | ||
14 | |||
15 | AtmTransformer.class: AtmTransformer.java | ||
16 | javac -cp javassist.jar AtmTransformer.java | ||
17 | |||
18 | ninedogs.class: ninedogs.java | ||
19 | javac ninedogs.java | ||
20 | |||
21 | QueryTransformer.class: QueryTransformer.java | ||
22 | javac -cp javassist.jar QueryTransformer.java | ||
23 | |||
24 | MyInstrumentationAgent.class: MyInstrumentationAgent.java | ||
25 | javac -cp . MyInstrumentationAgent.java | ||
26 |
File agent/java/agent/MyInstrumentationAgent.java added (mode: 100644) (index 0000000..8818f7d) | |||
1 | //package com.bla; | ||
2 | |||
3 | import java.lang.instrument.Instrumentation; | ||
4 | |||
5 | public class MyInstrumentationAgent | ||
6 | { | ||
7 | public static void premain(String agentArgs, Instrumentation inst) | ||
8 | { | ||
9 | System.err.println("MyInstrumentationAgent.Premain..."); | ||
10 | |||
11 | if (1 == 0) { | ||
12 | // This crashes badly | ||
13 | // Transform all classes | ||
14 | for (Class<?> clazz: inst.getAllLoadedClasses()) { | ||
15 | //System.err.println(" iter " + clazz.getName()); | ||
16 | transformClass(clazz.getName(), inst); | ||
17 | } | ||
18 | } else { | ||
19 | transformClass("org.postgresql.Driver", inst); | ||
20 | transformClass("org.postgresql.jdbc.PgPreparedStatement", inst); | ||
21 | transformClass("org.postgresql.jdbc.PgResultSet", inst); | ||
22 | transformClass("org.postgresql.jdbc.PgConnection", inst); | ||
23 | transformClass("org.postgresql.jdbc.PgStatement", inst); | ||
24 | |||
25 | transformClass("java.net.http.HttpClient", inst); | ||
26 | |||
27 | //transformClass("sun.security.ssl.X509TrustManager", inst); // not working | ||
28 | //transformClass("javax.net.ssl", inst); // not working | ||
29 | |||
30 | transformClass("sun.security.ssl.X509TrustManagerImpl", inst); | ||
31 | transformClass("java.security.cert.X509Certificate", inst); | ||
32 | transformClass("java.security.cert.Certificate", inst); | ||
33 | transformClass("java.security.cert.CertificateFactory", inst); | ||
34 | //transformClass("javax.net.ssl.SSLContext", inst); | ||
35 | transformClass("java.io.File", inst); | ||
36 | //transformClass("java.io.InputStream", inst); | ||
37 | //transformClass("java.io.Reader", inst); | ||
38 | //transformClass("java.io.DataInputStream", inst); | ||
39 | //transformClass("java.io.FileInputStream", inst); | ||
40 | //transformClass("java.io.ByteArrayInputStream", inst); | ||
41 | |||
42 | transformClass("javax.net.ssl.X509TrustManager", inst); | ||
43 | transformClass("javax.net.ssl.X509KeyManager", inst); | ||
44 | transformClass("sun.security.provider.X509Factory", inst); | ||
45 | transformClass("sun.security.x509.X509CertImpl", inst); | ||
46 | transformClass("sun.security.x509.X509CertInfo", inst); | ||
47 | } | ||
48 | |||
49 | System.err.println("Premain finish..."); | ||
50 | } | ||
51 | |||
52 | private static void transformClass(String className, Instrumentation instrumentation) | ||
53 | { | ||
54 | Class<?> targetCls = null; | ||
55 | ClassLoader targetClassLoader = null; | ||
56 | |||
57 | System.err.println("MyInstrumentationAgent.transformClass(" + className + ")..."); | ||
58 | |||
59 | // see if we can get the class using forName | ||
60 | //System.err.println(" trying using forName..."); | ||
61 | try { | ||
62 | targetCls = Class.forName(className); | ||
63 | targetClassLoader = targetCls.getClassLoader(); | ||
64 | transform(targetCls, targetClassLoader, instrumentation); | ||
65 | //System.err.println(" forName worked! return"); | ||
66 | return; | ||
67 | } catch (Exception ex) { | ||
68 | ///System.err.println(" Exception: " + ex); | ||
69 | } | ||
70 | //System.err.println("Class [" + className + "] not found with Class.forName"); | ||
71 | |||
72 | //System.err.println(" iterating all classes..."); | ||
73 | // otherwise iterate all loaded classes and find what we want | ||
74 | for (Class<?> clazz: instrumentation.getAllLoadedClasses()) { | ||
75 | //System.err.println(" comparing with " + clazz.getName()); | ||
76 | if (clazz.getName().equals(className)) { | ||
77 | targetCls = clazz; | ||
78 | targetClassLoader = targetCls.getClassLoader(); | ||
79 | transform(targetCls, targetClassLoader, instrumentation); | ||
80 | return; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | ///System.err.println(" failed to find class " + className); | ||
85 | //throw new RuntimeException("Failed to find class [" + className + "]"); | ||
86 | } | ||
87 | |||
88 | private static void transform(Class<?> clazz, ClassLoader classLoader, Instrumentation instrumentation) | ||
89 | { | ||
90 | String n = clazz.getName(); | ||
91 | |||
92 | //System.err.println("MyInstrumentationAgent.transform: clazz.getName()=" + n + " classLoader=" + classLoader); | ||
93 | |||
94 | //if (n.equals("org.postgresql.Driver")) { | ||
95 | // AtmTransformer dt = new AtmTransformer(n, classLoader); | ||
96 | // instrumentation.addTransformer(dt, true); | ||
97 | //} else if (n.equals("org.postgresql.jdbc.PgPreparedStatement")) { | ||
98 | // QueryTransformer dt = new QueryTransformer(n, classLoader); | ||
99 | // instrumentation.addTransformer(dt, true); | ||
100 | //if (n.equals("sun.security.ssl.X509TrustManagerImpl")) { | ||
101 | QueryTransformer qt = new QueryTransformer(n, classLoader); | ||
102 | instrumentation.addTransformer(qt, true); | ||
103 | //} else { | ||
104 | // return; | ||
105 | //} | ||
106 | |||
107 | try { | ||
108 | instrumentation.retransformClasses(clazz); | ||
109 | } catch (Exception ex) { | ||
110 | System.err.println(" transform: fail: " + ex); | ||
111 | // TODO: next line was un-commented | ||
112 | ///throw new RuntimeException(" Transform failed for class: [" + n + "]", ex); | ||
113 | } | ||
114 | } | ||
115 | } | ||
116 |
File agent/java/agent/QueryTransformer.java added (mode: 100644) (index 0000000..ad8e8aa) | |||
1 | //package com.bla; | ||
2 | |||
3 | import javassist.CannotCompileException; | ||
4 | import javassist.ClassPool; | ||
5 | import javassist.CtClass; | ||
6 | import javassist.CtMethod; | ||
7 | import javassist.CtConstructor; | ||
8 | import javassist.NotFoundException; | ||
9 | |||
10 | import java.io.IOException; | ||
11 | import java.lang.instrument.ClassFileTransformer; | ||
12 | import java.lang.instrument.IllegalClassFormatException; | ||
13 | import java.security.ProtectionDomain; | ||
14 | |||
15 | public class QueryTransformer implements ClassFileTransformer | ||
16 | { | ||
17 | private static final String WITHDRAW_MONEY_METHOD = "executeQuery"; | ||
18 | |||
19 | /** The internal form class name of the class to transform */ | ||
20 | private String targetClassName; | ||
21 | |||
22 | /** The class loader of the class we want to transform */ | ||
23 | private ClassLoader targetClassLoader; | ||
24 | |||
25 | public QueryTransformer(String targetClassName, ClassLoader targetClassLoader) | ||
26 | { | ||
27 | //System.err.println("QueryTransformer.QueryTransformer: targetClassname=" | ||
28 | // + targetClassName + " loader=" + targetClassLoader); | ||
29 | this.targetClassName = targetClassName; | ||
30 | this.targetClassLoader = targetClassLoader; | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, | ||
35 | ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException | ||
36 | { | ||
37 | byte[] byteCode = classfileBuffer; | ||
38 | |||
39 | if (loader != null) { | ||
40 | if (!loader.equals(this.targetClassLoader)) { | ||
41 | //System.err.println(" ignore loader [" + loader + "] != [" + this.targetClassLoader + "]"); | ||
42 | return byteCode; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | String finalTargetClassName = this.targetClassName.replaceAll("\\.", "/"); //replace . with / | ||
47 | |||
48 | if (!className.equals(finalTargetClassName)) { | ||
49 | //System.err.println(" ignore class [" + className + "] != [" + finalTargetClassName + "]"); | ||
50 | return byteCode; | ||
51 | } | ||
52 | |||
53 | //System.err.println("QueryTransformer.transform(loader=" + loader | ||
54 | // + ", className=" + className | ||
55 | // + ", classBeignRedefined=" + classBeingRedefined.getName() | ||
56 | // + ", protectionDomain=" + protectionDomain | ||
57 | // + ")..."); | ||
58 | |||
59 | //String s = new String(byteCode); | ||
60 | //System.err.println(" bytecode before: " + s); | ||
61 | try { | ||
62 | ClassPool cp = ClassPool.getDefault(); | ||
63 | CtClass cc = cp.get(targetClassName); | ||
64 | //CtMethod m = cc.getDeclaredMethod(WITHDRAW_MONEY_METHOD); | ||
65 | //System.err.println(" CtMethod: " + m); | ||
66 | |||
67 | //if (1 == 1) { // seems this crashes at some point | ||
68 | if (className.equals("java/io/File")) { | ||
69 | CtConstructor[] cons = cc.getDeclaredConstructors(); | ||
70 | for (CtConstructor con : cons) { | ||
71 | StringBuilder sb = new StringBuilder(); | ||
72 | StringBuilder eb = new StringBuilder(); | ||
73 | |||
74 | String sig = con.getSignature(); | ||
75 | System.err.println(" constructor: " + con + " sig=" + sig); | ||
76 | sb.append("ninedogs.log(\"constructor for class " + className + " " + sig + " this=\" + this + \" $0=\" + $0);"); | ||
77 | eb.append("ninedogs.log(\" exit this: \" + this + \" $0=\" + $0);"); // seems 'this' is always null... | ||
78 | |||
79 | CtClass[] pTypes = con.getParameterTypes(); | ||
80 | for (int i = 0; i < pTypes.length; i++) | ||
81 | sb.append("ninedogs.log(\" c-para[" + i + "] [" + pTypes[i].getName() + "]: \" + $args[" + i + "]);"); | ||
82 | |||
83 | con.insertBefore("{" + sb.toString() + "}"); | ||
84 | con.insertAfter("{" + eb.toString() + "}"); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | ///System.err.println(" Iterating methods..."); | ||
89 | // Searchy for (Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection; | ||
90 | CtMethod[] methods = cc.getDeclaredMethods(); | ||
91 | //CtMethod m = cc.getDeclaredMethod("connect", params); | ||
92 | for (CtMethod m : methods) { | ||
93 | String sig = m.getSignature(); | ||
94 | ///System.err.println(" method " + m.getName() + " sig: " + sig + "..."); | ||
95 | |||
96 | StringBuilder sb = new StringBuilder(); | ||
97 | StringBuilder eb = new StringBuilder(); | ||
98 | StringBuilder ee = new StringBuilder(); | ||
99 | //CtClass etype = ClassPool.getDefault().get("java.io.IOException"); | ||
100 | // TODO: for postgresql code the next code was un-commented! | ||
101 | //CtClass etype = cp.get("org.postgresql.util.PSQLException"); | ||
102 | |||
103 | // This is heavy debug | ||
104 | //sb.append("System.err.println(\"method " + className + "." + m.getName() + " " + sig + "\");"); | ||
105 | sb.append("ninedogs.log(\"method " + className + "." + m.getName() + " " + sig + "\");"); | ||
106 | eb.append("ninedogs.log(\" ret: \" + $_);"); | ||
107 | |||
108 | if (className.equals("org/postgresql/Driver") | ||
109 | && m.getName().equals("connect") | ||
110 | && sig.equals("(Ljava/lang/String;Ljava/util/Properties;)Ljava/sql/Connection;")) { | ||
111 | System.err.println("========= Intercept connect [" + className + "]"); | ||
112 | sb.append("ninedogs.log(\"db pg con s \" + $1);"); | ||
113 | eb.append("ninedogs.log(\"db pg con e \");"); | ||
114 | ee.append("ninedogs.log(\"db pg con x \" + $e + \"; Cause: \" + $e.getCause() + \" \" + $e.getStackTrace() + \".\"); throw $e;"); | ||
115 | } else if (className.equals("org/postgresql/jdbc/PgConnection") | ||
116 | && m.getName().equals("prepareStatement") | ||
117 | && (sig.equals("(Ljava/lang/String;III)Ljava/sql/PreparedStatement;"))) { | ||
118 | System.err.println("========= Intercept prepareStatement [" + className + "] [" + sig + "]"); | ||
119 | sb.append("ninedogs.log(\"db pg ps s \" + $1);"); | ||
120 | eb.append("ninedogs.log(\"db pg ps e \");"); | ||
121 | ee.append("ninedogs.log(\"db pg ps x \" + $e + \"; Cause: \" + $e.getCause() + \" \" + $e.getStackTrace() + \".\"); throw $e;"); | ||
122 | } else if (className.equals("org/postgresql/jdbc/PgStatement") | ||
123 | && m.getName().equals("executeInternal") | ||
124 | && (sig.equals("(Lorg/postgresql/core/CachedQuery;Lorg/postgresql/core/ParameterList;I)V"))) { | ||
125 | System.err.println("========= Intercept executeInternal[" + className + "] [" + sig + "]"); | ||
126 | sb.append("ninedogs.log(\"db pg exe s \" + $1 + \" \" + $2);"); | ||
127 | eb.append("ninedogs.log(\"db pg exe e \");"); | ||
128 | ee.append("ninedogs.log(\"db pg exe x \" + $e + \"; Cause: \" + $e.getCause() + \" \" + $e.getStackTrace() + \".\"); throw $e;"); | ||
129 | } else if (className.equals("sun/security/provider/X509Factory") | ||
130 | && m.getName().equals("engineGenerateCertificate") | ||
131 | && (sig.equals("(Ljava/io/InputStream;)Ljava/security/cert/Certificate;"))) { | ||
132 | //System.err.println(" Overwrite engineGenerateCertificate ================================="); | ||
133 | eb.append("ninedogs.log_cert($1, $_);"); | ||
134 | } else if (className.equals("java/security/cert/X509Certificate")) { | ||
135 | } else { | ||
136 | //System.err.println(" unknown class " + className + " in QueryTransformer! ==================="); | ||
137 | //sb.append("ninedogs.log(\"gen " + className + " " + m.getName() + " " + sig + "\");"); | ||
138 | //eb.append("ninedogs.log(\" db pg gen done " + className + " " + m.getName() + " " + sig + "\");"); | ||
139 | //continue; | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | System.err.println(" xxx " + m.getName() + ": descriptor = " + sig); | ||
144 | |||
145 | m.addLocalVariable("startTime", CtClass.longType); | ||
146 | m.addLocalVariable("endTime", CtClass.longType); | ||
147 | m.addLocalVariable("opTime", CtClass.longType); | ||
148 | m.addLocalVariable("stklen", CtClass.longType); | ||
149 | |||
150 | sb.append("stklen = Thread.currentThread().getStackTrace().length;"); | ||
151 | //sb.append("String xprefix = \" \".repeat(stk.length);"); | ||
152 | sb.append("startTime = System.currentTimeMillis();"); | ||
153 | sb.append("System.err.println(stklen + \" " + className + "." + m.getName() + ": enter\");"); | ||
154 | //sb.append("StringBuilder sbArgs = new StringBuilder();"); | ||
155 | //sb.append("sbArgs.append(System.identityHashCode( $0 ) );"); | ||
156 | */ | ||
157 | |||
158 | CtClass[] pTypes = m.getParameterTypes(); | ||
159 | for (int i = 0; i < pTypes.length; i++) { | ||
160 | //if ((i == 0) && (pTypes[i].toString() == "java.lang.String")) | ||
161 | ///sb.append("ninedogs.log(\" para[" + i + "] [" + pTypes[i].getName() + "]: \" + $args[" + i + "]);"); | ||
162 | // pType.toString() - too verbose | ||
163 | |||
164 | //if (pTypes[i].isPrimitive()) { | ||
165 | // sb.append("System.err.println(\" para prim " + i + ": " + pTypes[i].toString() + " prim: \" + $args[" + i + "]);"); | ||
166 | //} else { | ||
167 | // sb.append("System.err.println(\" para !prim " + i + ": \" + System.identityHashCode($args[" + i + "]));"); | ||
168 | //} | ||
169 | //sb.append("System.err.println(\" para " + i + ": class: \" + $args[" + i + "].getClass());"); | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | m.insertBefore("{" + sb.toString() + "}"); | ||
174 | |||
175 | eb.append("endTime = System.currentTimeMillis();"); | ||
176 | eb.append("opTime = endTime - startTime;"); | ||
177 | eb.append("System.err.println(\" " + m.getName() + ": \" + opTime + \"ms: \" + $_);"); | ||
178 | m.insertAfter("{" + eb.toString() + "}"); | ||
179 | */ | ||
180 | |||
181 | if (sb.length() > 0) | ||
182 | m.insertBefore("{" + sb.toString() + "}"); | ||
183 | if (eb.length() > 0) | ||
184 | m.insertAfter("{" + eb.toString() + "}"); | ||
185 | // TODO: this code was un-commented - see above | ||
186 | //if (ee.length() > 0) | ||
187 | // m.addCatch("{" + ee.toString() + "}", etype); | ||
188 | } | ||
189 | |||
190 | byteCode = cc.toBytecode(); | ||
191 | //System.err.println(" bytecode after: " + byteCode); | ||
192 | cc.detach(); | ||
193 | //System.err.println(" bytecode rewritten ok"); | ||
194 | } catch (NotFoundException | CannotCompileException | IOException e) { | ||
195 | ///System.err.println(" QueryTransformer.transform Exception: " + e); | ||
196 | } | ||
197 | |||
198 | return byteCode; | ||
199 | } | ||
200 | } | ||
201 |
File agent/java/agent/ninedogs.java added (mode: 100644) (index 0000000..f57bcf4) | |||
1 | import java.io.*; | ||
2 | import java.security.cert.X509Certificate; | ||
3 | |||
4 | public class ninedogs | ||
5 | { | ||
6 | private static File file; | ||
7 | private static FileOutputStream fd = null; | ||
8 | private static ThreadLocal<Integer> init = new ThreadLocal<Integer>(); //{ @Override protected Integer initialValue() { return 0; } }; | ||
9 | |||
10 | public static void init() | ||
11 | { | ||
12 | System.err.println("ninedogs.init"); | ||
13 | |||
14 | // First time, get() returns 'null' | ||
15 | if (init.get() != null) | ||
16 | return; | ||
17 | |||
18 | try { | ||
19 | file = new File("/dev/ninedogs"); | ||
20 | fd = new FileOutputStream(file); | ||
21 | init.set(1); | ||
22 | System.err.println("ninedogs.init: init=" + init.get()); | ||
23 | } catch (Exception e) { | ||
24 | System.err.println("ninedogs.init: exception " + e); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | public static void metric(byte[] s) | ||
29 | { | ||
30 | init(); | ||
31 | |||
32 | if (fd == null) | ||
33 | return; | ||
34 | |||
35 | try { | ||
36 | fd.write(s); | ||
37 | } catch (Exception e) { | ||
38 | System.err.println("ninedogs.log: exception " + e); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | public static void log(String s) | ||
43 | { | ||
44 | int stklen = Thread.currentThread().getStackTrace().length; | ||
45 | String prefix = ""; | ||
46 | |||
47 | if (stklen >= 5) | ||
48 | stklen -= 5; | ||
49 | for (int i = 0; i < stklen; i++) | ||
50 | prefix += " "; | ||
51 | |||
52 | System.err.println("T" + Thread.currentThread() + " " + prefix + s); | ||
53 | } | ||
54 | |||
55 | public static byte[] string2ninedogs(String type, byte[] ch) | ||
56 | { | ||
57 | byte[] header = type.getBytes(); | ||
58 | byte[] len = Integer.toString(ch.length).getBytes(); | ||
59 | byte[] ret = new byte[header.length + len.length + 1 + ch.length]; | ||
60 | Integer off = 0; | ||
61 | |||
62 | System.arraycopy(header, 0, ret, 0, header.length); off += header.length; | ||
63 | System.arraycopy(len, 0, ret, off, len.length); off += len.length; | ||
64 | ret[off] = ' '; off += 1; | ||
65 | System.arraycopy(ch, 0, ret, off, ch.length); | ||
66 | |||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | public static byte[] string2ninedogs(String type, String s) | ||
71 | { | ||
72 | byte[] ch = s.getBytes(); | ||
73 | return string2ninedogs(type, ch); | ||
74 | } | ||
75 | |||
76 | public static void log_cert(java.io.InputStream is, | ||
77 | java.security.cert.Certificate cert) | ||
78 | { | ||
79 | if (!(cert instanceof X509Certificate)) | ||
80 | return; | ||
81 | |||
82 | log("ninedogs.log_cert: is=" + is); | ||
83 | |||
84 | X509Certificate x = (X509Certificate) cert; | ||
85 | byte[] subj, issuer, alg, ser, start, end; | ||
86 | Long ts; | ||
87 | int off = 0; | ||
88 | |||
89 | subj = string2ninedogs("s", x.getSubjectX500Principal().toString()); | ||
90 | issuer = string2ninedogs("i", x.getIssuerX500Principal().toString()); | ||
91 | alg = string2ninedogs("a", x.getPublicKey().getAlgorithm().toString()); | ||
92 | ser = string2ninedogs("x", x.getSerialNumber().toString(16)); | ||
93 | //ser = string2ninedogs("x", x.getSerialNumber().toByteArray()); | ||
94 | |||
95 | ts = x.getNotBefore().getTime() / 1000; | ||
96 | start = string2ninedogs("S", Long.toString(ts)); | ||
97 | |||
98 | ts = x.getNotAfter().getTime() / 1000; | ||
99 | end = string2ninedogs("E", Long.toString(ts)); | ||
100 | |||
101 | byte[] last = new byte[1 + 1 + subj.length + issuer.length + alg.length + ser.length + start.length + end.length + 1]; | ||
102 | last[off] = 'c'; off += 1; // c = cert | ||
103 | last[off] = 'J'; off += 1; // J -> type (Java) | ||
104 | System.arraycopy(subj, 0, last, off, subj.length); off += subj.length; | ||
105 | System.arraycopy(issuer, 0, last, off, issuer.length); off += issuer.length; | ||
106 | System.arraycopy(alg, 0, last, off, alg.length); off += alg.length; | ||
107 | System.arraycopy(ser, 0, last, off, ser.length); off += ser.length; | ||
108 | System.arraycopy(start, 0, last, off, start.length); off += start.length; | ||
109 | System.arraycopy(end, 0, last, off, end.length); off += end.length; | ||
110 | last[off++] = 0; | ||
111 | metric(last); | ||
112 | } | ||
113 | } | ||
114 |
File agent/text2process.c copied from file ingestd/.gitignore (similarity 100%) |
File agent/text2process.h copied from file ingestd/.gitignore (similarity 100%) |
File ingestd/strace.sh added (mode: 100755) (index 0000000..e3ab876) | |||
1 | #!/bin/bash | ||
2 | |||
3 | strace -s2000 -f -tt -o ninedogs-ingestd.strace ./ninedogs-ingestd | ||
4 |
File samples/ninedogs-ingestd.service added (mode: 100644) (index 0000000..aacde51) | |||
1 | [Unit] | ||
2 | Description=Ninedogs ingestion daemon | ||
3 | |||
4 | [Service] | ||
5 | Type=exec | ||
6 | ExecStart=/date/sync/no-crypt/sync1/Dev/ninedogs/ingestd/ninedogs-ingestd | ||
7 | #User=rocketgit | ||
8 | #Group=rocketgit | ||
9 | PrivateTmp=true | ||
10 | Restart=on-failure | ||
11 | RestartSec=10 | ||
12 | ProtectSystem=full | ||
13 | NoNewPrivileges=yes | ||
14 | |||
15 | [Install] | ||
16 | WantedBy=multi-user.target |
File samples/ninedogs-webd.service added (mode: 100644) (index 0000000..f57aec8) | |||
1 | [Unit] | ||
2 | Description=Ninedogs Websocket daemon | ||
3 | |||
4 | [Service] | ||
5 | Type=exec | ||
6 | ExecStart=/date/sync/no-crypt/sync1/Dev/ninedogs/webd/ninedogs-webd | ||
7 | #User=rocketgit | ||
8 | #Group=rocketgit | ||
9 | PrivateTmp=true | ||
10 | Restart=on-failure | ||
11 | RestartSec=10 | ||
12 | ProtectSystem=full | ||
13 | NoNewPrivileges=yes | ||
14 | |||
15 | [Install] | ||
16 | WantedBy=multi-user.target |
File samples/ninedogs.conf added (mode: 100644) (index 0000000..cbdec8d) | |||
1 | upstream ninedogs_web { | ||
2 | server 127.0.0.1:6002; | ||
3 | } | ||
4 | |||
5 | upstream ninedogs_ingest { | ||
6 | server 127.0.0.1:6001; | ||
7 | } | ||
8 | |||
9 | server { | ||
10 | listen 36000 ssl; | ||
11 | listen [::]:36000 ssl; | ||
12 | |||
13 | root /usr/share/ninedogs/webroot; | ||
14 | |||
15 | access_log /var/log/nginx/ninedogs-access.log; | ||
16 | error_log /var/log/nginx/ninedogs-error.log debug; | ||
17 | |||
18 | location /ingest { | ||
19 | proxy_pass http://ninedogs_ingest; | ||
20 | proxy_http_version 1.1; | ||
21 | proxy_set_header X-Original-IP $remote_addr/$remote_port; | ||
22 | proxy_set_header Upgrade $http_upgrade; | ||
23 | proxy_set_header Connection "upgrade"; | ||
24 | proxy_read_timeout 120; | ||
25 | proxy_buffering off; | ||
26 | } | ||
27 | |||
28 | location /ws { | ||
29 | proxy_pass http://ninedogs_web; | ||
30 | proxy_http_version 1.1; | ||
31 | proxy_set_header X-Original-IP $remote_addr/$remote_port; | ||
32 | proxy_set_header Upgrade $http_upgrade; | ||
33 | proxy_set_header Connection "upgrade"; | ||
34 | proxy_read_timeout 120; | ||
35 | proxy_buffering off; | ||
36 | } | ||
37 | |||
38 | ssl_certificate /etc/letsencrypt/live/r1.embedromix.ro/fullchain.pem; | ||
39 | ssl_certificate_key /etc/letsencrypt/live/r1.embedromix.ro/privkey.pem; | ||
40 | ssl_prefer_server_ciphers off; | ||
41 | # Specify the cyphers to get an A+ on Qualys (ssllabs.com); recommended | ||
42 | # https://www.digicert.com/ssl-support/ssl-enabling-perfect-forward-secrecy.htm | ||
43 | ssl_protocols TLSv1.2 TLSv1.3; | ||
44 | ssl_session_cache shared:SSL:60m; | ||
45 | ssl_session_timeout 120m; | ||
46 | |||
47 | ssl_stapling on; | ||
48 | ssl_trusted_certificate /etc/letsencrypt/live/r1.embedromix.ro/chain.pem; | ||
49 | ssl_stapling_verify on; | ||
50 | } |
File test/curl-cert/TODO added (mode: 100644) (index 0000000..caa5b59) | |||
1 | [ ] Seems ca.crt is not sent. | ||
2 | [ ] I need to store on the server the last use of a cert. | ||
3 | [ ] |
File test/curl-cert/certs.inc.sh added (mode: 100644) (index 0000000..927e031) | |||
1 | #!/bin/bash | ||
2 | |||
3 | if [ ! -r ca.crt ]; then | ||
4 | openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:4096 -keyout ca.key -out ca.crt | ||
5 | fi | ||
6 | |||
7 | if [ ! -r client.crt ]; then | ||
8 | openssl genrsa -out client.key 4096 | ||
9 | openssl req -new -key client.key \ | ||
10 | -subj "/C=RO/CN=client-certificate-1/L=Brasov/O=bla" \ | ||
11 | -out client.csr | ||
12 | |||
13 | openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -out client.crt | ||
14 | fi | ||
15 | |||
16 | if [ ! -r server1.crt ]; then | ||
17 | openssl genrsa -out server1.key 4096 | ||
18 | openssl req -new \ | ||
19 | -subj "/C=RO/CN=a.example.com/L=Brasov/O=SomeCompany" \ | ||
20 | -key server1.key -out server1.csr | ||
21 | |||
22 | openssl x509 -req -days 365 -in server1.csr -CA ca.crt -CAkey ca.key -out server1.crt | ||
23 | fi |
File test/curl-cert/gdb.cmd added (mode: 100644) (index 0000000..f27c50f) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=50 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=36000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | set environment NINEDOGS_SYNC_FLUSH=1 | ||
7 | set args -v --key client.key --cert client.crt --cacert ca.crt https://127.0.0.1:1 | ||
8 | r |
File test/curl-cert/gdb.sh added (mode: 100755) (index 0000000..99ea941) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command gdb.cmd curl |
File test/curl-cert/run-ca.sh added (mode: 100755) (index 0000000..c10d043) | |||
1 | #!/bin/bash | ||
2 | |||
3 | . ./certs.inc.sh | ||
4 | |||
5 | |||
6 | openssl s_server -accept 127.3.3.3:64999 -cert server1.crt \ | ||
7 | -key server1.key \ | ||
8 | -www -naccept 1 & | ||
9 | |||
10 | |||
11 | export LD_PRELOAD=../../agent/ninedogs.so | ||
12 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
13 | export NINEDOGS_SERVER_PORT=36000 | ||
14 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55b55 | ||
15 | export NINEDOGS_SYNC_FLUSH=1 | ||
16 | export NINEDOGS_VERBOSE=41 | ||
17 | |||
18 | export LD_DEBUG=all | ||
19 | export LD_DEBUG_OUTPUT=ld-ca.txt | ||
20 | |||
21 | export DEBUGINFOD_URLS= | ||
22 | |||
23 | |||
24 | #valgrind -v --trace-children=yes \ | ||
25 | #strace -tt -f -s2000 -o 1-ca.strace \ | ||
26 | #ltrace -S -s200 -f -tt -S -o 1-ca.ltrace \ | ||
27 | curl -v \ | ||
28 | --cacert ca.crt \ | ||
29 | --connect-to a.example.com:443:127.3.3.3:64999 \ | ||
30 | https://a.example.com:443 | ||
31 | |||
32 | wait |
File test/curl-cert/run-client.sh added (mode: 100755) (index 0000000..823ad95) | |||
1 | #!/bin/bash | ||
2 | |||
3 | . ./certs.inc.sh | ||
4 | |||
5 | export LD_PRELOAD=../../agent/ninedogs.so | ||
6 | |||
7 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
8 | export NINEDOGS_SERVER_PORT=36000 | ||
9 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55b55 | ||
10 | export NINEDOGS_SYNC_FLUSH=1 | ||
11 | |||
12 | export NINEDOGS_VERBOSE=50 | ||
13 | #export LD_DEBUG=all | ||
14 | export LD_DEBUG_OUTPUT=ld-client.txt | ||
15 | |||
16 | export DEBUGINFOD_URLS= | ||
17 | |||
18 | ulimit -c 0 | ||
19 | |||
20 | #valgrind -v --trace-children=yes \ | ||
21 | #strace -tt -f -s2000 -o 1-client.strace \ | ||
22 | #ltrace -S -s200 -f -tt -S -o 1-client.ltrace \ | ||
23 | curl -v -k \ | ||
24 | --key client.key \ | ||
25 | --cert client.crt \ | ||
26 | https://localhost:36000 | ||
27 |
File test/curl-cert/run-no-9dogs.sh added (mode: 100755) (index 0000000..50a7d82) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_DEBUG=all | ||
4 | export LD_DEBUG_OUTPUT=ld-no-9dogs.txt | ||
5 | |||
6 | export DEBUGINFOD_URLS= | ||
7 | |||
8 | ulimit -c 0 | ||
9 | |||
10 | #valgrind -v --trace-children=yes \ | ||
11 | #strace -tt -f -s2000 -o 1.strace \ | ||
12 | #ltrace -S -s200 -f -tt -S -o 1-no-9dogs.ltrace \ | ||
13 | curl -v \ | ||
14 | --key client.key \ | ||
15 | --cert client.crt \ | ||
16 | --cacert ca.crt \ | ||
17 | https://localhost:36000 | ||
18 |
File test/dotnet/README added (mode: 100644) (index 0000000..74e3408) | |||
1 | dotnet is loading a .so file which is linked with the OpenSSL libraries. | ||
2 | In this case, I cannot lookup OpenSSL symbols, dlsym returns NULL. | ||
3 | |||
4 | Maybe I should store all dlopen calls and try to find the symbol in all of them? | ||
5 | Yes, this is how is done. | ||
6 |
File test/dotnet/a1/1.run added (mode: 100755) (index 0000000..9ec2e3e) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | dotnet build | ||
6 | |||
7 | export LD_PRELOAD=../../../agent/ninedogs.so | ||
8 | |||
9 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
10 | export NINEDOGS_SERVER_PORT=36000 | ||
11 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
12 | export NINEDOGS_VERBOSE=400 | ||
13 | export NINEDOGS_SYNC_FLUSH=1 | ||
14 | |||
15 | export NINEDOGS_VERBOSE=100 | ||
16 | #export LD_DEBUG=all | ||
17 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
18 | |||
19 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
20 | #strace -tt -f -s2000 -o 1.strace \ | ||
21 | dotnet run 2>&1 | LD_PRELOAD= LD_DEBUG= tee 1.out | ||
22 | |||
23 |
File test/dotnet/a1/Program.cs added (mode: 100644) (index 0000000..a824c19) | |||
1 | using Npgsql; | ||
2 | |||
3 | var cs = "Host=localhost;Username=ninedogs;Database=ninedogs"; | ||
4 | |||
5 | using var con = new NpgsqlConnection(cs); | ||
6 | |||
7 | Console.WriteLine("Connecting..."); | ||
8 | con.Open(); | ||
9 | |||
10 | Thread.Sleep(10 * 1000); | ||
11 | |||
12 | Console.WriteLine("Selecting..."); | ||
13 | var sql = "SELECT version()"; | ||
14 | using var cmd = new NpgsqlCommand(sql, con); | ||
15 | |||
16 | var version = cmd.ExecuteScalar().ToString(); | ||
17 | Console.WriteLine($"PostgreSQL version: {version}"); | ||
18 |
File test/dotnet/a1/a1.csproj added (mode: 100644) (index 0000000..a395946) | |||
1 | <Project Sdk="Microsoft.NET.Sdk"> | ||
2 | |||
3 | <PropertyGroup> | ||
4 | <OutputType>Exe</OutputType> | ||
5 | <TargetFramework>net6.0</TargetFramework> | ||
6 | <ImplicitUsings>enable</ImplicitUsings> | ||
7 | <Nullable>enable</Nullable> | ||
8 | </PropertyGroup> | ||
9 | |||
10 | <ItemGroup> | ||
11 | <PackageReference Include="Npgsql" Version="6.0.4" /> | ||
12 | </ItemGroup> | ||
13 | |||
14 | </Project> |
File test/dotnet/opent.sh added (mode: 100755) (index 0000000..20e40b6) | |||
1 | #!/bin/bash | ||
2 | |||
3 | rm -rf opent | ||
4 | mkdir opent | ||
5 | cd opent | ||
6 | dotnet new console | ||
7 | #dotnet add package OpenTelemetry | ||
8 | #dotnet add package OpenTelemetry.Exporter.Console |
File test/dotnet/opent/1.run added (mode: 100755) (index 0000000..b715392) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | dotnet build | ||
6 | |||
7 | #export LD_PRELOAD=../../../src/ninedogs.so | ||
8 | |||
9 | export NINEDOGS_VERBOSE=10 | ||
10 | export LD_DEBUG=symbols | ||
11 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
12 | |||
13 | echo "Running..." | ||
14 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
15 | #strace -tt -f -s2000 -o 1.strace \ | ||
16 | #valgrind -v \ | ||
17 | bin/Debug/net6.0/opent | ||
18 |
File test/dotnet/opent/Program.cs added (mode: 100644) (index 0000000..a3e1843) | |||
1 | Console.WriteLine("ninedogs"); // signal that is a fd used to communicate | ||
2 | Console.WriteLine("ninedogs Hello, World!"); |
File test/dotnet/opent/opent.csproj added (mode: 100644) (index 0000000..74abf5c) | |||
1 | <Project Sdk="Microsoft.NET.Sdk"> | ||
2 | |||
3 | <PropertyGroup> | ||
4 | <OutputType>Exe</OutputType> | ||
5 | <TargetFramework>net6.0</TargetFramework> | ||
6 | <ImplicitUsings>enable</ImplicitUsings> | ||
7 | <Nullable>enable</Nullable> | ||
8 | </PropertyGroup> | ||
9 | |||
10 | </Project> |
File test/dotnet/web-req1/1.run added (mode: 100755) (index 0000000..d593aac) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | dotnet build | ||
6 | |||
7 | export LD_PRELOAD=../../../agent/ninedogs.so | ||
8 | |||
9 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
10 | export NINEDOGS_SERVER_PORT=36000 | ||
11 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
12 | export NINEDOGS_VERBOSE=400 | ||
13 | export NINEDOGS_SYNC_FLUSH=1 | ||
14 | |||
15 | #export LD_DEBUG=all | ||
16 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
17 | |||
18 | echo "Running..." | ||
19 | #strace -tt -f -s2000 -o 1.strace \ | ||
20 | #valgrind -v \ | ||
21 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
22 | bin/Debug/net6.0/HttpRequestsConsoleSample 2>&1 | LD_PRELOAD= LD_DEBUG= tee 1.out | ||
23 | |||
24 |
File test/dotnet/web-req1/HttpRequestsConsoleSample.csproj added (mode: 100644) (index 0000000..d029cd8) | |||
1 | <Project Sdk="Microsoft.NET.Sdk"> | ||
2 | |||
3 | <PropertyGroup> | ||
4 | <OutputType>Exe</OutputType> | ||
5 | <TargetFramework>net6.0</TargetFramework> | ||
6 | <ImplicitUsings>enable</ImplicitUsings> | ||
7 | <Nullable>enable</Nullable> | ||
8 | </PropertyGroup> | ||
9 | |||
10 | <ItemGroup> | ||
11 | <PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" /> | ||
12 | <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" /> | ||
13 | </ItemGroup> | ||
14 | |||
15 | </Project> |
File test/dotnet/web-req1/Program.cs added (mode: 100644) (index 0000000..6cfdadc) | |||
1 | using System.Text.Json; | ||
2 | using System.Text.Json.Serialization; | ||
3 | using Microsoft.Extensions.DependencyInjection; | ||
4 | using Microsoft.Extensions.Hosting; | ||
5 | using Microsoft.Extensions.Logging; | ||
6 | |||
7 | var host = new HostBuilder() | ||
8 | .ConfigureServices(services => | ||
9 | { | ||
10 | services.AddHttpClient(); | ||
11 | services.AddTransient<GitHubService>(); | ||
12 | }) | ||
13 | .Build(); | ||
14 | |||
15 | try | ||
16 | { | ||
17 | var gitHubService = host.Services.GetRequiredService<GitHubService>(); | ||
18 | var gitHubBranches = await gitHubService.GetAspNetCoreDocsBranchesAsync(); | ||
19 | |||
20 | Console.WriteLine($"{gitHubBranches?.Count() ?? 0} GitHub Branches"); | ||
21 | |||
22 | if (gitHubBranches is not null) | ||
23 | { | ||
24 | foreach (var gitHubBranch in gitHubBranches) | ||
25 | { | ||
26 | Console.WriteLine($"- {gitHubBranch.Name}"); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | catch (Exception ex) | ||
31 | { | ||
32 | host.Services.GetRequiredService<ILogger<Program>>() | ||
33 | .LogError(ex, "Unable to load branches from GitHub."); | ||
34 | } | ||
35 | |||
36 | public class GitHubService | ||
37 | { | ||
38 | private readonly IHttpClientFactory _httpClientFactory; | ||
39 | |||
40 | public GitHubService(IHttpClientFactory httpClientFactory) => | ||
41 | _httpClientFactory = httpClientFactory; | ||
42 | |||
43 | public async Task<IEnumerable<GitHubBranch>?> GetAspNetCoreDocsBranchesAsync() | ||
44 | { | ||
45 | var httpRequestMessage = new HttpRequestMessage( | ||
46 | HttpMethod.Get, | ||
47 | "https://api.github.com/repos/dotnet/AspNetCore.Docs/branches") | ||
48 | { | ||
49 | Headers = | ||
50 | { | ||
51 | { "Accept", "application/vnd.github.v3+json" }, | ||
52 | { "User-Agent", "HttpRequestsConsoleSample" } | ||
53 | } | ||
54 | }; | ||
55 | |||
56 | var httpClient = _httpClientFactory.CreateClient(); | ||
57 | var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage); | ||
58 | |||
59 | httpResponseMessage.EnsureSuccessStatusCode(); | ||
60 | |||
61 | using var contentStream = | ||
62 | await httpResponseMessage.Content.ReadAsStreamAsync(); | ||
63 | |||
64 | return await JsonSerializer.DeserializeAsync | ||
65 | <IEnumerable<GitHubBranch>>(contentStream); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | public record GitHubBranch( | ||
70 | [property: JsonPropertyName("name")] string Name); |
File test/gnutls/TODO added (mode: 100644) (index 0000000..7fb6d1b) | |||
1 | [ ] We may want to signal to the user if an obsolete algorithm was used | ||
2 | in the certificate generation. | ||
3 | [ ] Generate a chain of certs. | ||
4 | [ ] |
File test/gnutls/gdb.cmd added (mode: 100644) (index 0000000..9d7afc8) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=50 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=36000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | set args --certificate-info --infile certificate.crt |
File test/gnutls/gdb.sh added (mode: 100755) (index 0000000..25c164a) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command gdb.cmd certtool |
File test/gnutls/run.sh added (mode: 100755) (index 0000000..b8c4497) | |||
1 | #!/bin/bash | ||
2 | |||
3 | if [ ! -r certificate.crt ]; then | ||
4 | openssl req -x509 \ | ||
5 | -utf8 \ | ||
6 | -sha256 \ | ||
7 | -nodes \ | ||
8 | -days 365 \ | ||
9 | -set_serial 0x1122334455667788 \ | ||
10 | -subj '/C=RO/CN=aaa.example.com/L=Brașov/O=gnutls' \ | ||
11 | -addext 'subjectAltName = DNS:bbb.example.com, DNS:ccc.example.com, DNS:È™' \ | ||
12 | -newkey rsa:4096 \ | ||
13 | -keyout private.key \ | ||
14 | -out certificate.crt | ||
15 | fi | ||
16 | |||
17 | export LD_PRELOAD=../../agent/ninedogs.so | ||
18 | |||
19 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
20 | export NINEDOGS_SERVER_PORT=36000 | ||
21 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
22 | export NINEDOGS_VERBOSE=50 | ||
23 | export NINEDOGS_SYNC_FLUSH=1 | ||
24 | |||
25 | #export LD_DEBUG=all | ||
26 | export LD_DEBUG_OUTPUT="1.ld.txt" | ||
27 | |||
28 | export DEBUGINFOD_URLS= | ||
29 | |||
30 | #export GNUTLS_DEBUG_LEVEL=99 | ||
31 | #export SSLKEYLOGFILE=run.key | ||
32 | |||
33 | #strace -tt -f -s2000 -o 1.strace \ | ||
34 | #ltrace -S -s200 -f -tt -S -o 1.ltrace \ | ||
35 | #valgrind -v --trace-children=yes \ | ||
36 | certtool --certificate-info --infile certificate.crt 2>&1 | LD_PRELOAD= tee run.out | ||
37 |
File test/java/jdbc/1.run added (mode: 100755) (index 0000000..793aeea) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | if [ pg1.class -ot pg1.java ]; then | ||
6 | echo "Compiling..." | ||
7 | javac pg1.java | ||
8 | fi | ||
9 | |||
10 | # We need postgreql-jdbc package | ||
11 | |||
12 | export LD_PRELOAD=../../../agent/ninedogs.so | ||
13 | |||
14 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
15 | export NINEDOGS_SERVER_PORT=36000 | ||
16 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
17 | export NINEDOGS_VERBOSE=10 | ||
18 | export NINEDOGS_SYNC_FLUSH=1 | ||
19 | |||
20 | #export LD_DEBUG=all | ||
21 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
22 | |||
23 | #strace -tt -f -s2000 -o 1.strace \ | ||
24 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
25 | #java -cp /usr/share/java/postgresql-jdbc.jar:. pg1 | ||
26 | |||
27 | #strace -s20000 -f -o 1.strace \ | ||
28 | # -javaagent:../../agent/java/agent/ninedogs-agent.jar \ | ||
29 | java \ | ||
30 | -cp /usr/share/java/postgresql-jdbc.jar:. pg1 | ||
31 | |||
32 | # ninedogs must inject this: | ||
33 | # -javaagent:../../../agent/java/agent/ninedogs-agent.jar | ||
34 |
File test/java/jdbc/pg1.java added (mode: 100644) (index 0000000..fd4446c) | |||
1 | import java.sql.Connection; | ||
2 | import java.sql.DriverManager; | ||
3 | import java.sql.PreparedStatement; | ||
4 | import java.sql.Statement; | ||
5 | import java.sql.ResultSet; | ||
6 | import java.sql.SQLException; | ||
7 | |||
8 | public class pg1 { | ||
9 | public static void main(String args[]) { | ||
10 | Connection c = null; | ||
11 | try { | ||
12 | System.err.println("Starting..."); | ||
13 | |||
14 | Class.forName("org.postgresql.Driver"); | ||
15 | System.err.println("getConnection..."); | ||
16 | c = DriverManager | ||
17 | .getConnection("jdbc:postgresql://localhost:5432/ninedogs?ApplicationName=pg1", | ||
18 | "ninedogs", ""); | ||
19 | |||
20 | System.err.println("Opened database successfully"); | ||
21 | |||
22 | /* | ||
23 | System.err.println("Query (prepared)..."); | ||
24 | //System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx prepare start"); | ||
25 | PreparedStatement preparedStatement = c.prepareStatement("SELECT ? AS id"); | ||
26 | //System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx prepare end"); | ||
27 | preparedStatement.setInt(1, 1); | ||
28 | System.err.println("Prepared statement: " + preparedStatement); | ||
29 | |||
30 | System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx execute q start"); | ||
31 | ResultSet rs = preparedStatement.executeQuery(); | ||
32 | System.err.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx execute q end"); | ||
33 | */ | ||
34 | |||
35 | System.err.println("Query (normal)..."); | ||
36 | Statement stmt = c.createStatement(); | ||
37 | ResultSet rs = stmt.executeQuery("SELECT * FROM n1 LIMIT 220"); | ||
38 | System.err.println("Query (normal) done"); | ||
39 | |||
40 | while (rs.next()) { | ||
41 | int id = rs.getInt("id"); | ||
42 | //System.err.println("id=" + id); | ||
43 | } | ||
44 | |||
45 | System.err.println("Done"); | ||
46 | } catch (Exception e) { | ||
47 | e.printStackTrace(); | ||
48 | System.err.println(e.getClass().getName()+": " + e.getMessage()); | ||
49 | System.exit(0); | ||
50 | } | ||
51 | |||
52 | } | ||
53 | } |
File test/java/tls/TODO added (mode: 100644) (index 0000000..e5f0d86) | |||
1 | [ ] Reading a cert from a stream: | ||
2 | FileInputStream fis = new FileInputStream(filename); | ||
3 | BufferedInputStream bis = new BufferedInputStream(fis); | ||
4 | |||
5 | CertificateFactory cf = CertificateFactory.getInstance("X.509"); | ||
6 | |||
7 | while (bis.available() > 0) { | ||
8 | Certificate cert = cf.generateCertificate(bis); | ||
9 | System.out.println(cert.toString()); | ||
10 | } | ||
11 |
File test/java/tls/tls1.java added (mode: 100644) (index 0000000..d741296) | |||
1 | import javax.net.ssl.SSLSocketFactory; | ||
2 | |||
3 | public class tls1 | ||
4 | { | ||
5 | public static void main(String args[]) | ||
6 | { | ||
7 | String host = "r1.embedromix.ro"; | ||
8 | Integer port = 443; | ||
9 | SSLSocketFactory sslsocketfactory = SSLSocketFactory.getDefault(); | ||
10 | SSLSocket sslsocket = (SSLSocket) sslsocketfactory | ||
11 | .createSocket(host, port); | ||
12 | InputStream in = sslsocket.getInputStream(); | ||
13 | OutputStream out = sslsocket.getOutputStream(); | ||
14 | |||
15 | out.write(1); | ||
16 | while (in.available() > 0) { | ||
17 | System.out.print(in.read()); | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 |
File test/java/tls/tls1.run added (mode: 100755) (index 0000000..be49a3a) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | if [ tls1.class -ot tls1.java ]; then | ||
6 | echo "Compiling..." | ||
7 | javac tls1.java | ||
8 | fi | ||
9 | |||
10 | # We need postgreql-jdbc package | ||
11 | |||
12 | export LD_PRELOAD=../../../src/ninedogs.so | ||
13 | |||
14 | export NINEDOGS_VERBOSE=10 | ||
15 | #export LD_DEBUG=all | ||
16 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
17 | |||
18 | #strace -tt -f -s2000 -o 1.strace \ | ||
19 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
20 | #java -cp /usr/share/java/postgresql-jdbc.jar:. tls | ||
21 | |||
22 | #strace -s20000 -f -o 1.strace \ | ||
23 | # -javaagent:../../src/java/agent/ninedogs-agent.jar \ | ||
24 | java \ | ||
25 | -cp ../../../src/java/agent/javassist.jar:/usr/share/java/postgresql-jdbc.jar:. tls | ||
26 | |||
27 | # ninedogs must inject this: | ||
28 | # -javaagent:../../../src/java/agent/ninedogs-agent.jar | ||
29 |
File test/java/tls/tls2.java added (mode: 100644) (index 0000000..7504413) | |||
1 | import java.io.IOException; | ||
2 | import java.net.URI; | ||
3 | import java.net.http.HttpClient; | ||
4 | import java.net.http.HttpRequest; | ||
5 | import java.net.http.HttpResponse; | ||
6 | |||
7 | public class tls2 | ||
8 | { | ||
9 | public static void main(String args[]) throws IOException, InterruptedException | ||
10 | { | ||
11 | HttpClient httpClient = HttpClient.newHttpClient(); | ||
12 | |||
13 | HttpRequest request = HttpRequest.newBuilder() | ||
14 | .uri(URI.create("https://r1.embedromix.ro")) | ||
15 | .build(); | ||
16 | |||
17 | HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | ||
18 | System.err.println(response); | ||
19 | } | ||
20 | } | ||
21 |
File test/java/tls/tls2.run added (mode: 100755) (index 0000000..1c8deaa) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | if [ tls2.class -ot tls2.java ]; then | ||
6 | echo "Compiling..." | ||
7 | javac tls2.java | ||
8 | fi | ||
9 | |||
10 | export LD_PRELOAD=../../../agent/ninedogs.so | ||
11 | |||
12 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
13 | export NINEDOGS_SERVER_PORT=36000 | ||
14 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
15 | export NINEDOGS_VERBOSE=50 | ||
16 | export NINEDOGS_SYNC_FLUSH=1 | ||
17 | |||
18 | #export LD_DEBUG=all | ||
19 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
20 | |||
21 | #strace -tt -f -s2000 -o 1.strace \ | ||
22 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
23 | #java -cp /usr/share/java/postgresql-jdbc.jar:. tls | ||
24 | |||
25 | #strace -s20000 -f -o 1.strace \ | ||
26 | # -javaagent:../../../agent/java/agent/ninedogs-agent.jar \ | ||
27 | java \ | ||
28 | -XX:DumpLoadedClassList=tls2.classes \ | ||
29 | -cp ../../../agent/java/agent/javassist.jar:. tls2 2>&1 | tee tls2.out |
File test/java/tls/tls3.java added (mode: 100644) (index 0000000..e8883ed) | |||
1 | // From: https://stackoverflow.com/questions/12967016/how-to-check-ssl-certificate-expiration-date-programmatically-in-java | ||
2 | |||
3 | import java.net.URL; | ||
4 | import java.security.SecureRandom; | ||
5 | import java.security.cert.Certificate; | ||
6 | import java.security.cert.CertificateException; | ||
7 | import java.security.cert.X509Certificate; | ||
8 | import javax.net.ssl.HostnameVerifier; | ||
9 | import javax.net.ssl.HttpsURLConnection; | ||
10 | import javax.net.ssl.KeyManager; | ||
11 | import javax.net.ssl.SSLContext; | ||
12 | import javax.net.ssl.SSLSession; | ||
13 | import javax.net.ssl.TrustManager; | ||
14 | import javax.net.ssl.X509TrustManager; | ||
15 | |||
16 | public class tls3 | ||
17 | { | ||
18 | public static void main(String [] args) throws Exception | ||
19 | { | ||
20 | System.out.println("Connecting..."); | ||
21 | URL url = new URL("https://r1.embedromix.ro"); | ||
22 | HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); | ||
23 | System.out.println("code=" + conn.getResponseCode()); | ||
24 | conn.disconnect(); | ||
25 | } | ||
26 | } |
File test/java/tls/tls3.run added (mode: 100755) (index 0000000..fc286bb) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | if [ tls3.class -ot tls3.java ]; then | ||
6 | echo "Compiling..." | ||
7 | javac tls3.java | ||
8 | fi | ||
9 | |||
10 | export LD_PRELOAD=../../../agent/ninedogs.so | ||
11 | |||
12 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
13 | export NINEDOGS_SERVER_PORT=36000 | ||
14 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
15 | export NINEDOGS_VERBOSE=20 | ||
16 | export NINEDOGS_SYNC_FLUSH=1 | ||
17 | |||
18 | #export LD_DEBUG=all | ||
19 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
20 | |||
21 | #strace -tt -f -s2000 -o 1.strace \ | ||
22 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
23 | #java -cp /usr/share/java/postgresql-jdbc.jar:. tls | ||
24 | |||
25 | #strace -s20000 -f -o 1.strace \ | ||
26 | # -javaagent:../../../agent/java/agent/ninedogs-agent.jar \ | ||
27 | java \ | ||
28 | -cp . tls3 2>&1 | tee tls3.out |
File test/nginx-docker/Dockerfile added (mode: 100644) (index 0000000..7dbd3b9) | |||
1 | FROM nginx | ||
2 | |||
3 | ADD src/ninedogs.so /usr/lib/ | ||
4 | |||
5 | RUN ls /usr/lib/nine* | ||
6 | |||
7 | ENV LD_PRELOAD="/usr/lib/ninedogs.so" | ||
8 |
File test/nginx-docker/exec.sh added (mode: 100755) (index 0000000..2868873) | |||
1 | #!/bin/bash | ||
2 | |||
3 | podman exec -it ninedogs-nginx1-a bash |
File test/nginx-docker/run.sh added (mode: 100755) (index 0000000..a45df49) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | #TODO podman pull nginx:latest | ||
6 | |||
7 | podman --log-level info \ | ||
8 | build \ | ||
9 | -t ninedogs-nginx1:latest \ | ||
10 | -f Dockerfile \ | ||
11 | ../.. | ||
12 | |||
13 | podman stop -t0 ninedogs-nginx1-a | ||
14 | podman run --name ninedogs-nginx1-a --rm -p 8:80 -d ninedogs-nginx1:latest | ||
15 | podman logs -f ninedogs-nginx1-a | ||
16 |
File test/nginx/gdb.cmd added (mode: 100644) (index 0000000..9ee95f0) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=50 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=36000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | set args -p ${PWD} -c nginx.conf | ||
7 | r |
File test/nginx/gdb.sh added (mode: 100755) (index 0000000..2beb07d) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command gdb.cmd nginx |
File test/nginx/nginx.conf added (mode: 100644) (index 0000000..ae3cc2f) | |||
1 | daemon off; | ||
2 | worker_processes auto; | ||
3 | |||
4 | events { | ||
5 | worker_connections 1024; | ||
6 | multi_accept on; | ||
7 | } | ||
8 | |||
9 | http { | ||
10 | server { | ||
11 | listen 127.127.127.127:64301 ssl http2 backlog=128 rcvbuf=64k; | ||
12 | ssl_certificate certificate1.crt; | ||
13 | ssl_certificate_key private1.key; | ||
14 | } | ||
15 | |||
16 | server { | ||
17 | listen 127.127.127.127:64302 ssl http2 backlog=128 rcvbuf=64k; | ||
18 | ssl_certificate certificate2.crt; | ||
19 | ssl_certificate_key private2.key; | ||
20 | } | ||
21 | |||
22 | server { | ||
23 | listen 127.127.127.127:64303 ssl http2 backlog=128 rcvbuf=64k; | ||
24 | ssl_certificate certificate-nonexisting.crt; | ||
25 | ssl_certificate_key private-nonexisting.key; | ||
26 | } | ||
27 | } | ||
28 |
File test/nginx/run.sh added (mode: 100755) (index 0000000..4cb54a8) | |||
1 | #!/bin/bash | ||
2 | |||
3 | for i in 1 2; do | ||
4 | if [ ! -r certificate${i}.crt ]; then | ||
5 | openssl req -x509 \ | ||
6 | -sha256 \ | ||
7 | -nodes \ | ||
8 | -days 365 \ | ||
9 | -set_serial 0x10203040506070809${i} \ | ||
10 | -subj "/C=RO/CN=aaa${i}.example.com/L=Brasov/O=SomeCompany" \ | ||
11 | -addext "subjectAltName = DNS:bbb${i}.example.com, DNS:ccc${i}.example.com" \ | ||
12 | -newkey rsa:4096 \ | ||
13 | -keyout private${i}.key \ | ||
14 | -out certificate${i}.crt | ||
15 | fi | ||
16 | done | ||
17 | |||
18 | export LD_PRELOAD=../../agent/ninedogs.so | ||
19 | |||
20 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
21 | export NINEDOGS_SERVER_PORT=36000 | ||
22 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55551 | ||
23 | export NINEDOGS_VERBOSE=50 | ||
24 | export NINEDOGS_SYNC_FLUSH=1 | ||
25 | |||
26 | #export LD_DEBUG=all | ||
27 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
28 | |||
29 | export DEBUGINFOD_URLS= | ||
30 | |||
31 | #strace -tt -f -s2000 -o 1.strace \ | ||
32 | #ltrace -S -s200 -f -tt -S -o $(date +%s).ltrace \ | ||
33 | #valgrind -v --trace-children=yes \ | ||
34 | nginx -p ${PWD} -c nginx.conf 2>&1 | tee run.out | ||
35 | |||
36 |
File test/openssl/TODO added (mode: 100644) (index 0000000..d95c478) | |||
1 | [ ] Seems the openssl 3 uses OSSL_STORE_open / OSSL_STORE_load to load a certificate. | ||
2 | We need to trap this. See 'man ossl_store'. | ||
3 | [ ] Deal with -addext parameters to openssl command | ||
4 | - we may want to report some attributes | ||
5 | [ ] We may want to signal to the user if an obsolete algorithm was used | ||
6 | in the certificate generation. | ||
7 | [ ] CN=Ș... seems to be packed strange (ASN1). | ||
8 | See do_buf function. | ||
9 | We should send UTF-8 to the server. | ||
10 | [ ] |
File test/openssl/gdb.cmd added (mode: 100644) (index 0000000..75fe71a) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=50 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=36000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | #break OSSL_STORE_close | ||
7 | set args x509 -in certificate.crt -text -noout |
File test/openssl/gdb.sh added (mode: 100755) (index 0000000..4e1dc4c) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command gdb.cmd openssl |
File test/openssl/run.sh added (mode: 100755) (index 0000000..85565d3) | |||
1 | #!/bin/bash | ||
2 | |||
3 | if [ ! -r certificate.crt ]; then | ||
4 | openssl req -x509 \ | ||
5 | -utf8 \ | ||
6 | -sha256 \ | ||
7 | -nodes \ | ||
8 | -days 365 \ | ||
9 | -set_serial 0x112233 \ | ||
10 | -subj '/C=RO/CN=aaa.example.com/L=Brasov/O=openssl' \ | ||
11 | -addext 'subjectAltName = DNS:bbb.example.com, DNS:ccc.example.com, DNS:șșș.example.com' \ | ||
12 | -newkey rsa:4096 \ | ||
13 | -keyout private.key \ | ||
14 | -out certificate.crt | ||
15 | fi | ||
16 | |||
17 | # To debug | ||
18 | #openssl s_server -cert fullchain.pem -key privkey.pem -port 6002 -debug -status_verbose -msg | ||
19 | |||
20 | export LD_PRELOAD=../../agent/ninedogs.so | ||
21 | |||
22 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
23 | export NINEDOGS_SERVER_PORT=36000 | ||
24 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
25 | export NINEDOGS_VERBOSE=50 | ||
26 | export NINEDOGS_SYNC_FLUSH=1 | ||
27 | |||
28 | export LD_DEBUG=all | ||
29 | export LD_DEBUG_OUTPUT="1.ld.txt" | ||
30 | |||
31 | export DEBUGINFOD_URLS= | ||
32 | |||
33 | #export GNUTLS_DEBUG_LEVEL=99 | ||
34 | #export SSLKEYLOGFILE=run.key | ||
35 | |||
36 | #strace -tt -f -s2000 -o 1.strace \ | ||
37 | #valgrind -v --trace-children=yes \ | ||
38 | #ltrace -S -s200 -f -tt -S -o 1.ltrace \ | ||
39 | openssl x509 -in certificate.crt -text -noout 2>&1 | LD_PRELOAD= LD_DEBUG= tee run.out | ||
40 | |||
41 |
File test/php-pg/1.TODO added (mode: 100644) (index 0000000..fbd99ed) | |||
1 | [ ] We get invalid stats for free_calls: | ||
2 | |||
3 | hash h[00][00][00] [fa]T[85]-[8a]hd[1b][e4][8a][e8]l[ef][e1][9a][e9]8[eb][19]E.#![e4]8X[a0]c[ea]([de]O | ||
4 | count c[00][00][00][00][00][00][00][01] | ||
5 | rows r[00][00][00][00][00][00][00][00] | ||
6 | aff A[00][00][00][00][00][00][00][00] | ||
7 | ts _[00][00][01][82]d[1d][06]@ | ||
8 | min i[00][00][00][00][00][00][00]= | ||
9 | max a[00][00][00][00][00][00][00]= | ||
10 | elap e[00][00][00][00][00][00][00]= | ||
11 | free_calls x[00][00]V5[ce]~[e0][d8] | ||
12 | free_errs y[00][00]V5[ce]~[e0][e0] | ||
13 | |||
14 | hash=fa54852d8a68641be48ae86cefe19ae938eb19452e2321e43858a063ea28de4f count=1 rows=0 aff=0 free_calls/errs=94789097677016/94789097677024 ts=1659537000000 min=61 max=61 elap=61 |
File test/php-pg/1.php added (mode: 100644) (index 0000000..b714e25) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | //echo 'Setting some tags...' . "\n"; | ||
5 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
6 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
7 | //exit(1); | ||
8 | |||
9 | echo 'Connecting...' . "\n"; | ||
10 | //$db = pg_connect(); // seems I cannot catch the fatal error! Should we? | ||
11 | |||
12 | // connect to an invalid host | ||
13 | //$db = pg_connect('host=192.168.79.44 dbname=ninedogs user=ninedogs', PGSQL_CONNECT_FORCE_NEW); // PGSQL_CONNECT_ASYNC | ||
14 | |||
15 | echo 'Connecting 4 times with PGSQL_CONNECT_FORCE_NEW' . "\n"; | ||
16 | $db1 = pg_connect('host=localhost dbname=ninedogs user=ninedogs', PGSQL_CONNECT_FORCE_NEW); // PGSQL_CONNECT_ASYNC | ||
17 | $db2 = pg_connect('host=localhost dbname=ninedogs user=ninedogs', PGSQL_CONNECT_FORCE_NEW); // PGSQL_CONNECT_ASYNC | ||
18 | $db3 = pg_connect('host=localhost dbname=ninedogs user=ninedogs', PGSQL_CONNECT_FORCE_NEW); // PGSQL_CONNECT_ASYNC | ||
19 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs', PGSQL_CONNECT_FORCE_NEW); // PGSQL_CONNECT_ASYNC | ||
20 | echo 'Connecting 2 times without PGSQL_CONNECT_FORCE_NEW' . "\n"; | ||
21 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
22 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
23 | echo "\n"; | ||
24 | |||
25 | echo 'Dropping non-existing table1...' . "\n"; | ||
26 | $r = @pg_send_query($db, 'DROP TABLE non_existing1'); | ||
27 | if ($r !== TRUE) { | ||
28 | echo ' Cannot send drop command!' . "\n"; | ||
29 | } else { | ||
30 | $res = pg_get_result($db); | ||
31 | if ($res === FALSE) { | ||
32 | echo ' Drop failed: cannot get result!' . "\n"; | ||
33 | } else { | ||
34 | $r = pg_result_error_field($res, PGSQL_DIAG_SQLSTATE); | ||
35 | echo ' Drop returned: ' . $r . "\n"; | ||
36 | pg_free_result($res); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | echo 'Dropping non-existing table2...' . "\n"; | ||
41 | $r = @pg_send_query($db, 'DROP TABLE non_existing2'); | ||
42 | $res = pg_get_result($db); | ||
43 | |||
44 | if (0) { | ||
45 | echo 'Dropping table...' . "\n"; | ||
46 | $res = pg_query($db, 'DROP TABLE IF EXISTS n1'); | ||
47 | pg_free_result($res); | ||
48 | |||
49 | echo 'Creating table...' . "\n"; | ||
50 | $res = pg_query($db, 'CREATE TABLE n1 (id INT, a1 TEXT, a2 TEXT, d NUMERIC)'); | ||
51 | pg_free_result($res); | ||
52 | |||
53 | echo 'Inserting...' . "\n"; | ||
54 | $res = pg_query($db, 'INSERT INTO n1 (id, a1, a2, d) SELECT i, i::text || i::text, i::text || i::text || i::text, i FROM generate_series(1,100000) as i'); | ||
55 | pg_free_result($res); | ||
56 | |||
57 | // query without '$db' | ||
58 | $res = pg_query('SELECT id FROM n1 LIMIT 1'); | ||
59 | $rows = pg_fetch_all($res); | ||
60 | pg_free_result($res); | ||
61 | } | ||
62 | |||
63 | if (0) { | ||
64 | echo 'Getting execution plan...' . "\n"; | ||
65 | $sql = 'EXPLAIN (VERBOSE, COSTS, BUFFERS, FORMAT JSON)' | ||
66 | . ' SELECT A.id, B.d FROM n1 A, n1 B WHERE A.id = B.id AND A.a1 = \'a\''; | ||
67 | $res = pg_query($db, $sql); | ||
68 | $rows = pg_fetch_all($res); | ||
69 | print_r($rows); | ||
70 | pg_free_result($res); | ||
71 | } | ||
72 | |||
73 | // query with parameters | ||
74 | echo 'Querying with parameters...' . "\n"; | ||
75 | $sql = 'SELECT id FROM n1 WHERE id = $1 OR id = $2 OR d = $3 OR a1 = $4 OR a1 = $5'; | ||
76 | $a = 3; $b = &$a; $c = $b; | ||
77 | $x = &$c; $y = "4"; $d = 1.2; | ||
78 | $params = array($x, $y, $d, NULL, FALSE); | ||
79 | if (1) { | ||
80 | $res = array(); | ||
81 | for ($i = 0; $i < 5; $i++) | ||
82 | $res[$i] = pg_query_params($db, $sql, $params); | ||
83 | } | ||
84 | $res = pg_query_params($db, $sql, $params); | ||
85 | echo "\n"; | ||
86 | |||
87 | echo 'Calling native pg_num_rows:' . "\n"; | ||
88 | echo 'native num_rows: ' . pg_num_rows($res) . "\n"; | ||
89 | echo 'fetching data...' . "\n"; | ||
90 | $rows = pg_fetch_all($res); | ||
91 | print_r($rows); | ||
92 | pg_free_result($res); | ||
93 | |||
94 | // give server a chanse to request the query hash | ||
95 | for ($i = 0; $i <= 7; $i++) { | ||
96 | $res = pg_query($db, 'SELECT * FROM n1 LIMIT 1'); | ||
97 | $rows = pg_fetch_all($res); | ||
98 | pg_free_result($res); | ||
99 | echo 'Tempo (10s)...' . "\n"; | ||
100 | sleep(10); | ||
101 | } | ||
102 | |||
103 | if (1) { | ||
104 | $res = pg_query($db, 'SELECT * FROM n1 LIMIT 1'); | ||
105 | $rows = pg_fetch_all($res); | ||
106 | echo count($rows) . ' row(s)' . "\n"; | ||
107 | pg_free_result($res); | ||
108 | var_dump($rows); | ||
109 | } | ||
110 | |||
111 | echo 'Done!' . "\n"; | ||
112 | exit(10); | ||
113 | |||
114 | //file_get_contents('http://localhost:4444'); | ||
115 |
File test/php-pg/1.run added (mode: 100755) (index 0000000..f037596) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=6000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55556 | ||
8 | export NINEDOGS_VERBOSE=41 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o 1.strace \ | ||
19 | php 1.php | ||
20 |
File test/php-pg/1.run.gdb added (mode: 100644) (index 0000000..c4f407c) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=40 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=6000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | set environment NINEDOGS_SYNC_FLUSH=1 | ||
7 | set args 1.php | ||
8 | r |
File test/php-pg/1.run.gdb.sh added (mode: 100755) (index 0000000..701e1ee) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command 1.run.gdb php |
File test/php-pg/1query.php added (mode: 100644) (index 0000000..4265026) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | //echo 'Setting some tags...' . "\n"; | ||
5 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
6 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
7 | //exit(1); | ||
8 | |||
9 | echo 'Connecting...' . "\n"; | ||
10 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=bla'); | ||
11 | echo "\n"; | ||
12 | |||
13 | $res = pg_query($db, 'SELECT * FROM n1 LIMIT 1'); | ||
14 | echo 'affected rows: ' . pg_affected_rows($res) . "\n"; | ||
15 | $rows = pg_fetch_all($res); | ||
16 | echo count($rows) . ' row(s)' . "\n"; | ||
17 | pg_free_result($res); | ||
18 |
File test/php-pg/1query.sh added (mode: 100755) (index 0000000..a26e19b) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55556 | ||
8 | export NINEDOGS_VERBOSE=241 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=1query.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o 1query.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o 1query.strace \ | ||
19 | php 1query.php | ||
20 |
File test/php-pg/1send-query.php added (mode: 100644) (index 0000000..86a2517) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | //echo 'Setting some tags...' . "\n"; | ||
5 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
6 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
7 | //exit(1); | ||
8 | |||
9 | echo 'Connecting...' . "\n"; | ||
10 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=bla'); | ||
11 | echo "\n"; | ||
12 | |||
13 | $sql = 'SELECT * FROM n1 LIMIT 1'; | ||
14 | $r = pg_send_query($db, $sql . '; ' . $sql); | ||
15 | |||
16 | echo 'artificial delay of 5s' . "\n"; | ||
17 | sleep(5); | ||
18 | |||
19 | $res = pg_get_result($db); | ||
20 | $rows = pg_fetch_all($res); | ||
21 | echo count($rows) . ' row(s)' . "\n"; | ||
22 | pg_free_result($res); | ||
23 | |||
24 | $res = pg_get_result($db); | ||
25 | $rows = pg_fetch_all($res); | ||
26 | echo count($rows) . ' row(s)' . "\n"; | ||
27 | pg_free_result($res); | ||
28 | |||
29 | echo 'Sleeping 61s...' . "\n"; | ||
30 | sleep(61); | ||
31 | |||
32 | echo 'Triggering the sending of the stats...' . "\n"; | ||
33 | pg_query($db, 'SELECT 1'); | ||
34 |
File test/php-pg/1send-query.sh added (mode: 100755) (index 0000000..4546e20) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55556 | ||
8 | export NINEDOGS_VERBOSE=101 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=1send-query.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o 1send-query.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o 1send-query.strace \ | ||
19 | php 1send-query.php | ||
20 |
File test/php-pg/2conn.php added (mode: 100644) (index 0000000..fcad0d6) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
5 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
6 |
File test/php-pg/2conn.sh added (mode: 100755) (index 0000000..025c27f) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc1 | ||
8 | export NINEDOGS_VERBOSE=41 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=2conn.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o 1.strace \ | ||
19 | php 2conn.php | ||
20 |
File test/php-pg/2pconn.php added (mode: 100644) (index 0000000..8edd02b) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | $db = pg_pconnect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
5 | $db = pg_pconnect('host=localhost dbname=ninedogs user=ninedogs application_name=reuse1'); | ||
6 |
File test/php-pg/2pconn.sh added (mode: 100755) (index 0000000..c21de51) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc1 | ||
8 | export NINEDOGS_VERBOSE=41 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=2conn.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o 1.strace \ | ||
19 | php 2pconn.php | ||
20 |
File test/php-pg/free-result.php added (mode: 100644) (index 0000000..ef11d9b) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | //echo 'Setting some tags...' . "\n"; | ||
5 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
6 | //@stat('/ninedogs/tag/tag1,tag2,tag3'); | ||
7 | //exit(1); | ||
8 | |||
9 | echo 'Connecting...' . "\n"; | ||
10 | $db = pg_connect('host=localhost dbname=ninedogs user=ninedogs application_name=bla'); | ||
11 | echo "\n"; | ||
12 | |||
13 | $res = pg_query($db, 'SELECT * FROM n1 LIMIT 2'); | ||
14 | $rows = pg_fetch_all($res); | ||
15 | pg_free_result($res); | ||
16 |
File test/php-pg/free-result.sh added (mode: 100755) (index 0000000..8dbebce) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55556 | ||
8 | export NINEDOGS_VERBOSE=251 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=free-result.ld.txt | ||
13 | |||
14 | export DEBUGINFOD_URLS= | ||
15 | |||
16 | #ltrace -s200 -f -tt -S -o free-result.ltrace \ | ||
17 | #valgrind -v --trace-children=yes \ | ||
18 | #strace -tt -f -s2000 -o free-result.strace \ | ||
19 | php free-result.php | ||
20 |
File test/php-sock/1.php added (mode: 100644) (index 0000000..9a4b1e2) | |||
1 | <?php | ||
2 | |||
3 | // Non opened port | ||
4 | file_get_contents('https://localhost:55555'); | ||
5 |
File test/php-sock/1.run added (mode: 100755) (index 0000000..fb758cc) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../src/ninedogs.so | ||
4 | |||
5 | export FORCE_NET_VERBOSE=100 | ||
6 | #export LD_DEBUG=symbols | ||
7 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
8 | |||
9 | strace -tt -f -s2000 -o 1.strace \ | ||
10 | php 1.php | ||
11 |
File test/php-sock/2.php added (mode: 100644) (index 0000000..0f1cae7) | |||
1 | <?php | ||
2 | |||
3 | // Non opened port | ||
4 | file_get_contents('https://192.168.79.235:55555'); | ||
5 |
File test/php-sock/2.run added (mode: 100755) (index 0000000..36b78e4) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../src/ninedogs.so | ||
4 | |||
5 | export FORCE_NET_VERBOSE=100 | ||
6 | #export LD_DEBUG=symbols | ||
7 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
8 | |||
9 | strace -tt -f -s2000 -o 2.strace \ | ||
10 | php 2.php | ||
11 |
File test/php-sock/3.php added (mode: 100644) (index 0000000..534035f) | |||
1 | <?php | ||
2 | |||
3 | $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
4 | socket_connect($sock, '127.0.0.1', 44444); | ||
5 | |||
6 |
File test/php-sock/3.run added (mode: 100755) (index 0000000..a8cdd15) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../src/ninedogs.so | ||
4 | |||
5 | export FORCE_NET_VERBOSE=100 | ||
6 | export LD_DEBUG=all | ||
7 | export LD_DEBUG_OUTPUT=3.ld.txt | ||
8 | |||
9 | #strace -tt -f -s2000 -o 3.strace \ | ||
10 | php 3.php | ||
11 |
File test/rg/1.run added (mode: 100755) (index 0000000..982f8f5) | |||
1 | #!/bin/bash | ||
2 | |||
3 | export LD_PRELOAD=../../agent/ninedogs.so | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=6000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc1 | ||
8 | |||
9 | export NINEDOGS_VERBOSE=300 | ||
10 | export LD_DEBUG=all | ||
11 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
12 | |||
13 | export DEBUGINFOD_URLS= | ||
14 | |||
15 | #ltrace -s200 -f -tt -S -o 1.ltrace \ | ||
16 | #valgrind -v --trace-children=yes \ | ||
17 | #strace -tt -f -s2000 -o 1.strace \ | ||
18 | php /BIG1T/sync1/Dev/rocketgit/scripts/builder.php |
File test/rg/gdb.cmd added (mode: 100644) (index 0000000..9925c54) | |||
1 | set environment LD_PRELOAD=../../agent/ninedogs.so | ||
2 | set environment NINEDOGS_VERBOSE=40 | ||
3 | set environment NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
4 | set environment NINEDOGS_SERVER_PORT=36000 | ||
5 | set environment NINEDOGS_ID=ba446a981b387e831db3f6a730c55bc3 | ||
6 | set args /BIG1T/sync1/Dev/rocketgit/scripts/builder.php | ||
7 | r |
File test/rg/gdb.sh added (mode: 100755) (index 0000000..7bbf67f) | |||
1 | #!/bin/bash | ||
2 | |||
3 | gdb --command gdb.cmd php |
File test/segv1/.gitignore copied from file ingestd/.gitignore (similarity 100%) |
File test/segv1/1.run added (mode: 100755) (index 0000000..cf48358) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | make segv | ||
6 | |||
7 | export LD_PRELOAD=../../agent/ninedogs.so | ||
8 | |||
9 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
10 | export NINEDOGS_SERVER_PORT=6000 | ||
11 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55556 | ||
12 | export NINEDOGS_VERBOSE=41 | ||
13 | export NINEDOGS_SYNC_FLUSH=1 | ||
14 | |||
15 | #export LD_DEBUG=symbols | ||
16 | #export LD_DEBUG_OUTPUT=1.ld.txt | ||
17 | |||
18 | ./segv bla1 bla2 | ||
19 |
File test/segv1/segv.c added (mode: 100644) (index 0000000..badfff0) | |||
1 | int main(void) | ||
2 | { | ||
3 | char *a = 0; | ||
4 | |||
5 | return *a; | ||
6 | } |
File test/trace/.gitignore copied from file ingestd/.gitignore (similarity 100%) |
File test/trace/1.php added (mode: 100644) (index 0000000..fc8ae64) | |||
1 | <?php | ||
2 | error_reporting(E_ALL); | ||
3 | |||
4 | // This is not working because php socket is in a separate .so!!! | ||
5 | |||
6 | sleep(1); | ||
7 | usleep(1000); | ||
8 | |||
9 | |||
10 | @unlink('/dev/ninedogs-non-existing'); | ||
11 | |||
12 | |||
13 | echo 'now we create inet sock...' . "\n"; flush(); | ||
14 | $u = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
15 | if ($u === FALSE) | ||
16 | die('cannot create socket!'); | ||
17 | |||
18 | $x = socket_connect($u, 'r1.embedromix.ro', 443); | ||
19 | |||
20 | socket_send($u, 'aaa', 3, 0); | ||
21 | |||
22 | echo 'now we are create/bind AF_UNIX...' . "\n"; flush(); | ||
23 | @unlink('/tmp/ninedogs-test.sock'); | ||
24 | $u = socket_create(AF_UNIX, SOCK_STREAM, 0); | ||
25 | socket_bind($u, '/tmp/ninedogs-test.sock'); | ||
26 | socket_listen($u, 100); | ||
27 | socket_set_nonblock($u); | ||
28 | $c = socket_accept($u); | ||
29 | |||
30 | //echo @file_get_contents('https://r1.embedromix.ro'); | ||
31 | |||
32 | echo 'Done!' . "\n"; |
File test/trace/1.run added (mode: 100755) (index 0000000..271eab9) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
6 | export NINEDOGS_SERVER_PORT=36000 | ||
7 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
8 | export NINEDOGS_VERBOSE=400 | ||
9 | export NINEDOGS_SYNC_FLUSH=1 | ||
10 | |||
11 | #export LD_DEBUG=all | ||
12 | export LD_DEBUG_OUTPUT=1.ld.txt | ||
13 | |||
14 | LD_PRELOAD=../../agent/ninedogs.so php 1.php &> 1.php.out & | ||
15 | echo "Child pid is ${!}" | ||
16 | sleep .4 | ||
17 | ../../trace/nd-trace -o 1.trace.out -p ${!} | ||
18 |
File test/trace/2.c added (mode: 100644) (index 0000000..32f9165) | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/socket.h> | ||
3 | #include <sys/un.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <unistd.h> | ||
8 | #include <arpa/inet.h> | ||
9 | |||
10 | int main(int argc, char *argv[]) | ||
11 | { | ||
12 | int sock, err; | ||
13 | struct sockaddr_un un; | ||
14 | socklen_t un_len; | ||
15 | unsigned char tos; | ||
16 | |||
17 | sleep(4); // allow nd-trace to attach | ||
18 | |||
19 | sock = socket(AF_UNIX, SOCK_STREAM, 0); | ||
20 | if (sock == -1) { | ||
21 | perror("socket"); | ||
22 | return 1; | ||
23 | } | ||
24 | |||
25 | memset(&un, 0, sizeof(struct sockaddr_un)); | ||
26 | un.sun_family = AF_UNIX; | ||
27 | strcpy(un.sun_path, "/tmp/ninedogs-test"); | ||
28 | |||
29 | unlink(un.sun_path); | ||
30 | |||
31 | un_len = sizeof(struct sockaddr_un); | ||
32 | err = bind(sock, (struct sockaddr *) &un, un_len); | ||
33 | if (err != 0) { | ||
34 | perror("bind"); | ||
35 | return 1; | ||
36 | } | ||
37 | |||
38 | listen(sock, 123); | ||
39 | |||
40 | tos = 0x12; | ||
41 | err = setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, 1); | ||
42 | if (err != 0) | ||
43 | perror("setsockopt"); | ||
44 | |||
45 | close(sock); | ||
46 | |||
47 | return 0; | ||
48 | } |
File test/trace/2.run added (mode: 100755) (index 0000000..67ca56e) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | gcc -Wall 2.c -o 2 | ||
6 | |||
7 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
8 | export NINEDOGS_SERVER_PORT=36000 | ||
9 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
10 | export NINEDOGS_VERBOSE=400 | ||
11 | export NINEDOGS_SYNC_FLUSH=1 | ||
12 | |||
13 | #export LD_DEBUG=all | ||
14 | export LD_DEBUG_OUTPUT=2.ld.txt | ||
15 | |||
16 | export DEBUGINFOD_URLS= | ||
17 | |||
18 | LD_PRELOAD=../../agent/ninedogs.so ./2 &> 2.out & | ||
19 | echo "Child pid is ${!}" | ||
20 | sleep .4 | ||
21 | ../../trace/nd-trace -o 2.trace.out -p ${!} | ||
22 |
File test/trace/segv.c added (mode: 100644) (index 0000000..6949a92) | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/socket.h> | ||
3 | #include <sys/un.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <stdio.h> | ||
6 | #include <string.h> | ||
7 | #include <unistd.h> | ||
8 | #include <arpa/inet.h> | ||
9 | |||
10 | int main(int argc, char *argv[]) | ||
11 | { | ||
12 | char *p = NULL; | ||
13 | |||
14 | sleep(2); | ||
15 | *p = 1; | ||
16 | |||
17 | return 0; | ||
18 | } |
File test/trace/segv.run added (mode: 100755) (index 0000000..e89da1a) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | gcc -Wall segv.c -o segv | ||
6 | |||
7 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
8 | export NINEDOGS_SERVER_PORT=36000 | ||
9 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
10 | export NINEDOGS_VERBOSE=400 | ||
11 | export NINEDOGS_SYNC_FLUSH=1 | ||
12 | |||
13 | #export LD_DEBUG=all | ||
14 | export LD_DEBUG_OUTPUT=segv.ld.txt | ||
15 | |||
16 | export DEBUGINFOD_URLS= | ||
17 | |||
18 | LD_PRELOAD=../../agent/ninedogs.so ./segv &> segv.out & | ||
19 | echo "Child pid is ${!}" | ||
20 | sleep .4 | ||
21 | ../../trace/nd-trace -o segv.trace.out -p ${!} | ||
22 |
File test/trace/thread1.c added (mode: 100644) (index 0000000..ef14799) | |||
1 | #include <sys/socket.h> | ||
2 | #include <sys/types.h> | ||
3 | #include <stdlib.h> | ||
4 | #include <stdio.h> | ||
5 | #include <string.h> | ||
6 | #include <unistd.h> | ||
7 | #include <pthread.h> | ||
8 | |||
9 | void *worker(void *arg) | ||
10 | { | ||
11 | listen(-1, 100); | ||
12 | return NULL; | ||
13 | } | ||
14 | |||
15 | int main(int argc, char *argv[]) | ||
16 | { | ||
17 | pthread_t t[2]; | ||
18 | |||
19 | sleep(2); | ||
20 | |||
21 | t[0] = pthread_create(&t[0], NULL, worker, NULL); | ||
22 | t[1] = pthread_create(&t[1], NULL, worker, NULL); | ||
23 | sleep(1); | ||
24 | |||
25 | return 0; | ||
26 | } |
File test/trace/thread1.run added (mode: 100755) (index 0000000..1e83def) | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e | ||
4 | |||
5 | gcc -Wall thread1.c -o thread1 | ||
6 | |||
7 | export NINEDOGS_SERVER_HOSTNAME=rg.embedromix.ro | ||
8 | export NINEDOGS_SERVER_PORT=36000 | ||
9 | export NINEDOGS_ID=ba446a981b387e831db3f6a730c55552 | ||
10 | export NINEDOGS_VERBOSE=400 | ||
11 | export NINEDOGS_SYNC_FLUSH=1 | ||
12 | |||
13 | #export LD_DEBUG=all | ||
14 | export LD_DEBUG_OUTPUT=thread1.ld.txt | ||
15 | |||
16 | export DEBUGINFOD_URLS= | ||
17 | |||
18 | LD_PRELOAD=../../agent/ninedogs.so ./thread1 &> thread1.out & | ||
19 | echo "Child pid is ${!}" | ||
20 | sleep .4 | ||
21 | ../../trace/nd-trace -o thread1.trace.out -p ${!} | ||
22 |
File trace/nd-trace.c added (mode: 100644) (index 0000000..f0bd9c9) | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #define _GNU_SOURCE | ||
3 | |||
4 | #include <sys/mman.h> | ||
5 | #include <sys/socket.h> | ||
6 | #include <sys/stat.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <sys/un.h> | ||
9 | |||
10 | #include <arpa/inet.h> | ||
11 | #include <errno.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <getopt.h> | ||
14 | #include <netdb.h> | ||
15 | #include <netinet/tcp.h> | ||
16 | #include <netinet/udp.h> | ||
17 | #include <poll.h> | ||
18 | #include <semaphore.h> | ||
19 | #include <stdint.h> | ||
20 | #include <stdio.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <string.h> | ||
23 | #include <unistd.h> | ||
24 | |||
25 | #include "shared.h" | ||
26 | #include "tools.h" | ||
27 | |||
28 | static const struct option options[] = | ||
29 | { | ||
30 | {"pid", required_argument, NULL, 'p'}, | ||
31 | {"output", required_argument, NULL, 'o'}, | ||
32 | {NULL, 0, NULL, 0} | ||
33 | }; | ||
34 | |||
35 | static void usage(void) | ||
36 | { | ||
37 | fprintf(stderr, | ||
38 | "Usage: nd-trace [options]\n" | ||
39 | " --pid -p pid to trace (can be added multiple times)\n" | ||
40 | " --output -o where to store the output\n" | ||
41 | "\n"); | ||
42 | exit(1); | ||
43 | } | ||
44 | |||
45 | static FILE *out; | ||
46 | static char do_exit; | ||
47 | |||
48 | static uint8_t decode8(unsigned char *d, unsigned int *i) | ||
49 | { | ||
50 | uint8_t u; | ||
51 | u = d[*i]; | ||
52 | *i = *i + 1; | ||
53 | return u; | ||
54 | } | ||
55 | |||
56 | static uint16_t decode16(unsigned char *d, unsigned int *i) | ||
57 | { | ||
58 | uint16_t u; | ||
59 | memcpy(&u, d + *i, 2); | ||
60 | *i = *i + 2; | ||
61 | return be16toh(u); | ||
62 | } | ||
63 | |||
64 | static uint32_t decode32(unsigned char *d, unsigned int *i) | ||
65 | { | ||
66 | uint32_t u; | ||
67 | memcpy(&u, d + *i, 4); | ||
68 | *i = *i + 4; | ||
69 | return be32toh(u); | ||
70 | } | ||
71 | |||
72 | static uint64_t decode64(unsigned char *d, unsigned int *i) | ||
73 | { | ||
74 | uint64_t u; | ||
75 | memcpy(&u, d + *i, 8); | ||
76 | *i = *i + 8; | ||
77 | return be64toh(u); | ||
78 | } | ||
79 | |||
80 | static char *decode_socket_domain(const int d) | ||
81 | { | ||
82 | switch (d) { | ||
83 | case AF_UNIX: return "unix"; | ||
84 | case AF_INET: return "ipv4"; | ||
85 | case AF_INET6: return "ipv6"; | ||
86 | case AF_KEY: return "key"; | ||
87 | case AF_NETLINK: return "netlink"; | ||
88 | case AF_PACKET: return "packet"; | ||
89 | } | ||
90 | |||
91 | return "?"; | ||
92 | } | ||
93 | |||
94 | static char *decode_socket_type(const int t) | ||
95 | { | ||
96 | switch (t) { | ||
97 | case SOCK_STREAM: return "stream"; | ||
98 | case SOCK_DGRAM: return "dgram"; | ||
99 | case SOCK_SEQPACKET: return "seqpacket"; | ||
100 | case SOCK_RAW: return "raw"; | ||
101 | } | ||
102 | |||
103 | return "?"; | ||
104 | } | ||
105 | |||
106 | // TODO: more to add from /usr/include/asm-generic/errno.h | ||
107 | static void decode_errno(char *out, unsigned out_max, const int e) | ||
108 | { | ||
109 | switch (e) { | ||
110 | case EPERM: snprintf(out, out_max, "EPERM"); break; | ||
111 | case ENOENT: snprintf(out, out_max, "ENOENT"); break; | ||
112 | case ESRCH: snprintf(out, out_max, "ESRCH"); break; | ||
113 | case EINTR: snprintf(out, out_max, "EINTR"); break; | ||
114 | case EIO: snprintf(out, out_max, "EIO"); break; | ||
115 | case ENXIO: snprintf(out, out_max, "ENXIO"); break; | ||
116 | case E2BIG: snprintf(out, out_max, "E2BIG"); break; | ||
117 | case ENOEXEC: snprintf(out, out_max, "NOEXEC"); break; | ||
118 | case EBADF: snprintf(out, out_max, "BADF"); break; | ||
119 | case ECHILD: snprintf(out, out_max, "ECHILD"); break; | ||
120 | case EAGAIN: snprintf(out, out_max, "EAGAIN"); break; | ||
121 | case ENOMEM: snprintf(out, out_max, "ENOMEM"); break; | ||
122 | case EACCES: snprintf(out, out_max, "EACCES"); break; | ||
123 | case EFAULT: snprintf(out, out_max, "EFAULT"); break; | ||
124 | case ENOTBLK: snprintf(out, out_max, "ENOTBLK"); break; | ||
125 | case EBUSY: snprintf(out, out_max, "EBUSY"); break; | ||
126 | case EEXIST: snprintf(out, out_max, "EEXIST"); break; | ||
127 | case EXDEV: snprintf(out, out_max, "EXDEV"); break; | ||
128 | case ENODEV: snprintf(out, out_max, "ENODEV"); break; | ||
129 | case ENOTDIR: snprintf(out, out_max, "ENOTDIR"); break; | ||
130 | case EISDIR: snprintf(out, out_max, "EISDIR"); break; | ||
131 | case EINVAL: snprintf(out, out_max, "EINVAL"); break; | ||
132 | case ENFILE: snprintf(out, out_max, "ENFILE"); break; | ||
133 | case ENOTTY: snprintf(out, out_max, "ENOTTY"); break; | ||
134 | case ETXTBSY: snprintf(out, out_max, "ETXTBSY"); break; | ||
135 | case EFBIG: snprintf(out, out_max, "EFBIG"); break; | ||
136 | case ENOSPC: snprintf(out, out_max, "ENOSPC"); break; | ||
137 | case ESPIPE: snprintf(out, out_max, "ESPIPE"); break; | ||
138 | case EROFS: snprintf(out, out_max, "EROFS"); break; | ||
139 | case EMLINK: snprintf(out, out_max, "EMLINK"); break; | ||
140 | case EPIPE: snprintf(out, out_max, "EPIPE"); break; | ||
141 | case EDOM: snprintf(out, out_max, "EDOM"); break; | ||
142 | case ERANGE: snprintf(out, out_max, "ERANGE"); break; | ||
143 | case EDEADLK: snprintf(out, out_max, "EDEADLK"); break; | ||
144 | case ENAMETOOLONG: snprintf(out, out_max, "ENAMETOOLONG"); break; | ||
145 | case ENOLCK: snprintf(out, out_max, "ENOLCK"); break; | ||
146 | |||
147 | case EINPROGRESS: snprintf(out, out_max, "EINPROGRESS"); break; | ||
148 | |||
149 | default: snprintf(out, out_max, "%d", e); break; | ||
150 | } | ||
151 | } | ||
152 | |||
153 | static int decode_ret_int(char *out, unsigned out_max, | ||
154 | unsigned char *d, unsigned int *i) | ||
155 | { | ||
156 | int ret = decode32(d, i); | ||
157 | if (ret != -1) { | ||
158 | snprintf(out, out_max, " = %d", ret); | ||
159 | return ret; | ||
160 | } | ||
161 | |||
162 | int xerrno = decode32(d, i); | ||
163 | char err[64]; | ||
164 | decode_errno(err, sizeof(err), xerrno); | ||
165 | snprintf(out, out_max, " = %d (%s)", ret, err); | ||
166 | |||
167 | return ret; | ||
168 | } | ||
169 | |||
170 | static ssize_t decode_ret_int64(char *out, unsigned out_max, | ||
171 | unsigned char *d, unsigned int *i) | ||
172 | { | ||
173 | ssize_t ret = decode64(d, i); | ||
174 | if (ret != -1) { | ||
175 | snprintf(out, out_max, " = %zd", ret); | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | int xerrno = decode32(d, i); | ||
180 | char err[64]; | ||
181 | decode_errno(err, sizeof(err), xerrno); | ||
182 | snprintf(out, out_max, " = %zd (%s)", ret, err); | ||
183 | |||
184 | return ret; | ||
185 | } | ||
186 | |||
187 | static void *decode_ret_pointer(char *out, unsigned out_max, | ||
188 | unsigned char *d, unsigned int *i) | ||
189 | { | ||
190 | void *ret = (void *) decode64(d, i); | ||
191 | if (ret) { | ||
192 | snprintf(out, out_max, " = %p", ret); | ||
193 | return ret; | ||
194 | } | ||
195 | |||
196 | int xerrno = decode32(d, i); | ||
197 | char err[64]; | ||
198 | decode_errno(err, sizeof(err), xerrno); | ||
199 | snprintf(out, out_max, " = %p (%s)", ret, err); | ||
200 | |||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | static void decode_dirfd(char *out, int v, const char *postfix) | ||
205 | { | ||
206 | switch (v) { | ||
207 | case AT_FDCWD: sprintf(out, "AT_FDCWD%s", postfix); return; | ||
208 | default: sprintf(out, "%d%s", v, postfix); return; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | static socklen_t decode_sockaddr(char *out, unsigned char *d, unsigned int *i) | ||
213 | { | ||
214 | struct sockaddr_storage ss; | ||
215 | socklen_t sl; | ||
216 | |||
217 | sl = decode16(d, i); | ||
218 | |||
219 | if (sl > sizeof(ss)) { | ||
220 | char dump[65]; | ||
221 | bin2hex(dump, d + *i, 32); | ||
222 | sprintf(out, "[sl is too big: %u: %s]", sl, dump); | ||
223 | return sl; | ||
224 | } | ||
225 | |||
226 | memcpy(&ss, d + *i, sl); *i = *i + sl; | ||
227 | |||
228 | switch (ss.ss_family) { | ||
229 | case AF_INET: | ||
230 | struct sockaddr_in *s4 = (struct sockaddr_in *) &ss; | ||
231 | char addr[16]; | ||
232 | inet_ntop(ss.ss_family, &s4->sin_addr, addr, sizeof(addr)); | ||
233 | sprintf(out, "ipv4/%s/%hu", | ||
234 | addr, be16toh(s4->sin_port)); | ||
235 | break; | ||
236 | |||
237 | case AF_INET6: | ||
238 | struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) &ss; | ||
239 | char addr6[40]; | ||
240 | inet_ntop(ss.ss_family, &s6->sin6_addr, addr6, sizeof(addr6)); | ||
241 | sprintf(out, "ipv6/%s/%hu/f%u/s%u", | ||
242 | addr6, be16toh(s6->sin6_port), | ||
243 | be32toh(s6->sin6_flowinfo), be32toh(s6->sin6_scope_id)); | ||
244 | break; | ||
245 | |||
246 | case AF_UNIX: | ||
247 | struct sockaddr_un *su = (struct sockaddr_un *) &ss; | ||
248 | sprintf(out, "unix/'%s'", su->sun_path); | ||
249 | break; | ||
250 | |||
251 | default: | ||
252 | bin2hex(out, &ss, sl); | ||
253 | break; | ||
254 | } | ||
255 | |||
256 | return sl; | ||
257 | } | ||
258 | |||
259 | static int decode_sock_level(char *out, unsigned out_size, | ||
260 | unsigned char *d, unsigned int *i) | ||
261 | { | ||
262 | int level = decode32(d, i); | ||
263 | |||
264 | switch (level) { | ||
265 | case SOL_SOCKET: snprintf(out, out_size, "SOL_SOCKET"); break; | ||
266 | case SOL_IP: snprintf(out, out_size, "SOL_IP"); break; | ||
267 | case SOL_RAW: snprintf(out, out_size, "SOL_RAW"); break; | ||
268 | case SOL_PACKET: snprintf(out, out_size, "SOL_PACKET"); break; | ||
269 | case SOL_NETLINK: snprintf(out, out_size, "SOL_NETLINK"); break; | ||
270 | case SOL_IPV6: snprintf(out, out_size, "SOL_IPV6"); break; | ||
271 | case SOL_ICMPV6: snprintf(out, out_size, "SOL_ICMPV6"); break; | ||
272 | case IPPROTO_UDP: snprintf(out, out_size, "IPPROTO_UDP"); break; | ||
273 | case IPPROTO_TCP: snprintf(out, out_size, "IPPROTO_TCP"); break; | ||
274 | default: snprintf(out, out_size, "todo(%d)", level); break; | ||
275 | } | ||
276 | |||
277 | return level; | ||
278 | } | ||
279 | |||
280 | static void decode_sock_optname_socket(char *out, unsigned out_size, | ||
281 | const int optname) | ||
282 | { | ||
283 | switch (optname) { | ||
284 | case SO_ACCEPTCONN: snprintf(out, out_size, "SO_ACCEPTCONN"); break; | ||
285 | case SO_BROADCAST: snprintf(out, out_size, "SO_BROADCAST"); break; | ||
286 | case SO_DONTROUTE: snprintf(out, out_size, "SO_DONTROUTE"); break; | ||
287 | case SO_ERROR: snprintf(out, out_size, "SO_ERROR"); break; | ||
288 | case SO_KEEPALIVE: snprintf(out, out_size, "SO_KEEPALIVE"); break; | ||
289 | case SO_LINGER: snprintf(out, out_size, "SO_LINGER"); break; | ||
290 | case SO_OOBINLINE: snprintf(out, out_size, "SO_OOBINLINE"); break; | ||
291 | case SO_RCVBUF: snprintf(out, out_size, "SO_RCVBUF"); break; | ||
292 | case SO_RCVLOWAT: snprintf(out, out_size, "SO_RCVLOWAT"); break; | ||
293 | case SO_REUSEADDR: snprintf(out, out_size, "SO_REUSEADDR"); break; | ||
294 | case SO_SNDBUF: snprintf(out, out_size, "SO_SNDBUF"); break; | ||
295 | case SO_SNDLOWAT: snprintf(out, out_size, "SO_SNDLOWAT"); break; | ||
296 | case SO_TYPE: snprintf(out, out_size, "SO_TYPE"); break; | ||
297 | case SO_RCVTIMEO: snprintf(out, out_size, "SO_RCVTIMEO"); break; | ||
298 | case SO_SNDTIMEO: snprintf(out, out_size, "SO_SNDTIMEO"); break; | ||
299 | case SO_TIMESTAMP: snprintf(out, out_size, "SO_TIMESTAMP"); break; | ||
300 | case SO_TIMESTAMPNS: snprintf(out, out_size, "SO_TIMESTAMPNS"); break; | ||
301 | case SO_TIMESTAMPING: snprintf(out, out_size, "SO_TIMESTAMPING"); break; | ||
302 | default: snprintf(out, out_size, "todo(%d)", optname); break; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | static void decode_sock_optname_ip(char *out, unsigned out_size, | ||
307 | const int optname) | ||
308 | { | ||
309 | switch (optname) { | ||
310 | case IP_OPTIONS: snprintf(out, out_size, "IP_OPTIONS"); break; | ||
311 | case IP_HDRINCL: snprintf(out, out_size, "IP_HDRINCL"); break; | ||
312 | case IP_TOS: snprintf(out, out_size, "IP_TOS"); break; | ||
313 | case IP_TTL: snprintf(out, out_size, "IP_TTL"); break; | ||
314 | case IP_RECVOPTS: snprintf(out, out_size, "IP_RECVOPTS"); break; | ||
315 | case IP_RETOPTS: snprintf(out, out_size, "IP_RETOPTS"); break; | ||
316 | case IP_MULTICAST_IF: snprintf(out, out_size, "IP_MULTICAST_IF"); break; | ||
317 | case IP_MULTICAST_TTL: snprintf(out, out_size, "IP_MULTICAST_TTL"); break; | ||
318 | case IP_MULTICAST_LOOP: snprintf(out, out_size, "IP_MULTICAST_LOOP"); break; | ||
319 | case IP_ADD_MEMBERSHIP: snprintf(out, out_size, "IP_ADD_MEMBERSHIP"); break; | ||
320 | case IP_DROP_MEMBERSHIP: snprintf(out, out_size, "IP_DROP_MEMBERSHIP"); break; | ||
321 | case IP_UNBLOCK_SOURCE: snprintf(out, out_size, "IP_UNBLOCK_SOURCE"); break; | ||
322 | case IP_BLOCK_SOURCE: snprintf(out, out_size, "IP_BLOCK_SOURCE"); break; | ||
323 | case IP_ADD_SOURCE_MEMBERSHIP: snprintf(out, out_size, "IP_ADD_SOURCE_MEMBERSHIP"); break; | ||
324 | case IP_DROP_SOURCE_MEMBERSHIP: snprintf(out, out_size, "IP_DROP_SOURCE_MEMBERSHIP"); break; | ||
325 | case IP_MSFILTER: snprintf(out, out_size, "IP_MSFILTER"); break; | ||
326 | case MCAST_JOIN_GROUP: snprintf(out, out_size, "MCAST_JOIN_GROUP"); break; | ||
327 | case MCAST_BLOCK_SOURCE: snprintf(out, out_size, "MCAST_BLOCK_SOURCE"); break; | ||
328 | case MCAST_UNBLOCK_SOURCE: snprintf(out, out_size, "MCAST_UNBLOCK_SOURCE"); break; | ||
329 | case MCAST_LEAVE_GROUP: snprintf(out, out_size, "MCAST_LEAVE_GROUP"); break; | ||
330 | case MCAST_JOIN_SOURCE_GROUP: snprintf(out, out_size, "MCAST_JOIN_SOURCE_GROUP"); break; | ||
331 | case MCAST_LEAVE_SOURCE_GROUP: snprintf(out, out_size, "MCAST_LEAVE_SOURCE_GROUP"); break; | ||
332 | case MCAST_MSFILTER: snprintf(out, out_size, "MCAST_MSFILTER"); break; | ||
333 | case IP_MULTICAST_ALL: snprintf(out, out_size, "IP_MULTICAST_ALL"); break; | ||
334 | case IP_UNICAST_IF: snprintf(out, out_size, "IP_UNICAST_IF"); break; | ||
335 | case IP_ROUTER_ALERT: snprintf(out, out_size, "IP_ROUTER_ALERT"); break; | ||
336 | case IP_PKTINFO: snprintf(out, out_size, "IP_PKTINFO"); break; | ||
337 | case IP_PKTOPTIONS: snprintf(out, out_size, "IP_PKTOPTIONS"); break; | ||
338 | case IP_MTU_DISCOVER: snprintf(out, out_size, "IP_MTU_DISCOVER"); break; | ||
339 | // TODO: these are for optname IP_MTU_DISCOVER | ||
340 | //case IP_PMTUDISC_DONT: snprintf(out, out_size, "IP_PMTUDISC_DONT"); break; | ||
341 | //case IP_PMTUDISC_WANT: snprintf(out, out_size, "IP_PMTUDISC_WANT"); break; | ||
342 | //case IP_PMTUDISC_DO: snprintf(out, out_size, "IP_PMTUDISC_DO"); break; | ||
343 | //case IP_PMTUDISC_PROBE: snprintf(out, out_size, "IP_PMTUDISC_PROBE"); break; | ||
344 | //case IP_PMTUDISC_INTERFACE: snprintf(out, out_size, "IP_PMTUDISC_INTERFACE"); break; | ||
345 | //case IP_PMTUDISC_OMIT: snprintf(out, out_size, "IP_PMTUDISC_OMIT"); break; | ||
346 | case IP_RECVERR: snprintf(out, out_size, "IP_RECVERR"); break; | ||
347 | case IP_RECVTTL: snprintf(out, out_size, "IP_RECVTTL"); break; | ||
348 | case IP_RECVTOS: snprintf(out, out_size, "IP_RECVTOS"); break; | ||
349 | case IP_MTU: snprintf(out, out_size, "IP_MTU"); break; | ||
350 | case IP_FREEBIND: snprintf(out, out_size, "IP_FREEBIND"); break; | ||
351 | case IP_IPSEC_POLICY: snprintf(out, out_size, "IP_IPSEC_POLICY"); break; | ||
352 | case IP_XFRM_POLICY: snprintf(out, out_size, "IP_XFRM_POLICY"); break; | ||
353 | case IP_PASSSEC: snprintf(out, out_size, "IP_PASSSEC"); break; | ||
354 | case IP_TRANSPARENT: snprintf(out, out_size, "IP_TRANSPARENT"); break; | ||
355 | case IP_ORIGDSTADDR: snprintf(out, out_size, "IP_ORIGDSTADDR"); break; | ||
356 | case IP_MINTTL: snprintf(out, out_size, "IP_MINTTL"); break; | ||
357 | case IP_NODEFRAG: snprintf(out, out_size, "IP_NODEFRAG"); break; | ||
358 | case IP_CHECKSUM: snprintf(out, out_size, "IP_CHECKSUM"); break; | ||
359 | case IP_BIND_ADDRESS_NO_PORT: snprintf(out, out_size, "IP_BIND_ADDRESS_NO_PORT"); break; | ||
360 | case IP_RECVFRAGSIZE: snprintf(out, out_size, "IP_RECVFRAGSIZE"); break; | ||
361 | case IP_RECVERR_RFC4884: snprintf(out, out_size, "IP_RECVERR_RFC4884"); break; | ||
362 | // TODO case IP_MAX_MEMBERSHIPS: snprintf(out, out_size, "IP_MAX_MEMBERSHIPS"); break; | ||
363 | default: snprintf(out, out_size, "todo(%d)", optname); break; | ||
364 | } | ||
365 | } | ||
366 | |||
367 | static void decode_sock_optname_ipv6(char *out, unsigned out_size, | ||
368 | const int optname) | ||
369 | { | ||
370 | switch (optname) { | ||
371 | case IPV6_ADDRFORM: snprintf(out, out_size, "IPV6_ADDRFORM"); break; | ||
372 | case IPV6_2292PKTINFO: snprintf(out, out_size, "IPV6_2292PKTINFO"); break; | ||
373 | case IPV6_2292HOPOPTS: snprintf(out, out_size, "IPV6_2292HOPOPTS"); break; | ||
374 | case IPV6_2292DSTOPTS: snprintf(out, out_size, "IPV6_2292DSTOPTS"); break; | ||
375 | case IPV6_2292RTHDR: snprintf(out, out_size, "IPV6_2292RTHDR"); break; | ||
376 | case IPV6_2292PKTOPTIONS: snprintf(out, out_size, "IPV6_2292PKTOPTIONS"); break; | ||
377 | case IPV6_CHECKSUM: snprintf(out, out_size, "IPV6_CHECKSUM"); break; | ||
378 | case IPV6_2292HOPLIMIT: snprintf(out, out_size, "IPV6_2292HOPLIMIT"); break; | ||
379 | case IPV6_NEXTHOP: snprintf(out, out_size, "IPV6_NEXTHOP"); break; | ||
380 | case IPV6_AUTHHDR: snprintf(out, out_size, "IPV6_AUTHHDR"); break; | ||
381 | case IPV6_UNICAST_HOPS: snprintf(out, out_size, "IPV6_UNICAST_HOPS"); break; | ||
382 | case IPV6_MULTICAST_IF: snprintf(out, out_size, "IPV6_MULTICAST_IF"); break; | ||
383 | case IPV6_MULTICAST_HOPS: snprintf(out, out_size, "IPV6_MULTICAST_HOPS"); break; | ||
384 | case IPV6_MULTICAST_LOOP: snprintf(out, out_size, "IPV6_MULTICAST_LOOP"); break; | ||
385 | case IPV6_JOIN_GROUP: snprintf(out, out_size, "IPV6_JOIN_GROUP"); break; | ||
386 | case IPV6_LEAVE_GROUP: snprintf(out, out_size, "IPV6_LEAVE_GROUP"); break; | ||
387 | case IPV6_ROUTER_ALERT: snprintf(out, out_size, "IPV6_ROUTER_ALERT"); break; | ||
388 | case IPV6_MTU_DISCOVER: snprintf(out, out_size, "IPV6_MTU_DISCOVER"); break; | ||
389 | case IPV6_MTU: snprintf(out, out_size, "IPV6_MTU"); break; | ||
390 | case IPV6_RECVERR: snprintf(out, out_size, "IPV6_RECVERR"); break; | ||
391 | case IPV6_V6ONLY: snprintf(out, out_size, "IPV6_V6ONLY"); break; | ||
392 | case IPV6_JOIN_ANYCAST: snprintf(out, out_size, "IPV6_JOIN_ANYCAST"); break; | ||
393 | case IPV6_LEAVE_ANYCAST: snprintf(out, out_size, "IPV6_LEAVE_ANYCAST"); break; | ||
394 | case IPV6_MULTICAST_ALL: snprintf(out, out_size, "IPV6_MULTICAST_ALL"); break; | ||
395 | case IPV6_ROUTER_ALERT_ISOLATE: snprintf(out, out_size, "IPV6_ROUTER_ALERT_ISOLATE"); break; | ||
396 | case IPV6_RECVERR_RFC4884: snprintf(out, out_size, "IPV6_RECVERR_RFC4884"); break; | ||
397 | case IPV6_IPSEC_POLICY: snprintf(out, out_size, "IPV6_IPSEC_POLICY"); break; | ||
398 | case IPV6_XFRM_POLICY: snprintf(out, out_size, "IPV6_XFRM_POLICY"); break; | ||
399 | case IPV6_HDRINCL: snprintf(out, out_size, "IPV6_HDRINCL"); break; | ||
400 | case IPV6_RECVPKTINFO: snprintf(out, out_size, "IPV6_RECVPKTINFO"); break; | ||
401 | case IPV6_PKTINFO: snprintf(out, out_size, "IPV6_PKTINFO"); break; | ||
402 | case IPV6_RECVHOPLIMIT: snprintf(out, out_size, "IPV6_RECVHOPLIMIT"); break; | ||
403 | case IPV6_HOPLIMIT: snprintf(out, out_size, "IPV6_HOPLIMIT"); break; | ||
404 | case IPV6_RECVHOPOPTS: snprintf(out, out_size, "IPV6_RECVHOPOPTS"); break; | ||
405 | case IPV6_HOPOPTS: snprintf(out, out_size, "IPV6_HOPOPTS"); break; | ||
406 | case IPV6_RTHDRDSTOPTS: snprintf(out, out_size, "IPV6_RTHDRDSTOPTS"); break; | ||
407 | case IPV6_RECVRTHDR: snprintf(out, out_size, "IPV6_RECVRTHDR"); break; | ||
408 | case IPV6_RTHDR: snprintf(out, out_size, "IPV6_RTHDR"); break; | ||
409 | case IPV6_RECVDSTOPTS: snprintf(out, out_size, "IPV6_RECVDSTOPTS"); break; | ||
410 | case IPV6_DSTOPTS: snprintf(out, out_size, "IPV6_DSTOPTS"); break; | ||
411 | case IPV6_RECVPATHMTU: snprintf(out, out_size, "IPV6_RECVPATHMTU"); break; | ||
412 | case IPV6_PATHMTU: snprintf(out, out_size, "IPV6_PATHMTU"); break; | ||
413 | case IPV6_DONTFRAG: snprintf(out, out_size, "IPV6_DONTFRAG"); break; | ||
414 | case IPV6_RECVTCLASS: snprintf(out, out_size, "IPV6_RECVTCLASS"); break; | ||
415 | case IPV6_TCLASS: snprintf(out, out_size, "IPV6_TCLASS"); break; | ||
416 | case IPV6_AUTOFLOWLABEL: snprintf(out, out_size, "IPV6_AUTOFLOWLABEL"); break; | ||
417 | case IPV6_ADDR_PREFERENCES: snprintf(out, out_size, "IPV6_ADDR_PREFERENCES"); break; | ||
418 | case IPV6_MINHOPCOUNT: snprintf(out, out_size, "IPV6_MINHOPCOUNT"); break; | ||
419 | case IPV6_ORIGDSTADDR: snprintf(out, out_size, "IPV6_ORIGDSTADDR"); break; | ||
420 | case IPV6_TRANSPARENT: snprintf(out, out_size, "IPV6_TRANSPARENT"); break; | ||
421 | case IPV6_UNICAST_IF: snprintf(out, out_size, "IPV6_UNICAST_IF"); break; | ||
422 | case IPV6_RECVFRAGSIZE: snprintf(out, out_size, "IPV6_RECVFRAGSIZE"); break; | ||
423 | case IPV6_FREEBIND: snprintf(out, out_size, "IPV6_FREEBIND"); break; | ||
424 | //case : snprintf(out, out_size, ""); break; | ||
425 | default: snprintf(out, out_size, "todo(%d)", optname); break; | ||
426 | } | ||
427 | } | ||
428 | |||
429 | static void decode_sock_optname_tcp(char *out, unsigned out_size, | ||
430 | const int optname) | ||
431 | { | ||
432 | switch (optname) { | ||
433 | case TCP_NODELAY: snprintf(out, out_size, "TCP_NODELAY"); break; | ||
434 | case TCP_MAXSEG: snprintf(out, out_size, "TCP_MAXSEG"); break; | ||
435 | case TCP_CORK: snprintf(out, out_size, "TCP_CORK"); break; | ||
436 | case TCP_KEEPIDLE: snprintf(out, out_size, "TCP_KEEPIDLE"); break; | ||
437 | case TCP_KEEPINTVL: snprintf(out, out_size, "TCP_KEEPINTVL"); break; | ||
438 | case TCP_KEEPCNT: snprintf(out, out_size, "TCP_KEEPCNT"); break; | ||
439 | case TCP_SYNCNT: snprintf(out, out_size, "TCP_SYNCNT"); break; | ||
440 | case TCP_LINGER2: snprintf(out, out_size, "TCP_LINGER2"); break; | ||
441 | case TCP_DEFER_ACCEPT: snprintf(out, out_size, "TCP_DEFER_ACCEPT"); break; | ||
442 | case TCP_WINDOW_CLAMP: snprintf(out, out_size, "TCP_WINDOW_CLAMP"); break; | ||
443 | case TCP_INFO: snprintf(out, out_size, "TCP_INFO"); break; | ||
444 | case TCP_QUICKACK: snprintf(out, out_size, "TCP_QUICKACK"); break; | ||
445 | case TCP_CONGESTION: snprintf(out, out_size, "TCP_CONGESTION"); break; | ||
446 | case TCP_MD5SIG: snprintf(out, out_size, "TCP_MD5SIG"); break; | ||
447 | case TCP_COOKIE_TRANSACTIONS: snprintf(out, out_size, "TCP_COOKIE_TRANSACTIONS"); break; | ||
448 | case TCP_THIN_LINEAR_TIMEOUTS: snprintf(out, out_size, "TCP_THIN_LINEAR_TIMEOUTS"); break; | ||
449 | case TCP_THIN_DUPACK: snprintf(out, out_size, "TCP_THIN_DUPACK"); break; | ||
450 | case TCP_USER_TIMEOUT: snprintf(out, out_size, "TCP_USER_TIMEOUT"); break; | ||
451 | case TCP_REPAIR: snprintf(out, out_size, "TCP_REPAIR"); break; | ||
452 | case TCP_REPAIR_QUEUE: snprintf(out, out_size, "TCP_REPAIR_QUEUE"); break; | ||
453 | case TCP_QUEUE_SEQ: snprintf(out, out_size, "TCP_QUEUE_SEQ"); break; | ||
454 | case TCP_REPAIR_OPTIONS: snprintf(out, out_size, "TCP_REPAIR_OPTIONS"); break; | ||
455 | case TCP_FASTOPEN: snprintf(out, out_size, "TCP_FASTOPEN"); break; | ||
456 | case TCP_TIMESTAMP: snprintf(out, out_size, "TCP_TIMESTAMP"); break; | ||
457 | case TCP_NOTSENT_LOWAT: snprintf(out, out_size, "TCP_NOTSENT_LOWAT"); break; | ||
458 | case TCP_CC_INFO: snprintf(out, out_size, "TCP_CC_INFO"); break; | ||
459 | case TCP_SAVE_SYN: snprintf(out, out_size, "TCP_SAVE_SYN"); break; | ||
460 | case TCP_SAVED_SYN: snprintf(out, out_size, "TCP_SAVED_SYN"); break; | ||
461 | case TCP_REPAIR_WINDOW: snprintf(out, out_size, "TCP_REPAIR_WINDOW"); break; | ||
462 | case TCP_FASTOPEN_CONNECT: snprintf(out, out_size, "TCP_FASTOPEN_CONNECT"); break; | ||
463 | case TCP_ULP: snprintf(out, out_size, "TCP_ULP"); break; | ||
464 | case TCP_MD5SIG_EXT: snprintf(out, out_size, "TCP_MD5SIG_EXT"); break; | ||
465 | case TCP_FASTOPEN_KEY: snprintf(out, out_size, "TCP_FASTOPEN_KEY"); break; | ||
466 | case TCP_FASTOPEN_NO_COOKIE: snprintf(out, out_size, "TCP_FASTOPEN_NO_COOKIE"); break; | ||
467 | case TCP_ZEROCOPY_RECEIVE: snprintf(out, out_size, "TCP_ZEROCOPY_RECEIVE"); break; | ||
468 | case TCP_INQ: snprintf(out, out_size, "TCP_INQ"); break; | ||
469 | case TCP_TX_DELAY: snprintf(out, out_size, "TCP_TX_DELAY"); break; | ||
470 | //case : snprintf(out, out_size, ""); break; | ||
471 | default: snprintf(out, out_size, "todo(%d)", optname); break; | ||
472 | } | ||
473 | } | ||
474 | |||
475 | static void decode_sock_optname_udp(char *out, unsigned out_size, | ||
476 | const int optname) | ||
477 | { | ||
478 | switch (optname) { | ||
479 | case UDP_CORK: snprintf(out, out_size, "UDP_CORK"); break; | ||
480 | case UDP_ENCAP: snprintf(out, out_size, "UDP_ENCAP"); break; | ||
481 | case UDP_NO_CHECK6_TX: snprintf(out, out_size, "UDP_NO_CHECK6_TX"); break; | ||
482 | case UDP_NO_CHECK6_RX: snprintf(out, out_size, "UDP_NO_CHECK6_RX"); break; | ||
483 | case UDP_SEGMENT: snprintf(out, out_size, "UDP_SEGMENT"); break; | ||
484 | case UDP_GRO: snprintf(out, out_size, "UDP_GRO"); break; | ||
485 | //case : snprintf(out, out_size, ""); break; | ||
486 | default: snprintf(out, out_size, "todo(%d)", optname); break; | ||
487 | } | ||
488 | } | ||
489 | |||
490 | static void decode_sock_optname(char *out, unsigned out_size, | ||
491 | const int level, | ||
492 | unsigned char *d, unsigned int *i) | ||
493 | { | ||
494 | int v = decode32(d, i); | ||
495 | |||
496 | if (level == SOL_SOCKET) | ||
497 | decode_sock_optname_socket(out, out_size, v); | ||
498 | else if (level == SOL_IP) | ||
499 | decode_sock_optname_ip(out, out_size, v); | ||
500 | else if (level == SOL_IPV6) | ||
501 | decode_sock_optname_ipv6(out, out_size, v); | ||
502 | else if (level == SOL_TCP) | ||
503 | decode_sock_optname_tcp(out, out_size, v); | ||
504 | else if (level == SOL_UDP) | ||
505 | decode_sock_optname_udp(out, out_size, v); | ||
506 | else | ||
507 | snprintf(out, out_size, "%d", v); | ||
508 | } | ||
509 | |||
510 | static void decode_func(unsigned char *d) | ||
511 | { | ||
512 | unsigned int i = 0; | ||
513 | unsigned short func_len; | ||
514 | char type, line[64000], rest[2000]; | ||
515 | uint64_t t; | ||
516 | |||
517 | rest[0] = '\0'; | ||
518 | |||
519 | t = decode64(d, &i); | ||
520 | func_len = decode16(d, &i); | ||
521 | char func[func_len + 1]; | ||
522 | memcpy(func, d + i, func_len); i += func_len; | ||
523 | func[func_len] = '\0'; | ||
524 | type = d[i++]; | ||
525 | uint32_t pid = decode32(d, &i); | ||
526 | uint32_t tid = decode32(d, &i); | ||
527 | //fprintf(out, "%s: t=%lu func_len=%hu func=[%s] type=%c pid=%u tid=%u\n", | ||
528 | // __func__, t, func_len, func, type, pid, tid); | ||
529 | |||
530 | switch (func[0]) { | ||
531 | case '-': // project specific | ||
532 | if (strcmp(func, "-stop") == 0) { | ||
533 | int ret = decode32(d, &i); | ||
534 | sprintf(line, "() = %d", ret); | ||
535 | do_exit = 1; | ||
536 | } else if (strcmp(func, "-segv") == 0) { | ||
537 | int r = decode32(d, &i); | ||
538 | sprintf(line, ":"); | ||
539 | for (int j = 0; j < r; j++) { | ||
540 | unsigned char len = decode8(d, &i); | ||
541 | char l[len + 1]; | ||
542 | memcpy(l, d + i, len); i += len; | ||
543 | l[len] = '\0'; | ||
544 | strcat(line, " "); | ||
545 | strcat(line, l); | ||
546 | } | ||
547 | do_exit = 1; | ||
548 | } break; | ||
549 | |||
550 | case 'a': | ||
551 | if (strcmp(func, "accept") == 0) { | ||
552 | int fd = decode32(d, &i); | ||
553 | int addrlen = decode32(d, &i); | ||
554 | if (type == 'c') { | ||
555 | sprintf(line, "(%d, addr, %u)%s", | ||
556 | fd, addrlen, rest); | ||
557 | } else { | ||
558 | char dump[addrlen * 2 + 1]; | ||
559 | bin2hex(dump, d + i, addrlen); i += addrlen; | ||
560 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
561 | sprintf(line, "(%d, 0x%s, %u)%s", | ||
562 | fd, dump, addrlen, rest); | ||
563 | } | ||
564 | } else if (strcmp(func, "accept4") == 0) { | ||
565 | int fd = decode32(d, &i); | ||
566 | int addrlen = decode32(d, &i); | ||
567 | int flags = decode32(d, &i); | ||
568 | if (type == 'c') { | ||
569 | sprintf(line, "(%d, addr, %u, 0x%x)", | ||
570 | fd, addrlen, flags); | ||
571 | } else { | ||
572 | char dump[addrlen * 2 + 1]; | ||
573 | bin2hex(dump, d + i, addrlen); i += addrlen; | ||
574 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
575 | sprintf(line, "(%d, 0x%s, %u, 0x%x)%s", | ||
576 | fd, dump, addrlen, flags, rest); | ||
577 | } | ||
578 | } break; | ||
579 | |||
580 | case 'b': | ||
581 | if (strcmp(func, "bind") == 0) { | ||
582 | int sock = decode32(d, &i); | ||
583 | char dump[128]; | ||
584 | socklen_t sl = decode_sockaddr(dump, d, &i); | ||
585 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
586 | sprintf(line, "(%d, %s, %d)%s", sock, dump, sl, rest); | ||
587 | } break; | ||
588 | |||
589 | case 'c': | ||
590 | if (strcmp(func, "close") == 0) { | ||
591 | int fd = decode32(d, &i); | ||
592 | if (type == 'r') | ||
593 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
594 | sprintf(line, "(%d)%s", fd, rest); | ||
595 | } else if (strcmp(func, "connect") == 0) { | ||
596 | int sock = decode32(d, &i); | ||
597 | if (type == 'c') { | ||
598 | char dump[128]; | ||
599 | socklen_t sl = decode_sockaddr(dump, d, &i); | ||
600 | sprintf(line, "(%d, %s, %d)", sock, dump, sl); | ||
601 | } else if (type == 'r') { | ||
602 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
603 | sprintf(line, "(%d)%s", sock, rest); | ||
604 | } | ||
605 | } break; | ||
606 | |||
607 | case 'd': | ||
608 | if (strcmp(func, "dlopen") == 0) { | ||
609 | uint16_t len = decode16(d, &i); | ||
610 | char filename[len + 1]; | ||
611 | memcpy(filename, d + i, len); i += len; | ||
612 | filename[len] = '\0'; | ||
613 | int flags = decode32(d, &i); | ||
614 | if (type == 'r') | ||
615 | decode_ret_pointer(rest, sizeof(rest), d, &i); | ||
616 | sprintf(line, "('%s', 0x%x)%s", filename, flags, rest); | ||
617 | } else if (strcmp(func, "dlclose") == 0) { | ||
618 | void *h = (void *) decode64(d, &i); | ||
619 | if (type == 'r') | ||
620 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
621 | sprintf(line, "(%p)%s", h, rest); | ||
622 | } break; | ||
623 | |||
624 | case 'g': | ||
625 | if (strcmp(func, "getaddrinfo") == 0) { | ||
626 | uint16_t len; | ||
627 | char node[256]; | ||
628 | char service[256]; | ||
629 | |||
630 | len = decode16(d, &i); | ||
631 | if (len == 0xFFFF) { | ||
632 | sprintf(node, "NULL"); | ||
633 | } else { | ||
634 | memcpy(node, d + i, len); i += len; | ||
635 | node[len] = '\0'; | ||
636 | } | ||
637 | |||
638 | len = decode16(d, &i); | ||
639 | if (len == 0xFFFF) { | ||
640 | sprintf(service, "NULL"); | ||
641 | } else { | ||
642 | memcpy(service, d + i, len); i += len; | ||
643 | service[0] = '\0'; | ||
644 | } | ||
645 | |||
646 | if (type == 'r') { | ||
647 | int ret = decode32(d, &i); | ||
648 | sprintf(rest, " = %d%s%s%s", | ||
649 | ret, ret > 0 ? " (" : "", | ||
650 | ret > 0 ? gai_strerror(ret) : "", | ||
651 | ret > 0 ? ")" : ""); | ||
652 | } | ||
653 | sprintf(line, "('%s', '%s')%s", | ||
654 | node, service, rest); | ||
655 | } else if (strcmp(func, "gethostbyname") == 0) { | ||
656 | uint16_t len = decode16(d, &i); | ||
657 | char host[len + 1]; | ||
658 | memcpy(host, d + i, len); i += len; | ||
659 | if (type == 'r') | ||
660 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
661 | sprintf(line, "('%s')%s", host, rest); | ||
662 | } else if (strcmp(func, "getrandom") == 0) { | ||
663 | size_t buflen = decode64(d, &i); | ||
664 | unsigned int flags = decode32(d, &i); | ||
665 | if (type == 'c') { | ||
666 | sprintf(line, "(buf, %zu, 0x%x)", buflen, flags); | ||
667 | } else { | ||
668 | ssize_t ret = decode_ret_int64(rest, sizeof(rest), d, &i); | ||
669 | if (ret != -1) { | ||
670 | unsigned short max = decode16(d, &i); | ||
671 | char dump[max * 2 + 1]; | ||
672 | bin2hex(dump, d + i, max); i += max; | ||
673 | sprintf(line, "('%s'%s, %zu, 0x%x)%s", | ||
674 | dump, max < buflen ? "..." : "", | ||
675 | buflen, flags, rest); | ||
676 | } else { | ||
677 | sprintf(line, "(buf, %zu, 0x%x)%s", | ||
678 | buflen, flags, rest); | ||
679 | } | ||
680 | } | ||
681 | } else if (strcmp(func, "getsockopt") == 0) { | ||
682 | //char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); | ||
683 | int sock = decode32(d, &i); | ||
684 | char level[32], optname[32]; | ||
685 | int ilevel = decode_sock_level(level, sizeof(level), d, &i); | ||
686 | decode_sock_optname(optname, sizeof(optname), ilevel, d, &i); | ||
687 | socklen_t optlen = decode32(d, &i); | ||
688 | char optval[optlen * 2 + 1]; | ||
689 | bin2hex(optval, d + i, optlen); i+= optlen; | ||
690 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
691 | sprintf(line, "(%d, %s, %s, 0x%s, %u)%s", | ||
692 | sock, level, optname, optval, optlen, rest); | ||
693 | } break; | ||
694 | |||
695 | case 'l': | ||
696 | if (strcmp(func, "listen") == 0) { | ||
697 | //char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); | ||
698 | int sock = decode32(d, &i); | ||
699 | int backlog = decode32(d, &i); | ||
700 | if (type == 'r') | ||
701 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
702 | sprintf(line, "(%d, %d)%s", sock, backlog, rest); | ||
703 | } break; | ||
704 | |||
705 | case 'n': | ||
706 | if (strcmp(func, "nanosleep") == 0) { | ||
707 | struct timespec req; | ||
708 | req.tv_sec = decode64(d, &i); | ||
709 | req.tv_nsec = decode64(d, &i); | ||
710 | if (type == 'c') { | ||
711 | sprintf(line, "(%lu.%09ld)", | ||
712 | req.tv_sec, req.tv_nsec); | ||
713 | } else { | ||
714 | struct timespec rem; | ||
715 | rem.tv_sec = decode64(d, &i); | ||
716 | rem.tv_nsec = decode64(d, &i); | ||
717 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
718 | sprintf(line, "(%lu.%09ld, %lu.%09ld)%s", | ||
719 | req.tv_sec, req.tv_nsec, rem.tv_sec, rem.tv_nsec, rest); | ||
720 | } | ||
721 | } break; | ||
722 | |||
723 | case 'o': | ||
724 | if ((strcmp(func, "open") == 0) || (strcmp(func, "open64") == 0) | ||
725 | || (strcmp(func, "openat") == 0)) { | ||
726 | char dirfd_decoded[32]; | ||
727 | if (strcmp(func, "openat") == 0) | ||
728 | decode_dirfd(dirfd_decoded, decode32(d, &i), " ,"); | ||
729 | else | ||
730 | dirfd_decoded[0] = '\0'; | ||
731 | uint16_t len = decode16(d, &i); | ||
732 | char filename[len + 1]; | ||
733 | memcpy(filename, d + i, len); i += len; | ||
734 | filename[len] = '\0'; | ||
735 | int flags = decode32(d, &i); | ||
736 | mode_t mode = decode32(d, &i); | ||
737 | if (type == 'r') | ||
738 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
739 | sprintf(line, "('%s'%s, 0x%x, 0x%x)%s", | ||
740 | dirfd_decoded, filename, flags, mode, rest); | ||
741 | } break; | ||
742 | |||
743 | case 'p': | ||
744 | if (strcmp(func, "poll") == 0) { | ||
745 | uint16_t nf = decode32(d, &i); | ||
746 | char list[nf * 16 + 1], *add = ""; | ||
747 | list[0] = '\0'; | ||
748 | for (unsigned j = 0; j < nf; j++) { | ||
749 | int fd = decode32(d, &i); | ||
750 | short ev = decode16(d, &i); | ||
751 | char tmp[16 + 1]; | ||
752 | snprintf(tmp, sizeof(tmp), | ||
753 | "%s%d%s%s%s", add, fd, | ||
754 | ev ? "/" : "", | ||
755 | ev & POLLIN ? "i" : "", | ||
756 | ev & POLLOUT ? "o" : ""); | ||
757 | strcat(list, tmp); | ||
758 | add = ","; | ||
759 | } | ||
760 | int timeout = decode32(d, &i); | ||
761 | if (type == 'r') | ||
762 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
763 | sprintf(line, "([%s], %u, %d)%s", | ||
764 | list, nf, timeout, rest); | ||
765 | } break; | ||
766 | |||
767 | case 'r': | ||
768 | if (strcmp(func, "recv") == 0) { | ||
769 | int sock = decode32(d, &i); | ||
770 | size_t len = decode64(d, &i); | ||
771 | int flags = decode32(d, &i); | ||
772 | sprintf(rest, ", %zu, 0x%x)", len, flags); | ||
773 | if (type == 'c') { | ||
774 | sprintf(line, "(%d, buf%s", sock, rest); | ||
775 | } else if (type == 'r') { | ||
776 | ssize_t ret = decode_ret_int64(rest, sizeof(rest), d, &i); | ||
777 | if (ret != -1) { | ||
778 | unsigned short max = decode16(d, &i); | ||
779 | char data[max * 4 + 1]; | ||
780 | bin2hex_ascii(data, d + i, max); i += max; | ||
781 | sprintf(line, "(%d, '%s'%s)%s", | ||
782 | sock, data, | ||
783 | max < ret ? "..." : "", rest); | ||
784 | } else { | ||
785 | sprintf(line, "(%d, [])%s", | ||
786 | sock, rest); | ||
787 | } | ||
788 | } | ||
789 | } break; | ||
790 | |||
791 | case 's': | ||
792 | if (strcmp(func, "send") == 0) { | ||
793 | int sock = decode32(d, &i); | ||
794 | size_t len = decode64(d, &i); | ||
795 | int flags = decode32(d, &i); | ||
796 | if (type == 'c') { | ||
797 | unsigned short max = decode16(d, &i); | ||
798 | char data[max * 4 + 1]; | ||
799 | bin2hex_ascii(data, d + i, max); i += max; | ||
800 | sprintf(line, "(%d, '%s'%s, %zu, 0x%x)", | ||
801 | sock, data, | ||
802 | max < len ? "..." : "", len, flags); | ||
803 | } else if (type == 'r') { | ||
804 | decode_ret_int64(rest, sizeof(rest), d, &i); | ||
805 | sprintf(line, "(%d, buf, %zu, 0x%x)%s", | ||
806 | sock, len, flags, rest); | ||
807 | } | ||
808 | } else if (strcmp(func, "sendmsg") == 0) { | ||
809 | int sock = decode32(d, &i); | ||
810 | if (type == 'c') { | ||
811 | size_t iovlen = decode64(d, &i); | ||
812 | sprintf(line, "(%d, iovlen=%zu:", sock, iovlen); | ||
813 | for (unsigned j = 0; j < iovlen; j++) { | ||
814 | size_t len = decode64(d, &i); | ||
815 | unsigned short max = decode16(d, &i); | ||
816 | char dump[max * 4 + 1]; | ||
817 | bin2hex_ascii(dump, d + i, max); i += max; | ||
818 | sprintf(rest, " %zu:'%s'%s", len, dump, max < len ? "..." : ""); | ||
819 | strcat(line, rest); | ||
820 | } | ||
821 | int flags = decode32(d, &i); | ||
822 | sprintf(rest, ", 0x%x)", flags); | ||
823 | strcat(line, rest); | ||
824 | } else if (type == 'r') { | ||
825 | int flags = decode32(d, &i); | ||
826 | decode_ret_int64(rest, sizeof(rest), d, &i); | ||
827 | sprintf(line, "(%d, msg, 0x%x)%s", | ||
828 | sock, flags, rest); | ||
829 | } | ||
830 | } else if (strcmp(func, "setsockopt") == 0) { | ||
831 | int sock = decode32(d, &i); | ||
832 | if (type == 'c') { | ||
833 | char level[32], optname[32]; | ||
834 | int ilevel = decode_sock_level(level, sizeof(level), d, &i); | ||
835 | decode_sock_optname(optname, sizeof(optname), ilevel, d, &i); | ||
836 | socklen_t optlen = decode32(d, &i); | ||
837 | char optval[optlen * 2 + 1]; | ||
838 | bin2hex(optval, d + i, optlen); i+= optlen; | ||
839 | sprintf(line, "(%d, %s, %s, 0x%s, %u)", | ||
840 | sock, level, optname, optval, optlen); | ||
841 | } else { | ||
842 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
843 | sprintf(line, "(%d)%s", sock, rest); | ||
844 | } | ||
845 | } else if (strcmp(func, "socket") == 0) { | ||
846 | //char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP[%s][%c]: %s\n", func, type, dump); | ||
847 | int xdomain = decode32(d, &i); | ||
848 | int xtype = decode32(d, &i); | ||
849 | int xprotocol = decode32(d, &i); | ||
850 | if (type == 'r') | ||
851 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
852 | sprintf(line, "(%s, %s, %d)%s", | ||
853 | decode_socket_domain(xdomain), | ||
854 | decode_socket_type(xtype), xprotocol, rest); | ||
855 | } break; | ||
856 | |||
857 | case 'u': | ||
858 | if (strcmp(func, "unlink") == 0) { | ||
859 | uint16_t len = decode16(d, &i); | ||
860 | char pathname[len + 1]; | ||
861 | memcpy(pathname, d + i, len); i += len; | ||
862 | pathname[len] = '\0'; | ||
863 | if (type == 'r') | ||
864 | decode_ret_int(rest, sizeof(rest), d, &i); | ||
865 | sprintf(line, "('%s')%s", pathname, rest); | ||
866 | } break; | ||
867 | |||
868 | case 'w': | ||
869 | if (strcmp(func, "write") == 0) { | ||
870 | //char dump[4096]; bin2hex_ascii(dump, d + i, 128); fprintf(out, "DUMP: %s\n", dump); | ||
871 | int fd = decode32(d, &i); | ||
872 | size_t count = decode64(d, &i); | ||
873 | if (type == 'c') { | ||
874 | unsigned short max = decode16(d, &i); | ||
875 | char data[max * 4 + 1]; | ||
876 | bin2hex_ascii(data, d + i, max); i += max; | ||
877 | sprintf(line, "(%d, '%s'%s, %zu)", | ||
878 | fd, data, | ||
879 | max < count ? "..." : "", count); | ||
880 | } else if (type == 'r') { | ||
881 | decode_ret_int64(rest, sizeof(rest), d, &i); | ||
882 | sprintf(line, "(%d, buf, %zu)%s", | ||
883 | fd, count, rest); | ||
884 | } | ||
885 | } break; | ||
886 | } | ||
887 | if (line[0] == '\0') { | ||
888 | fprintf(out, "I do not know how to decode func [%s] type [%c]!\n", | ||
889 | func, type); | ||
890 | return; | ||
891 | } | ||
892 | |||
893 | if (pid == tid) | ||
894 | fprintf(out, "%lu.%03lu %10u %s%s\n", | ||
895 | t / 1000, t % 1000, pid, func, line); | ||
896 | else | ||
897 | fprintf(out, "%lu.%03lu %10u %10u %s%s\n", | ||
898 | t / 1000, t % 1000, pid, tid, func, line); | ||
899 | } | ||
900 | |||
901 | static void decode(unsigned char *d, size_t len) | ||
902 | { | ||
903 | unsigned int i = 0; | ||
904 | char type; | ||
905 | |||
906 | type = d[i++]; | ||
907 | if (type == 'F') { | ||
908 | decode_func(d + i); | ||
909 | } else { | ||
910 | fprintf(out, "I do not know how to decode type [%c]!\n", type); | ||
911 | char dump[len * 4 + 1]; | ||
912 | bin2hex_ascii(dump, d, len); | ||
913 | fprintf(out, "Decode %s\n", dump); | ||
914 | } | ||
915 | } | ||
916 | |||
917 | int main(int argc, char *argv[]) | ||
918 | { | ||
919 | int c, r; | ||
920 | int options_index = 0; | ||
921 | char *out_file = NULL; | ||
922 | pid_t pids[256]; | ||
923 | int sm[256]; | ||
924 | struct shared *shared[256]; | ||
925 | unsigned int no_pids = 0; | ||
926 | |||
927 | setlinebuf(stderr); | ||
928 | |||
929 | while ((c = getopt_long(argc, argv, "p:o:", options, &options_index)) != -1) { | ||
930 | switch (c) { | ||
931 | case 'o': out_file = optarg; break; | ||
932 | case 'p': if (no_pids < 256) pids[no_pids++] = strtoull(optarg, NULL, 10); break; | ||
933 | default: usage(); | ||
934 | } | ||
935 | } | ||
936 | |||
937 | if (no_pids == 0) { | ||
938 | fprintf(stderr, "Error: no pids specified with -p!\n"); | ||
939 | return 1; | ||
940 | } | ||
941 | |||
942 | if (!out_file) { | ||
943 | out = stderr; | ||
944 | } else { | ||
945 | fprintf(stderr, "Saving output to [%s]\n", out_file); | ||
946 | out = fopen(out_file, "w"); | ||
947 | if (!out) { | ||
948 | fprintf(stderr, "Error: cannot open [%s]: %m\n", out_file); | ||
949 | return 1; | ||
950 | } | ||
951 | } | ||
952 | setlinebuf(out); | ||
953 | |||
954 | //pid_t my_pid = getpid(); | ||
955 | |||
956 | for (unsigned i = 0; i < no_pids; i++) { | ||
957 | char name[128]; | ||
958 | snprintf(name, sizeof(name), "/ninedogs-%d", pids[i]); | ||
959 | |||
960 | sm[i] = shm_open(name, O_RDWR, 0); | ||
961 | if (sm[i] == -1) { | ||
962 | fprintf(stderr, "Cannot do shm_open i%u pid %d: %m\n", i, pids[i]); | ||
963 | return 1; | ||
964 | } | ||
965 | fprintf(stderr, "shm_open i%u = %d\n", i, sm[i]); | ||
966 | |||
967 | shared[i] = mmap(NULL, sizeof(struct shared), | ||
968 | PROT_READ | PROT_WRITE, MAP_SHARED, sm[i], 0); | ||
969 | if (shared[i] == MAP_FAILED) { | ||
970 | fprintf(stderr, "Cannot mmap i%u: %m\n", i); | ||
971 | return 1; | ||
972 | } | ||
973 | |||
974 | #if 0 | ||
975 | unsigned j = 0; | ||
976 | shared[i]->buf[j++] = SHARED_CMD_INIT; | ||
977 | shared[i]->buf[j++] = SHARED_VERSION; | ||
978 | memcpy(shared[i]->buf + j, &my_pid, sizeof(pid_t)); | ||
979 | j += sizeof(pid_t); | ||
980 | |||
981 | r = sem_post(&shared[i]->sem1); | ||
982 | if (r == -1) { | ||
983 | fprintf(stderr, "Cannot post sem1: %m\n"); | ||
984 | return 1; | ||
985 | } | ||
986 | #endif | ||
987 | } | ||
988 | |||
989 | while (1) { | ||
990 | for (unsigned i = 0; i < no_pids; i++) { | ||
991 | unsigned char *p; | ||
992 | unsigned int ava; | ||
993 | unsigned char buf[64000]; | ||
994 | struct stat s; | ||
995 | |||
996 | if (do_exit) { | ||
997 | fprintf(stderr, "Bye!\n"); | ||
998 | break; | ||
999 | } | ||
1000 | |||
1001 | fstat(sm[i], &s); | ||
1002 | if (s.st_size == 0) { | ||
1003 | fprintf(out, "size[%u](fd %d)=%ld\n", i, sm[i], s.st_size); | ||
1004 | continue; | ||
1005 | } | ||
1006 | |||
1007 | r = sem_wait(&shared[i]->sem1); | ||
1008 | if (r == -1) { | ||
1009 | fprintf(stderr, "Cannot wait for sem1: %m\n"); | ||
1010 | return 1; | ||
1011 | } | ||
1012 | |||
1013 | r = sem_post(&shared[i]->sem1); | ||
1014 | if (r == -1) { | ||
1015 | fprintf(stderr, "Cannot post sem1: %m\n"); | ||
1016 | return 1; | ||
1017 | } | ||
1018 | |||
1019 | // tail-1 points to last value available | ||
1020 | if (shared[i]->tail == shared[i]->head) | ||
1021 | continue; | ||
1022 | else if (shared[i]->head < shared[i]->tail) // 01h3t5 => ava = 2 | ||
1023 | ava = shared[i]->tail - shared[i]->head; | ||
1024 | else // 01t345h78 => ava = 2 + (9 - 6) = 5 | ||
1025 | ava = shared[i]->tail + (shared[i]->buf_size - shared[i]->head); | ||
1026 | |||
1027 | //fprintf(out, "RING[%u]: head=%u tail=%u new_tail=%u msgs_lost=%u [after lock]\n", | ||
1028 | // i, shared[i]->head, shared[i]->tail, shared[i]->new_tail, shared[i]->msgs_lost); | ||
1029 | |||
1030 | //char dump[ava * 4 + 1]; | ||
1031 | //bin2hex_ascii(dump, shared[i]->buf + shared[i]->head, ava); | ||
1032 | //fprintf(out, "DUMP0[%hu]: %s\n", ava, dump); | ||
1033 | |||
1034 | while (ava >= 2) { | ||
1035 | unsigned short plen; | ||
1036 | |||
1037 | // TODO: we may have a byte at the end and the other at the beginning! | ||
1038 | if (shared[i]->buf_size - shared[i]->head == 1) { // ...h size=4 h=3 => max=1 or ..h. max=2 | ||
1039 | // Split length! | ||
1040 | plen = shared[i]->buf[shared[i]->head] << 8; | ||
1041 | plen |= shared[i]->buf[0]; | ||
1042 | } else { | ||
1043 | memcpy(&plen, shared[i]->buf + shared[i]->head, sizeof(plen)); | ||
1044 | plen = be16toh(plen); | ||
1045 | } | ||
1046 | if (plen > ava) { | ||
1047 | fprintf(out, " Too short packet: plen=%hu > ava[%u]!\n", | ||
1048 | plen, ava); | ||
1049 | break; | ||
1050 | } | ||
1051 | |||
1052 | if (shared[i]->head + plen <= shared[i]->buf_size) { // dddt...hddd size=11, head=7, plen=4 => 10 <= 11 | ||
1053 | p = shared[i]->buf + shared[i]->head; | ||
1054 | } else { // split data! dddt...hddd size=11, head=7, plen=8 => max=4 | ||
1055 | unsigned int max = shared[i]->buf_size - shared[i]->head; | ||
1056 | if (max > plen) max = plen; | ||
1057 | //fprintf(out, " DEBUG: split data. max=%u\n", max); | ||
1058 | //fprintf(out, " DEBUG: copy to buf from %p+%u, %u bytes\n", shared[i]->buf, shared[i]->head, max); | ||
1059 | memcpy(buf, shared[i]->buf + shared[i]->head, max); | ||
1060 | //fprintf(out, " DEBUG: copy to buf+%u from %p, %u bytes\n", max, shared[i]->buf, plen - max); | ||
1061 | memcpy(buf + max, shared[i]->buf, plen - max); | ||
1062 | p = buf; | ||
1063 | } | ||
1064 | |||
1065 | if (0) { | ||
1066 | char dump[plen * 4 + 1]; | ||
1067 | bin2hex_ascii(dump, p, plen); | ||
1068 | fprintf(out, " DUMP[%hu] head=%u: %s\n", plen, shared[i]->head, dump); | ||
1069 | } | ||
1070 | |||
1071 | decode(p + 2, plen - 2); | ||
1072 | |||
1073 | shared[i]->head = (shared[i]->head + plen) % shared[i]->buf_size; | ||
1074 | ava -= plen; | ||
1075 | //fprintf(out, " DEBUG: ava[%u] after substracting plen[%hu]; no_pids=%u\n", ava, plen, no_pids); | ||
1076 | } | ||
1077 | } | ||
1078 | |||
1079 | if (do_exit) | ||
1080 | break; | ||
1081 | } | ||
1082 | // TODO: print some stats | ||
1083 | return 0; | ||
1084 | } | ||
1085 |
Date/time (UTC) | Type | Misc | Labels |
---|---|---|---|
2022-10-21 12:31 | build | alma-9-x86_64 | worker/r1 builder/color=fff worker_elap/30s wait_time/1s date/2022-10-21 time/12:29 |
2022-10-21 13:03 | build | fedora-35-aarch64 | worker/r1 builder/color=fff worker_elap/1330s wait_time/90s date/2022-10-21 time/12:29 |
2022-10-21 13:06 | build | fedora-35-x86_64 | worker/r1 builder/color=fff worker_elap/27s wait_time/2151s date/2022-10-21 time/12:29 |
2022-10-21 13:46 | build | fedora-rawhide-x86_64 | worker/r1 builder/color=fff worker_elap/53s wait_time/4486s date/2022-10-21 time/12:29 |
2022-10-22 02:44 | build | fedora-36-x86_64 | worker/r1 builder/color=fff worker_elap/41s wait_time/51226s date/2022-10-21 time/12:29 |